19#include "absl/log/check.h"
20#include "absl/types/span.h"
34 DCHECK_EQ(
a.size(),
b.size());
35 for (
const ElementIndex i :
a.index_range()) {
42template <
typename IndexType,
typename ValueType>
46 double time_limit_in_seconds) {
48 time_limit_in_seconds);
53 double time_limit_in_seconds) {
55 const SubsetIndex num_subsets(
model->num_subsets());
56 const ElementIndex num_elements(
model->num_elements());
59 switch (mip_solver_) {
72 LOG(INFO) <<
"Defaulting to integer variables with SAT";
78 LOG(INFO) <<
"Defaulting to linear relaxation with GLOP";
84 LOG(INFO) <<
"Defaulting to linear relaxation with PDLP";
90 LOG(WARNING) <<
"Unknown solver value, defaulting to SCIP";
107 for (
const SubsetIndex subset : focus) {
108 vars[subset] = solver.
MakeVar(0, 1, use_integers,
"");
110 for (
const ElementIndex element :
model->columns()[subset]) {
113 if (coverage_outside_focus[element] == 0)
continue;
115 if (constraints[element] ==
nullptr) {
116 constexpr double kInfinity = std::numeric_limits<double>::infinity();
119 constraints[element]->SetCoefficient(vars[subset], 1);
123 solver.
set_time_limit(
static_cast<int64_t
>(time_limit_in_seconds * 1000));
127 switch (solve_status) {
133 LOG(ERROR) <<
"Did not find solution. Problem is infeasible.";
136 LOG(ERROR) <<
"Did not find solution. Problem is unbounded.";
139 LOG(ERROR) <<
"Solving resulted in an error.";
143 for (
const SubsetIndex subset : focus) {
144 choices[subset] = (vars[subset]->solution_value() > 0.9);
A class to express a linear objective.
void SetCoefficient(const MPVariable *var, double coeff)
void SetMinimization()
Sets the optimization direction to minimize.
MPVariable * MakeVar(double lb, double ub, bool integer, const std::string &name)
@ FEASIBLE
feasible, or stopped by limit.
@ INFEASIBLE
proven infeasible.
@ UNBOUNDED
proven unbounded.
ResultStatus Solve()
Solves the problem using the default parameter values.
const MPObjective & Objective() const
@ GLOP_LINEAR_PROGRAMMING
@ SCIP_MIXED_INTEGER_PROGRAMMING
Recommended default value for MIP problems.
@ SAT_INTEGER_PROGRAMMING
@ GUROBI_MIXED_INTEGER_PROGRAMMING
@ PDLP_LINEAR_PROGRAMMING
@ GUROBI_LINEAR_PROGRAMMING
Commercial software (need license).
MPObjective * MutableObjective()
Returns the mutable objective object.
void SuppressOutput()
Suppresses solver logging.
MPConstraint * MakeRowConstraint(double lb, double ub)
void set_time_limit(int64_t time_limit_milliseconds)
void LoadSolution(const SubsetBoolVector &solution)
Loads the solution and recomputes the data in the invariant.
const SubsetBoolVector & is_selected() const
Returns the subset assignment vector.
SetCoverModel * model() const
Returns the weighted set covering model to which the state applies.
const ElementToIntVector & coverage() const
Returns vector containing number of subsets covering each element.
ElementToIntVector ComputeCoverageInFocus(absl::Span< const SubsetIndex > focus) const
bool NextSolution(bool use_integers, double time_limit_in_seconds)
Main class for describing a weighted set-covering problem.
std::vector< SubsetIndex > all_subsets() const
Returns the list of indices for all the subsets in the model.
MPSolver::OptimizationProblemType problem_type
In SWIG mode, we don't want anything besides these top-level includes.
util_intops::StrongVector< ElementIndex, BaseInt, IntAllocator > ElementToIntVector