MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
cda_rail::instances::SolGeneralProblemInstance Class Reference

Base of every solution object. More...

#include <GeneralProblemInstance.hpp>

Inheritance diagram for cda_rail::instances::SolGeneralProblemInstance:
cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes cda_rail::instances::SolGeneralPerformanceOptimizationInstance cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance

Public Member Functions

std::filesystem::path get_export_path (const std::filesystem::path &working_directory, std::string_view const solutionSubdirectory, std::optional< std::string > const &parameter_identifier) const
 Computes the file path for exporting a solution.
virtual GeneralProblemInstance const * get_instance () const
 Provides access to the problem instance.
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.
virtual void load_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory, std::optional< std::string > const &parameter_identifier)
virtual void load_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory)
 Loads a solution from the specified working directory and solution subdirectory.
void load_solution (const std::string &path, std::string_view const solutionSubdirectory, std::optional< std::string > const &parameter_identifier={})
 Loads a solution from the specified path.
void load_solution (const char *path, std::string_view const solutionSubdirectory, std::optional< std::string > const &parameter_identifier={})
 Loads a solution from the specified location.
virtual void export_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory, std::optional< std::string > const &parameter_identifier) const
virtual void export_solution (const std::filesystem::path &working_directory, std::string_view solution_subdirectory) const
 Exports the solution without a parameter identifier.
void export_solution (const std::string &path, std::string_view const solutionSubdirectory, std::optional< std::string > const &parameter_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 &parameter_identifier={}) const
 Exports the solution to the specified directory and subdirectory.
virtual bool check_consistency () const
 Checks whether the stored solution metadata is consistent.
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

 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.
virtual nlohmann::json get_general_solution_data () const
 Serializes solution-wide metadata to JSON.
virtual void set_general_solution_data (const nlohmann::json &data)
 Loads solution-wide metadata from JSON.
GeneralProblemInstance const * get_uncast_instance_pointer () const
 Retrieves the underlying problem instance pointer.

Detailed Description

Base of every solution object.

A solution owns a copy of the instance it belongs to, so that it stays interpretable on its own, and stores what the solver was able to achieve, namely its status, its objective value and the best bound it proved.

Constructor & Destructor Documentation

◆ SolGeneralProblemInstance() [1/4]

cda_rail::instances::SolGeneralProblemInstance::SolGeneralProblemInstance ( std::shared_ptr< GeneralProblemInstance > instance_ptr)
inlineexplicitprotected

Creates a solution wrapper around the given problem instance.

◆ SolGeneralProblemInstance() [2/4]

cda_rail::instances::SolGeneralProblemInstance::SolGeneralProblemInstance ( std::shared_ptr< GeneralProblemInstance > instance_ptr,
SolutionStatus status,
double obj,
bool has_sol )
inlineprotected

Constructs a solution instance with problem instance and solution metadata.

Parameters
instance_ptrProblem instance.
statusSolution status.
objObjective value.
has_solWhether a solution exists.

◆ ~SolGeneralProblemInstance()

virtual cda_rail::instances::SolGeneralProblemInstance::~SolGeneralProblemInstance ( )
virtualdefault

Virtual destructor.

◆ SolGeneralProblemInstance() [3/4]

cda_rail::instances::SolGeneralProblemInstance::SolGeneralProblemInstance ( SolGeneralProblemInstance const & )
default

◆ SolGeneralProblemInstance() [4/4]

cda_rail::instances::SolGeneralProblemInstance::SolGeneralProblemInstance ( SolGeneralProblemInstance && )
defaultnoexcept

Member Function Documentation

◆ check_consistency()

bool cda_rail::instances::SolGeneralProblemInstance::check_consistency ( ) const
nodiscardvirtual

Checks whether the stored solution metadata is consistent.

Returns
true if the solution state is consistent, otherwise false.

Reimplemented in cda_rail::instances::SolGeneralPerformanceOptimizationInstance, cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes, and cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.

◆ export_solution() [1/4]

void cda_rail::instances::SolGeneralProblemInstance::export_solution ( const char * path,
std::string_view const solutionSubdirectory,
std::optional< std::string > const & parameter_identifier = {} ) const
inline

Exports the solution to the specified directory and subdirectory.

Parameters
pathDirectory path where the solution will be exported.
solutionSubdirectorySubdirectory name for organizing solutions.
parameter_identifierOptional identifier appended to the solution name.

◆ export_solution() [2/4]

virtual void cda_rail::instances::SolGeneralProblemInstance::export_solution ( const std::filesystem::path & working_directory,
std::string_view solution_subdirectory ) const
inlinevirtual

Exports the solution without a parameter identifier.

Parameters
working_directoryThe root directory for solution exports.
solution_subdirectoryThe subdirectory path for organizing solutions.

Reimplemented in cda_rail::instances::SolGeneralPerformanceOptimizationInstance, cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes, and cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.

◆ export_solution() [3/4]

void cda_rail::instances::SolGeneralProblemInstance::export_solution ( const std::filesystem::path & working_directory,
std::string_view solution_subdirectory,
std::optional< std::string > const & parameter_identifier ) const
virtual

◆ export_solution() [4/4]

void cda_rail::instances::SolGeneralProblemInstance::export_solution ( const std::string & path,
std::string_view const solutionSubdirectory,
std::optional< std::string > const & parameter_identifier = {} ) const
inline

Exports the solution to the specified directory.

Parameters
pathDirectory path where the solution will be exported.
solutionSubdirectorySolution subdirectory name.
parameter_identifierOptional parameter identifier appended to the export path.

◆ get_export_path()

std::filesystem::path cda_rail::instances::SolGeneralProblemInstance::get_export_path ( const std::filesystem::path & working_directory,
std::string_view const solutionSubdirectory,
std::optional< std::string > const & parameter_identifier ) const
inlinenodiscard

