2022-06-11 19:05:06 +08:00
|
|
|
|
//
|
|
|
|
|
// Created by ricardo on 2022/6/10.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef AUTO_BUS_GUI_BUS_MODEL_H
|
|
|
|
|
#define AUTO_BUS_GUI_BUS_MODEL_H
|
|
|
|
|
|
|
|
|
|
#include "railsModel.h"
|
|
|
|
|
#include "queryModel.h"
|
|
|
|
|
#include "define.h"
|
|
|
|
|
|
2022-06-17 11:25:02 +08:00
|
|
|
|
#include "cstdio"
|
2022-06-11 19:05:06 +08:00
|
|
|
|
#include "string"
|
|
|
|
|
#include "sstream"
|
|
|
|
|
|
|
|
|
|
class BusControllerModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* 指向公交车所在站点的指针
|
|
|
|
|
*/
|
|
|
|
|
rail_node_t *rail_pos;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前行进的距离
|
|
|
|
|
*/
|
|
|
|
|
int distance;
|
|
|
|
|
|
2022-06-17 11:25:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 当前前进的方向
|
|
|
|
|
*/
|
|
|
|
|
int direction;
|
|
|
|
|
|
2022-06-11 19:05:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* 轨道对象
|
|
|
|
|
*/
|
|
|
|
|
RailsModel *rail_manager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 请求控制对象
|
|
|
|
|
*/
|
|
|
|
|
QueryModel *query_manager;
|
|
|
|
|
|
2022-06-17 11:25:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 选定的策略
|
|
|
|
|
*/
|
|
|
|
|
int chosen_strategy = -1;
|
|
|
|
|
|
2022-06-11 19:05:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* 构造函数
|
2022-06-17 11:25:02 +08:00
|
|
|
|
*
|
2022-06-11 19:05:06 +08:00
|
|
|
|
*/
|
2022-06-17 11:25:02 +08:00
|
|
|
|
BusControllerModel();
|
2022-06-11 19:05:06 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 析构函数
|
|
|
|
|
*/
|
|
|
|
|
~BusControllerModel();
|
|
|
|
|
|
|
|
|
|
std::string PrintState();
|
2022-06-17 11:25:02 +08:00
|
|
|
|
bool JudgeOnStation();
|
2022-06-11 19:05:06 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int GetBusPosition() const;
|
2022-06-17 11:25:02 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取指定的配置文件
|
|
|
|
|
* @param file_name 提供的配置文件路径
|
|
|
|
|
*/
|
|
|
|
|
void ReadConfigFile(const std::string& file_name);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 给出在指定的方向下,指定的请求于公交车当前位置的距离
|
|
|
|
|
* @param query 指定的请求
|
|
|
|
|
* @param orientation 指定的方向 BUS_CLOCK_WISE BUS_COUNTER_CLOCK_WISE
|
|
|
|
|
* @return 距离
|
|
|
|
|
*/
|
|
|
|
|
int GetQueryDistance(bus_query_t *query, int orientation) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在先来先服务策略下应该前进的方向
|
|
|
|
|
* @return 前进的方向
|
|
|
|
|
*/
|
|
|
|
|
int FCFSDirection() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在先来先服务策略下给出处理的请求
|
|
|
|
|
* @return 需要处理的请求
|
|
|
|
|
*/
|
|
|
|
|
bus_query_t *FCFSQuery() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获得在SSTF策略下应该处理的请求
|
|
|
|
|
* @return 指向需要处理的请求的指针
|
|
|
|
|
*/
|
|
|
|
|
bus_query_t *SSTFGetQuery();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据指定的请求获得前进的方向,也就是前往指定的请求最近的方向
|
|
|
|
|
* 在SSTF策略中使用
|
|
|
|
|
* @param query 指定完成的请求
|
|
|
|
|
* @return 前进的方向
|
|
|
|
|
*/
|
|
|
|
|
int SSTFDirection(bus_query_t* query);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在当前站上可以顺便服务的请求
|
|
|
|
|
* @return 服务的请求指针
|
|
|
|
|
*/
|
|
|
|
|
bus_query_t *SSTFBTWQuery();
|
2022-06-11 19:05:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif //AUTO_BUS_GUI_BUS_MODEL_H
|