Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heuristic route generation #101

Draft
wants to merge 237 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
237 commits
Select commit Hold shift + click to select a range
d576967
Add nix devshell
ottoblep Nov 26, 2024
41cad83
Add tools for pre-commit hooks and linting
ottoblep Nov 27, 2024
8614ccb
Add example test for new simulation category
ottoblep Nov 27, 2024
be9c76f
Add tool for graph visualization
ottoblep Nov 27, 2024
132c990
Add empty class `SimulationInstance`
ottoblep Nov 27, 2024
de8214f
Add members and test for `SimulationInstance`
ottoblep Nov 28, 2024
b38dac7
Determine simulation parameters
ottoblep Nov 28, 2024
43f6870
Add struct `RoutingSolutionTrain`
ottoblep Nov 28, 2024
a048741
Switch integer type
ottoblep Nov 28, 2024
307ce13
Add general classes for routing
ottoblep Nov 28, 2024
2b37ceb
Add random solution generation
ottoblep Nov 29, 2024
328a6c0
Move consistency check and restrict access qualifiers
ottoblep Nov 29, 2024
f351e64
Update dev packages
ottoblep Dec 16, 2024
6650037
Add dev scripts
ottoblep Dec 16, 2024
64ad23f
Add class `RoutingSolution`
ottoblep Dec 16, 2024
5770496
Add class `EdgeTrajectory`
ottoblep Dec 16, 2024
d7bfb8e
Add struct `SpeedTargets`
ottoblep Dec 16, 2024
fd773d1
Add search through speed targets
ottoblep Dec 17, 2024
95135c8
Add edge trajectory simulation
ottoblep Dec 17, 2024
87921b6
Simplify edge simulation and add part of edge transition
ottoblep Dec 17, 2024
68c0546
Switch datatypes and structures
ottoblep Dec 17, 2024
2b7a5de
Switch to ninja build tool
ottoblep Dec 19, 2024
abb1c88
Fix random solution generation
ottoblep Dec 19, 2024
a800675
Add edge transition logic
ottoblep Dec 19, 2024
524a522
Add `TrainTrajectory`
ottoblep Dec 19, 2024
a209a06
Formalize edge transition outcomes
ottoblep Dec 20, 2024
423acaf
Fix includes and tests
ottoblep Dec 20, 2024
1d4ba1d
Add check for planned stop
ottoblep Dec 20, 2024
2ea7518
Generate amount of timestep from schedule
ottoblep Dec 20, 2024
430ee20
Generate initial train state from schedule
ottoblep Dec 20, 2024
7c25b00
Check overspeed outcome
ottoblep Dec 21, 2024
1be7189
Add part of trajectory construction
ottoblep Dec 21, 2024
54521f5
Keep reference to instance in trajectory objects
ottoblep Dec 22, 2024
a18bbe6
Add `limit_speed_after`
ottoblep Dec 22, 2024
a3eafea
Use const iterator
ottoblep Dec 22, 2024
68c9ced
Remove undefined constructor
ottoblep Dec 22, 2024
14d5269
Add test for `limit_speed_after`
ottoblep Dec 22, 2024
e5f1262
Add braking logic helper functions
ottoblep Dec 22, 2024
0a57c88
Save information about edge transitions
ottoblep Dec 22, 2024
bc63ca2
Fix range of `switch_directions`
ottoblep Dec 22, 2024
ea868ed
Index timesteps from 0
ottoblep Dec 22, 2024
9142d5d
Add `distance_to_last_transition` and `is_feasible_braking_point`
ottoblep Dec 22, 2024
238ead5
Fix orientation format
ottoblep Dec 22, 2024
aed668e
Fix test
ottoblep Dec 23, 2024
09e39ab
Convert member functions to const
ottoblep Dec 23, 2024
9f805d6
Add helpers to SpeedTargets
ottoblep Dec 23, 2024
b082911
Clarify trajectory object naming
ottoblep Dec 23, 2024
b988dd5
Sort member functions
ottoblep Dec 23, 2024
7d2e419
Consider carried over targets when limiting speeds
ottoblep Dec 23, 2024
4532079
Rename internal function
ottoblep Dec 23, 2024
3344328
Add const to `RoutingSolver` members
ottoblep Dec 23, 2024
da51d24
Add braking function
ottoblep Dec 24, 2024
88934ee
Fix const member initialization
ottoblep Dec 24, 2024
debc718
Enable holding both until a fixed time and a minimum time
ottoblep Dec 24, 2024
074e741
Add edge speed limiting logic
ottoblep Dec 24, 2024
0bd843d
Clarify timestep indexing
ottoblep Dec 24, 2024
fbbe86c
Begin trajectory construction logic
ottoblep Dec 26, 2024
db97cef
Add `find_next_reversal`
ottoblep Dec 26, 2024
bd4fb84
Finish trajectory construction logic
ottoblep Dec 26, 2024
74c35ef
Add test for trajectory construction
ottoblep Dec 26, 2024
1f7b076
Refactor random solution generation
ottoblep Dec 26, 2024
a394399
Use calculated amount of switch vars in test
ottoblep Dec 26, 2024
b1898ae
Fix edge simulation exiting immediately
ottoblep Dec 26, 2024
536561a
Fix timestep range check
ottoblep Dec 27, 2024
940d37b
Track visited stops
ottoblep Dec 27, 2024
57ebd6e
Rework edge transition logic
ottoblep Dec 27, 2024
4aa0c29
Narrow scope
ottoblep Dec 28, 2024
1e4e9c7
Fix acceleration sign
ottoblep Dec 28, 2024
d36eba7
Make sub trajectory selection more robust
ottoblep Dec 28, 2024
83490bc
Make checks for timestep range train specific
ottoblep Dec 28, 2024
8f7b1cf
Fix range error while pruning trajectories
ottoblep Dec 28, 2024
f5c97ee
Include hold in returned braking period
ottoblep Dec 28, 2024
783692c
Clarify error message
ottoblep Dec 28, 2024
fa9e0eb
Improve struct member names
ottoblep Dec 28, 2024
e2546a1
Determine last timestep during construction
ottoblep Dec 29, 2024
ba4c464
Fix transition timestep increment
ottoblep Dec 29, 2024
ce36c0e
Recalculate entire trajectory when adjusting first target
ottoblep Dec 29, 2024
77150e2
Rename variable to avoid confusion with member
ottoblep Dec 29, 2024
e31f24f
Terminate construction after simulation time ends
ottoblep Dec 29, 2024
da8b331
Establish invariant for `EdgeEntry`
ottoblep Dec 29, 2024
ad5acda
Fix control flow for revisited planned stop
ottoblep Dec 29, 2024
6f54ec7
Fix accidental iterator decrement
ottoblep Dec 29, 2024
ef54679
Update tools
ottoblep Dec 30, 2024
d92ffc6
Fix incorrect use of map erase
ottoblep Dec 30, 2024
d7e14b8
Resolve name collision
ottoblep Dec 30, 2024
917cf08
Fix missing member initialization
ottoblep Dec 30, 2024
f89d4b0
Skip target restoration at end of simulation
ottoblep Dec 30, 2024
ad0edad
Split functions for searching trajectories
ottoblep Dec 30, 2024
735fef2
When not reversing out of dead end wait until end of time
ottoblep Dec 30, 2024
b2aa7c1
Change type
ottoblep Dec 31, 2024
ff436b2
Replace `ulong` with `u_int64_t`
ottoblep Dec 31, 2024
28d3429
Edge index has type `size_t`
ottoblep Dec 31, 2024
1ba374a
Remove redundant range checks
ottoblep Dec 31, 2024
8274b30
Test more solutions with random target amount
ottoblep Dec 31, 2024
26d0ca6
Prevent integer underflow
ottoblep Dec 31, 2024
c3386c7
Remove redundant calculation
ottoblep Dec 31, 2024
4cc387e
Disable optimizations in debug mode
ottoblep Dec 31, 2024
ffc72f2
Fix braking distance calculation
ottoblep Jan 1, 2025
aeb1e69
Fix negative braking time
ottoblep Jan 1, 2025
4823622
Remove remaining distance calculation
ottoblep Jan 1, 2025
6e06be6
Fix incorrect `std::signbit` usage
ottoblep Jan 1, 2025
550d44a
Disallow default constructors
ottoblep Jan 2, 2025
5df5d93
Allow const members
ottoblep Jan 2, 2025
e59d801
Add include guards
ottoblep Jan 2, 2025
303afab
Add solution and trajectory sets
ottoblep Jan 2, 2025
5b14117
Explain map keys in solution and trajectory sets
ottoblep Jan 2, 2025
730200a
Add test for trajectory set
ottoblep Jan 2, 2025
1cf8eef
Pass solution set by reference
ottoblep Jan 2, 2025
7349976
Test size of solution and trajectory sets
ottoblep Jan 2, 2025
9788f21
Add trajectory set export to csv
ottoblep Jan 2, 2025
6ef2581
Add trajectory plotting
ottoblep Jan 2, 2025
5356fa3
Change test network
ottoblep Jan 2, 2025
0411aaf
Add speed limit checks
ottoblep Jan 2, 2025
58872ce
Add indication for inactive trains
ottoblep Jan 2, 2025
0b5fc25
Add todo
ottoblep Jan 3, 2025
1eaa553
Make a copy of traversal instead of referencing
ottoblep Jan 3, 2025
902c8f3
Add todo
ottoblep Jan 3, 2025
914d714
Introduce namespace `cda_rail::sim`
ottoblep Jan 3, 2025
2add735
Add random search
ottoblep Jan 3, 2025
4765850
Add train distance
ottoblep Jan 3, 2025
5032a22
Fix random solution test
ottoblep Jan 4, 2025
d4b780d
Add collision objective
ottoblep Jan 4, 2025
25f778c
Simplify and document distance penalties
ottoblep Jan 4, 2025
844e1ec
Fix missing iteration
ottoblep Jan 4, 2025
d726768
Test random search
ottoblep Jan 4, 2025
5e4ff96
Add test for train distance
ottoblep Jan 4, 2025
fe7884f
Fix distance calculation
ottoblep Jan 4, 2025
7ec4da4
Simplify random search abort criterium
ottoblep Jan 4, 2025
ce4e630
Reduce testing time
ottoblep Jan 4, 2025
d1f5516
Move test of trajectory export
ottoblep Jan 4, 2025
9edf862
Check for sufficient time resolution
ottoblep Jan 4, 2025
6647a70
Choose more appropriate exception types
ottoblep Jan 4, 2025
e0a6053
Fix missing train in plot
ottoblep Jan 4, 2025
8c553be
Add critical TODOs
ottoblep Jan 4, 2025
5d29b7a
Disable unused and cpp warnings
ottoblep Jan 7, 2025
edcf96c
Add vertex shortest paths
ottoblep Jan 7, 2025
c17dd7a
Add undirected vertex shortest paths
ottoblep Jan 7, 2025
23b8059
Fix train distance calculation with using vertex shortest paths
ottoblep Jan 7, 2025
8d68821
Add helpers for testing train distance exactly
ottoblep Jan 11, 2025
25b1eaa
Fix entry position
ottoblep Jan 11, 2025
c347773
Fix fall-through in switch statement
ottoblep Jan 11, 2025
9388faa
Add detailed test for train distance
ottoblep Jan 11, 2025
2322b4c
Refactor collision detection
ottoblep Jan 12, 2025
628c6fb
Add destination objective
ottoblep Jan 12, 2025
615ad7d
Enable early train exit according to schedule
ottoblep Jan 12, 2025
a59e32e
Add stop objective
ottoblep Jan 12, 2025
9acc21b
Add TODO
ottoblep Jan 13, 2025
43f22e7
Add plot for speed curves
ottoblep Jan 20, 2025
ccd9dd8
Make amount of speed targets into a decision variable
ottoblep Jan 20, 2025
934dec5
Add random search
ottoblep Jan 20, 2025
3f269eb
Add missing function
ottoblep Jan 22, 2025
754f331
Make trajectories copyable using reference wrapper
ottoblep Jan 22, 2025
4c114ea
Add `contains` helper to trajectory set
ottoblep Jan 22, 2025
2b5def0
Fix uninitialized variable
ottoblep Jan 22, 2025
fbbe341
Fix penalty for trains without stops
ottoblep Jan 22, 2025
e8053ae
Fix premature abort of greedy search
ottoblep Jan 22, 2025
bdbdafe
Plot all tests
ottoblep Jan 22, 2025
5e19f95
Add todo
ottoblep Jan 22, 2025
f19a319
Shuffle train placement order
ottoblep Jan 25, 2025
d31f646
Add `SolverResult` class
ottoblep Jan 25, 2025
b8ea728
Add destination penalty for single trains
ottoblep Jan 25, 2025
4fe1607
Add stop penalty for single trains
ottoblep Jan 25, 2025
5f2ddc4
Pass reference
ottoblep Jan 25, 2025
61a7c2c
Inline stop handling
ottoblep Jan 25, 2025
427322b
Simplify train iteration
ottoblep Jan 25, 2025
44977ac
Reduce duplicate calculations with solver result object
ottoblep Jan 25, 2025
c668d25
Add todo
ottoblep Jan 25, 2025
e6bcd85
Remove unused arguments
ottoblep Jan 25, 2025
89d4bbd
Add greedy search
ottoblep Jan 25, 2025
0b1637a
Test incremental solution building
ottoblep Jan 25, 2025
d83ae00
Add TODO
ottoblep Jan 27, 2025
8ca4438
Switch to normal second-order euler
ottoblep Jan 27, 2025
685db45
Record score history
ottoblep Jan 28, 2025
80da326
Add unidirectional network template
ottoblep Jan 29, 2025
177253b
Add score history csv export
ottoblep Jan 30, 2025
b26f7d9
Add `ScoreHistoryCollection`
ottoblep Jan 30, 2025
d98ef5e
Add app for collecting simulator statistics
ottoblep Jan 31, 2025
744ec8c
Move dev scripts into subdirectory
ottoblep Jan 31, 2025
9be1a2e
Solve resource conflict in parallel search
ottoblep Jan 31, 2025
38c9522
Limit thread count
ottoblep Jan 31, 2025
eb01427
Improve thread task assignment
ottoblep Jan 31, 2025
11f5d7e
Use explicit time types
ottoblep Feb 1, 2025
a1b9e2d
Expand search abort criteria
ottoblep Feb 1, 2025
1cdad41
Add network conversion script
ottoblep Feb 3, 2025
05f142c
Fix initial edge selection for tests
ottoblep Feb 3, 2025
2982644
Add second executable for simulator
ottoblep Feb 3, 2025
24efa4a
Add converted overtake network
ottoblep Feb 3, 2025
658c592
Remove unused import
ottoblep Feb 3, 2025
0b7ed88
Add local search
ottoblep Feb 4, 2025
fbe6723
Add search method comparison executable
ottoblep Feb 4, 2025
9779335
Remove outdated documentation
ottoblep Feb 4, 2025
87f57ec
Add grasp search
ottoblep Feb 4, 2025
94f9cf2
Update dev scripts for launching apps
ottoblep Feb 4, 2025
93986f3
Introduce local search parameter testing
ottoblep Feb 5, 2025
fe6a110
Improve parameter search and export
ottoblep Feb 5, 2025
b9c0824
Measure on same network
ottoblep Feb 5, 2025
0c96631
Shorten grasp name
ottoblep Feb 5, 2025
c87f526
Update best local search parameters
ottoblep Feb 6, 2025
ebe1f22
Convert Stammstrecke16Trains to unidirectional
ottoblep Feb 6, 2025
a44d106
Add openGA submodule
ottoblep Feb 15, 2025
cf89d0f
Add random solution overload for GA supplied random generator
ottoblep Feb 15, 2025
eb86b60
Remove outdated documentation
ottoblep Feb 15, 2025
78e7c81
Add GA mutate
ottoblep Feb 15, 2025
eec0b71
Add rest of GA helpers
ottoblep Feb 15, 2025
bdb2c7d
Bind member function objects
ottoblep Feb 15, 2025
ebe5e1b
Test genetic algorithm
ottoblep Feb 17, 2025
5938e18
Convert results of genetic search
ottoblep Feb 17, 2025
1a6eac9
Add GA to method comparison
ottoblep Feb 17, 2025
7d4d260
Pass parameters to GA
ottoblep Feb 17, 2025
8a43c46
Avoid copy when binding reference
ottoblep Feb 17, 2025
ebebd88
Add GA parameter search
ottoblep Feb 17, 2025
1b4754e
Fix GA testing parameters
ottoblep Feb 17, 2025
0743725
Add mutation rate to GA param testing
ottoblep Feb 17, 2025
ae384d6
Add GA population parameter testing
ottoblep Feb 18, 2025
ee7ddfa
Add GA elite to parameter testing
ottoblep Feb 18, 2025
e1c6c6e
Add GA with local improvment
ottoblep Feb 19, 2025
9b8c39b
Improve GA testing parameters
ottoblep Feb 19, 2025
3a4fe2c
Improve search parameter passing
ottoblep Feb 21, 2025
4a9110b
Automate measure for multiple networks
ottoblep Feb 24, 2025
8a7df52
Formalize local search params
ottoblep Feb 24, 2025
8956d8a
Prepare conversion to vss solution format
ottoblep Mar 3, 2025
6882224
Finish solution conversion
ottoblep Mar 4, 2025
3934ccd
Add TODO
ottoblep Mar 4, 2025
95f3701
Merge branch 'export-vss-sol' into heuristic-route-generation
ottoblep Mar 4, 2025
12b5079
Adjust optimal genetic params
ottoblep Mar 4, 2025
2a63d95
Add simultaneous measurement
ottoblep Mar 4, 2025
03afb60
Save individual scores in history
ottoblep Mar 6, 2025
ae5eb72
Fix double division
ottoblep Mar 7, 2025
c04c8aa
Further automate testing
ottoblep Mar 8, 2025
741e09d
Add bidirectional networks for exporting simulator solutions
ottoblep Mar 10, 2025
fe0b9d7
Indicate error attempting to export a train skipping tracks
ottoblep Mar 10, 2025
64ff689
Create example network without skipping for testing ExportVSS
ottoblep Mar 10, 2025
2bb739f
Remove TODO
ottoblep Mar 10, 2025
61ebd76
Merge remote-tracking branch 'origin/main' into heuristic-route-gener…
ottoblep Mar 10, 2025
18b8723
Normalize and test summing of objective scores
ottoblep Mar 11, 2025
2823f86
Automate parameter search measurements
ottoblep Mar 11, 2025
effc3e7
Reenable optimization
ottoblep Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bin/
build/
develop-eggs/
dist/
results/
eggs/
lib/
lib64/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "extern/plog"]
path = extern/plog
url = https://github.com/SergiusTheBest/plog.git
[submodule "extern/openGA"]
path = extern/openGA
url = https://github.com/Arash-codedev/openGA.git
5 changes: 5 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ endmacro()

