MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
cda_rail::solver::GeneralSolver< T, S > Class Template Referenceabstract

Base of every solver, connecting an instance type to its solution type. More...

#include <GeneralSolver.hpp>

Inheritance diagram for cda_rail::solver::GeneralSolver< T, S >:
cda_rail::solver::mip_based::GeneralMIPSolver< T, S >

Classes

struct  IsSingleInstanceArgument
struct  IsSingleInstanceArgument< Arg >
struct  FurtherData
 Solver-specific values to be written to solver_data.json. More...

Public Member Functions

const nlohmann::json & get_solver_data () const
 The solver data of the last solve, as written to solver_data.json if the solution is exported, so that it can be exported later. Null before the first solve.
const T & get_instance () const
 Accesses the problem instance stored in this solver.
T & editable_instance ()
 Provides mutable access to the problem instance.
S solve ()
 Solves the problem instance using default configuration.
S solve (int time_limit, bool debug_input)
 Solves the problem instance.
virtual S solve (int time_limit, bool debug_input, bool overwrite_severity)=0
 Solves the problem instance, which every solver implements.
virtual ~GeneralSolver ()=default
 Virtual destructor.

Protected Member Functions

void solve_init_general (bool debug_input, bool overwrite_severity)
 Initializes logging and records solver start time.
 GeneralSolver ()=default
 Constructs a solver with a default-initialized problem instance.
 GeneralSolver (T instance)
 Constructs a solver from a problem instance.
template<typename... Args>
requires (sizeof...(Args) > 0 && !IsSingleInstanceArgument<Args...>::value && std::constructible_from<T, Args...>)
 GeneralSolver (Args &&... args)
 Constructs a GeneralSolver with arguments for the problem instance constructor.
nlohmann::json solver_data (FurtherData const &further_data) const
 Solver data, i.e., timing and further information (e.g. iterations, nodes, etc.), as written to solver_data.json.
void export_solver_data (std::filesystem::path const &export_directory, FurtherData const &further_data={})
 Exports solver data, see solver_data, into solver_data.json.
std::optional< std::filesystem::path > export_general_solution (S &solution, const GeneralSolutionSettings &solution_settings, FurtherData const &further_data={})
 Exports the solution together with the solver data if requested.

Protected Attributes

T m_instance
decltype(std::chrono::high_resolution_clock::now()) m_start
decltype(std::chrono::high_resolution_clock::now()) m_model_created
decltype(std::chrono::high_resolution_clock::now()) m_model_solved
int64_t m_create_time = 0
int64_t m_solve_time = 0
nlohmann::json m_solver_data

Detailed Description

template<typename T, typename S>
class cda_rail::solver::GeneralSolver< T, S >

Base of every solver, connecting an instance type to its solution type.

Besides holding the instance, this is where everything that is not specific to a solving approach lives, namely the initialization of the logging, the measured times, and the export of the solution together with the solver data.

Template Parameters
TThe problem instance type, a child of GeneralProblemInstance.
SThe solution type belonging to it, a child of SolGeneralProblemInstance.

Constructor & Destructor Documentation

◆ GeneralSolver() [1/3]

template<typename T, typename S>
cda_rail::solver::GeneralSolver< T, S >::GeneralSolver ( )
protecteddefault

Constructs a solver with a default-initialized problem instance.

◆ GeneralSolver() [2/3]

template<typename T, typename S>
cda_rail::solver::GeneralSolver< T, S >::GeneralSolver ( T instance)
inlineexplicitprotected

Constructs a solver from a problem instance.

Parameters
instanceThe problem instance to store.

◆ GeneralSolver() [3/3]

template<typename T, typename S>
template<typename... Args>
requires (sizeof...(Args) > 0 && !IsSingleInstanceArgument<Args...>::value && std::constructible_from<T, Args...>)
cda_rail::solver::GeneralSolver< T, S >::GeneralSolver ( Args &&... args)
inlineexplicitprotected

Constructs a GeneralSolver with arguments for the problem instance constructor.

Parameters
argsArguments passed to construct the problem instance.

◆ ~GeneralSolver()

template<typename T, typename S>
virtual cda_rail::solver::GeneralSolver< T, S >::~GeneralSolver ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ editable_instance()

template<typename T, typename S>
T & cda_rail::solver::GeneralSolver< T, S >::editable_instance ( )
inlinenodiscard

Provides mutable access to the problem instance.

Returns
T& Reference to the problem instance.

◆ export_general_solution()

template<typename T, typename S>
std::optional< std::filesystem::path > cda_rail::solver::GeneralSolver< T, S >::export_general_solution ( S & solution,
const GeneralSolutionSettings & solution_settings,
FurtherData const & further_data = {} )
inlineprotected

