20#include "absl/log/check.h"
21#include "absl/strings/string_view.h"
24#include "ortools/sat/boolean_problem.pb.h"
29using ::operations_research::sat::LinearBooleanConstraint;
30using ::operations_research::sat::LinearBooleanProblem;
31using ::operations_research::sat::LinearObjective;
37 absl::string_view
name)
40 values_(problem.num_variables(), false),
41 recompute_cost_(true),
42 recompute_is_feasible_(true),
46 const LinearObjective& objective = problem.objective();
47 for (
int i = 0; i < objective.coefficients_size(); ++i) {
48 const VariableIndex
var(objective.literals(i) - 1);
49 values_[
var] = objective.coefficients(i) < 0;
53int64_t BopSolution::ComputeCost()
const {
54 recompute_cost_ =
false;
56 const LinearObjective& objective = problem_->objective();
57 const size_t num_sparse_vars = objective.literals_size();
58 CHECK_EQ(num_sparse_vars, objective.coefficients_size());
59 for (
int i = 0; i < num_sparse_vars; ++i) {
60 CHECK_GT(objective.literals(i), 0);
61 const VariableIndex
var(abs(objective.literals(i)) - 1);
63 sum += objective.coefficients(i);
69bool BopSolution::ComputeIsFeasible()
const {
70 recompute_is_feasible_ =
false;
71 for (
const LinearBooleanConstraint& constraint : problem_->constraints()) {
73 const size_t num_sparse_vars = constraint.literals_size();
74 CHECK_EQ(num_sparse_vars, constraint.coefficients_size());
76 for (
int i = 0;
i < num_sparse_vars; ++
i) {
78 CHECK_GT(constraint.literals(i), 0);
79 const VariableIndex
var(abs(constraint.literals(i)) - 1);
81 sum += constraint.coefficients(i);
85 if ((constraint.has_upper_bound() && sum > constraint.upper_bound()) ||
86 (constraint.has_lower_bound() && sum < constraint.lower_bound())) {
BopSolution(const sat::LinearBooleanProblem &problem, absl::string_view name)
const std::string name
A name for logging purposes.
In SWIG mode, we don't want anything besides these top-level includes.