增添湿度、温度指标进行预测

songhaibo_branch
1 year ago
parent 6441ef9490
commit 457cac305b

@ -0,0 +1,152 @@
#include <math.h>
#include <iostream>
#include "levelToSpeed.h"
using namespace std;
#define M_PI acos(-1)
class ForestFirePrediction {
public:
// 构造函数
ForestFirePrediction(int wind_direction, double wind_level, double slope, double altitude, int cover_type, double fire_size, double temperature, double waterlevel) {
this->wind_direction = wind_direction;
this->wind_level = wind_level;
this->slope = slope;
this->altitude = altitude;
this->cover_type = cover_type;
this->fire_size = fire_size;
this->temperature = temperature;
this->waterlevel = waterlevel;
}
// 计算受阻距离单位km
double get_distance() {
double rad_slope = slope * M_PI / 180.0; // 将坡度转化为弧度
double distance = sin(rad_slope) * altitude / 1000.0; // 计算受阻距离
return distance;
}
// 预测火灾蔓延范围
void predict_range() {
double impact_factor; // 植被类型影响系数
double correction_coef; // 风速补正系数
double distance; // 受阻距离
double composite_index; // 综合指数
// 根据植被类型获取影响系数
switch (cover_type) {
case 1: // 针叶林
impact_factor = 0.7;
break;
case 2: // 落叶林
impact_factor = 0.5;
break;
case 3: // 灌木林
impact_factor = 0.4;
break;
default:
cout << "植被类型输入错误!" << endl;
return;
}
// 计算风速补正系数
int angle = abs(wind_direction - 180); // 计算风向与火灾扩散方向之间的夹角
if (angle <= 45 || angle >= 315) { // 如果夹角较小,则不需要进行风速补正
correction_coef = 1;
}
else {
correction_coef = 0.65 + 0.35 * cos((angle - 45) * M_PI / 270.0); // 使用公式计算风速补正系数
}
// 计算受阻距离
distance = get_distance();
// 计算综合指数
composite_index = correction_coef * (1 + distance) * impact_factor;
// 计算火灾蔓延半径
double radius = sqrt(fire_size * 1000000 * composite_index) / M_PI;
double range = radius * pow(10, 1.5 * levelToSpeed(wind_level) / 30.0);
// 输出预测结果
cout << "火灾蔓延范围预测结果:" << endl;
cout << "火源最可能在" << radius << "米范围内发生。" << endl;
cout << "在风速为 " << wind_level << "级风的情况下,火源最可能的蔓延范围为 " << range << " 米。" << endl;
}
// 预测火灾蔓延速度
void predict_speed(int level) {
double slope_factor; // 坡度影响因子
double speed_factor; // 风速影响因子
double size_factor; // 火源面积影响因子
// 计算坡度影响因子
if (slope > 0) {
slope_factor = pow(3.33, sqrt(slope));
}
else {
slope_factor = 1;
}
// 计算风速影响因子
double wind_speed = levelToSpeed(wind_level);
speed_factor = 5.15 * pow(wind_speed, 0.39) + 0.299 * temperature + 0.009 * (100 - waterlevel) - 0.304;
// 计算火源面积影响因子
size_factor = pow(fire_size, 0.77);
// 计算火灾蔓延速度
double speed = 0.348 * sqrt(size_factor * slope_factor * speed_factor);
// 输出预测结果
cout << "火灾蔓延速度预测结果:" << endl;
cout << "火灾蔓延速度可能为" << speed << "km/h。" << endl;
}
private:
int wind_direction; // 风向(单位:度)
double wind_level; // 风力等级
double slope; // 坡度(单位:度)
double altitude; // 海拔高度单位m
int cover_type; // 植被类型1针叶林2落叶林3灌木林
double fire_size; // 火源面积(单位:平方米)
double temperature; // 温度(单位:摄氏度)
double waterlevel; // 湿度(单位:%
};
int main() {
// 读取参数
int wind_direction;
int wind_level;
double slope;
double altitude;
int cover_type;
double fire_size;
double temperature;
double waterlevel;
cout << "请输入风向0-360度" << endl;
cin >> wind_direction;
cout << "请输入风力等级(级):" << endl;
cin >> wind_level;
cout << "请输入坡度(度):" << endl;
cin >> slope;
cout << "请输入海拔高度m" << endl;
cin >> altitude;
cout << "请输入植被类型1针叶林2落叶林3灌木林" << endl;
cin >> cover_type;
cout << "请输入火源面积m^2" << endl;
cin >> fire_size;
cout << "请输入当天气温°C" << endl;
cin >> temperature;
cout << "请输入当天湿度(%" << endl;
cin >> waterlevel;
// 预测火灾蔓延范围和速度
ForestFirePrediction ffp(wind_direction, wind_level, slope, altitude, cover_type, fire_size, temperature, waterlevel);
ffp.predict_range();
ffp.predict_speed(wind_level);
return 0;
}

@ -0,0 +1,62 @@
#include<iostream>
using namespace std;
double levelToSpeed(int level) {
double speed = 0;
if (level >= 0 && level <= 12) {
double speed = 0;
switch (level) {
case 1:
speed = 0.3;
break;
case 2:
speed = 1.6;
break;
case 3:
speed = 3.4;
break;
case 4:
speed = 5.5;
break;
case 5:
speed = 8.0;
break;
case 6:
speed = 10.8;
break;
case 7:
speed = 13.9;
break;
case 8:
speed = 17.2;
break;
case 9:
speed = 20.8;
break;
case 10:
speed = 24.5;
break;
case 11:
speed = 28.5;
break;
case 12:
speed = 32.7;
break;
}
}
else if (level == 13) {
speed = 35.8;
}
else if (level == 14) {
speed = 41.5;
}
else if (level == 15) {
speed = 48.2;
}
else {
cout << "无效的风力等级!" << endl;
}
return speed;
}
Loading…
Cancel
Save