From 8a70c8255de85355150f00cb8bcdf2179ae0c67a Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sat, 21 May 2022 17:31:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=95=B4=E4=BD=93=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E8=AE=BE=E8=AE=A1=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + all_test/CMakeLists.txt | 10 +++ all_test/include/tools.h | 18 +++++ all_test/main.c | 133 +++++++++++++++++++++++++++++++ all_test/src/tools.c | 60 ++++++++++++++ all_test/test_cases/1/input.txt | 21 +++++ all_test/test_cases/1/ouput.txt | 134 ++++++++++++++++++++++++++++++++ 7 files changed, 377 insertions(+) create mode 100644 all_test/CMakeLists.txt create mode 100644 all_test/include/tools.h create mode 100644 all_test/main.c create mode 100644 all_test/src/tools.c create mode 100644 all_test/test_cases/1/input.txt create mode 100644 all_test/test_cases/1/ouput.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 245a3fd..cadff1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.10) # 设置cmake项目需要的cmake最小版本 add_subdirectory(test) +add_subdirectory(all_test) project(auto_pilot_bus) # 设置项目的名称 diff --git a/all_test/CMakeLists.txt b/all_test/CMakeLists.txt new file mode 100644 index 0000000..18be2fa --- /dev/null +++ b/all_test/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.0) +project(bus_all_test) + +include_directories(../include) +include_directories(include) + +aux_source_directory("../src/" SRCS) +aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}/src" ALL_TEST_SRCS) + +add_executable(bus_all_test ${SRCS} ${ALL_TEST_SRCS} main.c) \ No newline at end of file diff --git a/all_test/include/tools.h b/all_test/include/tools.h new file mode 100644 index 0000000..4f0f914 --- /dev/null +++ b/all_test/include/tools.h @@ -0,0 +1,18 @@ +// +// Created by ricardo on 2022/5/20. +// + +#ifndef AUTO_PILOT_BUS_TOOLS_H +#define AUTO_PILOT_BUS_TOOLS_H +#include "stdio.h" +#include "string.h" +#include "define.h" + +void ChooseTestCaseInput(char *path, int index); + +void ChooseTestCaseOutput(char *path, int index); + +void ReadOutputFile(char *result, FILE *f); + +int CheckOutput(char *program_output, char *read_output); +#endif //AUTO_PILOT_BUS_TOOLS_H diff --git a/all_test/main.c b/all_test/main.c new file mode 100644 index 0000000..ec5f4cb --- /dev/null +++ b/all_test/main.c @@ -0,0 +1,133 @@ +// +// Created by ricardo on 2022/5/20. +// +#include "bus_io.h" +#include "tools.h" + +int main() +{ + /** + * 输入的字符串 + */ + char input[30]; + /** + * 输出的字符串 + */ + char output[150]; + /** + * the_bus指针的本体 + */ + bus_t main_bus; + /** + * 公交车前进的方向 + */ + int direction; + /** + * 完成的请求 + */ + bus_query_t *finished_query; + int index; + char path[50]; + char read_output[150]; + FILE *input_file = NULL; + FILE *output_file = NULL; + + printf("Please choose which test case to use:"); + scanf("%d\n", &index); + + ChooseTestCaseInput(path, index); + input_file = fopen(path, "r"); + ChooseTestCaseOutput(path, index); + output_file = fopen(path, "r"); + + // 读取配置文件 + rails = ReadConfigFile(); + + // 制造公交车 + the_bus = &main_bus; + the_bus->distance = 0; + the_bus->rail_node_pos = FindNode(rails, 1); + + // 开始时公交车应该是停下的 + direction = BUS_STOP; + + PrintState(output); + ReadOutputFile(read_output, output_file); + if(CheckOutput(output, read_output) == BUS_FAlSE) + { + printf("%s\n", output); + } + else + { + printf("%d Ok\n", bus_time); + } + + for(;;) + { + fgets(input, sizeof input, input_file); + + int result = ReadInput(input); + if(result == IO_CLOCK) + { + // 时间流动 + AddTime(); + + switch (chosen_strategy) + { + case BUS_FCFS: + // 如果到站,处理请求和 + if(JudgeOnStation() == BUS_TRUE) + { + direction = FCFSDirection(); + finished_query = FCFSQuery(); + + if(finished_query != NULL) // 有请求就处理请求 + { + // 循环处理所有可以处理的请求,总共消耗一秒 + while (finished_query != NULL) + { + DeleteQuery(finished_query); + finished_query = FCFSQuery(); + } + } + else //如果没有请求就继续前进 + { + RunBus(direction); + } + } + else + { + RunBus(direction); + } + break; + case BUS_SSTF: + break; + case BUS_SCAN: + break; + default: + break; + } + + PrintState(output); + ReadOutputFile(read_output, output_file); + if(CheckOutput(output, read_output) == BUS_FAlSE) + { + printf("%s\n", output); + } + else + { + printf("%d Ok\n", bus_time); + } + + } + else if(result == IO_END) + { + printf("end\n"); + break; + } + else + { + //在读取到创建请求的情况下,不做任何事 + } + } +} diff --git a/all_test/src/tools.c b/all_test/src/tools.c new file mode 100644 index 0000000..1daf90b --- /dev/null +++ b/all_test/src/tools.c @@ -0,0 +1,60 @@ +// +// Created by ricardo on 2022/5/20. +// +#include "tools.h" + +void ChooseTestCaseInput(char *path, int index) +{ + memset(path, 0, 50); + + char root_path[] = "./test_cases/"; + char input_file[] = "/input.txt"; + char case_path[3]; + + sprintf(case_path, "%d", index); + + strcat(path, root_path); + strcat(path, case_path); + strcat(path, input_file); +} + +void ChooseTestCaseOutput(char *path, int index) +{ + memset(path, 0, 50); + + char root_path[] = "./test_cases/"; + char output_file[] = "/output.txt"; + char case_path[3]; + + sprintf(case_path, "%d", index); + + strcat(path, root_path); + strcat(path, case_path); + strcat(path, output_file); +} + +void ReadOutputFile(char *result, FILE *f) +{ + memset(result, 0, 150); + + for(size_t i = 0; i < 7; i++) + { + char temp[50]; + fgets(temp, 50, f); + strcat(result, temp); + } +} + +int CheckOutput(char *program_output, char *read_output) +{ + int result = strcmp(program_output, read_output); + + if(result == 0) + { + return BUS_TRUE; + } + else + { + return BUS_FAlSE; + } +} \ No newline at end of file diff --git a/all_test/test_cases/1/input.txt b/all_test/test_cases/1/input.txt new file mode 100644 index 0000000..cc018ca --- /dev/null +++ b/all_test/test_cases/1/input.txt @@ -0,0 +1,21 @@ +clock +counterclockwise 3 +clock +clock +clock +clock +clock +clock +target 10 +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/1/ouput.txt b/all_test/test_cases/1/ouput.txt new file mode 100644 index 0000000..0a94ab4 --- /dev/null +++ b/all_test/test_cases/1/ouput.txt @@ -0,0 +1,134 @@ +TIME:0 +BUS: +position:0 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:1 +BUS: +position:0 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:2 +BUS: +position:1 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0010000000 +TIME:3 +BUS: +position:2 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0010000000 +TIME:4 +BUS: +position:3 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0010000000 +TIME:5 +BUS: +position:4 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0010000000 +TIME:6 +BUS: +position:5 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0010000000 +TIME:7 +BUS: +position:6 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0010000000 +TIME:8 +BUS: +position:6 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:9 +BUS: +position:5 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:10 +BUS: +position:4 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:11 +BUS: +position:3 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:12 +BUS: +position:2 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:13 +BUS: +position:1 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:14 +BUS: +position:0 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:15 +BUS: +position:29 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:16 +BUS: +position:28 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:17 +BUS: +position:27 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:18 +BUS: +position:27 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +end From fa13a63fd06c9a49ade048682dcc68a63c0c5090 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sun, 22 May 2022 13:58:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=8C=87=E5=AE=9A=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all_test/CMakeLists.txt | 7 +- all_test/include/tools.h | 6 + all_test/main.c | 2 +- all_test/src/tools.c | 124 +++++++++++++++ all_test/test_cases/1/dict.dic | 3 + all_test/test_cases/2/dict.dic | 4 + all_test/test_cases/2/input.txt | 30 ++++ all_test/test_cases/2/output.txt | 176 +++++++++++++++++++++ all_test/test_cases/3/dict.dic | 4 + all_test/test_cases/3/input.txt | 30 ++++ all_test/test_cases/3/output.txt | 183 ++++++++++++++++++++++ all_test/test_cases/4/dict.dic | 4 + all_test/test_cases/4/input.txt | 34 ++++ all_test/test_cases/4/output.txt | 211 +++++++++++++++++++++++++ all_test/test_cases/5/dict.dic | 4 + all_test/test_cases/5/input.txt | 26 ++++ all_test/test_cases/5/output.txt | 155 ++++++++++++++++++ all_test/test_cases/6/dict.dic | 4 + all_test/test_cases/6/input.txt | 47 ++++++ all_test/test_cases/6/output.txt | 260 +++++++++++++++++++++++++++++++ all_test/test_cases/7/dict.dic | 4 + all_test/test_cases/7/input.txt | 42 +++++ all_test/test_cases/7/output.txt | 239 ++++++++++++++++++++++++++++ 23 files changed, 1597 insertions(+), 2 deletions(-) create mode 100644 all_test/test_cases/1/dict.dic create mode 100644 all_test/test_cases/2/dict.dic create mode 100644 all_test/test_cases/2/input.txt create mode 100644 all_test/test_cases/2/output.txt create mode 100644 all_test/test_cases/3/dict.dic create mode 100644 all_test/test_cases/3/input.txt create mode 100644 all_test/test_cases/3/output.txt create mode 100644 all_test/test_cases/4/dict.dic create mode 100644 all_test/test_cases/4/input.txt create mode 100644 all_test/test_cases/4/output.txt create mode 100644 all_test/test_cases/5/dict.dic create mode 100644 all_test/test_cases/5/input.txt create mode 100644 all_test/test_cases/5/output.txt create mode 100644 all_test/test_cases/6/dict.dic create mode 100644 all_test/test_cases/6/input.txt create mode 100644 all_test/test_cases/6/output.txt create mode 100644 all_test/test_cases/7/dict.dic create mode 100644 all_test/test_cases/7/input.txt create mode 100644 all_test/test_cases/7/output.txt diff --git a/all_test/CMakeLists.txt b/all_test/CMakeLists.txt index 18be2fa..7aa513d 100644 --- a/all_test/CMakeLists.txt +++ b/all_test/CMakeLists.txt @@ -7,4 +7,9 @@ include_directories(include) aux_source_directory("../src/" SRCS) aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}/src" ALL_TEST_SRCS) -add_executable(bus_all_test ${SRCS} ${ALL_TEST_SRCS} main.c) \ No newline at end of file +add_executable(bus_all_test ${SRCS} ${ALL_TEST_SRCS} main.c) + +add_custom_command(TARGET bus_all_test POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/test_cases/" + $) \ No newline at end of file diff --git a/all_test/include/tools.h b/all_test/include/tools.h index 4f0f914..f32f73a 100644 --- a/all_test/include/tools.h +++ b/all_test/include/tools.h @@ -7,12 +7,18 @@ #include "stdio.h" #include "string.h" #include "define.h" +#include "rail.h" +#include "controller.h" void ChooseTestCaseInput(char *path, int index); void ChooseTestCaseOutput(char *path, int index); +rail_node_t *ChooseConfigFile(int index); + void ReadOutputFile(char *result, FILE *f); int CheckOutput(char *program_output, char *read_output); + +rail_node_t *ReadChosenConfigFile(char *config_file_path); #endif //AUTO_PILOT_BUS_TOOLS_H diff --git a/all_test/main.c b/all_test/main.c index ec5f4cb..4d5333b 100644 --- a/all_test/main.c +++ b/all_test/main.c @@ -41,7 +41,7 @@ int main() output_file = fopen(path, "r"); // 读取配置文件 - rails = ReadConfigFile(); + rails = ChooseConfigFile(index); // 制造公交车 the_bus = &main_bus; diff --git a/all_test/src/tools.c b/all_test/src/tools.c index 1daf90b..8c32166 100644 --- a/all_test/src/tools.c +++ b/all_test/src/tools.c @@ -57,4 +57,128 @@ int CheckOutput(char *program_output, char *read_output) { return BUS_FAlSE; } +} + +rail_node_t *ChooseConfigFile(int index) +{ + char root_path[] = "./test_cases/"; + char config_path[] = "/dict.dic"; + char case_path[3]; + + sprintf(case_path, "%d", index); + + char file_path[30]; + + strcat(file_path, root_path); + strcat(file_path, case_path); + strcat(file_path, config_path); + + return ReadChosenConfigFile(file_path); +} + +rail_node_t *ReadChosenConfigFile(char *config_file_path) +{ + FILE *config_file = NULL; + char buffer[30]; + int total_station = 0; + int distance = 0; + + config_file = fopen(config_file_path, "r"); + + // 循环读取文件的每一行 + while (fgets(buffer, sizeof buffer, config_file) != NULL) + { + char first_char = buffer[0]; + char *p; + + switch (first_char) + { + case '#': + // 如果读取到#什么都不做 + break; + case 'T': + // TOTAL_STATION + p = buffer; + + // 把数字前面的所有字符全部干掉 + while (*p < '0' || *p > '9') + { + p++; + } + + if (*p == '1' && *(p + 1) != '\n') + { + total_station = 10; + } + else if (*(p + 1) == '\n') + { + total_station = *p - 48; + } + + break; + case 'S': + // STRATEGY + p = buffer; + // 将=前的字符全部略去 + while (*p != '=') + { + p++; + } + // =也去掉 + p++; + // =和策略之间的空格也去掉 + while (*p == ' ') + { + p++; + } + + if (*p == 'F' && *(p + 1) == 'C') //FCFS + { + chosen_strategy = BUS_FCFS; + } + else if (*p == 'S' && *(p + 1) == 'S') //SSTF + { + chosen_strategy = BUS_SSTF; + } + else if (*p == 'S' && *(p + 1) == 'C') //SCAN + { + chosen_strategy = BUS_SCAN; + } + else + { + // 读取失败 + chosen_strategy = -1; + } + + break; + case 'D': + // DISTANCE + p = buffer; + + // 把数字前面的所有字符全部干掉 + while (*p < '0' || *p > '9') + { + p++; + } + + if (*(p + 1) == '\n') + { + distance = *p - 48; + } + + break; + default: + continue; + } + + } + + if (distance != 0 && total_station != 0) + { + return CreateRails(distance, total_station); + } + else + { + return NULL; + } } \ No newline at end of file diff --git a/all_test/test_cases/1/dict.dic b/all_test/test_cases/1/dict.dic new file mode 100644 index 0000000..ba4ce4d --- /dev/null +++ b/all_test/test_cases/1/dict.dic @@ -0,0 +1,3 @@ +TOTAL_STATION = 10 +STRATEGY = FCFS +DISTANCE = 3 \ No newline at end of file diff --git a/all_test/test_cases/2/dict.dic b/all_test/test_cases/2/dict.dic new file mode 100644 index 0000000..d9bf0c8 --- /dev/null +++ b/all_test/test_cases/2/dict.dic @@ -0,0 +1,4 @@ +# first come first serve +STRATEGY = FCFS +TOTAL_STATION = 10 +DISTANCE = 2 \ No newline at end of file diff --git a/all_test/test_cases/2/input.txt b/all_test/test_cases/2/input.txt new file mode 100644 index 0000000..f2450ea --- /dev/null +++ b/all_test/test_cases/2/input.txt @@ -0,0 +1,30 @@ +clock +clockwise 2 +clock +clockwise 4 +clock +clock +clockwise 6 +clock +target 8 +clock +clock +clock +target 10 +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/2/output.txt b/all_test/test_cases/2/output.txt new file mode 100644 index 0000000..acc5063 --- /dev/null +++ b/all_test/test_cases/2/output.txt @@ -0,0 +1,176 @@ +TIME:0 +BUS: +position:0 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:1 +BUS: +position:0 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:2 +BUS: +position:1 +target:0000000000 +STATION: +clockwise:0100000000 +counterclockwise:0000000000 +TIME:3 +BUS: +position:2 +target:0000000000 +STATION: +clockwise:0101000000 +counterclockwise:0000000000 +TIME:4 +BUS: +position:2 +target:0000000000 +STATION: +clockwise:0001000000 +counterclockwise:0000000000 +TIME:5 +BUS: +position:3 +target:0000000000 +STATION: +clockwise:0001010000 +counterclockwise:0000000000 +TIME:6 +BUS: +position:4 +target:0000000100 +STATION: +clockwise:0001010000 +counterclockwise:0000000000 +TIME:7 +BUS: +position:5 +target:0000000100 +STATION: +clockwise:0001010000 +counterclockwise:0000000000 +TIME:8 +BUS: +position:6 +target:0000000100 +STATION: +clockwise:0001010000 +counterclockwise:0000000000 +TIME:9 +BUS: +position:6 +target:0000000101 +STATION: +clockwise:0000010000 +counterclockwise:0000000000 +TIME:10 +BUS: +position:7 +target:0000000101 +STATION: +clockwise:0000010000 +counterclockwise:0000000000 +TIME:11 +BUS: +position:8 +target:0000000101 +STATION: +clockwise:0000010000 +counterclockwise:0000000000 +TIME:12 +BUS: +position:9 +target:0000000101 +STATION: +clockwise:0000010000 +counterclockwise:0000000000 +TIME:13 +BUS: +position:10 +target:0000000101 +STATION: +clockwise:0000010000 +counterclockwise:0000000000 +TIME:14 +BUS: +position:10 +target:0000000101 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:15 +BUS: +position:11 +target:0000000101 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:16 +BUS: +position:12 +target:0000000101 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:17 +BUS: +position:13 +target:0000000101 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:18 +BUS: +position:14 +target:0000000101 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:19 +BUS: +position:14 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:20 +BUS: +position:15 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:21 +BUS: +position:16 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:22 +BUS: +position:17 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:23 +BUS: +position:18 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:24 +BUS: +position:18 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +end diff --git a/all_test/test_cases/3/dict.dic b/all_test/test_cases/3/dict.dic new file mode 100644 index 0000000..d9bf0c8 --- /dev/null +++ b/all_test/test_cases/3/dict.dic @@ -0,0 +1,4 @@ +# first come first serve +STRATEGY = FCFS +TOTAL_STATION = 10 +DISTANCE = 2 \ No newline at end of file diff --git a/all_test/test_cases/3/input.txt b/all_test/test_cases/3/input.txt new file mode 100644 index 0000000..57ac345 --- /dev/null +++ b/all_test/test_cases/3/input.txt @@ -0,0 +1,30 @@ +clock +clockwise 2 +clock +target 10 +clock +clock +clock +clockwise 3 +clock +clock +target 9 +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/3/output.txt b/all_test/test_cases/3/output.txt new file mode 100644 index 0000000..de95351 --- /dev/null +++ b/all_test/test_cases/3/output.txt @@ -0,0 +1,183 @@ +TIME:0 +BUS: +position:0 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:1 +BUS: +position:0 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:2 +BUS: +position:1 +target:0000000000 +STATION: +clockwise:0100000000 +counterclockwise:0000000000 +TIME:3 +BUS: +position:2 +target:0000000001 +STATION: +clockwise:0100000000 +counterclockwise:0000000000 +TIME:4 +BUS: +position:2 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:5 +BUS: +position:1 +target:0000000001 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:6 +BUS: +position:0 +target:0000000001 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:7 +BUS: +position:19 +target:0000000001 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:8 +BUS: +position:18 +target:0000000011 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:9 +BUS: +position:18 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:10 +BUS: +position:19 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:11 +BUS: +position:0 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:12 +BUS: +position:1 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:13 +BUS: +position:2 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:14 +BUS: +position:3 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:15 +BUS: +position:4 +target:0000000010 +STATION: +clockwise:0010000000 +counterclockwise:0000000000 +TIME:16 +BUS: +position:4 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:17 +BUS: +position:3 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:18 +BUS: +position:2 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:19 +BUS: +position:1 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:20 +BUS: +position:0 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:21 +BUS: +position:19 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:22 +BUS: +position:18 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:23 +BUS: +position:17 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:24 +BUS: +position:16 +target:0000000010 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +TIME:25 +BUS: +position:16 +target:0000000000 +STATION: +clockwise:0000000000 +counterclockwise:0000000000 +end diff --git a/all_test/test_cases/4/dict.dic b/all_test/test_cases/4/dict.dic new file mode 100644 index 0000000..f8e2ddb --- /dev/null +++ b/all_test/test_cases/4/dict.dic @@ -0,0 +1,4 @@ +DISTANCE = 4 +STRATEGY = SCAN +TOTAL_STATION = 6 +# scan serve diff --git a/all_test/test_cases/4/input.txt b/all_test/test_cases/4/input.txt new file mode 100644 index 0000000..5581d55 --- /dev/null +++ b/all_test/test_cases/4/input.txt @@ -0,0 +1,34 @@ +clock +clockwise 2 +clock +clock +counterclockwise 6 +clock +clock +clock +clock +clock +clock +clock +clock +target 1 +clock +clock +clock +clock +clock +clock +counterclockwise 5 +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/4/output.txt b/all_test/test_cases/4/output.txt new file mode 100644 index 0000000..f53acef --- /dev/null +++ b/all_test/test_cases/4/output.txt @@ -0,0 +1,211 @@ +TIME:0 +BUS: +position:0 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:1 +BUS: +position:0 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:2 +BUS: +position:1 +target:000000 +STATION: +clockwise:010000 +counterclockwise:000000 +TIME:3 +BUS: +position:2 +target:000000 +STATION: +clockwise:010000 +counterclockwise:000000 +TIME:4 +BUS: +position:3 +target:000000 +STATION: +clockwise:010000 +counterclockwise:000001 +TIME:5 +BUS: +position:4 +target:000000 +STATION: +clockwise:010000 +counterclockwise:000001 +TIME:6 +BUS: +position:4 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:7 +BUS: +position:3 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:8 +BUS: +position:2 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:9 +BUS: +position:1 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:10 +BUS: +position:0 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:11 +BUS: +position:23 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:12 +BUS: +position:22 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:13 +BUS: +position:21 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:14 +BUS: +position:20 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000001 +TIME:15 +BUS: +position:20 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:16 +BUS: +position:21 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:17 +BUS: +position:22 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:18 +BUS: +position:23 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:19 +BUS: +position:0 +target:100000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:20 +BUS: +position:0 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:21 +BUS: +position:23 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:22 +BUS: +position:22 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:23 +BUS: +position:21 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:24 +BUS: +position:20 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:25 +BUS: +position:19 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:26 +BUS: +position:18 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:27 +BUS: +position:17 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:28 +BUS: +position:16 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000010 +TIME:29 +BUS: +position:16 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000000 +end diff --git a/all_test/test_cases/5/dict.dic b/all_test/test_cases/5/dict.dic new file mode 100644 index 0000000..f8e2ddb --- /dev/null +++ b/all_test/test_cases/5/dict.dic @@ -0,0 +1,4 @@ +DISTANCE = 4 +STRATEGY = SCAN +TOTAL_STATION = 6 +# scan serve diff --git a/all_test/test_cases/5/input.txt b/all_test/test_cases/5/input.txt new file mode 100644 index 0000000..1adebd8 --- /dev/null +++ b/all_test/test_cases/5/input.txt @@ -0,0 +1,26 @@ +clock +clockwise 2 +counterclockwise 3 +clock +clock +clock +clock +clock +clock +target 4 +clock +clock +clock +clock +clock +clock +clockwise 5 +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/5/output.txt b/all_test/test_cases/5/output.txt new file mode 100644 index 0000000..d1ee609 --- /dev/null +++ b/all_test/test_cases/5/output.txt @@ -0,0 +1,155 @@ +TIME:0 +BUS: +position:0 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:1 +BUS: +position:0 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:2 +BUS: +position:1 +target:000000 +STATION: +clockwise:010000 +counterclockwise:001000 +TIME:3 +BUS: +position:2 +target:000000 +STATION: +clockwise:010000 +counterclockwise:001000 +TIME:4 +BUS: +position:3 +target:000000 +STATION: +clockwise:010000 +counterclockwise:001000 +TIME:5 +BUS: +position:4 +target:000000 +STATION: +clockwise:010000 +counterclockwise:001000 +TIME:6 +BUS: +position:4 +target:000000 +STATION: +clockwise:000000 +counterclockwise:001000 +TIME:7 +BUS: +position:5 +target:000000 +STATION: +clockwise:000000 +counterclockwise:001000 +TIME:8 +BUS: +position:6 +target:000100 +STATION: +clockwise:000000 +counterclockwise:001000 +TIME:9 +BUS: +position:7 +target:000100 +STATION: +clockwise:000000 +counterclockwise:001000 +TIME:10 +BUS: +position:8 +target:000100 +STATION: +clockwise:000000 +counterclockwise:001000 +TIME:11 +BUS: +position:8 +target:000100 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:12 +BUS: +position:9 +target:000100 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:13 +BUS: +position:10 +target:000100 +STATION: +clockwise:000000 +counterclockwise:000000 +TIME:14 +BUS: +position:11 +target:000100 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:15 +BUS: +position:12 +target:000100 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:16 +BUS: +position:12 +target:000000 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:17 +BUS: +position:13 +target:000000 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:18 +BUS: +position:14 +target:000000 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:19 +BUS: +position:15 +target:000000 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:20 +BUS: +position:16 +target:000000 +STATION: +clockwise:000010 +counterclockwise:000000 +TIME:21 +BUS: +position:16 +target:000000 +STATION: +clockwise:000000 +counterclockwise:000000 +end diff --git a/all_test/test_cases/6/dict.dic b/all_test/test_cases/6/dict.dic new file mode 100644 index 0000000..9edb3be --- /dev/null +++ b/all_test/test_cases/6/dict.dic @@ -0,0 +1,4 @@ +TOTAL_STATION = 5 +DISTANCE = 3 +# shortest seek time first +STRATEGY = SSTF diff --git a/all_test/test_cases/6/input.txt b/all_test/test_cases/6/input.txt new file mode 100644 index 0000000..b2940ee --- /dev/null +++ b/all_test/test_cases/6/input.txt @@ -0,0 +1,47 @@ +clock +clockwise 4 +clockwise 2 +counterclockwise 4 +clock +clockwise 2 +clock +clock +counterclockwise 1 +clock +clock +clockwise 3 +clock +clock +clock +clock +clock +clock +clock +target 5 +clock +target 3 +clock +clock +clock +clock +clock +clock +clock +clock +target 4 +target 1 +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/6/output.txt b/all_test/test_cases/6/output.txt new file mode 100644 index 0000000..d0b431f --- /dev/null +++ b/all_test/test_cases/6/output.txt @@ -0,0 +1,260 @@ +TIME:0 +BUS: +position:0 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:1 +BUS: +position:0 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:2 +BUS: +position:1 +target:00000 +STATION: +clockwise:01010 +counterclockwise:00010 +TIME:3 +BUS: +position:2 +target:00000 +STATION: +clockwise:01010 +counterclockwise:00010 +TIME:4 +BUS: +position:3 +target:00000 +STATION: +clockwise:01010 +counterclockwise:00010 +TIME:5 +BUS: +position:3 +target:00000 +STATION: +clockwise:00010 +counterclockwise:10010 +TIME:6 +BUS: +position:2 +target:00000 +STATION: +clockwise:00010 +counterclockwise:10010 +TIME:7 +BUS: +position:1 +target:00000 +STATION: +clockwise:00110 +counterclockwise:10010 +TIME:8 +BUS: +position:0 +target:00000 +STATION: +clockwise:00110 +counterclockwise:10010 +TIME:9 +BUS: +position:0 +target:00000 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:10 +BUS: +position:1 +target:00000 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:11 +BUS: +position:2 +target:00000 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:12 +BUS: +position:3 +target:00000 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:13 +BUS: +position:4 +target:00000 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:14 +BUS: +position:5 +target:00001 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:15 +BUS: +position:6 +target:00101 +STATION: +clockwise:00110 +counterclockwise:00010 +TIME:16 +BUS: +position:6 +target:00001 +STATION: +clockwise:00010 +counterclockwise:00010 +TIME:17 +BUS: +position:7 +target:00001 +STATION: +clockwise:00010 +counterclockwise:00010 +TIME:18 +BUS: +position:8 +target:00001 +STATION: +clockwise:00010 +counterclockwise:00010 +TIME:19 +BUS: +position:9 +target:00001 +STATION: +clockwise:00010 +counterclockwise:00010 +TIME:20 +BUS: +position:9 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:21 +BUS: +position:10 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:22 +BUS: +position:11 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:23 +BUS: +position:12 +target:10011 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:24 +BUS: +position:12 +target:10010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:25 +BUS: +position:13 +target:10010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:26 +BUS: +position:14 +target:10010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:27 +BUS: +position:0 +target:10010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:28 +BUS: +position:0 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:29 +BUS: +position:14 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:30 +BUS: +position:13 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:31 +BUS: +position:12 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:32 +BUS: +position:11 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:33 +BUS: +position:10 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:34 +BUS: +position:9 +target:00010 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:35 +BUS: +position:9 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:36 +BUS: +position:9 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +end diff --git a/all_test/test_cases/7/dict.dic b/all_test/test_cases/7/dict.dic new file mode 100644 index 0000000..9edb3be --- /dev/null +++ b/all_test/test_cases/7/dict.dic @@ -0,0 +1,4 @@ +TOTAL_STATION = 5 +DISTANCE = 3 +# shortest seek time first +STRATEGY = SSTF diff --git a/all_test/test_cases/7/input.txt b/all_test/test_cases/7/input.txt new file mode 100644 index 0000000..8ba05f6 --- /dev/null +++ b/all_test/test_cases/7/input.txt @@ -0,0 +1,42 @@ +clock +clockwise 2 +counterclockwise 4 +clock +clock +clock +clock +clock +counterclockwise 3 +clock +clock +clock +clock +target 5 +clock +clock +clock +clock +clock +clock +counterclockwise 4 +clock +clock +clock +clock +clock +target 1 +clockwise 3 +clock +clock +clock +clock +target 2 +clock +clock +clock +clock +clock +clock +clock +clock +end diff --git a/all_test/test_cases/7/output.txt b/all_test/test_cases/7/output.txt new file mode 100644 index 0000000..3509551 --- /dev/null +++ b/all_test/test_cases/7/output.txt @@ -0,0 +1,239 @@ +TIME:0 +BUS: +position:0 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:1 +BUS: +position:0 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:2 +BUS: +position:1 +target:00000 +STATION: +clockwise:01000 +counterclockwise:00010 +TIME:3 +BUS: +position:2 +target:00000 +STATION: +clockwise:01000 +counterclockwise:00010 +TIME:4 +BUS: +position:3 +target:00000 +STATION: +clockwise:01000 +counterclockwise:00010 +TIME:5 +BUS: +position:3 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00010 +TIME:6 +BUS: +position:4 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00010 +TIME:7 +BUS: +position:5 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:8 +BUS: +position:6 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:9 +BUS: +position:7 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:10 +BUS: +position:8 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:11 +BUS: +position:9 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:12 +BUS: +position:9 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:13 +BUS: +position:10 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:14 +BUS: +position:11 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:15 +BUS: +position:12 +target:00001 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:16 +BUS: +position:12 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:17 +BUS: +position:11 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:18 +BUS: +position:10 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:19 +BUS: +position:9 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00110 +TIME:20 +BUS: +position:9 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:21 +BUS: +position:8 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00100 +TIME:22 +BUS: +position:7 +target:10000 +STATION: +clockwise:00100 +counterclockwise:00100 +TIME:23 +BUS: +position:6 +target:10000 +STATION: +clockwise:00100 +counterclockwise:00100 +TIME:24 +BUS: +position:6 +target:10000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:25 +BUS: +position:5 +target:10000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:26 +BUS: +position:4 +target:11000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:27 +BUS: +position:3 +target:11000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:28 +BUS: +position:3 +target:10000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:29 +BUS: +position:2 +target:10000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:30 +BUS: +position:1 +target:10000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:31 +BUS: +position:0 +target:10000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:32 +BUS: +position:0 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +TIME:33 +BUS: +position:0 +target:00000 +STATION: +clockwise:00000 +counterclockwise:00000 +end