-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f87a363
commit f5b9dfd
Showing
77 changed files
with
4,062 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "input.h" | ||
#include "bus.h" | ||
#include "gui.h" | ||
#include<Windows.h> | ||
#include<process.h> | ||
#include <graphics.h> | ||
|
||
int main() { | ||
int station_count = 5; | ||
int station_distance = 2; | ||
int strategy = STRATEGY_FCFS; | ||
|
||
ReadInConfig(&station_count, &station_distance, &strategy); | ||
|
||
Bus* bus = NewBus(station_count, station_distance, strategy); | ||
|
||
initgraph(1200, 600, NULL); // EW_SHOWCONSOLE | ||
DrawBoardWithBus(bus); | ||
|
||
unsigned int tid; | ||
HANDLE handle = (HANDLE)_beginthreadex(nullptr, 0, &BackgroundClock, bus, 0, &tid); | ||
|
||
ReadCommandFromGUIAndAct(bus); | ||
|
||
WaitForSingleObject(handle, INFINITE); | ||
CloseHandle(handle); | ||
|
||
DeleteBus(bus); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.2.32616.157 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bus-schedual", "bus-schedual.vcxproj", "{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Debug|x64.ActiveCfg = Debug|x64 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Debug|x64.Build.0 = Debug|x64 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Debug|x86.Build.0 = Debug|Win32 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Release|x64.ActiveCfg = Release|x64 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Release|x64.Build.0 = Release|x64 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Release|x86.ActiveCfg = Release|Win32 | ||
{7FE1BBC4-3903-4157-8C11-1D76BDA3A1FE}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2C419D7B-AAE3-40C1-8187-42CA42B631CD} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>16.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{7fe1bbc4-3903-4157-8c11-1d76bda3a1fe}</ProjectGuid> | ||
<RootNamespace>busschedual</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="bus-schedual.cpp" /> | ||
<ClCompile Include="bus.cpp" /> | ||
<ClCompile Include="fcfs.cpp" /> | ||
<ClCompile Include="gui.cpp" /> | ||
<ClCompile Include="input.cpp" /> | ||
<ClCompile Include="list.cpp" /> | ||
<ClCompile Include="queue.cpp" /> | ||
<ClCompile Include="scan.cpp" /> | ||
<ClCompile Include="sstf.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="bus.h" /> | ||
<ClInclude Include="const.h" /> | ||
<ClInclude Include="gui.h" /> | ||
<ClInclude Include="input.h" /> | ||
<ClInclude Include="list.h" /> | ||
<ClInclude Include="queue.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="源文件"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="头文件"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="资源文件"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="bus.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="input.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="list.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="queue.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="fcfs.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="scan.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="sstf.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="bus-schedual.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
<ClCompile Include="gui.cpp"> | ||
<Filter>源文件</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="bus.h"> | ||
<Filter>头文件</Filter> | ||
</ClInclude> | ||
<ClInclude Include="const.h"> | ||
<Filter>头文件</Filter> | ||
</ClInclude> | ||
<ClInclude Include="input.h"> | ||
<Filter>头文件</Filter> | ||
</ClInclude> | ||
<ClInclude Include="list.h"> | ||
<Filter>头文件</Filter> | ||
</ClInclude> | ||
<ClInclude Include="queue.h"> | ||
<Filter>头文件</Filter> | ||
</ClInclude> | ||
<ClInclude Include="gui.h"> | ||
<Filter>头文件</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <Windows.h> | ||
#include "bus.h" | ||
#include "queue.h" | ||
#include "list.h" | ||
|
||
// 创建并初始化公交车实例 | ||
Bus* NewBus(int total_station, int distance, int strategy) { | ||
Bus* bus = (Bus*)malloc(sizeof(Bus)); | ||
bus->station_count = total_station; | ||
bus->station_distance = distance; | ||
bus->total_length = total_station * distance; | ||
bus->strategy = strategy; | ||
|
||
bus->time = 0; | ||
bus->direction = 0; | ||
bus->position = 0; | ||
for (int i = 0; i < SIZE_MAX_STATION; ++i) { | ||
bus->clockwise[i] = 0; | ||
bus->counter_clock[i] = 0; | ||
bus->target[i] = 0; | ||
} | ||
|
||
bus->cur_command = 0; | ||
bus->cur_arg = 0; | ||
bus->requests_list = NewListNode(0, 0, 0, NULL); | ||
if (strategy == STRATEGY_FCFS) { | ||
bus->requests_queue = NewQueue(); | ||
} | ||
bus->end = 0; | ||
return bus; | ||
} | ||
|
||
void ActionOnCommand(Bus* bus, int command, int arg) { | ||
switch (bus->strategy) { | ||
case STRATEGY_FCFS: | ||
FCFSActionOnCommand(bus, command, arg); | ||
break; | ||
case STRATEGY_SSTF: | ||
SSTFActionOnCommand(bus, command, arg); | ||
break; | ||
case STRATEGY_SCAN: | ||
SCANActionOnCommand(bus, command, arg); | ||
break; | ||
} | ||
if (command == CMD_CLOCK) { | ||
ShowBusStatus(bus); | ||
} | ||
} | ||
|
||
void ActionOnCommandNoOutput(Bus* bus, int command, int arg) { | ||
switch (bus->strategy) { | ||
case STRATEGY_FCFS: | ||
FCFSActionOnCommand(bus, command, arg); | ||
break; | ||
case STRATEGY_SSTF: | ||
SSTFActionOnCommand(bus, command, arg); | ||
break; | ||
case STRATEGY_SCAN: | ||
SCANActionOnCommand(bus, command, arg); | ||
break; | ||
} | ||
} | ||
|
||
//输出公交车状态 | ||
void ShowBusStatus(Bus* bus) { | ||
printf("TIME:%d\n", bus->time); | ||
printf("BUS:\n"); | ||
printf("position:%d\n", bus->position); | ||
printf("target:"); | ||
for (int i = 0; i < bus->station_count; ++i) { | ||
printf("%d", bus->target[i]); | ||
} | ||
printf("\n"); | ||
printf("STATION:\n"); | ||
printf("clockwise:"); | ||
for (int i = 0; i < bus->station_count; ++i) { | ||
printf("%d", bus->clockwise[i]); | ||
} | ||
printf("\n"); | ||
printf("counterclockwise:"); | ||
for (int i = 0; i < bus->station_count; ++i) { | ||
printf("%d", bus->counter_clock[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
// 释放公交车实例内存 | ||
void DeleteBus(Bus* bus) { | ||
free(bus); | ||
} |
Oops, something went wrong.