add_sim_executable(vss_generation_timetable_mip_testing)
add_sim_executable(vss_generation_timetable_mip_iterative_vss_testing)
add_sim_executable(vss_generation_timetable_simulator)
add_sim_executable(vss_generation_timetable_simulator_genetic_parameter_testing)
add_sim_executable(vss_generation_timetable_simulator_greedy_parameter_testing)
add_sim_executable(vss_generation_timetable_simulator_local_parameter_testing)
add_sim_executable(vss_generation_timetable_simulator_search_methods_testing)
add_sim_executable(vss_generation_timetable_iterative_parameter_testing)
add_sim_executable(vss_generation_timetable_using_mb_information_testing)
add_sim_executable(gen_po_moving_block_lazy_vss_gen_testing)
Expand Down
53 changes: 53 additions & 0 deletions apps/vss_generation_timetable_simulator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "simulation/RoutingSolver.hpp"

#include <filesystem>
#include <future>

Check warning on line 4 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:4:1 [misc-include-cleaner]

included header future is not used directly
#include <gsl/span>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Initializers/ConsoleInitializer.h>

Check warning on line 8 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:8:1 [misc-include-cleaner]

included header ConsoleInitializer.h is not used directly
#include <plog/Log.h>
#include <string>
#include <thread>

Check warning on line 11 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:11:1 [misc-include-cleaner]

