2026-05-25 08:25:48 +00:00
|
|
|
|
#ifndef BATTLEFIELD_CORE_PLAN_HPP
|
|
|
|
|
|
#define BATTLEFIELD_CORE_PLAN_HPP
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <map>
|
2026-05-26 05:33:17 +00:00
|
|
|
|
#include <set>
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
2026-05-25 08:25:48 +00:00
|
|
|
|
|
|
|
|
|
|
namespace battlefield {
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 子任务关系图谱节点,对应 T_PLAN_SUBTASK
|
|
|
|
|
|
struct PlanSubTask {
|
|
|
|
|
|
std::string id; ///< 子任务ID
|
2026-05-26 05:33:17 +00:00
|
|
|
|
std::string parentId; ///< 父任务ID(空为根任务)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
std::string name; ///< 子任务名称
|
|
|
|
|
|
std::string description; ///< 描述
|
|
|
|
|
|
int32_t orderIndex{0}; ///< 执行顺序
|
|
|
|
|
|
std::string assignedUnit; ///< 执行单元
|
2026-05-26 05:33:17 +00:00
|
|
|
|
double estimatedDuration{0.0}; ///< 预估时间(分钟)
|
|
|
|
|
|
int32_t resourceCost{0}; ///< 资源消耗
|
2026-05-25 08:25:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 作战方案主数据结构,对应 T_PLAN
|
|
|
|
|
|
struct Plan {
|
|
|
|
|
|
std::string id; ///< 方案ID
|
|
|
|
|
|
std::string name; ///< 方案名称
|
|
|
|
|
|
std::string description; ///< 方案描述
|
|
|
|
|
|
std::vector<PlanSubTask> subTasks; ///< 子任务列表
|
|
|
|
|
|
double score{0.0}; ///< 方案评分
|
2026-05-26 05:33:17 +00:00
|
|
|
|
|
|
|
|
|
|
/// @brief 计算子任务数(递归包含子任务树)
|
|
|
|
|
|
size_t SubTaskCount() const { return subTasks.size(); }
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 计算总预估时间
|
|
|
|
|
|
double TotalEstimatedDuration() const {
|
|
|
|
|
|
double total = 0.0;
|
|
|
|
|
|
for (const auto& st : subTasks) total += st.estimatedDuration;
|
|
|
|
|
|
return total;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 计算总资源消耗
|
|
|
|
|
|
int32_t TotalResourceCost() const {
|
|
|
|
|
|
int32_t total = 0;
|
|
|
|
|
|
for (const auto& st : subTasks) total += st.resourceCost;
|
|
|
|
|
|
return total;
|
|
|
|
|
|
}
|
2026-05-25 08:25:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 方案对比结果
|
|
|
|
|
|
struct PlanComparison {
|
|
|
|
|
|
Plan planA;
|
|
|
|
|
|
Plan planB;
|
|
|
|
|
|
std::vector<std::string> differences; ///< 差异描述列表
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 方案管理模块(SU-04,覆盖 SRS-F-05-001 ~ SRS-F-05-004)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
class PlanManager {
|
|
|
|
|
|
public:
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 创建新方案(SRS-F-05-001 集中式方案管理)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param name 方案名称
|
|
|
|
|
|
/// @param description 方案描述
|
|
|
|
|
|
/// @return 创建的 Plan 对象
|
|
|
|
|
|
Plan CreatePlan(const std::string& name, const std::string& description);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 获取所有方案列表
|
|
|
|
|
|
std::vector<Plan> GetPlanList() const;
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 获取单个方案
|
|
|
|
|
|
/// @param planId 方案ID
|
|
|
|
|
|
/// @return 方案对象(不存在则返回空)
|
|
|
|
|
|
Plan GetPlan(const std::string& planId) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 加权评分排序(SRS-F-05-001 偏好排序)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param ascending 是否升序
|
|
|
|
|
|
void SortPlansByScore(bool ascending = false);
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 按名称排序
|
|
|
|
|
|
void SortPlansByName(bool ascending = true);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 按子任务数量排序
|
|
|
|
|
|
void SortPlansBySubTaskCount(bool ascending = false);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 按总预估时间排序
|
|
|
|
|
|
void SortPlansByDuration(bool ascending = true);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 重新计算所有方案评分(加权算法)
|
|
|
|
|
|
void RecalculateAllScores();
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 计算单个方案评分(加权算法:资源效率、时间效率、复杂度等)
|
|
|
|
|
|
double CalculatePlanScore(const Plan& plan) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 方案详情对比(SRS-F-05-002)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param planIdA 方案A的ID
|
|
|
|
|
|
/// @param planIdB 方案B的ID
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @return 对比结果
|
|
|
|
|
|
PlanComparison ComparePlanDetails(const std::string& planIdA,
|
|
|
|
|
|
const std::string& planIdB) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 简化版对比(保持向后兼容)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
std::string ComparePlans(const std::string& planIdA, const std::string& planIdB);
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 重组方案(调整子任务,SRS-F-05-003)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param planId 方案ID
|
|
|
|
|
|
/// @param newSubTasks 新的子任务列表
|
|
|
|
|
|
/// @return 是否成功重组
|
2026-05-26 05:33:17 +00:00
|
|
|
|
bool ReorganizePlan(const std::string& planId,
|
|
|
|
|
|
const std::vector<PlanSubTask>& newSubTasks);
|
2026-05-25 08:25:48 +00:00
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 合并多个方案(SRS-F-05-004 分布式方案融合)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param planIds 待融合的方案ID列表
|
|
|
|
|
|
/// @return 融合后的新方案
|
|
|
|
|
|
Plan MergePlans(const std::vector<std::string>& planIds);
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 向方案添加子任务
|
|
|
|
|
|
bool AddSubTask(const std::string& planId, const PlanSubTask& subTask);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 移除方案中的子任务
|
|
|
|
|
|
bool RemoveSubTask(const std::string& planId, const std::string& subTaskId);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 获取方案的子任务拓扑排序(BFS)
|
|
|
|
|
|
std::vector<PlanSubTask> GetTopologicalOrder(const std::string& planId) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 获取方案总数
|
|
|
|
|
|
size_t GetPlanCount() const { return plans_.size(); }
|
|
|
|
|
|
|
2026-05-25 08:25:48 +00:00
|
|
|
|
private:
|
2026-05-26 05:33:17 +00:00
|
|
|
|
std::map<std::string, Plan> plans_; ///< 方案存储
|
|
|
|
|
|
size_t planCounter_{0}; ///< 方案计数
|
2026-05-25 08:25:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace battlefield
|
|
|
|
|
|
|
|
|
|
|
|
#endif // BATTLEFIELD_CORE_PLAN_HPP
|