14#ifndef OR_TOOLS_SAT_CP_MODEL_UTILS_H_
15#define OR_TOOLS_SAT_CP_MODEL_UTILS_H_
24#include "absl/container/flat_hash_set.h"
40 return !
ct.enforcement_literal().empty();
43 return ct.enforcement_literal(0);
48 LinearExpressionProto* output_negated_expr);
83template <
typename ProtoWithDomain>
85 for (
int i = 0; i <
proto.domain_size(); i += 2) {
92template <
typename ProtoWithDomain>
94 proto->clear_domain();
103template <
typename ProtoWithDomain>
105#if defined(__PORTABLE_PLATFORM__)
107 {
proto.domain().begin(),
proto.domain().end()});
117template <
typename ProtoWithDomain>
119 std::vector<int64_t> result;
120 for (
int i = 0; i <
proto.domain_size(); i += 2) {
121 for (int64_t v =
proto.domain(i); v <=
proto.domain(i + 1); ++v) {
132 double result =
static_cast<double>(
value);
134 result = -std::numeric_limits<double>::infinity();
136 result = std::numeric_limits<double>::infinity();
137 result +=
proto.offset();
138 if (
proto.scaling_factor() == 0)
return result;
139 return proto.scaling_factor() * result;
145 double result =
value;
146 if (
proto.scaling_factor() != 0) {
147 result /=
proto.scaling_factor();
149 return result -
proto.offset();
#define CHECK_LE(val1, val2)
We call domain any subset of Int64 = [kint64min, kint64max].
static Domain FromFlatSpanOfIntervals(absl::Span< const int64_t > flat_intervals)
Same as FromIntervals() for a flattened representation (start, end, start, end, .....
int NumIntervals() const
Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals.
static Domain FromFlatIntervals(const std::vector< int64_t > &flat_intervals)
This method is available in Python, Java and .NET.
SharedResponseManager * response
int64_t ComputeInnerObjective(const CpObjectiveProto &objective, const CpSolverResponse &response)
std::vector< int > UsedVariables(const ConstraintProto &ct)
double UnscaleObjectiveValue(const CpObjectiveProto &proto, double value)
bool RefIsPositive(int ref)
std::vector< int > UsedIntervals(const ConstraintProto &ct)
void SetToNegatedLinearExpression(const LinearExpressionProto &input_expr, LinearExpressionProto *output_negated_expr)
bool HasEnforcementLiteral(const ConstraintProto &ct)
bool DomainInProtoContains(const ProtoWithDomain &proto, int64_t value)
double ScaleObjectiveValue(const CpObjectiveProto &proto, int64_t value)
void ApplyToAllLiteralIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
void ApplyToAllIntervalIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
void FillDomainInProto(const Domain &domain, ProtoWithDomain *proto)
Domain ReadDomainFromProto(const ProtoWithDomain &proto)
void ApplyToAllVariableIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
IndexReferences GetReferencesUsedByConstraint(const ConstraintProto &ct)
std::string ConstraintCaseName(ConstraintProto::ConstraintCase constraint_case)
int EnforcementLiteral(const ConstraintProto &ct)
std::vector< int64_t > AllValuesInDomain(const ProtoWithDomain &proto)
Collection of objects used to extend the Constraint Solver library.
Represents a closed interval [start, end].
std::vector< int > variables
std::vector< int > literals