Exports the solution together with the solver data if requested.

The solution is written to the standard solution path, i.e., working_directory/solutions/solution_subdirectory/instance_subdirectory/ instance_name[-parameter_identifier]. Nothing is exported if the export option is GeneralExportOption::NoExport. If an evaluation time step is given and the solution type supports it, the solution is evaluated before it is exported, so that the evaluation is part of solution afterwards. If the evaluation fails, the solution is exported without it. The solver data is kept in any case, see get_solver_data.

Parameters
solutionThe solution to export
solution_settingsSettings describing where and what to export
further_dataAdditional solver-specific data for solver_data.json
Returns
The export directory if an export happened, std::nullopt otherwise

◆ export_solver_data()

template<typename T, typename S>
void cda_rail::solver::GeneralSolver< T, S >::export_solver_data ( std::filesystem::path const & export_directory,
FurtherData const & further_data = {} )
inlineprotected

Exports solver data, see solver_data, into solver_data.json.

Parameters
export_directoryThe directory of the solution export
further_dataAdditional solver-specific data
Exceptions
exceptions::ExportExceptionIf the export directory could not be created

◆ get_instance()

template<typename T, typename S>
const T & cda_rail::solver::GeneralSolver< T, S >::get_instance ( ) const
inlinenodiscard

Accesses the problem instance stored in this solver.

Returns
const T& Const reference to the stored problem instance.

◆ get_solver_data()

template<typename T, typename S>
const nlohmann::json & cda_rail::solver::GeneralSolver< T, S >::get_solver_data ( ) const
inlinenodiscard

The solver data of the last solve, as written to solver_data.json if the solution is exported, so that it can be exported later. Null before the first solve.

◆ solve() [1/3]

template<typename T, typename S>
S cda_rail::solver::GeneralSolver< T, S >::solve ( )
inlinenodiscard

Solves the problem instance using default configuration.

Returns
S The solution.

◆ solve() [2/3]

template<typename T, typename S>
S cda_rail::solver::GeneralSolver< T, S >::solve ( int time_limit,
bool debug_input )
inlinenodiscard

Solves the problem instance.

Parameters
time_limitMaximum time allowed for solving. Zero or negative values disable the limit.
debug_inputWhether to enable debug input mode.
Returns
S The computed solution.

◆ solve() [3/3]

template<typename T, typename S>
virtual S cda_rail::solver::GeneralSolver< T, S >::solve ( int time_limit,
bool debug_input,
bool overwrite_severity )
nodiscardpure virtual

Solves the problem instance, which every solver implements.

Parameters
time_limitMaximum time allowed for solving. Zero or negative values disable the limit.
debug_inputWhether to enable debug input mode.
overwrite_severityWhether the logging severity is overwritten, which it should not be if the solver is called by another one.
Returns
S The computed solution.

◆ solve_init_general()

template<typename T, typename S>
void cda_rail::solver::GeneralSolver< T, S >::solve_init_general ( bool debug_input,
bool overwrite_severity )
inlineprotected

Initializes logging and records solver start time.

Initializes the plog logging framework according to the settings provided. Records the current high-resolution clock time as the solver's start timestamp.

Parameters
debug_inputIf true, enables debug-level logging.
overwrite_severityIf true, overwrites the logging severity level.

◆ solver_data()

template<typename T, typename S>
nlohmann::json cda_rail::solver::GeneralSolver< T, S >::solver_data ( FurtherData const & further_data) const
inlinenodiscardprotected

Solver data, i.e., timing and further information (e.g. iterations, nodes, etc.), as written to solver_data.json.

Parameters
further_dataAdditional solver-specific data

Member Data Documentation

◆ m_create_time

template<typename T, typename S>
int64_t cda_rail::solver::GeneralSolver< T, S >::m_create_time = 0
protected

◆ m_instance

template<typename T, typename S>
T cda_rail::solver::GeneralSolver< T, S >::m_instance
protected

◆ m_model_created

template<typename T, typename S>
decltype(std::chrono::high_resolution_clock::now()) cda_rail::solver::GeneralSolver< T, S >::m_model_created
protected

◆ m_model_solved

template<typename T, typename S>
decltype(std::chrono::high_resolution_clock::now()) cda_rail::solver::GeneralSolver< T, S >::m_model_solved
protected

◆ m_solve_time

template<typename T, typename S>
int64_t cda_rail::solver::GeneralSolver< T, S >::m_solve_time = 0
protected

◆ m_solver_data

template<typename T, typename S>
nlohmann::json cda_rail::solver::GeneralSolver< T, S >::m_solver_data
protected

◆ m_start

template<typename T, typename S>
decltype(std::chrono::high_resolution_clock::now()) cda_rail::solver::GeneralSolver< T, S >::m_start
protected

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