1#ifndef CDA_RAIL_PROBLEMINSTANCES_GENERALPERFORMANCEOPTIMIZATIONINSTANCE_HPP
2#define CDA_RAIL_PROBLEMINSTANCES_GENERALPERFORMANCEOPTIMIZATIONINSTANCE_HPP
10#include "nlohmann/json_fwd.hpp"
13#include "gtest/gtest_prod.h"
32#define TEST_FRIENDS false
35class GeneralPerformanceOptimizationInstances;
36class GeneralPerformanceOptimizationInstances_PointerCopyIssue_Test;
38 GeneralPerformanceOptimizationInstances_ScheduledStopPointerCopyIssue_Test;
99 FRIEND_TEST(::GeneralPerformanceOptimizationInstances, PointerCopyIssue);
100 FRIEND_TEST(::GeneralPerformanceOptimizationInstances,
101 ScheduledStopPointerCopyIssue);
104 std::vector<double> m_train_weights{};
105 double m_station_delay_weight{1};
122 initialize_vectors();
132 std::move(network), std::move(timetable), std::move(routes)) {
133 initialize_vectors();
136 std::string_view instance_name, std::string_view instance_subdirectory,
137 std::filesystem::path
const& working_directory);
156 const std::vector<std::vector<double>>& stop_times,
157 bool throw_error_if_not_all_stops_specified =
true)
const;
171 const std::vector<std::vector<double>>& arrival_times)
const;
210 bool include_first_edge,
double start_time,
212 bool consider_earliest_departures)
const;
223 std::string_view
const instanceName,
224 std::string_view
const instanceSubdirectory,
225 std::string
const& working_directory)
227 instanceName, instanceSubdirectory,
228 std::filesystem::path(working_directory)) {}
239 std::string_view
const instanceName,
240 std::string_view
const instanceSubdirectory,
241 char const*
const workingDirectory)
243 instanceName, instanceSubdirectory,
244 std::filesystem::path(workingDirectory)) {}
256 return m_train_weights;
265 return m_station_delay_weight;
277 return m_train_weights.at(train_index);
313 m_station_delay_weight = new_weight;
325 m_train_weights.at(train_index) = weight;
369 size_t add_train(std::string
const& train_name,
double length,
370 double max_speed,
double acceleration,
double deceleration,
371 bool tim,
double entry_time,
double initial_velocity,
373 double exit_velocity,
375 double tr_weight = 1) {
377 train_name, length, max_speed, acceleration, deceleration, tim,
378 entry_time, initial_velocity, entry_vertex, exit_time, exit_velocity,
380 m_train_weights.emplace_back(tr_weight);
402 size_t add_train(std::string
const& train_name,
double length,
403 double max_speed,
double acceleration,
double deceleration,
404 double entry_time,
double initial_velocity,
406 double exit_velocity,
408 double tr_weight = 1) {
409 return add_train(train_name, length, max_speed, acceleration, deceleration,
410 true, entry_time, initial_velocity, entry_vertex,
411 exit_time, exit_velocity, exit_vertex, tr_weight);
421 bool save_network)
const override;
521 void initialize_vectors() {
522 m_train_weights.resize(
530 [[nodiscard]] std::pair<size_t, size_t>
532 bool tn_inclusive =
true)
const {
536 [[nodiscard]] std::pair<size_t, size_t>
538 bool tn_inclusive =
true)
const {
558 std::vector<std::pair<size_t, cda_rail::index_vector>>
643 std::vector<std::map<double, double>> m_train_pos;
644 std::vector<std::map<double, double>> m_train_speed;
646 std::vector<double> m_train_exit_times;
647 std::vector<std::vector<double>> m_train_stop_times;
649 std::optional<SolutionEvaluation> m_evaluation;
652 void initialize_vectors();
692 this->initialize_vectors();
708 status, obj, has_sol) {
709 this->initialize_vectors();
731 const std::filesystem::path& working_directory,
732 std::string_view solution_subdirectory,
733 std::optional<std::
string> const& parameter_identifier) override;
739 const std::filesystem::path& working_directory,
740 std::string_view const solutionSubdirectory,
741 std::optional<std::
string> const& parameter_identifier)
const override {
743 parameter_identifier);
756 const std::filesystem::path& working_directory,
757 std::string_view solution_subdirectory,
bool save_instance,
758 std::optional<std::string>
const& parameter_identifier)
const override;
780 [[nodiscard]]
double get_train_pos(
const std::string& tr_name,
850 [[nodiscard]] std::optional<PosVel>
869 [[nodiscard]] std::vector<double>
890 [[nodiscard]] std::vector<TrainDirection>
902 [[nodiscard]]
double get_time_at_pos(
const std::string& tr_name,
double pos,
903 bool ub =
false)
const;
911 [[nodiscard]]
double get_exit_time(
const std::string& tr_name)
const;
918 [[nodiscard]] std::vector<double>
927 [[nodiscard]]
double get_stop_time(
const std::string& tr_name,
928 const std::string& station_name)
const;
936 [[nodiscard]]
double get_stop_time(
const std::string& tr_name,
937 size_t stop_index)
const;
948 void add_train_pos(
const std::string& tr_name,
double t,
double pos);
956 void add_train_speed(
const std::string& tr_name,
double t,
double speed);
982 std::string
const& station_name,
double stop_time);
990 std::vector<double> stop_times);
1003 void set_stop_times(
const std::vector<std::vector<double>>& stop_times);
1040 [[nodiscard]]
const std::optional<SolutionEvaluation>&
1042 return m_evaluation;
1065 std::vector<std::vector<double>> m_vss_pos;
1067 void initialize_vss_vector();
1096 this->initialize_vss_vector();
1103 this->initialize_vss_vector();
1107 bool reverse_edge =
true);
1109 std::vector<double> pos);
1111 [[nodiscard]] std::vector<double>
1114 [[nodiscard]] std::vector<double>
1118 const std::filesystem::path& working_directory,
1119 std::string_view solution_subdirectory,
bool export_instance,
1120 std::optional<std::string>
const& parameter_identifier)
const override;
1125 const std::filesystem::path& working_directory,
1126 std::string_view solution_subdirectory,
1127 std::optional<std::string>
const& parameter_identifier)
override;
Directed multigraph representing a railway network.
Definition RailwayNetwork.hpp:163
Collection of named train routes built on top of a railway network.
Definition Route.hpp:374
size_t add_train(std::string const &train_name, double length, double max_speed, double acceleration, double deceleration, bool tim, double entry_time, double initial_velocity, Network::VertexInput const &entry_vertex, double exit_time, double exit_velocity, Network::VertexInput const &exit_vertex)
Adds a train with the specified properties to the timetable.
Definition GeneralProblemInstance.hpp:697
virtual void export_instance(std::filesystem::path const &working_directory, bool save_network) const
Exports the instance and optionally its network.
Definition GeneralProblemInstance.cpp:93
const auto & get_const_timetable() const
Accesses the timetable.
Definition GeneralProblemInstance.hpp:330
GeneralProblemInstanceWithScheduleAndRoutes()=default
Constructs an empty problem instance with schedule and routes.
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.
Definition GeneralProblemInstance.cpp:567
SolGeneralProblemInstanceWithScheduleAndRoutes(std::shared_ptr< GeneralProblemInstanceWithScheduleAndRoutes > instance_ptr)
Initializes a solution wrapper for a schedule-and-routes problem instance.
Definition GeneralProblemInstance.hpp:1241
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.
Definition GeneralProblemInstance.hpp:1419
GeneralProblemInstance const * get_uncast_instance_pointer() const
Retrieves the underlying problem instance pointer.
Definition GeneralProblemInstance.hpp:1006
StopDiscretization(StopDiscretization &&)=delete
StopDiscretization(GeneralPerformanceOptimizationInstance &instance)
Separates the station tracks of instance.
Definition GeneralPerformanceOptimizationInstance.cpp:259
StopDiscretization & operator=(StopDiscretization &&)=delete
const GeneralPerformanceOptimizationInstance & original() const
The instance as it was before its station tracks were separated.
Definition GeneralPerformanceOptimizationInstance.hpp:591
StopDiscretization & operator=(const StopDiscretization &)=delete
StopDiscretization(const StopDiscretization &)=delete
~StopDiscretization()
Restores the original instance.
Definition GeneralPerformanceOptimizationInstance.cpp:272
A separation function together with the name it is known by.
Definition VSSModel.hpp:32
Definition GeneralPerformanceOptimizationInstance.hpp:41
constexpr SeparationFunction UNIFORM
The separation functions that are known by name.
Definition VSSModel.hpp:194
constexpr double INF
Definition Definitions.hpp:25
std::unordered_set< size_t > index_set
Definition Definitions.hpp:22
std::vector< size_t > index_vector
Definition Definitions.hpp:21
SolutionStatus
What a solver was able to say about the instance it was given.
Definition Definitions.hpp:55
Earliest times at which a train can reach its remaining schedule.
Definition GeneralPerformanceOptimizationInstance.hpp:51
bool feasible
Whether the remaining schedule can be served at all.
Definition GeneralPerformanceOptimizationInstance.hpp:58
double exit_arrival
Earliest time at which the train's front can be at its exit vertex with every considered stop served.
Definition GeneralPerformanceOptimizationInstance.hpp:78
std::vector< double > stop_arrivals
Earliest arrival of the train's front at a stop vertex of the respective station, before its service.
Definition GeneralPerformanceOptimizationInstance.hpp:66
The delays of the trains in one simulation of a solution's decisions.
Definition GeneralPerformanceOptimizationInstance.hpp:603
std::vector< double > exit_times
Definition GeneralPerformanceOptimizationInstance.hpp:606
std::vector< double > exit_delays
Definition GeneralPerformanceOptimizationInstance.hpp:607
std::vector< std::vector< double > > stop_delays
Definition GeneralPerformanceOptimizationInstance.hpp:609
double obj
Definition GeneralPerformanceOptimizationInstance.hpp:605
bool success
Definition GeneralPerformanceOptimizationInstance.hpp:604
std::vector< std::vector< double > > stop_times
Definition GeneralPerformanceOptimizationInstance.hpp:608
What simulating the decisions of a solution yields, see SolGeneralPerformanceOptimizationInstance::ev...
Definition GeneralPerformanceOptimizationInstance.hpp:624
SimulatedDelays trajectory
Definition GeneralPerformanceOptimizationInstance.hpp:626
double dt
Definition GeneralPerformanceOptimizationInstance.hpp:625
SimulatedDelays greedy
Definition GeneralPerformanceOptimizationInstance.hpp:627
index_vector trains_violating_dynamics
Definition GeneralPerformanceOptimizationInstance.hpp:628