task_plan_2/include/core/plan.hpp

136 lines
4.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef BATTLEFIELD_CORE_PLAN_HPP
#define BATTLEFIELD_CORE_PLAN_HPP
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdint>
#include <nlohmann/json.hpp>
namespace battlefield {
/// @brief 子任务关系图谱节点,对应 T_PLAN_SUBTASK
struct PlanSubTask {
std::string id; ///< 子任务ID
std::string parentId; ///< 父任务ID空为根任务
std::string name; ///< 子任务名称
std::string description; ///< 描述
int32_t orderIndex{0}; ///< 执行顺序
std::string assignedUnit; ///< 执行单元
double estimatedDuration{0.0}; ///< 预估时间(分钟)
int32_t resourceCost{0}; ///< 资源消耗
};
/// @brief 作战方案主数据结构,对应 T_PLAN
struct Plan {
std::string id; ///< 方案ID
std::string name; ///< 方案名称
std::string description; ///< 方案描述
std::vector<PlanSubTask> subTasks; ///< 子任务列表
double score{0.0}; ///< 方案评分
/// @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;
}
};
/// @brief 方案对比结果
struct PlanComparison {
Plan planA;
Plan planB;
std::vector<std::string> differences; ///< 差异描述列表
};
/// @brief 方案管理模块SU-04覆盖 SRS-F-05-001 ~ SRS-F-05-004
class PlanManager {
public:
/// @brief 创建新方案SRS-F-05-001 集中式方案管理)
/// @param name 方案名称
/// @param description 方案描述
/// @return 创建的 Plan 对象
Plan CreatePlan(const std::string& name, const std::string& description);
/// @brief 获取所有方案列表
std::vector<Plan> GetPlanList() const;
/// @brief 获取单个方案
/// @param planId 方案ID
/// @return 方案对象(不存在则返回空)
Plan GetPlan(const std::string& planId) const;
/// @brief 加权评分排序SRS-F-05-001 偏好排序)
/// @param ascending 是否升序
void SortPlansByScore(bool ascending = false);
/// @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
/// @param planIdA 方案A的ID
/// @param planIdB 方案B的ID
/// @return 对比结果
PlanComparison ComparePlanDetails(const std::string& planIdA,
const std::string& planIdB) const;
/// @brief 简化版对比(保持向后兼容)
std::string ComparePlans(const std::string& planIdA, const std::string& planIdB);
/// @brief 重组方案调整子任务SRS-F-05-003
/// @param planId 方案ID
/// @param newSubTasks 新的子任务列表
/// @return 是否成功重组
bool ReorganizePlan(const std::string& planId,
const std::vector<PlanSubTask>& newSubTasks);
/// @brief 合并多个方案SRS-F-05-004 分布式方案融合)
/// @param planIds 待融合的方案ID列表
/// @return 融合后的新方案
Plan MergePlans(const std::vector<std::string>& planIds);
/// @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(); }
private:
std::map<std::string, Plan> plans_; ///< 方案存储
size_t planCounter_{0}; ///< 方案计数
};
} // namespace battlefield
#endif // BATTLEFIELD_CORE_PLAN_HPP