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);
83 template <
typename ProtoWithDomain>
85 for (
int i = 0; i <
proto.domain_size(); i += 2) {
92 template <
typename ProtoWithDomain>
94 proto->clear_domain();
103 template <
typename ProtoWithDomain>
105 #if defined(__PORTABLE_PLATFORM__) 107 {
proto.domain().begin(),
proto.domain().end()});
117 template <
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();
161 #endif // OR_TOOLS_SAT_CP_MODEL_UTILS_H_ std::vector< int > UsedVariables(const ConstraintProto &ct)
void ApplyToAllIntervalIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
std::vector< int64_t > AllValuesInDomain(const ProtoWithDomain &proto)
void ApplyToAllVariableIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
Represents a closed interval [start, end].
double ScaleObjectiveValue(const CpObjectiveProto &proto, int64_t value)
#define CHECK_LE(val1, val2)
SharedResponseManager * response
std::vector< int > UsedIntervals(const ConstraintProto &ct)
double UnscaleObjectiveValue(const CpObjectiveProto &proto, double value)
int EnforcementLiteral(const ConstraintProto &ct)
std::string ConstraintCaseName(ConstraintProto::ConstraintCase constraint_case)
static Domain FromFlatSpanOfIntervals(absl::Span< const int64_t > flat_intervals)
Same as FromIntervals() for a flattened representation (start, end, start, end, .....
We call domain any subset of Int64 = [kint64min, kint64max].
void FillDomainInProto(const Domain &domain, ProtoWithDomain *proto)
static Domain FromFlatIntervals(const std::vector< int64_t > &flat_intervals)
This method is available in Python, Java and .NET.
bool HasEnforcementLiteral(const ConstraintProto &ct)
Collection of objects used to extend the Constraint Solver library.
int64_t ComputeInnerObjective(const CpObjectiveProto &objective, const CpSolverResponse &response)
std::vector< int > literals
bool RefIsPositive(int ref)
std::vector< int > variables
Domain ReadDomainFromProto(const ProtoWithDomain &proto)
bool DomainInProtoContains(const ProtoWithDomain &proto, int64_t value)
void ApplyToAllLiteralIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
int NumIntervals() const
Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals.
IndexReferences GetReferencesUsedByConstraint(const ConstraintProto &ct)
void SetToNegatedLinearExpression(const LinearExpressionProto &input_expr, LinearExpressionProto *output_negated_expr)