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. | |
Var & | 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. | |
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< Var > | 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) |
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 > | |
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. | |
A SCIP optimization model.
Variables and constraints are automatically released when the model is destructed.
|
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.
name | for the problem. |
scip | to create the problem in. If nullptr , a new SCIP data structure will be created. |
includeDefaultPlugins | if true , the default plugins are added to scip . |
scippp::Model::~Model | ( | ) |
Releases the variables and constraints.
void scippp::Model::addConstr | ( | const LinIneq & | ineq, |
const std::string & | name | ||
) |
Adds a constraint to the model.
ineq | linear inequality to add. |
name | for the constraint when the model is written. |
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.
name | of the variable when the model is written. |
coeff | Coefficient in the objective function. |
varType | variable type. |
lb | lower bound. std::nullopt is interpreted as -infinity. |
ub | upper bound. std::nullopt is interpreted as infinity. |
|
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.
NumVars | Number of variables to add. |
CoeffType | Type of the object holding the coefficients. They are accessed via [i] where i goes from 0 to NumVars - 1. |
prefix | to construct variable names from: prefix + index. |
coeffs | Object holding the coefficients for the objective function. |
varType | variable type. |
lb | lower bound. |
ub | upper bound. |
Definition at line 151 of file model.hpp.
References addVars().
|
inline |
Adds multiple variables to the model.
CoeffType | Type of the object holding the coefficients. They are accessed via [i] where i goes from 0 to numVars - 1. |
prefix | to construct variable names from: prefix + index. |
numVars | number of variables to create. |
coeffs | Object holding the coefficients for the objective function. |
varType | variable type. |
lb | lower bound. std::nullopt is interpreted as -infinity. |
ub | upper bound. std::nullopt is interpreted as infinity. |
Definition at line 117 of file model.hpp.
References addVar().
SCIP_Real scippp::Model::epsilon | ( | ) | const |
Value treated as zero.
Solution scippp::Model::getBestSol | ( | ) | const |
Returns the best feasible primal solution found so far or best solution candidate.
SCIP_Retcode scippp::Model::getLastReturnCode | ( | ) | const |
Gets the return code of the last call to SCIP's C API when the default call wrapper is used.
int scippp::Model::getNSols | ( | ) | const |
Returns the number of feasible primal solutions stored in the solution storage.
double scippp::Model::getPrimalbound | ( | ) | const |
Returns the objective value of best solution.
|
inline |
SCIP_Status scippp::Model::getStatus | ( | ) | const |
Returns the solution status.
SCIP_Real scippp::Model::infinity | ( | ) | const |
Infinity according the SCIP config.
To be used in variable bounds and constants in constraints.
bool scippp::Model::isZero | ( | SCIP_Real | value | ) | const |
Checks, if value is in range epsilon of 0.0.
value | to check |
true
iff the value is in range epsilon of 0.0. SCIP_Real scippp::Model::round | ( | SCIP_Real | value | ) | const |
Rounds value to the nearest integer with epsilon tolerance.
value | to round |
Scip * scippp::Model::scip | ( | ) | const |
Returns a pointer to the underlying SCIP object.
void scippp::Model::setObjsense | ( | Sense | objsense | ) |
Set objective goal.
objsense | Minimize or Maximize. |
|
inline |
Sets a parameter.
See the namespace scippp::params for a list of parameters, or create new ones using params::Param.
T | Type of the value. |
PT | Value type the parameter expects |
parameter | to set. |
value | to set the parameter to. |
Definition at line 272 of file model.hpp.
References scippp::params::Param< baseType >::scipName.
void scippp::Model::setScipCallWrapper | ( | std::function< void(SCIP_Retcode)> | wrapper | ) |
Replace the current wrapper for every call to SCIP's C API.
wrapper | New wrapper tp use. |
void scippp::Model::solve | ( | ) |
Solve the model.
void scippp::Model::writeOrigProblem | ( | const std::filesystem::directory_entry & | filename, |
bool | genericNames = false |
||
) | const |
Writes original problem to file.
filename | output file name including extension |
genericNames | using generic variable (x0, x1, ...) and constraint names (c0, c1, ...) instead of the user-given names? |
filename
, as this will call the other overload instead! void scippp::Model::writeOrigProblem | ( | const std::string & | extension, |
bool | genericNames = false |
||
) | const |
Writes original problem to standard output.
extension | file extension to derive the output format from |
genericNames | using generic variable (x0, x1, ...) and constraint names (c0, c1, ...) instead of the user-given names? |