Computes the file path for exporting a solution.

Constructs a path of the form working_directory/solutions/<solutionSubdirectory>/<instance_subdirectory>/<instance_name>, with -<parameter_identifier> appended to the instance name if provided.

Parameters
parameter_identifierOptional identifier appended to the instance name.
Returns
The constructed solution export path.

◆ get_general_solution_data()

nlohmann::json cda_rail::instances::SolGeneralProblemInstance::get_general_solution_data ( ) const
nodiscardprotectedvirtual

Serializes solution-wide metadata to JSON.

Returns
JSON object containing status, objective, and availability flags.

Reimplemented in cda_rail::instances::SolGeneralPerformanceOptimizationInstance.

◆ get_instance()

virtual GeneralProblemInstance const * cda_rail::instances::SolGeneralProblemInstance::get_instance ( ) const
inlinenodiscardvirtual

Provides access to the problem instance.

Returns
GeneralProblemInstance const* A const pointer to the underlying problem instance.

Reimplemented in cda_rail::instances::SolGeneralPerformanceOptimizationInstance, and cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes.

◆ get_lower_bound()

double cda_rail::instances::SolGeneralProblemInstance::get_lower_bound ( ) const
inlinenodiscard

Gets the lower bound on the objective value of the solution.

Returns
double The lower bound.

◆ get_obj()

double cda_rail::instances::SolGeneralProblemInstance::get_obj ( ) const
inlinenodiscard

Gets the objective value of the solution.

Returns
double The objective value. -1 indicates no objective value has been set.

◆ get_status()

SolutionStatus cda_rail::instances::SolGeneralProblemInstance::get_status ( ) const
inlinenodiscard

Retrieves the current solution status.

Returns
SolutionStatus The solution state.

◆ get_uncast_instance_pointer()

GeneralProblemInstance const * cda_rail::instances::SolGeneralProblemInstance::get_uncast_instance_pointer ( ) const
inlinenodiscardprotected

Retrieves the underlying problem instance pointer.

Returns
Const pointer to the underlying GeneralProblemInstance.

◆ has_solution()

bool cda_rail::instances::SolGeneralProblemInstance::has_solution ( ) const
inlinenodiscard

Indicates whether a solution has been found.

Returns
bool true if a solution has been found, false otherwise.

◆ load_solution() [1/4]

void cda_rail::instances::SolGeneralProblemInstance::load_solution ( const char * path,
std::string_view const solutionSubdirectory,
std::optional< std::string > const & parameter_identifier = {} )
inline

Loads a solution from the specified location.

Parameters
pathWorking directory path.
solutionSubdirectorySubdirectory containing solutions.
parameter_identifierOptional identifier to append to the instance name when constructing the solution path.

◆ load_solution() [2/4]

virtual void cda_rail::instances::SolGeneralProblemInstance::load_solution ( const std::filesystem::path & working_directory,
std::string_view solution_subdirectory )
inlinevirtual

Loads a solution from the specified working directory and solution subdirectory.

Parameters
working_directoryThe base working directory path.
solution_subdirectoryThe subdirectory containing the solution.

Reimplemented in cda_rail::instances::SolGeneralPerformanceOptimizationInstance, cda_rail::instances::SolGeneralProblemInstanceWithScheduleAndRoutes, and cda_rail::instances::SolVSSGeneralPerformanceOptimizationInstance.

◆ load_solution() [3/4]

void cda_rail::instances::SolGeneralProblemInstance::load_solution ( const std::filesystem::path & working_directory,
std::string_view solution_subdirectory,
std::optional< std::string > const & parameter_identifier )
virtual

◆ load_solution() [4/4]

void cda_rail::instances::SolGeneralProblemInstance::load_solution ( const std::string & path,
std::string_view const solutionSubdirectory,
std::optional< std::string > const & parameter_identifier = {} )
inline

Loads a solution from the specified path.

Parameters
pathWorking directory path.
solutionSubdirectorySubdirectory containing solution files.
parameter_identifierOptional identifier appended to the instance name when locating solution files.

◆ operator=() [1/2]

SolGeneralProblemInstance & cda_rail::instances::SolGeneralProblemInstance::operator= ( SolGeneralProblemInstance && )
defaultnoexcept

◆ operator=() [2/2]

SolGeneralProblemInstance & cda_rail::instances::SolGeneralProblemInstance::operator= ( SolGeneralProblemInstance const & )
default

◆ set_general_solution_data()

void cda_rail::instances::SolGeneralProblemInstance::set_general_solution_data ( const nlohmann::json & data)
protectedvirtual

Loads solution-wide metadata from JSON.

Parameters
dataJSON object containing general solution fields.

Reimplemented in cda_rail::instances::SolGeneralPerformanceOptimizationInstance.

◆ set_lower_bound()

void cda_rail::instances::SolGeneralProblemInstance::set_lower_bound ( double new_lb)
inline

Sets the lower bound of the objective value of the solution.

Parameters
new_objThe lower bound.

◆ set_obj()

void cda_rail::instances::SolGeneralProblemInstance::set_obj ( double new_obj)
inline

Sets the objective value of the solution.

Parameters
new_objThe new objective value.

◆ set_solution_found()

void cda_rail::instances::SolGeneralProblemInstance::set_solution_found ( )
inline

Marks the solution as found.

◆ set_solution_not_found()

void cda_rail::instances::SolGeneralProblemInstance::set_solution_not_found ( )
inline

Marks that no solution has been found.

◆ set_status()

void cda_rail::instances::SolGeneralProblemInstance::set_status ( SolutionStatus new_status)
inline

Sets the solution status.


The documentation for this class was generated from the following files: