14#ifndef OR_TOOLS_SAT_CP_MODEL_UTILS_H_
15#define OR_TOOLS_SAT_CP_MODEL_UTILS_H_
22#include "absl/container/flat_hash_set.h"
25#include "ortools/sat/cp_model.pb.h"
38 return !
ct.enforcement_literal().empty();
41 return ct.enforcement_literal(0);
46 LinearExpressionProto* output_negated_expr);
81template <
typename ProtoWithDomain>
83 for (
int i = 0; i <
proto.domain_size(); i += 2) {
90template <
typename ProtoWithDomain>
92 proto->clear_domain();
101template <
typename ProtoWithDomain>
103#if defined(__PORTABLE_PLATFORM__)
105 {
proto.domain().begin(),
proto.domain().end()});
115template <
typename ProtoWithDomain>
117 std::vector<int64> result;
118 for (
int i = 0; i <
proto.domain_size(); i += 2) {
129 double result =
static_cast<double>(
value);
130 if (
value ==
kint64min) result = -std::numeric_limits<double>::infinity();
131 if (
value ==
kint64max) result = std::numeric_limits<double>::infinity();
132 result +=
proto.offset();
133 if (
proto.scaling_factor() == 0)
return result;
134 return proto.scaling_factor() * result;
140 double result =
value;
141 if (
proto.scaling_factor() != 0) {
142 result /=
proto.scaling_factor();
144 return result -
proto.offset();
#define CHECK_LE(val1, val2)
We call domain any subset of Int64 = [kint64min, kint64max].
static Domain FromFlatIntervals(const std::vector< int64 > &flat_intervals)
This method is available in Python, Java and .NET.
int NumIntervals() const
Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals.
static Domain FromFlatSpanOfIntervals(absl::Span< const int64 > flat_intervals)
Same as FromIntervals() for a flattened representation (start, end, start, end, .....
SharedResponseManager * response
static const int64 kint64max
static const int64 kint64min
bool HasEnforcementLiteral(const ConstraintProto &ct)
std::vector< int > UsedVariables(const ConstraintProto &ct)
std::vector< int > UsedIntervals(const ConstraintProto &ct)
void SetToNegatedLinearExpression(const LinearExpressionProto &input_expr, LinearExpressionProto *output_negated_expr)
std::vector< int64 > AllValuesInDomain(const ProtoWithDomain &proto)
Domain ReadDomainFromProto(const ProtoWithDomain &proto)
int64 ComputeInnerObjective(const CpObjectiveProto &objective, const CpSolverResponse &response)
double UnscaleObjectiveValue(const CpObjectiveProto &proto, double value)
void ApplyToAllLiteralIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
void ApplyToAllIntervalIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
int EnforcementLiteral(const ConstraintProto &ct)
double ScaleObjectiveValue(const CpObjectiveProto &proto, int64 value)
void ApplyToAllVariableIndices(const std::function< void(int *)> &f, ConstraintProto *ct)
IndexReferences GetReferencesUsedByConstraint(const ConstraintProto &ct)
std::string ConstraintCaseName(ConstraintProto::ConstraintCase constraint_case)
bool RefIsPositive(int ref)
bool DomainInProtoContains(const ProtoWithDomain &proto, int64 value)
void FillDomainInProto(const Domain &domain, ProtoWithDomain *proto)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Represents a closed interval [start, end].
std::vector< int > variables
std::vector< int > literals