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

Base of every solver that builds a MIP and hands it to Gurobi. More...

#include <GeneralMIPSolver.hpp>

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

Protected Member Functions

virtual void cleanup ()
 Releases the model and the environment after solving.
void solve_init_general_mip (bool debug_input, bool overwrite_severity)
 Initializes the model with the default message callback.
void solve_init_general_mip (bool debug_input, bool overwrite_severity, GRBCallback *cb)
 Initializes the logging, the Gurobi environment, and the model.
 GeneralMIPSolver ()=default
 Constructs a solver with a default-initialized problem instance.
 GeneralMIPSolver (const T &instance)
 Constructs a solver from a problem instance.
template<typename... Args>
requires ( !GeneralSolver<T, S>::template IsSingleInstanceArgument<Args...>::value)
 GeneralMIPSolver (Args &&... args)
 Constructs the problem instance from the given arguments.
Protected Member Functions inherited from cda_rail::solver::GeneralSolver< T, S >
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

std::vector< GRBTempConstr > m_lazy_constraints
std::optional< GRBEnv > m_env
std::optional< GRBModel > m_model
std::unordered_map< std::string, MultiArray< GRBVar > > m_vars
GRBLinExpr m_objective_expr
Protected Attributes inherited from cda_rail::solver::GeneralSolver< T, S >
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

Additional Inherited Members

Public Member Functions inherited from cda_rail::solver::GeneralSolver< T, S >
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.

Detailed Description

template<typename T, typename S>
class cda_rail::solver::mip_based::GeneralMIPSolver< T, S >

Base of every solver that builds a MIP and hands it to Gurobi.

It owns the Gurobi environment, the model, and its variables, and takes care of everything that is the same for every model, namely its creation and its cleanup.

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

Constructor & Destructor Documentation

◆ GeneralMIPSolver() [1/3]

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

Constructs a solver with a default-initialized problem instance.

◆ GeneralMIPSolver() [2/3]

template<typename T, typename S>
cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::GeneralMIPSolver ( const T & instance)
inlineexplicitprotected

Constructs a solver from a problem instance.

◆ GeneralMIPSolver() [3/3]

template<typename T, typename S>
template<typename... Args>
requires ( !GeneralSolver<T, S>::template IsSingleInstanceArgument<Args...>::value)
cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::GeneralMIPSolver ( Args &&... args)
inlineexplicitprotected

Constructs the problem instance from the given arguments.

Member Function Documentation

◆ cleanup()

template<typename T, typename S>
virtual void cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::cleanup ( )
inlineprotectedvirtual

◆ solve_init_general_mip() [1/2]

template<typename T, typename S>
void cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::solve_init_general_mip ( bool debug_input,
bool overwrite_severity )
inlineprotected

Initializes the model with the default message callback.

◆ solve_init_general_mip() [2/2]

template<typename T, typename S>
void cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::solve_init_general_mip ( bool debug_input,
bool overwrite_severity,
GRBCallback * cb )
inlineprotected

Initializes the logging, the Gurobi environment, and the model.

Parameters
debug_inputIf true, enables debug-level logging.
overwrite_severityIf true, overwrites the logging severity level.
cbThe callback of the model, which a solver using lazy constraints provides itself.

Member Data Documentation

◆ m_env

template<typename T, typename S>
std::optional<GRBEnv> cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::m_env
protected

◆ m_lazy_constraints

template<typename T, typename S>
std::vector<GRBTempConstr> cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::m_lazy_constraints
protected

◆ m_model

template<typename T, typename S>
std::optional<GRBModel> cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::m_model
protected

◆ m_objective_expr

template<typename T, typename S>
GRBLinExpr cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::m_objective_expr
protected

◆ m_vars

template<typename T, typename S>
std::unordered_map<std::string, MultiArray<GRBVar> > cda_rail::solver::mip_based::GeneralMIPSolver< T, S >::m_vars
protected

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