1#ifndef CDA_RAIL_SOLVER_ASTAR_BASED_GENPOMOVINGBLOCKASTARSOLVER_HPP
2#define CDA_RAIL_SOLVER_ASTAR_BASED_GENPOMOVINGBLOCKASTARSOLVER_HPP
12#include "gtest/gtest_prod.h"
29#define TEST_FRIENDS false
32class GenPOMovingBlockAStarSolver_NextTrains_Test;
33class GenPOMovingBlockAStarSolver_PathExtensions_Test;
34class GenPOMovingBlockAStarSolver_PathExtensionsCloseToEnd_Test;
35class GenPOMovingBlockAStarSolver_InferInsertionBounds_Test;
36class GenPOMovingBlockAStarSolver_ExtendStateWithPathExtension_Test;
37class GenPOMovingBlockAStarSolver_ExtendTrainOrderEntry_Test;
38class GenPOMovingBlockAStarSolver_ExtendTrainOrderExit_Test;
39class GenPOMovingBlockAStarSolver_ExtendTrainOrderNothingToChange_Test;
40class GenPOMovingBlockAStarSolver_NextStates_Test;
41class GenPOMovingBlockAStarSolver_NextStatesTTD_Test;
46#define DEBUG_LOGGING_RATE 1000
71 return "NextRelevantTTD";
74 "Unknown next-state strategy");
137 instances::GeneralPerformanceOptimizationInstance,
138 instances::SolGeneralPerformanceOptimizationInstance> {
177 std::string_view
const instanceSubdirectory,
178 std::filesystem::path
const& working_directory)
179 :
GeneralSolver(instanceName, instanceSubdirectory, working_directory) {}
209 solve(
int time_limit,
bool debug_input,
bool overwrite_severity)
override {
210 return solve({}, {}, {}, time_limit, debug_input, overwrite_severity);
228 int time_limit = -1,
bool debug_input =
false,
229 bool overwrite_severity =
true);
277 get_relevant_trains_for_state_transition(
291 [[nodiscard]]
static std::vector<cda_rail::index_vector> get_entry_paths(
294 struct PathExtensionData {
296 size_t stop_possible_from_idx_onward{0};
298 bool operator==(
const PathExtensionData& other)
const {
299 return path == other.path && stop_possible_from_idx_onward ==
300 other.stop_possible_from_idx_onward;
313 [[nodiscard]]
static std::vector<PathExtensionData> get_path_extensions(
314 size_t tr, simulator::SimulatorState
const& simulator_state,
316 instances::GeneralPerformanceOptimizationInstance
const* instance,
317 std::vector<cda_rail::index_set>
const& ttd_sections);
324 bool operator==(
const IndexBound& other)
const {
325 return lb == other.lb && ub == other.ub;
338 [[nodiscard]]
static IndexBound infer_order_insertion_bounds(
352 [[nodiscard]]
static IndexBound infer_order_entry_order_bounds(
354 bool late_entry_possible,
bool insert_at_end,
355 instances::GeneralPerformanceOptimizationInstance
const* instance);
367 [[nodiscard]]
static std::vector<simulator::SimulatorState>
368 extend_state_by_path_extension(
369 size_t tr, simulator::SimulatorState state,
370 PathExtensionData
const& path_extension_data,
371 instances::GeneralPerformanceOptimizationInstance
const* instance);
383 [[nodiscard]]
static std::vector<simulator::SimulatorState>
384 extend_train_orders_of_state(
385 size_t tr, simulator::SimulatorState state,
386 const ModelDetailMBAStar& model_detail_input,
387 const SolverStrategyMBAStar& solver_strategy_input,
388 std::vector<cda_rail::index_set>
const& ttd_sections,
389 instances::GeneralPerformanceOptimizationInstance
const* instance);
404 [[nodiscard]]
static std::vector<simulator::SimulatorState>
405 extend_train_orders_of_state_recursive_helper(
406 size_t tr, simulator::SimulatorState state,
407 const SolverStrategyMBAStar& solver_strategy_input,
408 std::vector<cda_rail::index_set>
const& ttd_sections,
409 instances::GeneralPerformanceOptimizationInstance
const* instance,
411 std::optional<size_t>
const& safe_ttd);
429 [[nodiscard]]
static std::vector<simulator::SimulatorState>
430 next_states(
const simulator::SimulatorState& simulator_state,
431 const simulator::SimulatorResults& simulator_results,
432 const ModelDetailMBAStar& model_detail_input,
433 const SolverStrategyMBAStar& solver_strategy_input,
434 instances::GeneralPerformanceOptimizationInstance
const* instance,
435 std::vector<cda_rail::index_set>
const& ttd_sections);
441 struct StateObjectivePair {
442 double simulated_objective_val{};
443 double heuristic_val{};
444 double state_value{};
445 double unweighted_state_value{};
446 bool is_final_state{};
447 simulator::SimulatorState state{};
448 simulator::SimulatorResults results{};
452 struct CompareByObjective {
464 bool operator()(
const StateObjectivePair& a,
465 const StateObjectivePair& b)
const {
466 return (a.state_value > b.state_value) ||
467 (a.state_value == b.state_value && !a.is_final_state &&
469 (a.state_value == b.state_value && !a.is_final_state &&
470 !b.is_final_state && b.state > a.state);
474 using MinPriorityQueue =
475 std::priority_queue<StateObjectivePair, std::vector<StateObjectivePair>,
Thrown when a consistency check fails.
Definition CustomExceptions.hpp:80
S solve()
Solves the problem instance using default configuration.
Definition GeneralSolver.hpp:314
GenPOMovingBlockAStarSolver & operator=(const GenPOMovingBlockAStarSolver &)=default
Copy assignment operator.
S solve()
Solves the problem instance using default configuration.
Definition GeneralSolver.hpp:314
GenPOMovingBlockAStarSolver(GenPOMovingBlockAStarSolver &&)=default
Move constructor.
GenPOMovingBlockAStarSolver(const instances::GeneralPerformanceOptimizationInstance &instance)
Constructs the solver from a performance optimization instance.
Definition GenPOMovingBlockAStarSolver.hpp:166
GenPOMovingBlockAStarSolver & operator=(GenPOMovingBlockAStarSolver &&)=default
Move assignment operator.
GenPOMovingBlockAStarSolver()=default
Constructs a default solver instance.
GenPOMovingBlockAStarSolver(const GenPOMovingBlockAStarSolver &)=default
Copy constructor.
GenPOMovingBlockAStarSolver(std::string_view const instanceName, std::string_view const instanceSubdirectory, std::filesystem::path const &working_directory)
Constructs a solver instance from file-based configuration.
Definition GenPOMovingBlockAStarSolver.hpp:176
instances::SolGeneralPerformanceOptimizationInstance solve(int time_limit, bool debug_input, bool overwrite_severity) override
Solves the problem with default model and strategy configurations.
Definition GenPOMovingBlockAStarSolver.hpp:209
~GenPOMovingBlockAStarSolver() override=default
RemainingTimeHeuristicType
Which lower bound on the remaining time the A* search uses.
Definition GreedyHeuristic.hpp:20
@ Simple
Definition GreedyHeuristic.hpp:20
SimulatorType
Which simulator obtains the trajectories of a state.
Definition GeneralSimulator.hpp:28
@ Greedy
Definition GeneralSimulator.hpp:28
Definition CompletionHeuristic.hpp:10
constexpr std::string next_state_strategy_to_string(NextStateStrategy strategy)
The name of strategy, as it is reported and parsed.
Definition GenPOMovingBlockAStarSolver.hpp:64
NextStateStrategy
How far the trains are moved by one state transition.
Definition GenPOMovingBlockAStarSolver.hpp:57
@ NextRelevantTTD
Definition GenPOMovingBlockAStarSolver.hpp:60
@ SingleEdge
Definition GenPOMovingBlockAStarSolver.hpp:58
@ NextTTD
Definition GenPOMovingBlockAStarSolver.hpp:59
std::unordered_set< size_t > index_set
Definition Definitions.hpp:22
std::vector< size_t > index_vector
Definition Definitions.hpp:21
bool operator==(const FixedSizeVector< T > &lhs, const std::vector< T > &rhs)
Equality comparison between a FixedSizeVector and a std::vector.
Definition FixedSizeVector.hpp:276
What a simulation run produced.
Definition GeneralSimulator.hpp:51
Everything a simulation run needs beyond the instance itself.
Definition GeneralSimulator.hpp:74
Where a solver writes its solution to, see GeneralSolver::export_general_solution.
Definition GeneralSolver.hpp:61
What the simulation underlying the A* search does.
Definition GenPOMovingBlockAStarSolver.hpp:85
bool limit_speed_by_leaving_edges
Definition GenPOMovingBlockAStarSolver.hpp:89
double dt
Definition GenPOMovingBlockAStarSolver.hpp:86
bool late_entry_possible
Definition GenPOMovingBlockAStarSolver.hpp:88
simulator::SimulatorType simulator_type
Definition GenPOMovingBlockAStarSolver.hpp:87
How the A* search itself explores the states.
Definition GenPOMovingBlockAStarSolver.hpp:104
bool time_aware_state_transitions
Definition GenPOMovingBlockAStarSolver.hpp:109
NextStateStrategy next_state_strategy
Definition GenPOMovingBlockAStarSolver.hpp:107
double a_star_weight
Definition GenPOMovingBlockAStarSolver.hpp:110
size_t completion_interval
Definition GenPOMovingBlockAStarSolver.hpp:111
simulator::RemainingTimeHeuristicType remaining_time_heuristic_type
Definition GenPOMovingBlockAStarSolver.hpp:105
bool consider_earliest_exit
Definition GenPOMovingBlockAStarSolver.hpp:108