19#include "absl/log/check.h"
20#include "absl/log/log.h"
21#include "absl/types/span.h"
35 DCHECK_EQ(a.size(),
b.size());
36 for (
const ElementIndex i : a.index_range()) {
37 delta[
i] = a[
i] -
b[
i];
43template <
typename IndexType,
typename ValueType>
50 const ElementIndex num_elements(
model()->num_elements());
53 switch (mip_solver_) {
66 VLOG(1) <<
"Defaulting to integer variables with SAT";
72 VLOG(1) <<
"Defaulting to linear relaxation with GLOP";
73 use_integers_ =
false;
78 VLOG(1) <<
"Defaulting to linear relaxation with PDLP";
79 use_integers_ =
false;
84 LOG(WARNING) <<
"Unknown solver value, defaulting to SCIP";
92 MPSolver solver(
"set cover mip", problem_type);
100 Subtract(
inv()->coverage(),
inv()->ComputeCoverageInFocus(focus));
101 for (
const SubsetIndex subset : focus) {
102 vars[subset] = solver.
MakeVar(0, 1, use_integers_,
"");
104 for (
const ElementIndex element :
model()->columns()[subset]) {
107 if (coverage_outside_focus[element] != 0)
continue;
108 if (constraints[element] ==
nullptr) {
109 constexpr double kInfinity = std::numeric_limits<double>::infinity();
112 constraints[element]->SetCoefficient(vars[subset], 1);
119 solve_status_ = solver.
Solve();
120 switch (solve_status_) {
126 LOG(ERROR) <<
"Did not find solution. Problem is infeasible.";
129 LOG(ERROR) <<
"Did not find solution. Problem is unbounded.";
132 LOG(ERROR) <<
"Solving resulted in an error.";
137 for (
const SubsetIndex subset : focus) {
138 if (vars[subset]->solution_value() > 0.9 &&
139 !
inv()->is_selected()[subset]) {
140 inv()->
Select(subset, CL::kCostAndCoverage);
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)
const SubsetBoolVector & is_selected() const
Returns the subset assignment vector.
void ReportLowerBound(Cost lower_bound, bool is_cost_consistent)
bool Select(SubsetIndex subset, ConsistencyLevel consistency)
bool NextSolution() final
Virtual methods that must be implemented by derived classes.
BaseInt num_subsets() const
absl::Duration run_time_
run_time_ is an abstract duration for the time spent in NextSolution().
SetCoverModel * model() const
Accessors.
SetCoverInvariant * inv() const
double time_limit_in_seconds() const
The time limit in seconds.
In SWIG mode, we don't want anything besides these top-level includes.
static constexpr double kInfinity
SetCoverInvariant::ConsistencyLevel CL
util_intops::StrongVector< ElementIndex, BaseInt > ElementToIntVector
util_intops::StrongVector< SubsetIndex, bool > SubsetBoolVector
glop::StrictITIVector< IndexType, ValueType > StrictVector