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()) {
36 delta[
i] = a[
i] -
b[
i];
42template <
typename IndexType,
typename ValueType>
46 double time_limit_in_seconds) {
47 return NextSolution(inv_->model()->all_subsets(), use_integers,
48 time_limit_in_seconds);
53 double time_limit_in_seconds) {
55 const SubsetIndex num_subsets(model->
num_subsets());
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";
98 MPSolver solver(
"set cover mip", problem_type);
106 Subtract(inv_->coverage(), inv_->ComputeCoverageInFocus(focus));
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;
114 if (constraints[element] ==
nullptr) {
115 constexpr double kInfinity = std::numeric_limits<double>::infinity();
118 constraints[element]->SetCoefficient(vars[subset], 1);
122 solver.
set_time_limit(
static_cast<int64_t
>(time_limit_in_seconds * 1000));
126 switch (solve_status) {
132 LOG(ERROR) <<
"Did not find solution. Problem is infeasible.";
135 LOG(ERROR) <<
"Did not find solution. Problem is unbounded.";
138 LOG(ERROR) <<
"Solving resulted in an error.";
143 for (
const SubsetIndex subset : focus) {
144 if (vars[subset]->solution_value() > 0.9) {
145 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)
bool NextSolution(bool use_integers, double time_limit_in_seconds)
Main class for describing a weighted set-covering problem.
BaseInt num_elements() const
const SubsetCostVector & subset_costs() const
Vector of costs for each subset.
const SparseColumnView & columns() const
Column view of the set covering problem.
BaseInt num_subsets() const
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