13#include "scippp/constant_coefficient.hpp" 
   14#include "scippp/initial_solution.hpp" 
   15#include "scippp/lin_expr.hpp" 
   16#include "scippp/lin_ineq.hpp" 
   17#include "scippp/param.hpp" 
   18#include "scippp/solution.hpp" 
   19#include "scippp/statistics.hpp" 
   20#include "scippp/var.hpp" 
   21#include "scippp/var_type.hpp" 
   44    bool m_weCreatedANewScipObject { 
false };
 
   46    std::vector<Var> m_vars {};
 
   48    std::vector<SCIP_Cons*> m_cons {};
 
   50    SCIP_Retcode m_lastReturnCode;
 
   52    std::function<void(SCIP_Retcode)> m_scipCallWrapper;
 
   65    explicit Model(
const std::string& name, SCIP* 
scip = 
nullptr, 
bool includeDefaultPlugins = 
true);
 
   98        const std::string& name,
 
   99        SCIP_Real coeff = 0.0,
 
  101        std::optional<SCIP_Real> lb = 0.0,
 
  102        std::optional<SCIP_Real> ub = 1.0);
 
  117    template <
typename CoeffType = ConstantCoefficient>
 
  119        const std::string& prefix,
 
  123        std::optional<SCIP_Real> lb = 0.0,
 
  124        std::optional<SCIP_Real> ub = 1.0)
 
  126        std::vector<Var> result;
 
  127        result.reserve(numVars);
 
  128        for (
size_t index { 0 }; index < numVars; index++) {
 
  129            result.push_back(
addVar(prefix + std::to_string(index), coeffs[index], varType, lb, ub));
 
 
  151    template <
size_t NumVars, 
typename CoeffType = ConstantCoefficient>
 
  153        const std::string& prefix,
 
  156        std::optional<SCIP_Real> lb = 0.0,
 
  157        std::optional<SCIP_Real> ub = 1.0)
 
  159        std::array<Var, NumVars> result;
 
  160        auto vec { 
addVars(prefix, NumVars, coeffs, varType, lb, ub) };
 
  161        std::copy_n(std::make_move_iterator(vec.begin()), NumVars, result.begin());
 
 
  193    [[nodiscard]] SCIP_Real 
round(SCIP_Real value) 
const;
 
  201    [[nodiscard]] 
bool isZero(SCIP_Real value) 
const;
 
  231    template <
typename T>
 
  234        return statistic(m_scip);
 
 
  257    [[deprecated(
"use getSolvingStatistic with statistics::PRIMALBOUND instead")]] 
 
  272    template <
typename T, 
typename PT>
 
  275        auto ptValue { 
static_cast<PT
>(value) };
 
  276        const auto* cName { parameter.
scipName.data() };
 
  277        if constexpr (std::is_same_v<PT, int>) {
 
  278            m_scipCallWrapper(SCIPsetIntParam(m_scip, cName, ptValue));
 
  279        } 
else if constexpr (std::is_same_v<PT, double>) {
 
  280            m_scipCallWrapper(SCIPsetRealParam(m_scip, cName, ptValue));
 
  281        } 
else if constexpr (std::is_same_v<PT, char>) {
 
  282            m_scipCallWrapper(SCIPsetCharParam(m_scip, cName, value));
 
  283        } 
else if constexpr (std::is_same_v<PT, bool>) {
 
  284            m_scipCallWrapper(SCIPsetBoolParam(m_scip, cName, value));
 
  285        } 
else if constexpr (std::is_same_v<PT, SCIP_Longint>) {
 
  286            m_scipCallWrapper(SCIPsetLongintParam(m_scip, cName, value));
 
  287        } 
else if constexpr (std::is_same_v<PT, std::string>) {
 
  288            m_scipCallWrapper(SCIPsetStringParam(m_scip, cName, value.c_str()));
 
  292            static_assert(
sizeof(T) == 0);
 
 
  306    void writeOrigProblem(
const std::filesystem::directory_entry& filename, 
bool genericNames = 
false) 
const;
 
  326    [[deprecated(R
"(Use this to access the raw SCIP object. 
  327                    That is only required for use-cases not supported by SCIP++. 
  328                    Consider adding the feature you are using to SCIP++!)")]] [[nodiscard]] Scip* 
  345        bool printReason = 
true,
 
  346        bool completely = 
true,
 
  347        bool checkBounds = 
true,
 
  348        bool checkIntegrality = 
true,
 
  349        bool checkLpRows = 
true);
 
 
A primal solution to be added to SCIP's solution pool.
 
Represents a linear inequality: lhs <= expr <= rhs.
 
A SCIP optimization model.
 
void setObjsense(Sense objsense)
Set objective goal.
 
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 writeOrigProblem(const std::string &extension, bool genericNames=false) const
Writes original problem to standard output.
 
bool addSolution(const InitialSolution &initialSolution, bool printReason=true, bool completely=true, bool checkBounds=true, bool checkIntegrality=true, bool checkLpRows=true)
Adds a solution to SCIP's solution pool.
 
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.
 
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.
 
void setParam(params::Param< PT > parameter, T value)
Sets a parameter.
 
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.
 
void solve()
Solve the model.
 
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.
 
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.