完善了README文件
重写了获得公交车位置的函数
This commit is contained in:
parent
79c3318faa
commit
a9c1d2dbf8
23
README.md
23
README.md
|
@ -1,8 +1,8 @@
|
|||
# Auto Bus GUI
|
||||
|
||||
北京邮电大学计算机学院2021级《计算导论与程序设计》实践大作业的GUI分支。
|
||||
北京邮电大学计算机学院2021级《计算导论与程序设计》实践大作业“公交车调度”的GUI分支。
|
||||
|
||||
## 项目构建
|
||||
## 构建
|
||||
|
||||
### 构建环境
|
||||
|
||||
|
@ -26,5 +26,24 @@ cmake .. -G "Visual Studio 17 2022"
|
|||
>
|
||||
> 现代VS已经支持用`cmake`管理`C/C++`项目
|
||||
|
||||
## 使用
|
||||
|
||||

|
||||
|
||||
### 主界面
|
||||
|
||||
主界面由四个部分组成,分别是最上方的菜单栏,左侧的动画区,右侧的控制面板,下方的日志输出。
|
||||
|
||||
### 使用
|
||||
|
||||
首先使用`File-Read ConfigFile`读取一个配置文件,在读取结束后动画区会显示公交车与公交站台,在控制面板的上方会显示当前选择的策略种类。
|
||||
|
||||
使用`Run-Run Bus`和`Run-Stop Bus`控制公交的启动和停止。在开始运行之后,在日志输出区会打印当前的状态。
|
||||
|
||||
在控制面板的下方可以查看当前存在的请求与添加请求。
|
||||
|
||||

|
||||
|
||||
### 策略上的补充说明
|
||||
|
||||
由于GUI的性质,所有的请求都是立即调度的,不同于OJ版的等待一个clock结束之后在进行调度。
|
||||
|
|
|
@ -16,11 +16,29 @@ class BusStrategyBase : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* 轨道模型
|
||||
*/
|
||||
RailsModel *rails_model;
|
||||
|
||||
/**
|
||||
* 请求模型
|
||||
*/
|
||||
QueryModel *query_model;
|
||||
|
||||
/**
|
||||
* 公交车模型
|
||||
*/
|
||||
BusModel *bus_model;
|
||||
|
||||
/**
|
||||
* 当前的计时时刻
|
||||
*/
|
||||
int bus_tick;
|
||||
|
||||
/**
|
||||
* 当前的处理策略
|
||||
*/
|
||||
int strategy;
|
||||
|
||||
BusStrategyBase();
|
||||
|
@ -94,8 +112,14 @@ public slots:
|
|||
*/
|
||||
void OneTickSlot(int remaining_time);
|
||||
|
||||
/**
|
||||
* 获得公交车前进方向的槽函数
|
||||
*/
|
||||
void GetBusDirectionSlot();
|
||||
|
||||
/**
|
||||
* 处理到站事件的槽函数
|
||||
*/
|
||||
void OnStopSlot();
|
||||
|
||||
private:
|
||||
|
@ -110,9 +134,14 @@ private:
|
|||
*/
|
||||
QString PrintState(int remaining_time) const;
|
||||
|
||||
|
||||
/**
|
||||
* 设置各种连接
|
||||
*/
|
||||
void SetConnection() const;
|
||||
|
||||
/**
|
||||
* 处理请求
|
||||
*/
|
||||
void HandleQuery();
|
||||
};
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
class BusModel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* 公交车当前所在的站点
|
||||
*/
|
||||
rail_node_t *rail_pos;
|
||||
|
||||
/**
|
||||
|
@ -46,6 +49,11 @@ public:
|
|||
*/
|
||||
void ResetBus(rail_node_t *head);
|
||||
|
||||
/**
|
||||
* 获得公交车当前所在位置
|
||||
* @param remaining_time 行驶计时器剩下的时间
|
||||
* @return 到起点的距离
|
||||
*/
|
||||
double GetBusPosition(int remaining_time);
|
||||
|
||||
/**
|
||||
|
|
BIN
md_pic/main.png
Normal file
BIN
md_pic/main.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
md_pic/running.png
Normal file
BIN
md_pic/running.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
|
@ -29,6 +29,7 @@ void BusModel::ResetBus(rail_node_t *head)
|
|||
double BusModel::GetBusPosition(int remaining_time)
|
||||
{
|
||||
double result = 0;
|
||||
double length = 0;
|
||||
rail_node_t *now_pos = rail_pos;
|
||||
rail_node_t *node = rail_head;
|
||||
|
||||
|
@ -39,23 +40,43 @@ double BusModel::GetBusPosition(int remaining_time)
|
|||
node = node->next_node;
|
||||
} while (node != now_pos);
|
||||
|
||||
// 如果就在起始点,距离为0
|
||||
if(now_pos == rail_head)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
// 获得可能存在的偏移量
|
||||
if(remaining_time > 0)
|
||||
{
|
||||
if(direction == BUS_CLOCK_WISE)
|
||||
{
|
||||
double length = now_pos->next_node_distance - (double)remaining_time / 1000.0 * velocity;
|
||||
result = result + length;
|
||||
length = now_pos->next_node_distance - (double)remaining_time / 1000.0 * velocity;
|
||||
}
|
||||
else if(direction == BUS_COUNTER_CLOCK_WISE)
|
||||
{
|
||||
double length = now_pos->last_node_distance - (double)remaining_time / 1000.0 * velocity;
|
||||
result = result - length;
|
||||
length = now_pos->last_node_distance - (double)remaining_time / 1000.0 * velocity;
|
||||
length = -length;
|
||||
}
|
||||
}
|
||||
|
||||
if(now_pos == rail_head)
|
||||
{
|
||||
// 在起点
|
||||
if(length >= 0)
|
||||
{
|
||||
result = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result + length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 在其他点
|
||||
if(now_pos == rail_head->last_node and length == -rail_head->last_node_distance)
|
||||
{
|
||||
// 恰好即将回到出发点的情况
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result + length;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,26 @@ void CentralWidget::DeleteQueryList()
|
|||
|
||||
void CentralWidget::AppendQueryItemSlot(int query_type, int node_id)
|
||||
{
|
||||
// 判断是否存在相同的请求
|
||||
// 如果存在就不再添加
|
||||
bool is_exist = false;
|
||||
auto first_item = query_items.begin();
|
||||
first_item++;
|
||||
|
||||
for(auto itor = first_item; itor != query_items.end(); ++itor)
|
||||
{
|
||||
if((*itor)->query_type == query_type and (*itor)->target_node_id == node_id)
|
||||
{
|
||||
is_exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_exist)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QueryListItem *item = new QueryListItem(query_type, node_id);
|
||||
|
||||
query_items.push_back(item);
|
||||
|
|
Loading…
Reference in New Issue
Block a user