included header thread is not used directly

// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape)

int main(int argc, char** argv) {
// Only log to console using std::cerr and std::cout respectively unless
// initialized differently
if (plog::get() == nullptr) {

Check warning on line 18 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:18:13 [misc-include-cleaner]

no header providing "plog::get" is directly included
static plog::ColorConsoleAppender<plog::TxtFormatter> console_appender;
plog::init(plog::debug, &console_appender);

Check warning on line 20 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:20:11 [misc-include-cleaner]

no header providing "plog::init" is directly included

Check warning on line 20 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:20:22 [misc-include-cleaner]

no header providing "plog::debug" is directly included
}

if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ||

Check warning on line 23 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:23:7 [misc-include-cleaner]

no header providing "strcmp" is directly included

Check warning on line 23 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:23:14 [cppcoreguidelines-pro-bounds-pointer-arithmetic]

do not use pointer arithmetic

Check warning on line 23 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:23:48 [cppcoreguidelines-pro-bounds-pointer-arithmetic]

do not use pointer arithmetic
argc != 3) {
PLOGI << "Usage: vss_generation_timetable_simulator [NETWORK PATH] [OUTPUT "
"PATH]"
<< std::endl;

Check warning on line 27 in apps/vss_generation_timetable_simulator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/vss_generation_timetable_simulator.cpp:27:14 [performance-avoid-endl]

do not use 'std::endl' with streams; use '\n' instead
std::exit(0);
}

