获得方向与处理请求两个槽函数完成
This commit is contained in:
parent
04d6ab09ee
commit
c9b7908e4c
|
@ -68,7 +68,16 @@ public:
|
||||||
*/
|
*/
|
||||||
~BusControllerModel();
|
~BusControllerModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印当前状态
|
||||||
|
* @return 状态的字符串
|
||||||
|
*/
|
||||||
std::string PrintState();
|
std::string PrintState();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断公交车是否到站
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
bool JudgeOnStation();
|
bool JudgeOnStation();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -85,6 +94,22 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void AddQuerySlot(int query_type, int node_id) const;
|
void AddQuerySlot(int query_type, int node_id) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除上下车请求的槽函数
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
void DeleteQuerySlot(bus_query_t *query) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得公交车应该前进方向的槽函数
|
||||||
|
*/
|
||||||
|
void GetBusDirectionSlot();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理公交车可以处理请求的槽函数
|
||||||
|
*/
|
||||||
|
void HandleQuerySlot();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* 创建轨道链表完成的信号
|
* 创建轨道链表完成的信号
|
||||||
|
@ -93,9 +118,10 @@ signals:
|
||||||
void RailsCreated(int node_num);
|
void RailsCreated(int node_num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求发生修改的槽函数
|
* 删除指定请求的信号
|
||||||
|
* @param query 需要删除的请求
|
||||||
*/
|
*/
|
||||||
void QueryChangedSignal();
|
void DeleteQuerySignal(bus_query_t *query);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -104,6 +130,10 @@ private:
|
||||||
*/
|
*/
|
||||||
int total_distance = 10;
|
int total_distance = 10;
|
||||||
|
|
||||||
|
bus_query_t *target_query;
|
||||||
|
|
||||||
|
void SetConnection() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得公交车当前所在的位置
|
* 获得公交车当前所在的位置
|
||||||
* @return 公交车当前所在的位置
|
* @return 公交车当前所在的位置
|
||||||
|
@ -145,10 +175,9 @@ private:
|
||||||
/**
|
/**
|
||||||
* 根据指定的请求获得前进的方向,也就是前往指定的请求最近的方向
|
* 根据指定的请求获得前进的方向,也就是前往指定的请求最近的方向
|
||||||
* 在SSTF策略中使用
|
* 在SSTF策略中使用
|
||||||
* @param query 指定完成的请求
|
|
||||||
* @return 前进的方向
|
* @return 前进的方向
|
||||||
*/
|
*/
|
||||||
int SSTFDirection(bus_query_t* query);
|
int SSTFDirection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在当前站上可以顺便服务的请求
|
* 在当前站上可以顺便服务的请求
|
||||||
|
@ -168,7 +197,7 @@ private:
|
||||||
* @param query 指定完成的请求
|
* @param query 指定完成的请求
|
||||||
* @return 前进的方向
|
* @return 前进的方向
|
||||||
*/
|
*/
|
||||||
int SCANDirection(bus_query_t *query);
|
int SCANDirection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在当前站上可以顺便服务的请求
|
* 在当前站上可以顺便服务的请求
|
||||||
|
|
119
src/busModel.cpp
119
src/busModel.cpp
|
@ -13,9 +13,12 @@ BusControllerModel::BusControllerModel()
|
||||||
rail_pos = rail_manager->rails;
|
rail_pos = rail_manager->rails;
|
||||||
distance = 0;
|
distance = 0;
|
||||||
direction = BUS_STOP;
|
direction = BUS_STOP;
|
||||||
|
target_query = nullptr;
|
||||||
|
|
||||||
// 设置初始时间
|
// 设置初始时间
|
||||||
bus_time = 0;
|
bus_time = 0;
|
||||||
|
|
||||||
|
SetConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
BusControllerModel::~BusControllerModel()
|
BusControllerModel::~BusControllerModel()
|
||||||
|
@ -24,6 +27,12 @@ BusControllerModel::~BusControllerModel()
|
||||||
delete(query_manager);
|
delete(query_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BusControllerModel::SetConnection() const
|
||||||
|
{
|
||||||
|
QObject::connect(this, &BusControllerModel::DeleteQuerySignal,
|
||||||
|
this, &BusControllerModel::DeleteQuerySlot);
|
||||||
|
}
|
||||||
|
|
||||||
void BusControllerModel::ReadConfigFileSlot(const QString& file_name)
|
void BusControllerModel::ReadConfigFileSlot(const QString& file_name)
|
||||||
{
|
{
|
||||||
ReadConfigFile(file_name.toStdString());
|
ReadConfigFile(file_name.toStdString());
|
||||||
|
@ -35,6 +44,102 @@ void BusControllerModel::AddQuerySlot(int query_type, int node_id) const
|
||||||
query_manager->CreateQuery(query_type, node_pos);
|
query_manager->CreateQuery(query_type, node_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BusControllerModel::DeleteQuerySlot(bus_query_t *query) const
|
||||||
|
{
|
||||||
|
query_manager->DeleteQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BusControllerModel::GetBusDirectionSlot()
|
||||||
|
{
|
||||||
|
switch (chosen_strategy)
|
||||||
|
{
|
||||||
|
case BUS_FCFS:
|
||||||
|
direction = FCFSDirection();
|
||||||
|
break;
|
||||||
|
case BUS_SSTF:
|
||||||
|
if(target_query == nullptr)
|
||||||
|
{
|
||||||
|
target_query = SSTFGetQuery();
|
||||||
|
}
|
||||||
|
direction = SSTFDirection();
|
||||||
|
case BUS_SCAN:
|
||||||
|
if(target_query == nullptr)
|
||||||
|
{
|
||||||
|
target_query = SCANGetQuery();
|
||||||
|
}
|
||||||
|
direction = SCANDirection();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BusControllerModel::HandleQuerySlot()
|
||||||
|
{
|
||||||
|
bus_query_t *finished_query;
|
||||||
|
|
||||||
|
switch (chosen_strategy)
|
||||||
|
{
|
||||||
|
case BUS_FCFS:
|
||||||
|
finished_query = FCFSQuery();
|
||||||
|
while (finished_query != nullptr)
|
||||||
|
{
|
||||||
|
emit DeleteQuerySignal(finished_query);
|
||||||
|
finished_query = FCFSQuery();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BUS_SSTF:
|
||||||
|
if(target_query == nullptr)
|
||||||
|
{
|
||||||
|
// 这里可能需要处理一下新生成的请求可以处理的情况
|
||||||
|
}
|
||||||
|
else if(target_query->node == rail_pos)
|
||||||
|
{
|
||||||
|
// 到达目标站点
|
||||||
|
while (target_query != nullptr and target_query->node == rail_pos)
|
||||||
|
{
|
||||||
|
emit DeleteQuerySignal(target_query);
|
||||||
|
target_query = SSTFGetQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 顺便处理请求
|
||||||
|
finished_query = SSTFBTWQuery();
|
||||||
|
while (finished_query != nullptr)
|
||||||
|
{
|
||||||
|
emit DeleteQuerySignal(finished_query);
|
||||||
|
finished_query = SSTFBTWQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BUS_SCAN:
|
||||||
|
if(target_query == nullptr)
|
||||||
|
{
|
||||||
|
// 这里可能需要处理一下新生成的请求可以处理的情况
|
||||||
|
}
|
||||||
|
else if(target_query->node == rail_pos)
|
||||||
|
{
|
||||||
|
// 到达目标站点
|
||||||
|
while (target_query != nullptr and target_query->node == rail_pos)
|
||||||
|
{
|
||||||
|
emit DeleteQuerySignal(target_query);
|
||||||
|
target_query = SCANGetQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 顺便处理
|
||||||
|
finished_query = SCANBTWQuery();
|
||||||
|
while (finished_query != nullptr)
|
||||||
|
{
|
||||||
|
emit DeleteQuerySignal(finished_query);
|
||||||
|
finished_query = SCANBTWQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 以下函数的实现移植自auto_pilot_bus
|
* 以下函数的实现移植自auto_pilot_bus
|
||||||
* 源程序采用C写成
|
* 源程序采用C写成
|
||||||
|
@ -416,14 +521,14 @@ bus_query_t *BusControllerModel::SSTFGetQuery()
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BusControllerModel::SSTFDirection(bus_query_t *query)
|
int BusControllerModel::SSTFDirection()
|
||||||
{
|
{
|
||||||
if (query == nullptr)
|
if (target_query == nullptr)
|
||||||
{
|
{
|
||||||
return BUS_STOP;
|
return BUS_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = GetQueryDistance(query, BUS_CLOCK_WISE);
|
int length = GetQueryDistance(target_query, BUS_CLOCK_WISE);
|
||||||
if(length > total_distance / 2)
|
if(length > total_distance / 2)
|
||||||
{
|
{
|
||||||
return BUS_COUNTER_CLOCK_WISE;
|
return BUS_COUNTER_CLOCK_WISE;
|
||||||
|
@ -530,16 +635,16 @@ bus_query_t *BusControllerModel::SCANGetQuery()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int BusControllerModel::SCANDirection(bus_query_t *query)
|
int BusControllerModel::SCANDirection()
|
||||||
{
|
{
|
||||||
if(query == nullptr)
|
if(target_query == nullptr)
|
||||||
{
|
{
|
||||||
return BUS_STOP;
|
return BUS_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(direction == BUS_STOP)
|
if(direction == BUS_STOP)
|
||||||
{
|
{
|
||||||
int length = GetQueryDistance(query, BUS_CLOCK_WISE);
|
int length = GetQueryDistance(target_query, BUS_CLOCK_WISE);
|
||||||
if(length > total_distance / 2)
|
if(length > total_distance / 2)
|
||||||
{
|
{
|
||||||
return BUS_COUNTER_CLOCK_WISE;
|
return BUS_COUNTER_CLOCK_WISE;
|
||||||
|
@ -551,7 +656,7 @@ int BusControllerModel::SCANDirection(bus_query_t *query)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int length = GetQueryDistance(query, direction);
|
int length = GetQueryDistance(target_query, direction);
|
||||||
if(length > total_distance / 2)
|
if(length > total_distance / 2)
|
||||||
{
|
{
|
||||||
if(direction == BUS_CLOCK_WISE)
|
if(direction == BUS_CLOCK_WISE)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user