From 9aeddde25c1cb2a54ef5196ba2667fd6e661f3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9A?= <1486806484@qq.com> Date: Wed, 28 Jun 2023 09:22:56 +0800 Subject: [PATCH] update --- src/林火预测/pixel.cpp | 19 +++ src/林火预测/pixel.h | 29 ++++ .../风速补正综合指标法/model.cpp | 149 ++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 src/林火预测/pixel.cpp create mode 100644 src/林火预测/pixel.h create mode 100644 src/林火预测/风速补正综合指标法/model.cpp diff --git a/src/林火预测/pixel.cpp b/src/林火预测/pixel.cpp new file mode 100644 index 0000000..20440aa --- /dev/null +++ b/src/林火预测/pixel.cpp @@ -0,0 +1,19 @@ +#include "pixel.h" +#include + +using namespace std; + +int main() { + // ʵͼռ + PixelRatioConverter p(5, 10, 100, 200); + + // ȡرϵ + double ratio = p.getPixelRatio(); + cout << "رϵ" << ratio << endl; + + // һͼռ + int next_pixel_area = p.getNextPixelArea(15); + cout << "һͼռ" << next_pixel_area << endl; + + return 0; +} \ No newline at end of file diff --git a/src/林火预测/pixel.h b/src/林火预测/pixel.h new file mode 100644 index 0000000..5a590a6 --- /dev/null +++ b/src/林火预测/pixel.h @@ -0,0 +1,29 @@ +class PixelRatioConverter { +public: + // 캯ʵеͼռ + PixelRatioConverter(double real_area1, double real_area2, int pixel_area1, int pixel_area2) { + this->real_area1 = real_area1; + this->real_area2 = real_area2; + this->pixel_area1 = pixel_area1; + this->pixel_area2 = pixel_area2; + } + + // ȡرϵ + double getPixelRatio() { + double ratio = (real_area1 / real_area2) * (pixel_area2 / pixel_area1); + return ratio; // رϵ + } + + // رϵһͼռ + int getNextPixelArea(int next_real_area) { + double ratio = this->getPixelRatio(); + int next_pixel_area = static_cast(next_real_area / ratio); + return next_pixel_area; // һͼռ + } + +private: + double real_area1; // һʵе + double real_area2; // ڶʵе + int pixel_area1; // һͼռ + int pixel_area2; // ڶͼռ +}; diff --git a/src/林火预测/风速补正综合指标法/model.cpp b/src/林火预测/风速补正综合指标法/model.cpp new file mode 100644 index 0000000..1d8191f --- /dev/null +++ b/src/林火预测/风速补正综合指标法/model.cpp @@ -0,0 +1,149 @@ +#include +#include + +using namespace std; + +class ForestFireModel { +private: + int rows; // ɭֵͼ + int cols; // ɭֵͼ + double ignitionProbability; // ȼ + double burningProbability; // Ӹ + double** forestMap; // ɭֵͼ + +public: + ForestFireModel(int rows, int cols, double ignitionProbability, double burningProbability) { + this->rows = rows; + this->cols = cols; + this->ignitionProbability = ignitionProbability; + this->burningProbability = burningProbability; + + // ʼɭֵͼ + forestMap = new double* [rows]; + for (int i = 0; i < rows; i++) { + forestMap[i] = new double[cols]; + for (int j = 0; j < cols; j++) { + forestMap[i][j] = (double)rand() / (RAND_MAX); + } + } + } + + // ģɢ + void simulate(int steps) { + for (int t = 0; t < steps; t++) { + double** nextMap = new double* [rows]; + for (int i = 0; i < rows; i++) { + nextMap[i] = new double[cols]; + for (int j = 0; j < cols; j++) { + bool isBurning = false; + bool isIgnited = (double)rand() / (RAND_MAX) < ignitionProbability; + if (isIgnited || forestMap[i][j] > 0) { + // ȼǰλѾŻжΧǷлɢ + for (int k = -1; k <= 1; k++) { + for (int l = -1; l <= 1; l++) { + if (k == 0 && l == 0) { + continue; + } + int ii = i + k; + int jj = j + l; + if (ii < 0 || ii >= rows || jj < 0 || jj >= cols) { + continue; + } + if (forestMap[ii][jj] > 0) { + // Χл𣬵ǰλҲŻ + isBurning = true; + } + else if ((double)rand() / (RAND_MAX) < burningProbability) { + // ͨʾǰλǷŻ + isBurning = true; + } + } + } + } + nextMap[i][j] = isBurning ? 1 : (isIgnited ? 0.5 : forestMap[i][j]); + } + } + // ɭֵͼ + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + forestMap[i][j] = nextMap[i][j]; + } + delete[] nextMap[i]; + } + delete[] nextMap; + } + } + + // ָλõĻٶ + double spreadSpeed(int x, int y) { + double speed = 0; + if (forestMap[x][y] == 0) { + return speed; + } + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + double distance = sqrt(pow(x - i, 2) + pow(y - j, 2)); + if (forestMap[i][j] > 0 && distance > 0) { + speed += forestMap[i][j] / distance; + } + } + } + return speed; + } + + // 㵱ǰΧİ뾶 + double fireRadius() { + double radius = 0; + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + if (forestMap[i][j] >= 1) { + double distance = sqrt(pow(i - rows / 2, 2) + pow(j - cols / 2, 2)); + radius = max(radius, distance); + } + } + } + return radius; + } + + // ɭֵͼ + void printMap() { + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + if (forestMap[i][j] >= 1) { + cout << "* "; + } + else if (forestMap[i][j] > 0) { + cout << "o "; + } + else { + cout << ". "; + } + } + cout << endl; + } + } + + ~ForestFireModel() { + for (int i = 0; i < rows; i++) { + delete[] forestMap[i]; + } + delete[] forestMap; + } +}; + +int main() { + srand(time(0)); + + // ģһ5x5ɭ֣ȼΪ0.2ӸΪ0.8ģ100 + ForestFireModel model(5, 5, 0.2, 0.8); + model.simulate(100); + model.printMap(); + + // ָλõĻٶ + cout << "Spread speed at position (2, 3): " << model.spreadSpeed(2, 3) << endl; + + // 㵱ǰΧİ뾶 + cout << "Fire radius: " << model.fireRadius() << endl; + + return 0; +}