auto args = gsl::span<char*>(argv, argc);

const std::string model_path = args[1];
const std::string output_path = args[2];

cda_rail::Network network =
cda_rail::Network::import_network(model_path + "/network");
cda_rail::Timetable timetable =
cda_rail::Timetable::import_timetable(model_path + "/timetable", network);

cda_rail::sim::SimulationInstance instance{network, timetable, false};

cda_rail::sim::RoutingSolver solver{instance};

auto res = solver.greedy_search(std::chrono::seconds{6}, {},
{std::chrono::milliseconds{50}});

if (std::get<0>(res))
std::get<0>(res).value().get_trajectories().export_csv(output_path +
"/result.csv");
}

// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape)
200 changes: 200 additions & 0 deletions apps/vss_generation_timetable_simulator_genetic_parameter_testing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#include "simulation/RoutingSolver.hpp"

#include <filesystem>
#include <future>
#include <gsl/span>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Initializers/ConsoleInitializer.h>
#include <plog/Log.h>
#include <string>
#include <thread>

// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape)

int main(int argc, char** argv) {
auto args = gsl::span<char*>(argv, argc);

const std::string model_path = args[1];
const std::string output_path = args[2];
const std::string model_name =
model_path.substr(model_path.find_last_of("/"), model_path.length());

cda_rail::Network network =
cda_rail::Network::import_network(model_path + "/network");
cda_rail::Timetable timetable =
cda_rail::Timetable::import_timetable(model_path + "/timetable", network);

cda_rail::sim::SimulationInstance instance{network, timetable, false};

size_t processor_count = std::thread::hardware_concurrency();
if (processor_count == 0)
processor_count = 1;

cda_rail::sim::GeneticParams ga_params{
.is_multithread = false,
.population = 1000,
.gen_max = 20,
.stall_max = 5,
.n_elite = 100,
.xover_frac = 0.7,
.mut_rate = 0.1,
};

{
std::vector<double> xover_fractions = {0.01, 0.025, 0.1, 0.5, 0.7, 0.99};

for (double xover_fraction : xover_fractions) {
cda_rail::sim::ScoreHistoryCollection score_coll;
std::mutex hist_mutex;

ga_params.xover_frac = xover_fraction;

std::vector<std::thread> workers;
for (size_t process = 0; process < processor_count; process++) {
workers.push_back(std::thread{[&]() {
cda_rail::sim::RoutingSolver solver{instance};

for (size_t sample_runs = 0; sample_runs < 3; sample_runs++) {
auto res = solver.genetic_search(ga_params);

if (std::get<0>(res)) {
const std::lock_guard<std::mutex> lock(hist_mutex);
score_coll.add(std::get<1>(res));
}
}
}});
}

while (workers.size() > 0) {
workers.back().join();
workers.pop_back();
}

auto save_path =
output_path + "/results/genetic_params/crossover/" + model_name;
cda_rail::is_directory_and_create(save_path);
score_coll.export_csv(save_path + "/score_hist_" +
std::to_string(xover_fraction).substr(0, 5) +
".csv");
}
}

{
std::vector<double> mut_rates = {0.01, 0.1, 0.25, 0.5, 0.75, 0.9, 0.99};

for (double mut_rate : mut_rates) {
cda_rail::sim::ScoreHistoryCollection score_coll;
std::mutex hist_mutex;

ga_params.mut_rate = mut_rate;

std::vector<std::thread> workers;
for (size_t process = 0; process < processor_count; process++) {
workers.push_back(std::thread{[&]() {
cda_rail::sim::RoutingSolver solver{instance};

for (size_t sample_runs = 0; sample_runs < 3; sample_runs++) {
auto res = solver.genetic_search(ga_params);

if (std::get<0>(res)) {
const std::lock_guard<std::mutex> lock(hist_mutex);
score_coll.add(std::get<1>(res));
}
}
}});
}

while (workers.size() > 0) {
workers.back().join();
workers.pop_back();
}

auto save_path =
output_path + "/results/genetic_params/mut_rate/" + model_name;
cda_rail::is_directory_and_create(save_path);
score_coll.export_csv(save_path + "/score_hist_" +
std::to_string(mut_rate).substr(0, 5) + ".csv");
}
}

{
std::vector<size_t> pops = {10, 100, 1000, 10000};

for (size_t pop : pops) {
cda_rail::sim::ScoreHistoryCollection score_coll;
std::mutex hist_mutex;

ga_params.population = pop;
ga_params.n_elite = (size_t)std::round(0.1 * pop);

std::vector<std::thread> workers;
for (size_t process = 0; process < processor_count; process++) {
workers.push_back(std::thread{[&]() {
cda_rail::sim::RoutingSolver solver{instance};

for (size_t sample_runs = 0; sample_runs < 3; sample_runs++) {
auto res = solver.genetic_search(ga_params);

if (std::get<0>(res)) {
const std::lock_guard<std::mutex> lock(hist_mutex);
score_coll.add(std::get<1>(res));
}
}
}});
}

while (workers.size() > 0) {
workers.back().join();
workers.pop_back();
}

auto save_path =
output_path + "/results/genetic_params/pop/" + model_name;
cda_rail::is_directory_and_create(save_path);
score_coll.export_csv(save_path + "/score_hist_" +
std::to_string(pop).substr(0, 5) + ".csv");
}
}

{
std::vector<double> elites = {0.01, 0.05, 0.1, 0.25, 0.5};

for (double elite : elites) {
cda_rail::sim::ScoreHistoryCollection score_coll;
std::mutex hist_mutex;

ga_params.n_elite =
(size_t)std::round(elite * (double)ga_params.population);

std::vector<std::thread> workers;
for (size_t process = 0; process < processor_count; process++) {
workers.push_back(std::thread{[&]() {
cda_rail::sim::RoutingSolver solver{instance};

for (size_t sample_runs = 0; sample_runs < 3; sample_runs++) {
auto res = solver.genetic_search(ga_params);

if (std::get<0>(res)) {
const std::lock_guard<std::mutex> lock(hist_mutex);
score_coll.add(std::get<1>(res));
}
}
}});
}

while (workers.size() > 0) {
workers.back().join();
workers.pop_back();
}

auto save_path =
output_path + "/results/genetic_params/elite/" + model_name;
cda_rail::is_directory_and_create(save_path);
score_coll.export_csv(save_path + "/score_hist_" +
std::to_string(elite).substr(0, 5) + ".csv");
}
}
}

// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "simulation/RoutingSolver.hpp"

#include <filesystem>
#include <future>
#include <gsl/span>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Initializers/ConsoleInitializer.h>
#include <plog/Log.h>
#include <string>
#include <thread>

// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape)

int main(int argc, char** argv) {
auto args = gsl::span<char*>(argv, argc);

const std::string model_path = args[1];
const std::string output_path = args[2];
const std::string model_name =
model_path.substr(model_path.find_last_of("/"), model_path.length());

cda_rail::Network network =
cda_rail::Network::import_network(model_path + "/network");
cda_rail::Timetable timetable =
cda_rail::Timetable::import_timetable(model_path + "/timetable", network);

cda_rail::sim::SimulationInstance instance{network, timetable, false};

size_t processor_count = std::thread::hardware_concurrency();
if (processor_count == 0)
processor_count = 1;

std::vector<size_t> test_timeouts = {1, 2, 5, 10, 50, 100, 250};

for (size_t train_to : test_timeouts) {
cda_rail::sim::ScoreHistoryCollection score_coll;
std::mutex hist_mutex;

std::vector<std::thread> workers;
for (size_t process = 0; process < processor_count; process++) {
workers.push_back(std::thread{[&]() {
cda_rail::sim::RoutingSolver solver{instance};

for (size_t sample = 0; sample < std::floor(100 / processor_count);
sample++) {
auto res =
solver.greedy_search(std::chrono::seconds{6}, {},
{std::chrono::milliseconds{train_to}});

if (std::get<0>(res)) {
const std::lock_guard<std::mutex> lock(hist_mutex);
score_coll.add(std::get<1>(res));
}
}
}});
}

while (workers.size() > 0) {
workers.back().join();
workers.pop_back();
}

auto save_path =
output_path + "/results/greedy_params/stall_time/" + model_name;
cda_rail::is_directory_and_create(save_path);
score_coll.export_csv(save_path + "/score_hist_" +
std::to_string(train_to).substr(0, 5) + ".csv");
}
}

// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape)
Loading
Loading