完善了README文件

重写了获得公交车位置的函数
This commit is contained in:
jackfiled 2022-06-29 16:47:19 +08:00
parent 79c3318faa
commit a9c1d2dbf8
7 changed files with 110 additions and 13 deletions

View File

@ -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++`项目
## 使用
![主界面截图](md_pic/main.png)
### 主界面
主界面由四个部分组成,分别是最上方的菜单栏,左侧的动画区,右侧的控制面板,下方的日志输出。
### 使用
首先使用`File-Read ConfigFile`读取一个配置文件,在读取结束后动画区会显示公交车与公交站台,在控制面板的上方会显示当前选择的策略种类。
使用`Run-Run Bus`和`Run-Stop Bus`控制公交的启动和停止。在开始运行之后,在日志输出区会打印当前的状态。
在控制面板的下方可以查看当前存在的请求与添加请求。
![运行时截图](md_pic/running.png)
### 策略上的补充说明
由于GUI的性质所有的请求都是立即调度的不同于OJ版的等待一个clock结束之后在进行调度。

View File

@ -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();
};

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
md_pic/running.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -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;
}
}

View File

@ -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);