MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
GreedyHeuristic.hpp
Go to the documentation of this file.
1#ifndef CDA_RAIL_SIMULATOR_GREEDYHEURISTIC_HPP
2#define CDA_RAIL_SIMULATOR_GREEDYHEURISTIC_HPP
3
7
8#include <cstddef>
9#include <cstdint>
10#include <string>
11#include <vector>
12
13namespace cda_rail::simulator {
20enum class RemainingTimeHeuristicType : std::uint8_t { Zero = 0, Simple = 1 };
22constexpr std::string
24 switch (type) {
26 return "Zero";
28 return "Simple";
29 default:
31 "Unknown remaining-time heuristic type");
32 }
33}
34
35// --------------------------
36// Objective Value
45
46[[nodiscard]] inline double
48 const std::vector<double>& tr_exit_times,
49 const std::vector<std::vector<double>>& stop_times) {
50 return instance.get_objective_val(tr_exit_times, stop_times, false);
51}
52
53// ----------------------------
54// Remaining Time Heuristic
55// ----------------------------
56
69// Remaining time heuristics for A*
81 size_t tr,
83 const SimulatorState& state, double tr_exit_time,
84 bool consider_earliest_exit);
85
107 RemainingTimeHeuristicType type, size_t tr,
109 const SimulatorState& state, double tr_exit_time,
110 bool consider_earliest_exit) {
111 switch (type) {
113 return {
114 .feasible = true,
115 .remaining_exit_time = 0.0,
116 .average_remaining_stop_delay = 0.0,
117 };
119 return simple_remaining_time_heuristic(tr, instance, state, tr_exit_time,
120 consider_earliest_exit);
121 }
122 // This should never be reached
124 "This code should not have been reachable...");
125}
126
127// --------------------------
128// Full Heuristic
129// --------------------------
130
136
156 RemainingTimeHeuristicType remaining_time_heuristic_type, size_t tr,
158 const SimulatorState& state, double tr_exit_time,
159 bool consider_earliest_exit);
160
179 RemainingTimeHeuristicType remaining_time_heuristic_type,
181 const SimulatorState& state, const SimulatorResults& sim_results,
182 bool consider_earliest_exit);
183
184} // namespace cda_rail::simulator
185
186#endif // CDA_RAIL_SIMULATOR_GREEDYHEURISTIC_HPP
Thrown when a consistency check fails.
Definition CustomExceptions.hpp:80
An instance in which the trains are routed as efficiently as possible.
Definition GeneralPerformanceOptimizationInstance.hpp:95
double get_objective_val(const std::vector< double > &tr_exit_times, const std::vector< std::vector< double > > &stop_times, bool throw_error_if_not_all_stops_specified=true) const
Evaluates the objective for explicit exit and stop times.
Definition GeneralPerformanceOptimizationInstance.cpp:55
Definition EventSimulator.hpp:25
RemainingTimeHeuristicResult remaining_time_heuristic(RemainingTimeHeuristicType type, size_t tr, const instances::GeneralPerformanceOptimizationInstance &instance, const SimulatorState &state, double tr_exit_time, bool consider_earliest_exit)
Computes a remaining-time heuristic estimate using the selected strategy.
Definition GreedyHeuristic.hpp:106
constexpr std::string remaining_time_heuristic_type_to_string(RemainingTimeHeuristicType const type)
The name of type, as it is reported and parsed.
Definition GreedyHeuristic.hpp:23
RemainingTimeHeuristicType
Which lower bound on the remaining time the A* search uses.
Definition GreedyHeuristic.hpp:20
@ Simple
Definition GreedyHeuristic.hpp:20
@ Zero
Definition GreedyHeuristic.hpp:20
RemainingTimeHeuristicResult simple_remaining_time_heuristic(size_t tr, const instances::GeneralPerformanceOptimizationInstance &instance, const SimulatorState &state, double tr_exit_time, bool consider_earliest_exit)
Computes the simple remaining-time heuristic for one train.
Definition GreedyHeuristic.cpp:15
HeuristicResult full_greedy_heuristic(RemainingTimeHeuristicType remaining_time_heuristic_type, const instances::GeneralPerformanceOptimizationInstance &instance, const SimulatorState &state, const SimulatorResults &sim_results, bool consider_earliest_exit)
Computes a weighted-sum objective-value difference for all trains.
Definition GreedyHeuristic.cpp:121
HeuristicResult greedy_heuristic(RemainingTimeHeuristicType remaining_time_heuristic_type, size_t tr, const instances::GeneralPerformanceOptimizationInstance &instance, const SimulatorState &state, double tr_exit_time, bool consider_earliest_exit)
Combines braking-time and remaining-time heuristics into a single objective-value difference for a tr...
Definition GreedyHeuristic.cpp:105
double objective_val(const instances::GeneralPerformanceOptimizationInstance &instance, const std::vector< double > &tr_exit_times, const std::vector< std::vector< double > > &stop_times)
Computes the objective value based on train exit times and stop times.
Definition GreedyHeuristic.hpp:47
A lower bound on how much the objective still increases.
Definition GreedyHeuristic.hpp:132
double objective_value_difference
Definition GreedyHeuristic.hpp:134
bool feasible
Definition GreedyHeuristic.hpp:133
What a remaining-time heuristic estimates for one train.
Definition GreedyHeuristic.hpp:64
double remaining_exit_time
Definition GreedyHeuristic.hpp:66
double average_remaining_stop_delay
Definition GreedyHeuristic.hpp:67
bool feasible
Definition GreedyHeuristic.hpp:65
What a simulation run produced.
Definition GeneralSimulator.hpp:51
Everything a simulation run needs beyond the instance itself.
Definition GeneralSimulator.hpp:74