13#include "scippp/constant_coefficient.hpp"
14#include "scippp/iis.hpp"
15#include "scippp/initial_solution.hpp"
16#include "scippp/lin_expr.hpp"
17#include "scippp/lin_ineq.hpp"
18#include "scippp/param.hpp"
19#include "scippp/solution.hpp"
20#include "scippp/statistics.hpp"
21#include "scippp/var.hpp"
22#include "scippp/var_type.hpp"
45 bool m_weCreatedANewScipObject {
false };
47 std::vector<Var> m_vars {};
49 std::vector<SCIP_Cons*> m_cons {};
51 mutable SCIP_Retcode m_lastReturnCode;
53 std::function<void(SCIP_Retcode)> m_scipCallWrapper;
66 explicit Model(
const std::string& name, SCIP*
scip =
nullptr,
bool includeDefaultPlugins =
true);
99 const std::string& name,
100 SCIP_Real coeff = 0.0,
102 std::optional<SCIP_Real> lb = 0.0,
103 std::optional<SCIP_Real> ub = 1.0);
118 template <
typename CoeffType = ConstantCoefficient>
120 const std::string& prefix,
124 std::optional<SCIP_Real> lb = 0.0,
125 std::optional<SCIP_Real> ub = 1.0)
127 std::vector<Var> result;
128 result.reserve(numVars);
129 for (
size_t index { 0 }; index < numVars; index++) {
130 result.push_back(
addVar(prefix + std::to_string(index), coeffs[index], varType, lb, ub));
152 template <
size_t NumVars,
typename CoeffType = ConstantCoefficient>
154 const std::string& prefix,
157 std::optional<SCIP_Real> lb = 0.0,
158 std::optional<SCIP_Real> ub = 1.0)
160 std::array<Var, NumVars> result;
161 auto vec {
addVars(prefix, NumVars, coeffs, varType, lb, ub) };
162 std::copy_n(std::make_move_iterator(vec.begin()), NumVars, result.begin());
194 [[nodiscard]] SCIP_Real
round(SCIP_Real value)
const;
202 [[nodiscard]]
bool isZero(SCIP_Real value)
const;
232 template <
typename T>
235 return statistic(m_scip);
258 [[deprecated(
"use getSolvingStatistic with statistics::PRIMALBOUND instead")]]
273 template <
typename T,
typename PT>
276 auto ptValue {
static_cast<PT
>(value) };
277 const auto* cName { parameter.
scipName.data() };
278 if constexpr (std::is_same_v<PT, int>) {
279 m_scipCallWrapper(SCIPsetIntParam(m_scip, cName, ptValue));
280 }
else if constexpr (std::is_same_v<PT, double>) {
281 m_scipCallWrapper(SCIPsetRealParam(m_scip, cName, ptValue));
282 }
else if constexpr (std::is_same_v<PT, char>) {
283 m_scipCallWrapper(SCIPsetCharParam(m_scip, cName, value));
284 }
else if constexpr (std::is_same_v<PT, bool>) {
285 m_scipCallWrapper(SCIPsetBoolParam(m_scip, cName, value));
286 }
else if constexpr (std::is_same_v<PT, SCIP_Longint>) {
287 m_scipCallWrapper(SCIPsetLongintParam(m_scip, cName, value));
288 }
else if constexpr (std::is_same_v<PT, std::string>) {
289 m_scipCallWrapper(SCIPsetStringParam(m_scip, cName, value.c_str()));
293 static_assert(
sizeof(T) == 0);
307 void writeOrigProblem(
const std::filesystem::directory_entry& filename,
bool genericNames =
false)
const;
327 [[deprecated(R
"(Use this to access the raw SCIP object.
328 That is only required for use-cases not supported by SCIP++.
329 Consider adding the feature you are using to SCIP++!)")]] [[nodiscard]] Scip*
346 bool printReason =
true,
347 bool completely =
true,
348 bool checkBounds =
true,
349 bool checkIntegrality =
true,
350 bool checkLpRows =
true)
const;
A primal solution to be added to SCIP's solution pool.
Represents a linear inequality: lhs <= expr <= rhs.
A SCIP optimization model.
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.
void writeOrigProblem(const std::filesystem::directory_entry &filename, bool genericNames=false) const
Writes original problem to file.
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.
Scip * scip() const
Returns a pointer to the underlying SCIP object.
Model(const std::string &name, SCIP *scip=nullptr, bool includeDefaultPlugins=true)
Creates an empty problem and sets the optimization goal to Sense::MINIMIZE.
void setScipCallWrapper(std::function< void(SCIP_Retcode)> wrapper)
Replace the current wrapper for every call to SCIP's C API.
void solve() const
Solve the model.
void setParam(params::Param< PT > parameter, T value) const
Sets a parameter.
void writeOrigProblem(const std::string &extension, bool genericNames=false) const
Writes original problem to standard output.
SCIP_Retcode getLastReturnCode() const
Gets the return code of the last call to SCIP's C API when the default call wrapper is used.
T getSolvingStatistic(const statistics::Statistic< T > &statistic) const
Query statistics about the solving process.
SCIP_Real infinity() const
Infinity according the SCIP config.
void setObjsense(Sense objsense) const
Set objective goal.
bool isZero(SCIP_Real value) const
Checks, if value is in range epsilon of 0.0.
void addConstr(const LinIneq &ineq, const std::string &name)
Adds a constraint to the model.
SCIP_Real epsilon() const
Value treated as zero.
~Model()
Releases the variables and constraints.
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.
bool addSolution(const InitialSolution &initialSolution, bool printReason=true, bool completely=true, bool checkBounds=true, bool checkIntegrality=true, bool checkLpRows=true) const
Adds a solution to SCIP's solution pool.
IIS generateIIS() const
Creates an Irreducible Infeasible Subsystem (IIS) of the current model.
SCIP_Status getStatus() const
Returns the solution status.
double getPrimalbound() const
Returns the objective value of best solution.
int getNSols() const
Returns the number of feasible primal solutions stored in the solution storage.
SCIP_Real round(SCIP_Real value) const
Rounds value to the nearest integer with epsilon tolerance.
Solution getBestSol() const
Returns the best feasible primal solution found so far or best solution candidate.
static constexpr ConstantCoefficient COEFF_ZERO
An object which index operator always returns 0.
VarType
Type of a variable.
@ CONTINUOUS
Continuous variable.
A data structure to hold an IIS (Irreducible Infeasible Subsystem).
Wrapper for a SCIP solution.
Wrapper for a SCIP variable.
Stores the argument type and string representation of a parameter.
std::string_view scipName
Original name of the parameter in SCIP.
Storage for a function pointer.