From 77a3426981ed5f8a176bd1575fddf91ca9602983 Mon Sep 17 00:00:00 2001 From: Yerolling <2911328695@qq.com> Date: Fri, 27 May 2022 21:24:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86FCFSDirectoin?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller.c | 49 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/controller.c b/src/controller.c index 1189744..2b05d6d 100644 --- a/src/controller.c +++ b/src/controller.c @@ -8,13 +8,48 @@ int chosen_strategy = -1; int FCFSDirection() { - int rabbish; - int a; - int b = a + a; - // 这是用来产生冲突的代码 - int resil; - char slkdfnasjkfgjasdvasndvjasdv; - return BUS_STOP; + bus_query_t *p = queries; + int id = the_bus->rail_node_pos->id; //获取当前站点的id + + + while(p->node->id == p->next_node->node->id) //如果下一个请求对应的站点与当前是同一个站点 + { + p = p->next_node; + } //处理完所有连续相同站点请求 + + if(p->next_node == NULL) + { + return BUS_STOP; + } //如果没有请求了,公交车停止 + + else + { + int clockwise = 0; + int counterclockwise = 0; //用于顺,逆时针方向所经站台计数 + bus_query_t *t = p; //将指针p的地址暂存 + + while(p->node->id != p->next_node->node->id) + { + p->node = p->node->next_node; + clockwise++; + }//顺时针方向计数 + while(t->node->id != t->next_node->node->id) + { + t->next_node->node = t->next_node->node->next_node; + counterclockwise++; + }//逆时针方向计数 + + if(clockwise <= counterclockwise) + { + return BUS_CLOCK_WISE; + }//若顺时针距离短(或顺逆相等),公交车顺时针运行 + else + { + return BUS_COUNTER_CLOCK_WISE; + }//若逆时针距离短,公交车逆时针运行 + } + + } bus_query_t *FCFSQuery()