4 #include <carl-formula/model/Model.h>
9 template<
typename Solver>
45 [&objective](
const auto& e) {
46 return e.function == objective;
58 std::tuple<Answer,Model,ObjectiveValues>
compute(
bool full =
true) {
64 bool isOptimal =
true;
67 const auto& objective = *iter;
68 SMTRAT_LOG_DEBUG(
"smtrat.optimization",
"Optimizing objective " << objective.function <<
" (minimize=" << objective.minimize <<
")");
76 mSolver.remove(objectiveEquality);
77 mSolver.setObjectiveVariable(carl::Variable::NO_VARIABLE);
88 assert(objModel != model.end());
91 if (objModel->second.isMinusInfinity()) {
92 optVal = objective.minimize ? objModel->second.asInfinity() :
InfinityValue{
true};
96 assert(objModel->second.isRational());
97 optVal = (objective.minimize ? objModel->second.asRational() : -(objModel->second.asRational()));
98 SMTRAT_LOG_TRACE(
"smtrat.optimization",
"Found optimal value " << optVal.asRational());
100 optimalValues.emplace_back(objective.function, optVal);
104 assert(objModel->second.isRational());
105 FormulaT minimumUpperBound( (objective.minimize ? objective.function : -(objective.function)) - objModel->second.asRational(), carl::Relation::LEQ );
106 SMTRAT_LOG_TRACE(
"smtrat.optimization",
"Adding minimum upper bound " << minimumUpperBound);
107 mSolver.add(minimumUpperBound);
112 SMTRAT_LOG_WARN(
"smtrat.optimization",
"Answer not necessarily optimal!");
114 SMTRAT_LOG_TRACE(
"smtrat.optimization",
"Removing optimization variables from model");
117 return std::make_tuple(isOptimal ?
OPTIMAL :
SAT, model, optimalValues);
carl::Variable mOptimizationVarInt
const carl::Variable & objectiveVariable(const Objective &objective) const
std::vector< Objective > mObjectives
void add_objective(const Poly &objective, bool minimize=true)
carl::Variable mOptimizationVarReal
void remove_objective(const Poly &objective)
const std::vector< Objective > & objectives() const
std::tuple< Answer, Model, ObjectiveValues > compute(bool full=true)
Class to create the formulas for axioms.
carl::ModelValue< Rational, Poly > ModelValue
carl::Formula< Poly > FormulaT
std::vector< std::pair< std::variant< Poly, std::string >, Model::mapped_type > > ObjectiveValues
carl::Model< Rational, Poly > Model
carl::MultivariatePolynomial< Rational > Poly
Answer
An enum with the possible answers a Module can give.
carl::InfinityValue InfinityValue
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_WARN(channel, msg)
#define SMTRAT_LOG_INFO(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)