SCIP++ refs/heads/main
 
Loading...
Searching...
No Matches
scippp::Model Class Reference

A SCIP optimization model. More...

#include <model.hpp>

Public Member Functions

 Model (const std::string &name, SCIP *scip=nullptr, bool includeDefaultPlugins=true)
 Creates an empty problem and sets the optimization goal to Sense::MINIMIZE.
 
 ~Model ()
 Releases the variables and constraints.
 
void addConstr (const LinIneq &ineq, const std::string &name)
 Adds a constraint to the model.
 
VaraddVar (const std::string &name, SCIP_Real coeff=0.0, VarType varType=VarType::CONTINUOUS, std::optional< SCIP_Real > lb=0.0, std::optional< SCIP_Real > ub=1.0)
 Adds a variable to the model.
 
template<size_t NumVars, typename CoeffType = ConstantCoefficient>
std::array< Var, NumVars > addVars (const std::string &prefix, const CoeffType &coeffs=COEFF_ZERO, VarType varType=VarType::CONTINUOUS, std::optional< SCIP_Real > lb=0.0, std::optional< SCIP_Real > ub=1.0)
 Adds multiple variables to the model.
 
template<typename CoeffType = ConstantCoefficient>
std::vector< VaraddVars (const std::string &prefix, size_t numVars, const CoeffType &coeffs=COEFF_ZERO, VarType varType=VarType::CONTINUOUS, std::optional< SCIP_Real > lb=0.0, std::optional< SCIP_Real > ub=1.0)
 Adds multiple variables to the model.
 
SCIP_Real epsilon () const
 Value treated as zero.
 
Solution getBestSol () const
 Returns the best feasible primal solution found so far or best solution candidate.
 
SCIP_Retcode getLastReturnCode () const
 Gets the return code of the last call to SCIP's C API when the default call wrapper is used.
 
int getNSols () const
 Returns the number of feasible primal solutions stored in the solution storage.
 
double getPrimalbound () const
 Returns the objective value of best solution.
 
template<typename T >
getSolvingStatistic (const statistics::Statistic< T > &statistic) const
 Query statistics about the solving process.
 
SCIP_Status getStatus () const
 Returns the solution status.
 
SCIP_Real infinity () const
 Infinity according the SCIP config.
 
bool isZero (SCIP_Real value) const
 Checks, if value is in range epsilon of 0.0.
 
SCIP_Real round (SCIP_Real value) const
 Rounds value to the nearest integer with epsilon tolerance.
 
Scip * scip () const
 Returns a pointer to the underlying SCIP object.
 
void setObjsense (Sense objsense)
 Set objective goal.
 
template<typename T , typename PT >
void setParam (params::Param< PT > parameter, T value)
 Sets a parameter.
 
void setScipCallWrapper (std::function< void(SCIP_Retcode)> wrapper)
 Replace the current wrapper for every call to SCIP's C API.
 
void solve ()
 Solve the model.
 
void writeOrigProblem (const std::filesystem::directory_entry &filename, bool genericNames=false) const
 Writes original problem to file.
 
void writeOrigProblem (const std::string &extension, bool genericNames=false) const
 Writes original problem to standard output.
 

Detailed Description

A SCIP optimization model.

Variables and constraints are automatically released when the model is destructed.

Since
1.0.0

Definition at line 39 of file model.hpp.

Constructor & Destructor Documentation

◆ Model()

scippp::Model::Model ( const std::string & name,
SCIP * scip = nullptr,
bool includeDefaultPlugins = true )
explicit

Creates an empty problem and sets the optimization goal to Sense::MINIMIZE.

By default, all calls to the underlying C API are wrapped and the last return code is stored.

Since
1.0.0
Parameters
namefor the problem.
scipto create the problem in. If nullptr, a new SCIP data structure will be created.
includeDefaultPluginsif true, the default plugins are added to scip.

◆ ~Model()

scippp::Model::~Model ( )

Releases the variables and constraints.

Since
1.0.0

Member Function Documentation

◆ addConstr()

void scippp::Model::addConstr ( const LinIneq & ineq,
const std::string & name )

Adds a constraint to the model.

Since
1.0.0
Parameters
ineqlinear inequality to add.
namefor the constraint when the model is written.

◆ addVar()

Var & scippp::Model::addVar ( const std::string & name,
SCIP_Real coeff = 0.0,
VarType varType = VarType::CONTINUOUS,
std::optional< SCIP_Real > lb = 0.0,
std::optional< SCIP_Real > ub = 1.0 )

Adds a variable to the model.

Since
1.0.0
Parameters
nameof the variable when the model is written.
coeffCoefficient in the objective function.
varTypevariable type.
lblower bound. std::nullopt is interpreted as -infinity.
ubupper bound. std::nullopt is interpreted as infinity.
Returns
Reference to the newly created variable.

◆ addVars() [1/2]

template<size_t NumVars, typename CoeffType = ConstantCoefficient>
std::array< Var, NumVars > scippp::Model::addVars ( const std::string & prefix,
const CoeffType & coeffs = COEFF_ZERO,
VarType varType = VarType::CONTINUOUS,
std::optional< SCIP_Real > lb = 0.0,
std::optional< SCIP_Real > ub = 1.0 )
inline

Adds multiple variables to the model.

This method can be used when the number of variables to add is known at compile time. The result can be used in a structured binding.

Since
1.0.0
Template Parameters
NumVarsNumber of variables to add.
CoeffTypeType of the object holding the coefficients. They are accessed via [i] where i goes from 0 to NumVars - 1.
Parameters
prefixto construct variable names from: prefix + index.
coeffsObject holding the coefficients for the objective function.
varTypevariable type.
lblower bound.
ubupper bound.
Returns
Array of variables.

