给效能评估模块各文件增加了注释
This commit is contained in:
parent
f5ee933d05
commit
28d6996c58
208
Program.cs
208
Program.cs
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using ActiveProtect.Simulation;
|
||||
using ActiveProtect.Models;
|
||||
using ActiveProtect.Utility;
|
||||
using System.Collections.Generic;
|
||||
using ActiveProtect.Evaluation;
|
||||
|
||||
namespace ActiveProtect
|
||||
@ -15,207 +10,10 @@ namespace ActiveProtect
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// 初始化坦克信息
|
||||
TankInfo tankinfo = new()
|
||||
{
|
||||
xp = 100,
|
||||
yp = 0,
|
||||
zp = 100
|
||||
};
|
||||
|
||||
// 创建仿真配置
|
||||
var config = new SimulationConfig
|
||||
{
|
||||
// 配置坦克
|
||||
TankConfigs = new List<TankProperties>
|
||||
{
|
||||
new(tankinfo)
|
||||
{
|
||||
Id = "Tank_1",
|
||||
InitialOrientation = new Orientation(Math.PI/4, 0, 0),
|
||||
InitialSpeed = 20,
|
||||
MaxSpeed = 25,
|
||||
MaxArmor = 100,
|
||||
InfraredRadiationIntensity = 150,
|
||||
RadarCrossSection = 10,
|
||||
MillimeterWaveRadiationTemperature = 100,
|
||||
HasLaserWarner = false,
|
||||
HasLaserJammer = true
|
||||
}
|
||||
},
|
||||
// 配置激光指示器
|
||||
LaserDesignatorConfig = new LaserDesignatorConfig
|
||||
{
|
||||
Id = "LD_1",
|
||||
InitialPosition = new Vector3D(2000, 150, 100),
|
||||
LaserPower = 1e6,
|
||||
LaserDivergenceAngle = 0.01
|
||||
},
|
||||
// 配置激光告警器
|
||||
LaserWarnerConfig = new LaserWarnerConfig
|
||||
{
|
||||
Id = "LW_1",
|
||||
AlarmDuration = 5.0
|
||||
},
|
||||
// 配置激光干扰器
|
||||
LaserJammerConfig = new LaserJammerConfig
|
||||
{
|
||||
Id = "LJ_1",
|
||||
MaxJammingCooldown = 5.0,
|
||||
MaxJammingPower = 10000.0,
|
||||
InitialJammingPower = 4000.0,
|
||||
PowerIncreaseRate = 2000.0
|
||||
},
|
||||
// 配置激光驾束仪
|
||||
LaserBeamRiderConfig = new LaserBeamRiderConfig
|
||||
{
|
||||
Id = "LBR_1",
|
||||
InitialPosition = new Vector3D(2000, 10, 100),
|
||||
LaserPower = 1000,
|
||||
ControlFieldDiameter = 6
|
||||
},
|
||||
// 配置导弹
|
||||
MissileConfigs = new List<MissileProperties>
|
||||
{
|
||||
// 激光半主动制导导弹配置
|
||||
new() {
|
||||
Id = "LSGM_1",
|
||||
InitialPosition = new Vector3D(2000, 100, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, -0.1, 0),
|
||||
InitialSpeed = 700,
|
||||
MaxSpeed = 800,
|
||||
MaxFlightTime = 10,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 400,
|
||||
ProportionalNavigationCoefficient = 4,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
Mass = 50,
|
||||
Type = MissileType.LaserSemiActiveGuidance
|
||||
},
|
||||
// 激光驾束制导导弹配置
|
||||
new() {
|
||||
Id = "LBRM_1",
|
||||
InitialPosition = new Vector3D(2000, 10, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0.0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 10,
|
||||
MaxFlightDistance = 3000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 400,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
Mass = 50,
|
||||
Type = MissileType.LaserBeamRiderGuidance
|
||||
},
|
||||
// 末敏弹配置
|
||||
new() {
|
||||
Id = "TSM_1",
|
||||
InitialPosition = new Vector3D(3000, 0, 100), // 发射位置
|
||||
InitialOrientation = new Orientation(Math.PI, 0, 0), // 使用计算得到的发射角度
|
||||
InitialSpeed = 800,
|
||||
MaxSpeed = 1000,
|
||||
MaxFlightTime = 30,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 0,
|
||||
MaxEngineBurnTime = 0,
|
||||
MaxAcceleration = 10,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
Mass = 50,
|
||||
Type = MissileType.TerminalSensitiveMissile
|
||||
},
|
||||
// 红外指令制导导弹配置
|
||||
new() {
|
||||
Id = "ICGM_1",
|
||||
InitialPosition = new Vector3D(2000, 10, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 60,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 100,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
Mass = 50,
|
||||
Type = MissileType.InfraredCommandGuidance
|
||||
},
|
||||
// 红外成像末制导导弹配置
|
||||
new() {
|
||||
Id = "ITGM_1",
|
||||
InitialPosition = new Vector3D(2000, 20, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 60,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 50,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
Mass = 50,
|
||||
Type = MissileType.InfraredImagingTerminalGuidance
|
||||
},
|
||||
// 毫米波导引头制导导弹配置
|
||||
new() {
|
||||
Id = "MMWG_1",
|
||||
InitialPosition = new Vector3D(2000, 200, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 60,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 50,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
Mass = 50,
|
||||
Type = MissileType.MillimeterWaveTerminalGuidance
|
||||
}
|
||||
},
|
||||
// 配置红外测角仪
|
||||
InfraredTrackerConfig = new InfraredTrackerConfig
|
||||
{
|
||||
Id = "IT_1",
|
||||
InitialPosition = new Vector3D(2000, 0, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0, 0),
|
||||
MaxTrackingRange = 10000, // 10公里
|
||||
FieldOfView = Math.PI / 4, // 45度
|
||||
AngleMeasurementAccuracy = 0.0005, // 0.0005弧度 (约0.029度)
|
||||
UpdateFrequency = 100 // 100赫兹
|
||||
},
|
||||
SimulationTimeStep = 0.01 // 仿真时间步长, 激光驾束制导导弹需要更小的步长,< 0.025s
|
||||
};
|
||||
|
||||
// 创建仿真管理器
|
||||
var simulationManager = new SimulationManager(config);
|
||||
|
||||
// 运行仿真
|
||||
int maxIterations = 10000;
|
||||
int iteration = 0;
|
||||
while (!simulationManager.IsSimulationEnded && iteration < maxIterations)
|
||||
{
|
||||
simulationManager.Update();
|
||||
simulationManager.PrintStatus();
|
||||
Thread.Sleep(20); // 暂停100毫秒,使输出更易读
|
||||
iteration++;
|
||||
}
|
||||
|
||||
Console.WriteLine("仿真结束");
|
||||
// 运行仿真示例
|
||||
//SimulationExample.RunAllExamples();
|
||||
|
||||
// 运行效能评估示例
|
||||
EvaluationExample.RunAllExamples();
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,22 +5,45 @@ using System.Linq;
|
||||
namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 层次分析法评估模型
|
||||
/// 适用于层次分明的指标体系
|
||||
/// 层次分析法(AHP)评估模型
|
||||
/// 适用于层次分明的指标体系,通过建立判断矩阵进行评估
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 特点:
|
||||
/// 1. 层次结构清晰
|
||||
/// 2. 考虑指标间的相对重要性
|
||||
/// 3. 结果具有较好的可解释性
|
||||
/// </remarks>
|
||||
public class AHPEvaluationModel : IEvaluationModel
|
||||
{
|
||||
private readonly float[,] judgmentMatrix; // 判断矩阵
|
||||
private readonly float[] weights; // 计算得到的权重
|
||||
/// <summary>
|
||||
/// 判断矩阵,用于表示指标间的相对重要性
|
||||
/// 矩阵元素a[i,j]表示指标i相对于指标j的重要程度
|
||||
/// </summary>
|
||||
private readonly float[,] judgmentMatrix;
|
||||
|
||||
/// <summary>
|
||||
/// 权重向量,由判断矩阵计算得到
|
||||
/// </summary>
|
||||
private readonly float[] weights;
|
||||
|
||||
public string ModelName => "层次分析法模型";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="judgmentMatrix">判断矩阵,必须是正互反矩阵</param>
|
||||
public AHPEvaluationModel(float[,] judgmentMatrix)
|
||||
{
|
||||
this.judgmentMatrix = judgmentMatrix;
|
||||
this.weights = CalculateWeights();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行AHP评估
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据字典</param>
|
||||
/// <returns>评估结果,范围在[0,1]之间</returns>
|
||||
public float Evaluate(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
float result = 0;
|
||||
@ -35,6 +58,11 @@ namespace ActiveProtect.Evaluation
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算权重向量
|
||||
/// 使用几何平均法计算特征向量作为权重
|
||||
/// </summary>
|
||||
/// <returns>归一化后的权重向量</returns>
|
||||
private float[] CalculateWeights()
|
||||
{
|
||||
int n = judgmentMatrix.GetLength(0);
|
||||
|
||||
@ -8,13 +8,28 @@ namespace ActiveProtect.Evaluation
|
||||
/// 贝叶斯网络评估模型
|
||||
/// 适用于具有不确定性和条件依赖关系的指标评估
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 特点:
|
||||
/// 1. 考虑指标间的概率依赖关系
|
||||
/// 2. 支持先验知识的引入
|
||||
/// 3. 可进行概率推理和预测
|
||||
/// </remarks>
|
||||
public class BayesianNetworkModel : IEvaluationModel
|
||||
{
|
||||
// 节点之间的条件概率表
|
||||
/// <summary>
|
||||
/// 条件概率表,表示节点间的条件依赖关系
|
||||
/// key为子节点,value为父节点及对应的条件概率
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, Dictionary<string, float>> conditionalProbabilities;
|
||||
// 先验概率
|
||||
|
||||
/// <summary>
|
||||
/// 先验概率,表示节点的初始概率分布
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, float> priorProbabilities;
|
||||
// 节点之间的依赖关系
|
||||
|
||||
/// <summary>
|
||||
/// 节点依赖关系,key为子节点,value为父节点列表
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, List<string>> dependencies;
|
||||
|
||||
public string ModelName => "贝叶斯网络模型";
|
||||
@ -22,7 +37,7 @@ namespace ActiveProtect.Evaluation
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="priorProbabilities">先验概率</param>
|
||||
/// <param name="priorProbabilities">先验概率字典</param>
|
||||
/// <param name="conditionalProbabilities">条件概率表</param>
|
||||
/// <param name="dependencies">节点依赖关系</param>
|
||||
public BayesianNetworkModel(
|
||||
@ -35,24 +50,29 @@ namespace ActiveProtect.Evaluation
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行贝叶斯网络评估
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据字典</param>
|
||||
/// <returns>评估结果,范围在[0,1]之间</returns>
|
||||
public float Evaluate(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
float result = 0;
|
||||
|
||||
// 对每个评估指标进行概率计算
|
||||
foreach (var node in evaluationData.Keys)
|
||||
{
|
||||
// 计算每个节点的后验概率
|
||||
float nodeProb = CalculateNodeProbability(node, evaluationData);
|
||||
result += nodeProb * evaluationData[node];
|
||||
}
|
||||
|
||||
// 归一化处理
|
||||
return result / evaluationData.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算节点的后验概率
|
||||
/// </summary>
|
||||
/// <param name="node">目标节点</param>
|
||||
/// <param name="evidence">观测数据</param>
|
||||
/// <returns>节点的后验概率</returns>
|
||||
private float CalculateNodeProbability(string node, Dictionary<string, float> evidence)
|
||||
{
|
||||
// 如果是根节点,直接返回先验概率
|
||||
@ -62,8 +82,6 @@ namespace ActiveProtect.Evaluation
|
||||
}
|
||||
|
||||
float probability = 1.0f;
|
||||
|
||||
// 获取父节点
|
||||
var parents = dependencies[node];
|
||||
|
||||
// 计算条件概率
|
||||
@ -83,8 +101,11 @@ namespace ActiveProtect.Evaluation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新条件概率表
|
||||
/// 更新条件概率
|
||||
/// </summary>
|
||||
/// <param name="node">子节点</param>
|
||||
/// <param name="parent">父节点</param>
|
||||
/// <param name="probability">新的条件概率值</param>
|
||||
public void UpdateConditionalProbability(string node, string parent, float probability)
|
||||
{
|
||||
if (!conditionalProbabilities.ContainsKey(node))
|
||||
@ -97,6 +118,8 @@ namespace ActiveProtect.Evaluation
|
||||
/// <summary>
|
||||
/// 添加新的依赖关系
|
||||
/// </summary>
|
||||
/// <param name="node">子节点</param>
|
||||
/// <param name="parent">父节点</param>
|
||||
public void AddDependency(string node, string parent)
|
||||
{
|
||||
if (!dependencies.ContainsKey(node))
|
||||
|
||||
@ -6,14 +6,29 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 直接赋权评估模型
|
||||
/// 最简单的评估方法,直接通过权重进行加权计算
|
||||
/// 通过直接指定权重进行加权计算的最基础评估方法
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 适用场景:
|
||||
/// 1. 评价指标较少(通常≤5个)
|
||||
/// 2. 各指标重要性差异明显
|
||||
/// 3. 有充分的专家经验支持
|
||||
/// 4. 需要快速得出评估结果
|
||||
/// </remarks>
|
||||
public class DirectWeightModel : IEvaluationModel
|
||||
{
|
||||
private readonly float[] weights; // 权重向量
|
||||
/// <summary>
|
||||
/// 权重向量,表示各个指标的相对重要性
|
||||
/// </summary>
|
||||
private readonly float[] weights;
|
||||
|
||||
public string ModelName => "直接赋权模型";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="weights">权重数组,必须满足非负性和归一性</param>
|
||||
/// <exception cref="ArgumentException">当权重无效时抛出异常</exception>
|
||||
public DirectWeightModel(float[] weights)
|
||||
{
|
||||
this.weights = weights;
|
||||
@ -24,6 +39,12 @@ namespace ActiveProtect.Evaluation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行评估计算
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
/// <returns>加权平均后的评估结果</returns>
|
||||
/// <exception cref="ArgumentException">当数据数量与权重数量不匹配时抛出异常</exception>
|
||||
public float Evaluate(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
if (evaluationData.Count != weights.Length)
|
||||
@ -46,6 +67,7 @@ namespace ActiveProtect.Evaluation
|
||||
/// <summary>
|
||||
/// 验证权重的有效性
|
||||
/// </summary>
|
||||
/// <returns>权重是否有效</returns>
|
||||
private bool ValidateWeights()
|
||||
{
|
||||
// 检查权重是否都为非负数
|
||||
|
||||
@ -5,7 +5,16 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 评估模型示例类
|
||||
/// 展示了各种评估模型的使用方法和效果
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 包含的示例:
|
||||
/// 1. 直接赋权模型
|
||||
/// 2. 模糊评价模型
|
||||
/// 3. AHP层次分析模型
|
||||
/// 4. 灰色关联分析模型
|
||||
/// 5. 贝叶斯网络模型
|
||||
/// </remarks>
|
||||
public class EvaluationExample
|
||||
{
|
||||
/// <summary>
|
||||
@ -16,34 +25,46 @@ namespace ActiveProtect.Evaluation
|
||||
// 准备评估数据
|
||||
Dictionary<string, float> evaluationData = new Dictionary<string, float>
|
||||
{
|
||||
{ "告警响应时间", 0.85f },
|
||||
{ "探测覆盖范围", 0.92f },
|
||||
{ "系统稳定性", 0.78f }
|
||||
{ "告警响应时间", 0.85f }, // 值越大表示响应越快
|
||||
{ "探测覆盖范围", 0.92f }, // 值越大表示覆盖范围越大
|
||||
{ "系统稳定性", 0.78f } // 值越大表示系统越稳定
|
||||
};
|
||||
|
||||
// 1. 模糊评价模型示例
|
||||
DemoFuzzyEvaluation(evaluationData);
|
||||
|
||||
// 2. AHP层次分析模型示例
|
||||
DemoAHPEvaluation(evaluationData);
|
||||
|
||||
// 3. 灰色关联分析模型示例
|
||||
DemoGreyRelationEvaluation(evaluationData);
|
||||
|
||||
// 4. 贝叶斯网络模型示例
|
||||
DemoBayesianEvaluation(evaluationData);
|
||||
|
||||
// 5. 直接赋权模型示例
|
||||
// 依次运行各个评估模型示例
|
||||
DemoDirectWeightEvaluation(evaluationData);
|
||||
DemoFuzzyEvaluation(evaluationData);
|
||||
DemoAHPEvaluation(evaluationData);
|
||||
DemoGreyRelationEvaluation(evaluationData);
|
||||
DemoBayesianEvaluation(evaluationData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接赋权模型示例
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
private static void DemoDirectWeightEvaluation(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
Console.WriteLine("\n=== 直接赋权模型示例 ===");
|
||||
|
||||
// 设置权重,权重之和必须为1
|
||||
float[] weights = new float[] { 0.4f, 0.3f, 0.3f };
|
||||
|
||||
var directModel = EvaluationModelFactory.CreateModel("direct",
|
||||
new object[] { weights });
|
||||
|
||||
float result = directModel.Evaluate(evaluationData);
|
||||
Console.WriteLine($"直接赋权评价结果: {result:F4}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模糊评价模型示例
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
private static void DemoFuzzyEvaluation(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
Console.WriteLine("\n=== 模糊评价模型示例 ===");
|
||||
|
||||
// 设置隶属度矩阵,每行和为1
|
||||
float[,] membershipMatrix = new float[3,3] {
|
||||
{0.5f, 0.3f, 0.2f}, // 告警响应时间的隶属度分布
|
||||
{0.4f, 0.4f, 0.2f}, // 探测覆盖范围的隶属度分布
|
||||
@ -61,14 +82,16 @@ namespace ActiveProtect.Evaluation
|
||||
/// <summary>
|
||||
/// AHP层次分析模型示例
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
private static void DemoAHPEvaluation(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
Console.WriteLine("\n=== AHP层次分析模型示例 ===");
|
||||
|
||||
// 设置判断矩阵,表示指标间的相对重要性
|
||||
float[,] judgmentMatrix = new float[3,3] {
|
||||
{1.0f, 2.0f, 3.0f},
|
||||
{0.5f, 1.0f, 2.0f},
|
||||
{0.33f, 0.5f, 1.0f}
|
||||
{1.0f, 2.0f, 3.0f}, // 告警响应时间相对于其他指标的重要性
|
||||
{0.5f, 1.0f, 2.0f}, // 探测覆盖范围相对于其他指标的重要性
|
||||
{0.33f, 0.5f, 1.0f} // 系统稳定性相对于其他指标的重要性
|
||||
};
|
||||
|
||||
var ahpModel = EvaluationModelFactory.CreateModel("ahp",
|
||||
@ -81,10 +104,12 @@ namespace ActiveProtect.Evaluation
|
||||
/// <summary>
|
||||
/// 灰色关联分析模型示例
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
private static void DemoGreyRelationEvaluation(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
Console.WriteLine("\n=== 灰色关联分析模型示例 ===");
|
||||
|
||||
// 设置参考序列,表示理想的指标值
|
||||
float[] referenceSequence = new float[] { 0.9f, 0.95f, 0.85f };
|
||||
|
||||
var greyModel = EvaluationModelFactory.CreateModel("grey",
|
||||
@ -97,10 +122,12 @@ namespace ActiveProtect.Evaluation
|
||||
/// <summary>
|
||||
/// 贝叶斯网络模型示例
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
private static void DemoBayesianEvaluation(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
Console.WriteLine("\n=== 贝叶斯网络模型示例 ===");
|
||||
|
||||
// 设置先验概率
|
||||
var priorProbabilities = new Dictionary<string, float>
|
||||
{
|
||||
{ "告警响应时间", 0.8f },
|
||||
@ -108,6 +135,7 @@ namespace ActiveProtect.Evaluation
|
||||
{ "系统稳定性", 0.9f }
|
||||
};
|
||||
|
||||
// 设置条件概率表
|
||||
var conditionalProbabilities = new Dictionary<string, Dictionary<string, float>>
|
||||
{
|
||||
{ "系统稳定性", new Dictionary<string, float>
|
||||
@ -118,6 +146,7 @@ namespace ActiveProtect.Evaluation
|
||||
}
|
||||
};
|
||||
|
||||
// 设置节点依赖关系
|
||||
var dependencies = new Dictionary<string, List<string>>
|
||||
{
|
||||
{ "系统稳定性", new List<string> { "告警响应时间", "探测覆盖范围" } }
|
||||
@ -129,22 +158,5 @@ namespace ActiveProtect.Evaluation
|
||||
float result = bayesianModel.Evaluate(evaluationData);
|
||||
Console.WriteLine($"贝叶斯网络评价结果: {result:F4}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接赋权模型示例
|
||||
/// </summary>
|
||||
private static void DemoDirectWeightEvaluation(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
Console.WriteLine("\n=== 直接赋权模型示例 ===");
|
||||
|
||||
// 设置权重
|
||||
float[] weights = new float[] { 0.4f, 0.3f, 0.3f };
|
||||
|
||||
var directModel = EvaluationModelFactory.CreateModel("direct",
|
||||
new object[] { weights });
|
||||
|
||||
float result = directModel.Evaluate(evaluationData);
|
||||
Console.WriteLine($"直接赋权评价结果: {result:F4}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,40 +5,55 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 评估模型工厂类
|
||||
/// 用于创建和管理不同的评估模型
|
||||
/// 用于创建和管理不同类型的评估模型
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 支持的模型类型:
|
||||
/// - direct: 直接赋权模型
|
||||
/// - fuzzy: 模糊评价模型
|
||||
/// - ahp: 层次分析模型
|
||||
/// - grey: 灰色关联分析模型
|
||||
/// - bayesian: 贝叶斯网络模型
|
||||
/// </remarks>
|
||||
public class EvaluationModelFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建评估模型实例
|
||||
/// </summary>
|
||||
/// <param name="modelType">模型类型名称</param>
|
||||
/// <param name="parameters">模型参数数组</param>
|
||||
/// <returns>评估模型实例</returns>
|
||||
/// <exception cref="ArgumentException">当模型类型不支持时抛出异常</exception>
|
||||
public static IEvaluationModel CreateModel(string modelType, object[] parameters)
|
||||
{
|
||||
switch (modelType.ToLower())
|
||||
{
|
||||
case "fuzzy":
|
||||
return new FuzzyEvaluationModel(
|
||||
(float[,])parameters[0],
|
||||
(float[])parameters[1]
|
||||
(float[,])parameters[0], // 隶属度矩阵
|
||||
(float[])parameters[1] // 权重向量
|
||||
);
|
||||
|
||||
case "ahp":
|
||||
return new AHPEvaluationModel(
|
||||
(float[,])parameters[0]
|
||||
(float[,])parameters[0] // 判断矩阵
|
||||
);
|
||||
|
||||
case "grey":
|
||||
return new GreyRelationModel(
|
||||
(float[])parameters[0]
|
||||
(float[])parameters[0] // 参考序列
|
||||
);
|
||||
|
||||
case "bayesian":
|
||||
return new BayesianNetworkModel(
|
||||
(Dictionary<string, float>)parameters[0],
|
||||
(Dictionary<string, Dictionary<string, float>>)parameters[1],
|
||||
(Dictionary<string, List<string>>)parameters[2]
|
||||
(Dictionary<string, float>)parameters[0], // 先验概率
|
||||
(Dictionary<string, Dictionary<string, float>>)parameters[1], // 条件概率表
|
||||
(Dictionary<string, List<string>>)parameters[2] // 依赖关系
|
||||
);
|
||||
|
||||
case "direct":
|
||||
return new DirectWeightModel(
|
||||
(float[])parameters[0]
|
||||
(float[])parameters[0] // 权重向量
|
||||
);
|
||||
|
||||
default:
|
||||
|
||||
@ -6,15 +6,36 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 模糊评价模型
|
||||
/// 适用于不确定性强的指标评估
|
||||
/// 适用于不确定性强的指标评估,通过隶属度矩阵进行综合评价
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 特点:
|
||||
/// 1. 能够处理模糊性和不确定性
|
||||
/// 2. 支持多指标综合评价
|
||||
/// 3. 通过隶属度函数量化定性指标
|
||||
/// </remarks>
|
||||
public class FuzzyEvaluationModel : IEvaluationModel
|
||||
{
|
||||
private readonly float[,] membershipMatrix; // 隶属度矩阵,每一行表示一个指标对不同评价等级的隶属度分布
|
||||
private readonly float[] weights; // 权重向量,表示各个指标的权重
|
||||
/// <summary>
|
||||
/// 隶属度矩阵,每一行表示一个指标对不同评价等级的隶属度分布
|
||||
/// 矩阵元素必须在[0,1]区间内,且每行元素之和为1
|
||||
/// </summary>
|
||||
private readonly float[,] membershipMatrix;
|
||||
|
||||
/// <summary>
|
||||
/// 权重向量,表示各个指标的相对重要性
|
||||
/// 权重必须为非负数且和为1
|
||||
/// </summary>
|
||||
private readonly float[] weights;
|
||||
|
||||
public string ModelName => "模糊评价模型";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="membershipMatrix">隶属度矩阵</param>
|
||||
/// <param name="weights">权重向量</param>
|
||||
/// <exception cref="ArgumentException">当隶属度矩阵无效时抛出异常</exception>
|
||||
public FuzzyEvaluationModel(float[,] membershipMatrix, float[] weights)
|
||||
{
|
||||
this.membershipMatrix = membershipMatrix;
|
||||
@ -22,10 +43,15 @@ namespace ActiveProtect.Evaluation
|
||||
|
||||
if (!ValidateMembershipMatrix())
|
||||
{
|
||||
throw new ArgumentException("隶属度矩阵无效");
|
||||
throw new ArgumentException("隶属度矩阵无效:矩阵元素必须在[0,1]区间内,且每行元素之和为1");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行模糊综合评价
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据字典</param>
|
||||
/// <returns>评估结果,范围在[0,1]之间</returns>
|
||||
public float Evaluate(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
int factorCount = evaluationData.Count; // 评价因素个数
|
||||
@ -38,6 +64,7 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
for (int j = 0; j < gradeCount; j++)
|
||||
{
|
||||
// 计算每个指标对每个评价等级的隶属度
|
||||
fuzzyMatrix[i, j] = membershipMatrix[i, j] * data.Value;
|
||||
}
|
||||
i++;
|
||||
@ -63,13 +90,19 @@ namespace ActiveProtect.Evaluation
|
||||
finalResult += result[i] * (i * gradeStep);
|
||||
}
|
||||
|
||||
// 归一化处理
|
||||
// 归一化处理,确保结果在[0,1]区间内
|
||||
return finalResult / result.Sum();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证隶属度矩阵的有效性
|
||||
/// </summary>
|
||||
/// <returns>矩阵是否有效</returns>
|
||||
/// <remarks>
|
||||
/// 验证规则:
|
||||
/// 1. 所有元素必须在[0,1]区间内
|
||||
/// 2. 每行元素之和必须为1(允许小误差)
|
||||
/// </remarks>
|
||||
private bool ValidateMembershipMatrix()
|
||||
{
|
||||
int rows = membershipMatrix.GetLength(0);
|
||||
|
||||
@ -6,20 +6,42 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 灰色关联分析模型
|
||||
/// 适用于数据不完整的情况
|
||||
/// 适用于数据不完整的情况,通过计算评估指标与参考序列的关联度进行评估
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 特点:
|
||||
/// 1. 适应不完整信息
|
||||
/// 2. 计算简单直观
|
||||
/// 3. 能反映系统发展趋势
|
||||
/// </remarks>
|
||||
public class GreyRelationModel : IEvaluationModel
|
||||
{
|
||||
private readonly float[] referenceSequence; // 参考数列
|
||||
private readonly float resolution = 0.5f; // 分辨系数
|
||||
/// <summary>
|
||||
/// 参考数列,表示理想的评估指标值
|
||||
/// </summary>
|
||||
private readonly float[] referenceSequence;
|
||||
|
||||
/// <summary>
|
||||
/// 分辨系数,通常取0.5
|
||||
/// </summary>
|
||||
private readonly float resolution = 0.5f;
|
||||
|
||||
public string ModelName => "灰色关联分析模型";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="referenceSequence">参考数列,表示最优或理想的指标值序列</param>
|
||||
public GreyRelationModel(float[] referenceSequence)
|
||||
{
|
||||
this.referenceSequence = referenceSequence;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行灰色关联分析评估
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据字典</param>
|
||||
/// <returns>关联度,范围在[0,1]之间,值越大表示与参考序列越接近</returns>
|
||||
public float Evaluate(Dictionary<string, float> evaluationData)
|
||||
{
|
||||
float[] compareSequence = evaluationData.Values.ToArray();
|
||||
@ -34,10 +56,16 @@ namespace ActiveProtect.Evaluation
|
||||
);
|
||||
}
|
||||
|
||||
// 计算关联度
|
||||
// 计算平均关联度
|
||||
return correlationCoefficients.Average();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算两个值之间的关联系数
|
||||
/// </summary>
|
||||
/// <param name="refValue">参考值</param>
|
||||
/// <param name="compValue">比较值</param>
|
||||
/// <returns>关联系数</returns>
|
||||
private float CalculateCorrelationCoefficient(float refValue, float compValue)
|
||||
{
|
||||
float delta = Math.Abs(refValue - compValue);
|
||||
|
||||
@ -5,14 +5,15 @@ namespace ActiveProtect.Evaluation
|
||||
{
|
||||
/// <summary>
|
||||
/// 评估模型接口
|
||||
/// 定义了所有评估模型必须实现的基本功能
|
||||
/// </summary>
|
||||
public interface IEvaluationModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行评估
|
||||
/// </summary>
|
||||
/// <param name="evaluationData">评估数据</param>
|
||||
/// <returns>评估结果</returns>
|
||||
/// <param name="evaluationData">评估数据字典,键为指标名称,值为指标值</param>
|
||||
/// <returns>评估结果,范围在[0,1]之间,值越大表示评估结果越好</returns>
|
||||
float Evaluate(Dictionary<string, float> evaluationData);
|
||||
|
||||
/// <summary>
|
||||
|
||||
222
src/Simulation/SimulationExample.cs
Normal file
222
src/Simulation/SimulationExample.cs
Normal file
@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using ActiveProtect.Models;
|
||||
using ActiveProtect.Utility;
|
||||
|
||||
namespace ActiveProtect.Simulation
|
||||
{
|
||||
/// <summary>
|
||||
/// 仿真示例类
|
||||
/// </summary>
|
||||
public class SimulationExample
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行所有仿真示例
|
||||
/// </summary>
|
||||
public static void RunAllExamples()
|
||||
{
|
||||
// 初始化坦克信息
|
||||
TankInfo tankinfo = new()
|
||||
{
|
||||
xp = 100,
|
||||
yp = 0,
|
||||
zp = 100
|
||||
};
|
||||
|
||||
// 创建仿真配置
|
||||
var config = new SimulationConfig
|
||||
{
|
||||
// 配置坦克
|
||||
TankConfigs = new List<TankProperties>
|
||||
{
|
||||
new(tankinfo)
|
||||
{
|
||||
Id = "Tank_1",
|
||||
InitialOrientation = new Orientation(Math.PI/4, 0, 0),
|
||||
InitialSpeed = 20,
|
||||
MaxSpeed = 25,
|
||||
MaxArmor = 100,
|
||||
InfraredRadiationIntensity = 150,
|
||||
RadarCrossSection = 10,
|
||||
MillimeterWaveRadiationTemperature = 100,
|
||||
HasLaserWarner = false,
|
||||
HasLaserJammer = true
|
||||
}
|
||||
},
|
||||
// 配置激光指示器
|
||||
LaserDesignatorConfig = new LaserDesignatorConfig
|
||||
{
|
||||
Id = "LD_1",
|
||||
InitialPosition = new Vector3D(2000, 150, 100),
|
||||
LaserPower = 1e6,
|
||||
LaserDivergenceAngle = 0.01
|
||||
},
|
||||
// 配置激光告警器
|
||||
LaserWarnerConfig = new LaserWarnerConfig
|
||||
{
|
||||
Id = "LW_1",
|
||||
AlarmDuration = 5.0
|
||||
},
|
||||
// 配置激光干扰器
|
||||
LaserJammerConfig = new LaserJammerConfig
|
||||
{
|
||||
Id = "LJ_1",
|
||||
MaxJammingCooldown = 5.0,
|
||||
MaxJammingPower = 10000.0,
|
||||
InitialJammingPower = 4000.0,
|
||||
PowerIncreaseRate = 2000.0
|
||||
},
|
||||
// 配置激光驾束仪
|
||||
LaserBeamRiderConfig = new LaserBeamRiderConfig
|
||||
{
|
||||
Id = "LBR_1",
|
||||
InitialPosition = new Vector3D(2000, 10, 100),
|
||||
LaserPower = 1000,
|
||||
ControlFieldDiameter = 6
|
||||
},
|
||||
// 配置导弹
|
||||
MissileConfigs = new List<MissileProperties>
|
||||
{
|
||||
// 激光半主动制导导弹配置
|
||||
new() {
|
||||
Id = "LSGM_1",
|
||||
InitialPosition = new Vector3D(2000, 100, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, -0.1, 0),
|
||||
InitialSpeed = 700,
|
||||
MaxSpeed = 800,
|
||||
MaxFlightTime = 10,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 400,
|
||||
ProportionalNavigationCoefficient = 4,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
Mass = 50,
|
||||
Type = MissileType.LaserSemiActiveGuidance
|
||||
},
|
||||
// 激光驾束制导导弹配置
|
||||
new() {
|
||||
Id = "LBRM_1",
|
||||
InitialPosition = new Vector3D(2000, 10, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0.0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 10,
|
||||
MaxFlightDistance = 3000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 400,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
Mass = 50,
|
||||
Type = MissileType.LaserBeamRiderGuidance
|
||||
},
|
||||
// 末敏弹配置
|
||||
new() {
|
||||
Id = "TSM_1",
|
||||
InitialPosition = new Vector3D(3000, 0, 100), // 发射位置
|
||||
InitialOrientation = new Orientation(Math.PI, 0, 0), // 使用计算得到的发射角度
|
||||
InitialSpeed = 800,
|
||||
MaxSpeed = 1000,
|
||||
MaxFlightTime = 30,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 0,
|
||||
MaxEngineBurnTime = 0,
|
||||
MaxAcceleration = 10,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
Mass = 50,
|
||||
Type = MissileType.TerminalSensitiveMissile
|
||||
},
|
||||
// 红外指令制导导弹配置
|
||||
new() {
|
||||
Id = "ICGM_1",
|
||||
InitialPosition = new Vector3D(2000, 10, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 60,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 100,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
Mass = 50,
|
||||
Type = MissileType.InfraredCommandGuidance
|
||||
},
|
||||
// 红外成像末制导导弹配置
|
||||
new() {
|
||||
Id = "ITGM_1",
|
||||
InitialPosition = new Vector3D(2000, 20, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 60,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 50,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
Mass = 50,
|
||||
Type = MissileType.InfraredImagingTerminalGuidance
|
||||
},
|
||||
// 毫米波导引头制导导弹配置
|
||||
new() {
|
||||
Id = "MMWG_1",
|
||||
InitialPosition = new Vector3D(2000, 200, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0.0, 0),
|
||||
InitialSpeed = 300,
|
||||
MaxSpeed = 400,
|
||||
MaxFlightTime = 60,
|
||||
MaxFlightDistance = 5000,
|
||||
LaunchAcceleration = 50,
|
||||
MaxEngineBurnTime = 10,
|
||||
MaxAcceleration = 50,
|
||||
ExplosionRadius = 5,
|
||||
HitProbability = 0.9,
|
||||
ProportionalNavigationCoefficient = 3,
|
||||
Mass = 50,
|
||||
Type = MissileType.MillimeterWaveTerminalGuidance
|
||||
}
|
||||
},
|
||||
// 配置红外测角仪
|
||||
InfraredTrackerConfig = new InfraredTrackerConfig
|
||||
{
|
||||
Id = "IT_1",
|
||||
InitialPosition = new Vector3D(2000, 0, 100),
|
||||
InitialOrientation = new Orientation(Math.PI, 0, 0),
|
||||
MaxTrackingRange = 10000, // 10公里
|
||||
FieldOfView = Math.PI / 4, // 45度
|
||||
AngleMeasurementAccuracy = 0.0005, // 0.0005弧度 (约0.029度)
|
||||
UpdateFrequency = 100 // 100赫兹
|
||||
},
|
||||
SimulationTimeStep = 0.01 // 仿真时间步长, 激光驾束制导导弹需要更小的步长,< 0.025s
|
||||
};
|
||||
|
||||
// 创建仿真管理器
|
||||
var simulationManager = new SimulationManager(config);
|
||||
|
||||
// 运行仿真
|
||||
int maxIterations = 10000;
|
||||
int iteration = 0;
|
||||
while (!simulationManager.IsSimulationEnded && iteration < maxIterations)
|
||||
{
|
||||
simulationManager.Update();
|
||||
simulationManager.PrintStatus();
|
||||
Thread.Sleep(20); // 暂停100毫秒,使输出更易读
|
||||
iteration++;
|
||||
}
|
||||
|
||||
Console.WriteLine("仿真结束");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -239,7 +239,7 @@ namespace ActiveProtect.Simulation
|
||||
private void ActivateSomeElements()
|
||||
{
|
||||
// 激活坦克
|
||||
//Elements.FindAll(e => e.Id == "Tank_1").ForEach(e => e.Activate());
|
||||
Elements.FindAll(e => e.Id == "Tank_1").ForEach(e => e.Activate());
|
||||
|
||||
// 激活激光告警器
|
||||
//Elements.FindAll(e => e.Id == "LW_1").ForEach(e => e.Activate());
|
||||
@ -269,7 +269,7 @@ namespace ActiveProtect.Simulation
|
||||
//Elements.FindAll(e => e.Id == "MMWG_1").ForEach(e => e.Activate());
|
||||
|
||||
// 激活末敏弹
|
||||
//Elements.FindAll(e => e.Id == "TSM_1").ForEach(e => e.Activate());
|
||||
Elements.FindAll(e => e.Id == "TSM_1").ForEach(e => e.Activate());
|
||||
|
||||
// 激活毫米波干扰器
|
||||
//Elements.FindAll(e => e.Id == "MMWJ_1").ForEach(e => e.Activate());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user