Files
RCS-3000/include/dispatch/rl/state_encoder.h

124 lines
3.1 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 STATE_ENCODER_H
#define STATE_ENCODER_H
#include "dispatch/graph_map.h"
#include <vector>
#include <memory>
// 前向声明
class ResourceManager;
class AGV;
/**
* @brief 任务结构体 (简化版)
*/
struct Task {
int id;
int start_point_id;
int end_point_id;
int priority;
double deadline;
double time_remaining;
};
/**
* @brief 状态编码器
*
* 将C++对象编码为DQN可用的状态向量
*/
class StateEncoder {
public:
StateEncoder(GraphMap* map, ResourceManager* rm);
// ========== 路径规划状态编码 (35维) ==========
/**
* @brief 编码路径规划状态
*
* 状态组成 (35维):
* - 任务信息 (3维): 起点(x,y)、终点(x)
* - AGV状态 (4维): 位置(x,y)、速度、电量
* - 候选路径特征 (20维): 5条路径 × 4特征
* - 全局拥堵 (4维): 各区域占用AGV数
* - 时间信息 (2维): 当前时段、历史拥堵预测
* - 紧急度 (2维): 任务优先级、剩余时间
*/
std::vector<float> encodePathPlanningState(
AGV* agv,
Task* task,
const std::vector<std::vector<Path*>>& candidates
);
/**
* @brief 编码单条路径特征
*/
std::vector<float> encodeSinglePathFeatures(
const std::vector<Path*>& path
);
// ========== 任务分配状态编码 (~85维) ==========
/**
* @brief 编码任务分配状态
*
* 状态组成 (~85维):
* - 任务特征 (8维): 起终点坐标、距离、优先级、截止时间、类型
* - 可用AGV池 (50维): 10辆AGV × 5特征
* - 全局状态 (7维): 等待任务数、执行中任务数等
* - 资源状态 (20维): 关键路径占用情况
* - 时间特征 (2维): 时段、历史成功率
*/
std::vector<float> encodeDispatchState(
Task* task,
const std::vector<AGV*>& available_agvs
);
/**
* @brief 编码单个AGV特征
*/
std::vector<float> encodeSingleAGVFeatures(
AGV* agv,
Point* task_start
);
// ========== 工具函数 ==========
/**
* @brief 归一化到[0, 1]
*/
static float normalize(float value, float min, float max) {
if (max - min < 1e-6f) return 0.5f;
return (value - min) / (max - min);
}
/**
* @brief 裁剪到[0, 1]
*/
static float clip(float value) {
return std::max(0.0f, std::min(1.0f, value));
}
private:
GraphMap* map_;
ResourceManager* resource_manager_;
// 地图边界
float map_min_x_, map_max_x_;
float map_min_y_, map_max_y_;
float max_path_length_;
/**
* @brief 初始化地图边界
*/
void initializeMapBounds();
/**
* @brief 计算区域拥堵情况
*/
std::vector<int> calculateZoneOccupancy(int num_zones = 4);
/**
* @brief 计算路径平滑度
*/
float calculatePathSmoothness(const std::vector<Path*>& path);
};
#endif // STATE_ENCODER_H