Definition at line 151 of file model.hpp.

References addVars().

◆ addVars() [2/2]

template<typename CoeffType = ConstantCoefficient>
std::vector< Var > scippp::Model::addVars ( const std::string & prefix,
size_t numVars,
const CoeffType & coeffs = COEFF_ZERO,
VarType varType = VarType::CONTINUOUS,
std::optional< SCIP_Real > lb = 0.0,
std::optional< SCIP_Real > ub = 1.0 )
inline

Adds multiple variables to the model.

Since
1.0.0
Template Parameters
CoeffTypeType of the object holding the coefficients. They are accessed via [i] where i goes from 0 to numVars - 1.
Parameters
prefixto construct variable names from: prefix + index.
numVarsnumber of variables to create.
coeffsObject holding the coefficients for the objective function.
varTypevariable type.
lblower bound. std::nullopt is interpreted as -infinity.
ubupper bound. std::nullopt is interpreted as infinity.
Returns
Vector of variables.

Definition at line 117 of file model.hpp.

References addVar().

◆ epsilon()

SCIP_Real scippp::Model::epsilon ( ) const
nodiscard

Value treated as zero.

Since
1.1.0
Returns
value treated as zero.

◆ getBestSol()

Solution scippp::Model::getBestSol ( ) const
nodiscard

Returns the best feasible primal solution found so far or best solution candidate.

Since
1.0.0
Returns
best feasible primal solution.

◆ getLastReturnCode()

SCIP_Retcode scippp::Model::getLastReturnCode ( ) const
nodiscard

Gets the return code of the last call to SCIP's C API when the default call wrapper is used.

Since
1.0.0
Returns
return code of the last call to SCIP's C API.

◆ getNSols()

int scippp::Model::getNSols ( ) const
nodiscard

Returns the number of feasible primal solutions stored in the solution storage.

Since
1.0.0
Returns
number of solutions.

◆ getPrimalbound()

double scippp::Model::getPrimalbound ( ) const
nodiscard

Returns the objective value of best solution.

Since
1.0.0
Deprecated
since 1.2.0, use getSolvingStatistic with statistics::PRIMALBOUND instead.
Returns
objective value of best solution.

◆ getSolvingStatistic()

template<typename T >
T scippp::Model::getSolvingStatistic ( const statistics::Statistic< T > & statistic) const
inlinenodiscard

Query statistics about the solving process.

Template Parameters
TType of the statistics value.
Since
1.2.0
Parameters
statisticStatistics value to access.
Returns
Statistics value.

Definition at line 231 of file model.hpp.

◆ getStatus()

SCIP_Status scippp::Model::getStatus ( ) const
nodiscard

Returns the solution status.

Since
1.0.0
Returns
solution status.

◆ infinity()

SCIP_Real scippp::Model::infinity ( ) const
nodiscard

Infinity according the SCIP config.

To be used in variable bounds and constants in constraints.

Since
1.0.0
Returns
infinity according the SCIP config.

◆ isZero()

bool scippp::Model::isZero ( SCIP_Real value) const
nodiscard

Checks, if value is in range epsilon of 0.0.

Since
1.1.0
Parameters
valueto check
Returns
true iff the value is in range epsilon of 0.0.

◆ round()

SCIP_Real scippp::Model::round ( SCIP_Real value) const
nodiscard

Rounds value to the nearest integer with epsilon tolerance.

Since
1.1.0
Parameters
valueto round
Returns
nearest integer as double

◆ scip()

Scip * scippp::Model::scip ( ) const
nodiscard

Returns a pointer to the underlying SCIP object.

Since
1.0.0
Attention
Use this to access the raw SCIP object. That is required only for use-cases not supported by SCIP++. Consider adding the feature you are using to SCIP++!
Returns
the underlying SCIP object.

◆ setObjsense()

void scippp::Model::setObjsense ( Sense objsense)

Set objective goal.

Since
1.0.0
Parameters
objsenseMinimize or Maximize.

◆ setParam()

template<typename T , typename PT >
void scippp::Model::setParam ( params::Param< PT > parameter,
T value )
inline

Sets a parameter.

See the namespace scippp::params for a list of parameters, or create new ones using params::Param.

Since
1.0.0
Template Parameters
TType of the value.
PTValue type the parameter expects
Parameters
parameterto set.
valueto set the parameter to.

Definition at line 272 of file model.hpp.

References scippp::params::Param< baseType >::scipName.

◆ setScipCallWrapper()

void scippp::Model::setScipCallWrapper ( std::function< void(SCIP_Retcode)> wrapper)

Replace the current wrapper for every call to SCIP's C API.

Since
1.0.0
Parameters
wrapperNew wrapper tp use.

◆ solve()

void scippp::Model::solve ( )

Solve the model.

Since
1.0.0

◆ writeOrigProblem() [1/2]

void scippp::Model::writeOrigProblem ( const std::filesystem::directory_entry & filename,
bool genericNames = false ) const

Writes original problem to file.

Since
1.1.0
Parameters
filenameoutput file name including extension
genericNamesusing generic variable (x0, x1, ...) and constraint names (c0, c1, ...) instead of the user-given names?
Attention
Do not use an std::string or std::filesystem::path as argument filename, as this will call the other overload instead!

◆ writeOrigProblem() [2/2]

void scippp::Model::writeOrigProblem ( const std::string & extension,
bool genericNames = false ) const

Writes original problem to standard output.

Since
1.1.0
Parameters
extensionfile extension to derive the output format from
genericNamesusing generic variable (x0, x1, ...) and constraint names (c0, c1, ...) instead of the user-given names?

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