上传文件至 include/dispatch

This commit is contained in:
TY
2026-01-12 10:00:53 +08:00
parent 93969ee34b
commit ccf5cba672
5 changed files with 863 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
#ifndef AGV_MANAGER_BASE_H
#define AGV_MANAGER_BASE_H
#include "graph_map.h"
#include <unordered_map>
#include <vector>
#include <memory>
/**
* @brief AGV状态枚举
*/
enum class AGVState {
IDLE, // 空闲
ASSIGNED, // 已分配任务
MOVING, // 移动中
LOADING, // 装载中
UNLOADING, // 卸载中
CHARGING, // 充电中
ERROR, // 错误状态
MAINTENANCE // 维护中
};
/**
* @brief 任务状态枚举
*/
enum class TaskStatus {
PENDING, // 待处理
ASSIGNED, // 已分配
IN_PROGRESS, // 执行中
COMPLETED, // 已完成
FAILED // 失败
};
// 前向声明以解决循环依赖
struct Task;
struct AGV;
/**
* @brief AGV小车结构
*/
struct AGV {
int id;
std::string name;
AGVState state;
Point* current_position;
double x, y; // 坐标位置
double battery_level; // 电量百分比
double max_speed; // 最大速度
Task* current_task; // 当前任务
AGV()
: id(0), name(""), state(AGVState::IDLE), current_position(nullptr),
x(0), y(0), battery_level(100.0), max_speed(2.0), current_task(nullptr) {}
};
/**
* @brief 任务结构
*/
struct Task {
int id;
int priority;
Point* start_point;
Point* end_point;
std::string description;
TaskStatus status;
AGV* assigned_agv;
Task(int task_id, int prio, Point* start, Point* end, const std::string& desc)
: id(task_id), priority(prio), start_point(start), end_point(end),
description(desc), status(TaskStatus::PENDING), assigned_agv(nullptr) {}
};
/**
* @brief AGV基础管理器
* 提供AGV管理的基本功能供EnhancedAGVManager继承
*/
class AGVManagerBase {
protected:
GraphMap* map_;
std::unordered_map<int, AGV*> agvs_;
std::vector<std::unique_ptr<Task>> task_queue_;
std::unordered_map<int, std::vector<Path*>> agv_paths_;
public:
AGVManagerBase(GraphMap* map) : map_(map) {}
virtual ~AGVManagerBase() = default;
/**
* @brief 添加AGV到管理器
*/
virtual void addAGV(int id, double x, double y, const std::string& name = "");
/**
* @brief 移除AGV
*/
virtual void removeAGV(int id);
/**
* @brief 获取AGV
*/
AGV* getAGV(int id);
/**
* @brief 获取所有AGV
*/
std::vector<AGV*> getAllAGVs();
/**
* @brief 获取空闲AGV列表
*/
std::vector<AGV*> getIdleAGVs();
/**
* @brief 获取AGV数量
*/
size_t getAGVCount() const { return agvs_.size(); }
/**
* @brief 添加任务到队列
*/
virtual void addTask(int task_id, int start_point_id, int end_point_id,
const std::string& description, int priority = 1);
/**
* @brief 获取待处理任务
*/
std::vector<Task*> getPendingTasks();
/**
* @brief 为AGV设置路径
*/
void setAGVPath(int agv_id, const std::vector<Path*>& path);
/**
* @brief 获取AGV的当前路径
*/
std::vector<Path*> getAGVPath(int agv_id);
/**
* @brief 清除AGV路径
*/
void clearAGVPath(int agv_id);
/**
* @brief 任务分配基类实现简单的FIFO分配
*/
virtual int assignTasks();
/**
* @brief 打印AGV状态
*/
virtual void printAGVStatus();
/**
* @brief 打印任务队列状态
*/
virtual void printTaskQueue();
protected:
/**
* @brief 寻找路径使用GraphMap的A*算法)
*/
std::vector<Path*> findPath(AGV* agv, Task* task);
/**
* @brief 计算两点间距离
*/
double calculateDistance(AGV* agv, Task* task);
};
#endif // AGV_MANAGER_BASE_H