|
MTCT
Design Automation and Optimization for ETCS Railway Networks
|
The trajectories a solver found for a performance optimization instance. More...
#include <GeneralPerformanceOptimizationInstance.hpp>
Classes | |
| struct | EvaluationSetup |
| The network and sections the simulation of evaluate() runs on. More... | |
| struct | EdgeTimeBound |
| struct | PosBound |
| struct | VelBound |
| struct | PosVelBound |
| struct | PosVel |
| struct | TrainDirection |
Public Member Functions | |
| SolGeneralPerformanceOptimizationInstance (const GeneralPerformanceOptimizationInstance &instance) | |
| Initializes a solution object for a performance optimization problem instance. | |
| SolGeneralPerformanceOptimizationInstance (const GeneralPerformanceOptimizationInstance &instance, SolutionStatus status, double obj, bool has_sol) | |
| Constructs a solution instance with metadata for the given optimization problem. | |
| SolGeneralPerformanceOptimizationInstance (SolGeneralPerformanceOptimizationInstance const &)=default | |
| Constructs a copy of an existing solution instance. | |
| SolGeneralPerformanceOptimizationInstance & | operator= (SolGeneralPerformanceOptimizationInstance const &)=default |
| SolGeneralPerformanceOptimizationInstance (SolGeneralPerformanceOptimizationInstance &&) noexcept=default | |
| SolGeneralPerformanceOptimizationInstance & | operator= (SolGeneralPerformanceOptimizationInstance &&) noexcept=default |
| ~SolGeneralPerformanceOptimizationInstance () override=default | |
| Virtual destructor. | |
| void | load_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory, std::optional< std::string > const ¶meter_identifier) override |
| void | export_solution (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier) const override |
| Exports the solution without saving the instance. | |
| void | export_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory, bool save_instance, std::optional< std::string > const ¶meter_identifier) const override |
| Exports the solution, optionally including the instance data. | |
| GeneralPerformanceOptimizationInstance const * | get_instance () const override |
| Retrieves the underlying problem instance. | |
| double | get_train_pos (const std::string &tr_name, double t) const |
| Returns the stored position of a train at a given time. | |
| EdgeTimeBound | get_edge_and_time_bounds (const std::string &tr_name, double t) const |
| Returns the containing edge and surrounding time bounds. | |
| PosVelBound | get_exact_pos_and_vel_bounds (const std::string &tr_name, double t) const |
| Returns exact lower and upper bounds on position and velocity. | |
| std::optional< PosVel > | get_approximate_train_pos_and_vel (const std::string &tr_name, double t) const |
| Returns an approximate position/velocity pair if available. | |
| double | get_train_speed (const std::string &tr_name, double t) const |
| Returns the stored train speed at a given time. | |
| std::vector< double > | get_train_times (const std::string &tr_name) const |
| Returns all recorded times for one train. | |
| cda_rail::index_vector | get_train_order (size_t edge_index) const |
| Returns train order on a given edge. | |
| std::vector< TrainDirection > | get_train_order_with_reverse (size_t edge_index) const |
| Returns train order on a given edge together with orientation. | |
| double | get_time_at_pos (const std::string &tr_name, double pos, bool ub=false) const |
| Returns the time at which a train reaches a route position. | |
| double | get_exit_time (const std::string &tr_name) const |
| Returns the stored exit time of a train. | |
| std::vector< double > | get_stop_times (const std::string &tr_name) const |
| Returns all stored stop times of a train. | |
| double | get_stop_time (const std::string &tr_name, const std::string &station_name) const |
| Returns one stored stop time identified by station name. | |
| double | get_stop_time (const std::string &tr_name, size_t stop_index) const |
| Returns one stored stop time identified by stop index. | |
| void | add_train_pos (const std::string &tr_name, double t, double pos) |
| Stores a train position sample. | |
| void | add_train_speed (const std::string &tr_name, double t, double speed) |
| Stores a train speed sample. | |
| void | set_train_exit_time (const std::string &tr_name, double t) |
| Stores the exit time of a train. | |
| void | set_train_stop_time (const std::string &tr_name, size_t stop_idx, double stop_time) |
| Stores one stop time identified by stop index. | |
| void | set_train_stop_time (const std::string &tr_name, std::string const &station_name, double stop_time) |
| Stores one stop time identified by station name. | |
| void | set_train_stop_times (const std::string &tr_name, std::vector< double > stop_times) |
| Replaces all stop times of one train. | |
| void | set_exit_times (const std::vector< double > &exit_times) |
| Replaces all stored exit times. | |
| void | set_stop_times (const std::vector< std::vector< double > > &stop_times) |
| Replaces all stored stop times. | |
| void | evaluate (double dt) |
| Simulates the decisions of this solution greedily and stores the resulting delays, which are exported with the solution. | |
| const std::optional< SolutionEvaluation > & | get_evaluation () const |
| Returns the result of the last evaluate(), if any. | |
| bool | check_consistency () const override |
| Checks whether the stored performance-optimization solution is consistent. | |
| void | export_solution (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory) const override |
| Exports the solution without saving the problem instance. | |
| void | load_solution (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory) override |
| Loads a solution from the specified working directory and solution subdirectory. | |
| Public Member Functions inherited from cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes | |
| SolGeneralProblemInstanceWithScheduleAndRoutes (GeneralProblemInstanceWithScheduleAndRoutes const &instance) | |
| Creates a solution wrapper from a problem instance. | |
| SolGeneralProblemInstanceWithScheduleAndRoutes (GeneralProblemInstanceWithScheduleAndRoutes const &instance, SolutionStatus status, double obj, bool has_sol) | |
| Initializes a solution wrapper around a copy of the provided instance. | |
| SolGeneralProblemInstanceWithScheduleAndRoutes (const SolGeneralProblemInstanceWithScheduleAndRoutes &)=default | |
| SolGeneralProblemInstanceWithScheduleAndRoutes & | operator= (const SolGeneralProblemInstanceWithScheduleAndRoutes &)=default |
| SolGeneralProblemInstanceWithScheduleAndRoutes (SolGeneralProblemInstanceWithScheduleAndRoutes &&) noexcept=default | |
| SolGeneralProblemInstanceWithScheduleAndRoutes & | operator= (SolGeneralProblemInstanceWithScheduleAndRoutes &&) noexcept=default |
| ~SolGeneralProblemInstanceWithScheduleAndRoutes () override=default | |
| void | load_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory, std::optional< std::string > const ¶meter_identifier) override |
| Loads the route-aware part of a solution from disk. | |
| void | load_solution (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory) override |
| Loads a solution from the specified working directory and solution subdirectory. | |
| GeneralProblemInstanceWithScheduleAndRoutes const * | get_instance () const override |
| Accesses the underlying schedule-and-routes problem instance. | |
| RouteMap const & | get_const_solution_routes () const |
| Retrieves the solution routes. | |
| double | route_length (const std::string &train_name) const |
| Computes the total length of a train's solution route. | |
| void | reset_routes () |
| Resets solution routes to the instance's fixed routes. | |
| void | add_empty_route (const std::string &train_name) |
| Adds an empty solution route for a train. | |
| void | push_back_edge_to_route (const std::string &train_name, Network::EdgeInput const &edge_input) |
| Appends an edge to the end of a train's solution route. | |
| void | push_front_edge_to_route (const std::string &train_name, Network::EdgeInput const &edge_input) |
| Adds an edge to the front of the solution route for a train. | |
| void | remove_first_edge_from_route (const std::string &train_name) |
| Removes the first edge from a train's route in the solution. | |
| void | remove_last_edge_from_route (const std::string &train_name) |
| Removes the last edge from a train's route in the solution. | |
| Route::EdgePosition | route_edge_pos (const std::string &train_name, Network::EdgeInput const &edge) const |
| Determines the position of an edge on a train's solution route. | |
| void | export_solution (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier) const override |
| Exports the solution without saving the underlying instance. | |
| void | export_solution (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory) const override |
| Exports the solution without saving the problem instance. | |
| bool | check_consistency () const override |
| Checks whether the solution routes are consistent with the instance. | |
| void | export_solution (const std::string &path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) const |
| Exports the solution to the specified directory. | |
| void | export_solution (const char *path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) const |
| Exports the solution to the specified directory and subdirectory. | |
| void | load_solution (const std::string &path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) |
| Loads a solution from the specified path. | |
| void | load_solution (const char *path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) |
| Loads a solution from the specified location. | |
| Public Member Functions inherited from cda_rail::instances::SolGeneralProblemInstance | |
| std::filesystem::path | get_export_path (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier) const |
| Computes the file path for exporting a solution. | |
| SolutionStatus | get_status () const |
| Retrieves the current solution status. | |
| double | get_obj () const |
| Gets the objective value of the solution. | |
| double | get_lower_bound () const |
| Gets the lower bound on the objective value of the solution. | |
| bool | has_solution () const |
| Indicates whether a solution has been found. | |
| void | set_status (SolutionStatus new_status) |
| Sets the solution status. | |
| void | set_obj (double new_obj) |
| Sets the objective value of the solution. | |
| void | set_lower_bound (double new_lb) |
| Sets the lower bound of the objective value of the solution. | |
| void | set_solution_found () |
| Marks the solution as found. | |
| void | set_solution_not_found () |
| Marks that no solution has been found. | |
| void | load_solution (const std::string &path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) |
| Loads a solution from the specified path. | |
| void | load_solution (const char *path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) |
| Loads a solution from the specified location. | |
| void | export_solution (const std::string &path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) const |
| Exports the solution to the specified directory. | |
| void | export_solution (const char *path, std::string_view const solutionSubdirectory, std::optional< std::string > const ¶meter_identifier={}) const |
| Exports the solution to the specified directory and subdirectory. | |
| virtual | ~SolGeneralProblemInstance ()=default |
| Virtual destructor. | |
| SolGeneralProblemInstance (SolGeneralProblemInstance const &)=default | |
| SolGeneralProblemInstance & | operator= (SolGeneralProblemInstance const &)=default |
| SolGeneralProblemInstance (SolGeneralProblemInstance &&) noexcept=default | |
| SolGeneralProblemInstance & | operator= (SolGeneralProblemInstance &&) noexcept=default |
Protected Member Functions | |
| virtual EvaluationSetup | get_evaluation_setup () const |
| Prepares the simulation of evaluate(). | |
| nlohmann::json | get_general_solution_data () const override |
| Adds the evaluation, if any, to the solution-wide metadata. | |
| void | set_general_solution_data (const nlohmann::json &data) override |
| Loads the solution-wide metadata including the evaluation. | |
| Protected Member Functions inherited from cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes | |
| SolGeneralProblemInstanceWithScheduleAndRoutes (std::shared_ptr< GeneralProblemInstanceWithScheduleAndRoutes > instance_ptr) | |
| Initializes a solution wrapper for a schedule-and-routes problem instance. | |
| SolGeneralProblemInstanceWithScheduleAndRoutes (std::shared_ptr< GeneralProblemInstanceWithScheduleAndRoutes > instance_ptr, SolutionStatus status, double obj, bool has_sol) | |
| Initializes a solution instance with an existing problem instance and solution metadata. | |
| Protected Member Functions inherited from cda_rail::instances::SolGeneralProblemInstance | |
| SolGeneralProblemInstance (std::shared_ptr< GeneralProblemInstance > instance_ptr) | |
| Creates a solution wrapper around the given problem instance. | |
| SolGeneralProblemInstance (std::shared_ptr< GeneralProblemInstance > instance_ptr, SolutionStatus status, double obj, bool has_sol) | |
| Constructs a solution instance with problem instance and solution metadata. | |
| GeneralProblemInstance const * | get_uncast_instance_pointer () const |
| Retrieves the underlying problem instance pointer. | |
The trajectories a solver found for a performance optimization instance.
Positions and velocities are stored per train as samples over time, which the solvers fill at the points in time their model knows about. The exit and stop times are stored separately, since they are what the objective is evaluated on.
|
inlineexplicit |
Initializes a solution object for a performance optimization problem instance.
| instance | The problem instance to associate with this solution. |
|
inline |
Constructs a solution instance with metadata for the given optimization problem.
| instance | The optimization problem instance to solve. |
| status | The solution status. |
| obj | The objective value. |
| has_sol | Whether a valid solution has been obtained. |
|
default |
Constructs a copy of an existing solution instance.
|
defaultnoexcept |
|
overridedefault |
Virtual destructor.
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::add_train_pos | ( | const std::string & | tr_name, |
| double | t, | ||
| double | pos ) |
Stores a train position sample.
| tr_name | Name of the train. |
| t | Sample time. |
| pos | Sample position. |
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::add_train_speed | ( | const std::string & | tr_name, |
| double | t, | ||
| double | speed ) |
Stores a train speed sample.
| tr_name | Name of the train. |
| t | Sample time. |
| speed | Sample speed. |
|
nodiscardoverridevirtual |
Checks whether the stored performance-optimization solution is consistent.
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::evaluate | ( | double | dt | ) |
Simulates the decisions of this solution greedily and stores the resulting delays, which are exported with the solution.
The routes, the orders in which the trains pass every block section and every entry and exit vertex, and the stop positions are taken from this solution. Every train then drives as fast as the greedy simulator allows. This is done twice, see SolutionEvaluation. In the first simulation, neither the front nor the braking point of a train may get ahead of the train of this solution at the same time, so that the timing of this solution is not overtaken. If the trajectory of a train follows its acceleration and deceleration, up to the precision to which positions are rounded, the train hence leaves no earlier than in this solution. Its exit time is then not enforced separately, so that it may leave the network as slowly as in this solution. Between two samples of this solution, its trajectory is approximated by a constant line speed, bounded by what the next sample fixes exactly. In the second simulation, the trains are only bound by the decisions, as in the A* search. In both, trains may enter later than scheduled, which then shows up as delay. The objective is that of the instance evaluated at the simulated times.
| dt | Time step of the simulation in seconds. |
| cda_rail::exceptions::ConsistencyException | If there is no solution to evaluate. |
|
inlineoverridevirtual |
Exports the solution without saving the problem instance.
Exports only the solution data (routes) to the specified directory without exporting the underlying problem instance.
| working_directory | Root working directory for the solution export. |
| solutionSubdirectory | Subdirectory within the solutions folder for this solution. |
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
|
inlineoverridevirtual |
Exports the solution without saving the instance.
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
|
overridevirtual |
Exports the solution, optionally including the instance data.
| working_directory | Base export directory. |
| solution_subdirectory | Solution subdirectory. |
| save_instance | Whether to export the instance as well. |
| parameter_identifier | Optional parameter identifier for the export path. |
Reimplemented from cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
|
nodiscard |
Returns an approximate position/velocity pair if available.
Between two stored states, the train is assumed to change its speed fully to a line speed, drive at it and change it fully to the next stored speed. The line speed is found by a bisection that stops as soon as the candidate speeds differ by at most LINE_SPEED_ACCURACY or the travel time is less than LINE_SPEED_TIME_ACCURACY too short, and the faster candidate is used. Hence, the profile can end before the next stored time. From then on, the position and speed of the next stored state are returned.
| tr_name | Name of the train. |
| t | Query time. |
|
nodiscard |
Returns the containing edge and surrounding time bounds.
Between the train's last sample and its exit time, both time bounds are the last sample.
| tr_name | Name of the train. |
| t | Query time. |
t.
|
inlinenodiscard |
Returns the result of the last evaluate(), if any.
|
nodiscardprotectedvirtual |
Prepares the simulation of evaluate().
Under moving block, the instance and its routes are used as they are and only the unbreakable sections are block sections.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
|
nodiscard |
Returns exact lower and upper bounds on position and velocity.
The bounds intersect the states reachable from the stored state before t with the states from which the stored state after t is still reachable, given the train's acceleration, deceleration and speed limit as well as the highest speed limit of the edges between both states. Up to what corresponds to GRB_EPS in time for each bound, the lower bounds do not exceed the upper bounds. Otherwise, e.g., if the stored times are not physically possible, only the former are used.
| tr_name | Name of the train. |
| t | Query time. |
t.
|
nodiscard |
Returns the stored exit time of a train.
| tr_name | Name of the train. |
|
nodiscardoverrideprotectedvirtual |
Adds the evaluation, if any, to the solution-wide metadata.
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
|
inlinenodiscardoverridevirtual |
Retrieves the underlying problem instance.
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
|
nodiscard |
Returns one stored stop time identified by station name.
| tr_name | Name of the train. |
| station_name | Name of the station. |
|
nodiscard |
Returns one stored stop time identified by stop index.
| tr_name | Name of the train. |
| stop_index | Stop index in schedule order. |
|
nodiscard |
Returns all stored stop times of a train.
| tr_name | Name of the train. |
|
nodiscard |
Returns the time at which a train reaches a route position.
| tr_name | Name of the train. |
| pos | Position on the route. |
| ub | Whether to return a upper-bound on the time if no exact timing is available. |
pos.
|
nodiscard |
Returns train order on a given edge.
| edge_index | Edge index. |
|
nodiscard |
Returns train order on a given edge together with orientation.
| edge_index | Edge index. |
|
nodiscard |
Returns the stored position of a train at a given time.
| tr_name | Name of the train. |
| t | Query time. |
|
nodiscard |
Returns the stored train speed at a given time.
| tr_name | Name of the train. |
| t | Query time. |
|
nodiscard |
Returns all recorded times for one train.
| tr_name | Name of the train. |
|
inlineoverridevirtual |
Loads a solution from the specified working directory and solution subdirectory.
| working_directory | The root directory containing solutions. |
| solutionSubdirectory | The solution subdirectory within the working directory. |
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
|
overridevirtual |
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
Reimplemented in cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.
|
defaultnoexcept |
|
default |
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::set_exit_times | ( | const std::vector< double > & | exit_times | ) |
Replaces all stored exit times.
| exit_times | Exit times indexed by train. |
|
overrideprotectedvirtual |
Loads the solution-wide metadata including the evaluation.
Reimplemented from cda_rail::instances::SolGeneralProblemInstance.
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::set_stop_times | ( | const std::vector< std::vector< double > > & | stop_times | ) |
Replaces all stored stop times.
| stop_times | Stop times indexed by train and stop. |
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::set_train_exit_time | ( | const std::string & | tr_name, |
| double | t ) |
Stores the exit time of a train.
| tr_name | Name of the train. |
| t | Exit time to store. |
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::set_train_stop_time | ( | const std::string & | tr_name, |
| size_t | stop_idx, | ||
| double | stop_time ) |
Stores one stop time identified by stop index.
| tr_name | Name of the train. |
| stop_idx | Stop index in schedule order. |
| stop_time | Stop time to store. |
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::set_train_stop_time | ( | const std::string & | tr_name, |
| std::string const & | station_name, | ||
| double | stop_time ) |
Stores one stop time identified by station name.
| tr_name | Name of the train. |
| station_name | Name of the station. |
| stop_time | Stop time to store. |
| void cda_rail::instances::SolGeneralPerformanceOptimizationInstance::set_train_stop_times | ( | const std::string & | tr_name, |
| std::vector< double > | stop_times ) |
Replaces all stop times of one train.
| tr_name | Name of the train. |
| stop_times | Stop times in schedule order. |