Unreachable();
}
-void OptimizationSolver::pushObjective(
- TNode target, OptimizationObjective::ObjectiveType type, bool bvSigned)
+void OptimizationSolver::addObjective(TNode target,
+ OptimizationObjective::ObjectiveType type,
+ bool bvSigned)
{
if (!OMTOptimizer::nodeSupportsOptimization(target))
{
CVC5_FATAL()
- << "Objective not pushed: Target node does not support optimization";
+ << "Objective failed to add: Target node does not support optimization";
}
d_optChecker.reset();
d_objectives.emplace_back(target, type, bvSigned);
d_results.emplace_back(OptimizationResult::UNKNOWN, Node());
}
-void OptimizationSolver::popObjective()
+void OptimizationSolver::resetObjectives()
{
d_optChecker.reset();
- d_objectives.pop_back();
- d_results.pop_back();
+ d_objectives.clear();
+ d_results.clear();
}
std::vector<OptimizationResult> OptimizationSolver::getValues()
* v_x = max(x) s.t. phi(x, y) = sat
* v_y = max(y) s.t. phi(x, y) = sat
*
- * Lexicographic: optimize the objectives one-by-one, in the order they push
- * v_x = max(x) s.t. phi(x, y) = sat
+ * Lexicographic: optimize the objectives one-by-one, in the order they are
+ * added:
+ * v_x = max(x) s.t. phi(x, y) = sat
* v_y = max(y) s.t. phi(v_x, y) = sat
*
* Pareto: optimize multiple goals to a state such that
- * further optimization of one goal will worsen the other goal(s)
+ * further optimization of one goal will worsen the other goal(s)
* (v_x, v_y) s.t. phi(v_x, v_y) = sat, and
* forall (x, y), (phi(x, y) = sat) -> (x <= v_x or y <= v_y)
**/
~OptimizationSolver() = default;
/**
- * Run the optimization loop for the pushed objective
+ * Run the optimization loop for the added objective
* For multiple objective combination, it defaults to lexicographic,
* and combination could be set by calling
* setObjectiveCombination(BOX/LEXICOGRAPHIC/PARETO)
OptimizationResult::ResultType checkOpt();
/**
- * Push an objective.
- * @param target the Node representing the expression that will be optimized
- *for
+ * Add an optimization objective.
+ * @param target Node representing the expression that will be optimized for
* @param type specifies whether it's maximize or minimize
* @param bvSigned specifies whether we should use signed/unsigned
* comparison for BitVectors (only effective for BitVectors)
* and its default is false
**/
- void pushObjective(TNode target,
- OptimizationObjective::ObjectiveType type,
- bool bvSigned = false);
+ void addObjective(TNode target,
+ OptimizationObjective::ObjectiveType type,
+ bool bvSigned = false);
/**
- * Pop the most recently successfully-pushed objective.
+ * Clear all the added optimization objectives
**/
- void popObjective();
+ void resetObjectives();
/**
* Returns the values of the optimized objective after checkOpt is called
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_ULE, a, x));
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_ULE, x, b));
- d_optslv->pushObjective(x, OptimizationObjective::MINIMIZE, false);
+ d_optslv->addObjective(x, OptimizationObjective::MINIMIZE, false);
OptimizationResult::ResultType r = d_optslv->checkOpt();
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<BitVector>(),
BitVector(32u, (uint32_t)0x3FFFFFA1));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteBVOpt, signed_min)
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_SLE, a, x));
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_SLE, x, b));
- d_optslv->pushObjective(x, OptimizationObjective::MINIMIZE, true);
+ d_optslv->addObjective(x, OptimizationObjective::MINIMIZE, true);
OptimizationResult::ResultType r = d_optslv->checkOpt();
// expect the minimum x = -1
ASSERT_EQ(val, BitVector(32u, (uint32_t)0x80000000));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteBVOpt, unsigned_max)
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_ULE, a, x));
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_ULE, x, b));
- d_optslv->pushObjective(x, OptimizationObjective::MAXIMIZE, false);
+ d_optslv->addObjective(x, OptimizationObjective::MAXIMIZE, false);
OptimizationResult::ResultType r = d_optslv->checkOpt();
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<BitVector>(),
BitVector(32u, 2u));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteBVOpt, signed_max)
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_SLE, a, x));
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_SLE, x, b));
- d_optslv->pushObjective(x, OptimizationObjective::MAXIMIZE, true);
+ d_optslv->addObjective(x, OptimizationObjective::MAXIMIZE, true);
OptimizationResult::ResultType r = d_optslv->checkOpt();
// expect the maxmum x =
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<BitVector>(),
BitVector(32u, 10u));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteBVOpt, min_boundary)
// that existed previously
d_smtEngine->assertFormula(d_nodeManager->mkNode(kind::BITVECTOR_SLE, y, x));
- d_optslv->pushObjective(x, OptimizationObjective::MINIMIZE, false);
+ d_optslv->addObjective(x, OptimizationObjective::MINIMIZE, false);
OptimizationResult::ResultType r = d_optslv->checkOpt();
// expect the maximum x = 18
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<BitVector>(),
BitVector(32u, 18u));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
-
} // namespace test
} // namespace cvc5
d_smtEngine->assertFormula(lowb);
// We activate our objective so the subsolver knows to optimize it
- d_optslv->pushObjective(max_cost, OptimizationObjective::MAXIMIZE);
+ d_optslv->addObjective(max_cost, OptimizationObjective::MAXIMIZE);
OptimizationResult::ResultType r = d_optslv->checkOpt();
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<Rational>(),
Rational("99"));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteIntOpt, min)
d_smtEngine->assertFormula(lowb);
// We activate our objective so the subsolver knows to optimize it
- d_optslv->pushObjective(max_cost, OptimizationObjective::MINIMIZE);
+ d_optslv->addObjective(max_cost, OptimizationObjective::MINIMIZE);
OptimizationResult::ResultType r = d_optslv->checkOpt();
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<Rational>(),
Rational("1"));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteIntOpt, result)
d_smtEngine->assertFormula(lowb);
// We activate our objective so the subsolver knows to optimize it
- d_optslv->pushObjective(max_cost, OptimizationObjective::MAXIMIZE);
+ d_optslv->addObjective(max_cost, OptimizationObjective::MAXIMIZE);
// This should return OPT_UNSAT since 0 > x > 100 is impossible.
OptimizationResult::ResultType r = d_optslv->checkOpt();
// We expect our check to have returned UNSAT
ASSERT_EQ(r, OptimizationResult::UNSAT);
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
TEST_F(TestTheoryWhiteIntOpt, open_interval)
*/
Node cost3 = d_nodeManager->mkNode(kind::PLUS, cost1, cost2);
- d_optslv->pushObjective(cost3, OptimizationObjective::MINIMIZE);
+ d_optslv->addObjective(cost3, OptimizationObjective::MINIMIZE);
OptimizationResult::ResultType r = d_optslv->checkOpt();
// expect the minimum result of cost3 = cost1 + cost2 to be 1 + 111 = 112
ASSERT_EQ(d_optslv->getValues()[0].getValue().getConst<Rational>(),
Rational("112"));
- d_optslv->popObjective();
+ d_optslv->resetObjectives();
}
} // namespace test
optSolver.setObjectiveCombination(OptimizationSolver::BOX);
// minimize x
- optSolver.pushObjective(x, OptimizationObjective::MINIMIZE, false);
+ optSolver.addObjective(x, OptimizationObjective::MINIMIZE, false);
// maximize y with `signed` comparison over bit-vectors.
- optSolver.pushObjective(y, OptimizationObjective::MAXIMIZE, true);
+ optSolver.addObjective(y, OptimizationObjective::MAXIMIZE, true);
// maximize z
- optSolver.pushObjective(z, OptimizationObjective::MAXIMIZE, false);
+ optSolver.addObjective(z, OptimizationObjective::MAXIMIZE, false);
OptimizationResult::ResultType r = optSolver.checkOpt();
optSolver.setObjectiveCombination(OptimizationSolver::LEXICOGRAPHIC);
// minimize x
- optSolver.pushObjective(x, OptimizationObjective::MINIMIZE, false);
+ optSolver.addObjective(x, OptimizationObjective::MINIMIZE, false);
// maximize y with `signed` comparison over bit-vectors.
- optSolver.pushObjective(y, OptimizationObjective::MAXIMIZE, true);
+ optSolver.addObjective(y, OptimizationObjective::MAXIMIZE, true);
// maximize z
- optSolver.pushObjective(z, OptimizationObjective::MAXIMIZE, false);
+ optSolver.addObjective(z, OptimizationObjective::MAXIMIZE, false);
OptimizationResult::ResultType r = optSolver.checkOpt();
*/
OptimizationSolver optSolver(d_smtEngine.get());
optSolver.setObjectiveCombination(OptimizationSolver::PARETO);
- optSolver.pushObjective(a, OptimizationObjective::MAXIMIZE);
- optSolver.pushObjective(b, OptimizationObjective::MAXIMIZE);
+ optSolver.addObjective(a, OptimizationObjective::MAXIMIZE);
+ optSolver.addObjective(b, OptimizationObjective::MAXIMIZE);
OptimizationResult::ResultType r;