 |
OR-Tools
8.1
|
Go to the documentation of this file.
38 #ifndef OR_TOOLS_SAT_CP_MODEL_H_
39 #define OR_TOOLS_SAT_CP_MODEL_H_
43 #include "absl/container/flat_hash_map.h"
44 #include "absl/types/span.h"
75 const std::string&
Name()
const {
return Proto().name(); }
82 return other.cp_model_ == cp_model_ && other.index_ == index_;
87 return other.cp_model_ != cp_model_ || other.index_ != index_;
94 const IntegerVariableProto&
Proto()
const {
95 return cp_model_->variables(index_);
100 return cp_model_->mutable_variables(index_);
109 int index()
const {
return index_; }
124 CpModelProto* cp_model_ =
nullptr;
161 const std::string&
Name()
const {
return Proto().name(); }
169 return other.cp_model_ == cp_model_ && other.index_ == index_;
174 return other.cp_model_ != cp_model_ || other.index_ != index_;
181 const IntegerVariableProto&
Proto()
const {
182 return cp_model_->variables(index_);
187 return cp_model_->mutable_variables(index_);
191 int index()
const {
return index_; }
207 CpModelProto* cp_model_ =
nullptr;
279 absl::Span<const int64> coeffs);
286 absl::Span<const int64> coeffs);
291 const std::vector<IntVar>&
variables()
const {
return variables_; }
294 const std::vector<int64>&
coefficients()
const {
return coefficients_; }
302 std::vector<IntVar> variables_;
303 std::vector<int64> coefficients_;
335 std::string
Name()
const;
355 return other.cp_model_ == cp_model_ && other.index_ == index_;
360 return other.cp_model_ != cp_model_ || other.index_ != index_;
367 const IntervalConstraintProto&
Proto()
const {
368 return cp_model_->constraints(index_).interval();
373 return cp_model_->mutable_constraints(index_)->mutable_interval();
377 int index()
const {
return index_; }
387 CpModelProto* cp_model_ =
nullptr;
430 const std::string&
Name()
const;
500 void AddTuple(absl::Span<const int64> tuple);
663 absl::Span<const IntVar> variables,
734 absl::Span<const IntVar> inverse_variables);
784 absl::Span<const IntVar> transition_variables,
int starting_state,
785 absl::Span<const int> final_states);
792 absl::Span<const LinearExpr> exprs);
799 absl::Span<const LinearExpr> exprs);
849 absl::Span<const IntVar> variables,
850 DecisionStrategyProto::VariableSelectionStrategy var_strategy,
851 DecisionStrategyProto::DomainReductionStrategy domain_strategy);
855 absl::Span<const BoolVar> variables,
856 DecisionStrategyProto::VariableSelectionStrategy var_strategy,
857 DecisionStrategyProto::DomainReductionStrategy domain_strategy);
866 const CpModelProto&
Proto()
const {
return cp_model_; }
874 void LinearExprToProto(
const LinearExpr& expr,
875 LinearExpressionProto* expr_proto);
885 int GetOrCreateIntegerIndex(
int index);
888 LinearConstraintProto*
proto);
890 CpModelProto cp_model_;
891 absl::flat_hash_map<int64, int> constant_to_index_map_;
892 absl::flat_hash_map<int, int> bool_to_integer_index_map_;
910 #endif // OR_TOOLS_SAT_CP_MODEL_H_
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
BoolVar Not(BoolVar x)
A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.
TableConstraint AddAllowedAssignments(absl::Span< const IntVar > vars)
Adds an allowed assignments constraint.
LinearExpr AddConstant(int64 value) const
Adds a constant value to an integer variable and returns a linear expression.
Constraint(ConstraintProto *proto)
const std::string & Name() const
Returns the name of the variable (or the empty string if not set).
BoolVar TrueVar()
Creates an always true Boolean variable.
bool operator!=(const BoolVar &other) const
Dis-Equality test.
void AddVar(IntVar var)
Adds a single integer variable to the linear expression.
friend int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
void AddEvent(IntVar time, int64 demand)
Adds a mandatory event.
Specialized no_overlap2D constraint.
void AddRectangle(IntervalVar x_coordinate, IntervalVar y_coordinate)
Adds a rectangle (parallel to the axis) to the constraint.
bool operator!=(const IntVar &other) const
Difference test with anpther IntVar.
Constraint AddAbsEquality(IntVar target, IntVar var)
Adds target == abs(var).
static LinearExpr Term(IntVar var, int64 coefficient)
Construncts var * coefficient.
const CpModelProto & Proto() const
int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Specialized automaton constraint.
Specialized circuit constraint.
CumulativeConstraint AddCumulative(IntVar capacity)
The cumulative constraint.
Constraint WithName(const std::string &name)
Sets the name of the constraint.
void Maximize(const LinearExpr &expr)
Adds a linear maximization objective.
static LinearExpr BooleanScalProd(absl::Span< const BoolVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of Booleans and coefficients.
const std::vector< int64 > & coefficients() const
Returns the vector of coefficients.
static LinearExpr ScalProd(absl::Span< const IntVar > vars, absl::Span< const int64 > coeffs)
Constructs the scalar product of variables and coefficients.
void AddDecisionStrategy(absl::Span< const IntVar > variables, DecisionStrategyProto::VariableSelectionStrategy var_strategy, DecisionStrategyProto::DomainReductionStrategy domain_strategy)
Adds a decision strategy on a list of integer variables.
Constraint AddLinMinEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == min(exprs).
bool operator==(const BoolVar &other) const
Equality test with another boolvar.
Constraint AddInverseConstraint(absl::Span< const IntVar > variables, absl::Span< const IntVar > inverse_variables)
An inverse constraint.
const IntervalConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
IntervalVar NewOptionalIntervalVar(IntVar start, IntVar size, IntVar end, BoolVar presence)
Creates an optional interval variable.
Constraint AddNotEqual(const LinearExpr &left, const LinearExpr &right)
Adds left != right.
std::string DebugString() const
Debug string.
Constraint AddMinEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == min(vars).
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
bool operator==(const IntVar &other) const
Equality test with another IntVar.
BoolVar Not() const
Returns the logical negation of the current Boolean variable.
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
void AddOptionalEvent(IntVar time, int64 demand, BoolVar is_active)
Adds a optional event.
Specialized circuit constraint.
static LinearExpr BooleanSum(absl::Span< const BoolVar > vars)
Constructs the sum of a list of Booleans.
Specialized assignment constraint.
We call domain any subset of Int64 = [kint64min, kint64max].
bool operator==(const IntervalVar &other) const
Equality test with another interval variable.
friend bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
Constraint AddGreaterThan(const LinearExpr &left, const LinearExpr &right)
Adds left > right.
void AddDemand(IntervalVar interval, IntVar demand)
Adds a pair (interval, demand) to the constraint.
Wrapper class around the cp_model proto.
BoolVar ToBoolVar() const
Cast IntVar -> BoolVar.
friend std::ostream & operator<<(std::ostream &os, const IntervalVar &var)
NoOverlap2DConstraint AddNoOverlap2D()
The no_overlap_2d constraint prevents a set of boxes from overlapping.
MultipleCircuitConstraint AddMultipleCircuitConstraint()
Adds a multiple circuit constraint, aka the "VRP" (Vehicle Routing Problem) constraint.
void AddTransition(int tail, int head, int64 transition_label)
Adds a transitions to the automaton.
Constraint AddDivisionEquality(IntVar target, IntVar numerator, IntVar denominator)
Adds target = num / denom (integer division rounded towards 0).
Constraint AddImplication(BoolVar a, BoolVar b)
Adds a => b.
const CpModelProto & Build() const
CpModelProto * MutableProto()
Constraint AddNoOverlap(absl::Span< const IntervalVar > vars)
Adds a no-overlap constraint that ensures that all present intervals do not overlap in time.
Constraint AddElement(IntVar index, absl::Span< const int64 > values, IntVar target)
Adds the element constraint: values[index] == target.
LinearExpr & AddConstant(int64 value)
Adds a constant value to the linear expression.
TableConstraint AddForbiddenAssignments(absl::Span< const IntVar > vars)
Adds an forbidden assignments constraint.
std::string DebugString() const
Returns a debug string.
Constraint AddBoolAnd(absl::Span< const BoolVar > literals)
Adds the constraint that all literals must be true.
IntVar SizeVar() const
Returns the size variable.
friend int64 SolutionIntegerMax(const CpSolverResponse &r, IntVar x)
Returns the max of an integer variable in a solution.
int index() const
Returns the index of the variable in the model.
const ConstraintProto & Proto() const
Returns the underlying protobuf object (useful for testing).
Constraint AddLinMaxEquality(const LinearExpr &target, absl::Span< const LinearExpr > exprs)
Adds target == max(exprs).
Constraint AddLessOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left <= right.
IntVar EndVar() const
Returns the end variable.
std::string Name() const
Returns the name of the interval (or the empty string if not set).
IntervalConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
BoolVar FalseVar()
Creates an always false Boolean variable.
Constraint AddModuloEquality(IntVar target, IntVar var, IntVar mod)
Adds target = var % mod.
void AddTerm(IntVar var, int64 coeff)
Adds a term (var * coeff) to the linear expression.
void AddTuple(absl::Span< const int64 > tuple)
Adds a tuple of possible values to the constraint.
IntVar WithName(const std::string &name)
Sets the name of the variable.
Constraint AddBoolXor(absl::Span< const BoolVar > literals)
Adds the constraint that a odd number of literal is true.
int index() const
Returns the index of the interval constraint in the model.
static const int32 kint32min
AutomatonConstraint AddAutomaton(absl::Span< const IntVar > transition_variables, int starting_state, absl::Span< const int > final_states)
An automaton constraint/.
int index() const
Returns the index of the variable in the model.
CircuitConstraint AddCircuitConstraint()
Adds a circuit constraint.
ReservoirConstraint AddReservoirConstraint(int64 min_level, int64 max_level)
Adds a reservoir constraint with optional refill/emptying events.
const std::vector< IntVar > & variables() const
Returns the vector of variables.
Specialized cumulative constraint.
void ScaleObjectiveBy(double scaling)
Sets scaling of the objective.
int64 SolutionIntegerValue(const CpSolverResponse &r, const LinearExpr &expr)
Evaluates the value of an linear expression in a solver response.
Constraint AddBoolOr(absl::Span< const BoolVar > literals)
Adds the constraint that at least one of the literals must be true.
IntervalVar NewIntervalVar(IntVar start, IntVar size, IntVar end)
Creates an interval variable.
bool operator!=(const IntervalVar &other) const
Difference test with another interval variable.
std::string DebugString() const
Returns a debug string.
IntVar NewConstant(int64 value)
Creates a constant variable.
Constraint AddLinearConstraint(const LinearExpr &expr, const Domain &domain)
Adds expr in domain.
Represents a Interval variable.
friend int64 SolutionIntegerMin(const CpSolverResponse &r, IntVar x)
Returns the min of an integer variable in a solution.
BoolVar WithName(const std::string &name)
Sets the name of the variable.
Constraint AddLessThan(const LinearExpr &left, const LinearExpr &right)
Adds left < right.
int64 constant() const
Returns the constant term.
Constraint AddEquality(const LinearExpr &left, const LinearExpr &right)
Adds left == right.
BoolVar PresenceBoolVar() const
Returns a BoolVar indicating the presence of this interval.
IntVar NewIntVar(const Domain &domain)
Creates an integer variable with the given domain.
Constraint AddGreaterOrEqual(const LinearExpr &left, const LinearExpr &right)
Adds left >= right.
IntVar StartVar() const
Returns the start variable.
void AddHint(IntVar var, int64 value)
Adds hinting to a variable.
const std::string & Name() const
Returns the name of the constraint (or the empty string if not set).
Constraint AddAllDifferent(absl::Span< const IntVar > vars)
this constraint forces all variables to have different values.
IntervalVar()
Default ctor.
const std::string & Name() const
Returns the name of the variable.
IntegerVariableProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
static LinearExpr Sum(absl::Span< const IntVar > vars)
Constructs the sum of a list of variables.
Specialized reservoir constraint.
const IntegerVariableProto & Proto() const
Returns the underlying protobuf object (useful for testing).
void Minimize(const LinearExpr &expr)
Adds a linear minimization objective.
ConstraintProto * MutableProto() const
Returns the mutable underlying protobuf object (useful for model edition).
Constraint AddProductEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == prod(vars).
bool SolutionBooleanValue(const CpSolverResponse &r, BoolVar x)
Evaluates the value of a Boolean literal in a solver response.
Constraint OnlyEnforceIf(absl::Span< const BoolVar > literals)
The constraint will be enforced iff all literals listed here are true.
IntervalVar WithName(const std::string &name)
Sets the name of the variable.
Constraint AddMaxEquality(IntVar target, absl::Span< const IntVar > vars)
Adds target == max(vars).
A dedicated container for linear expressions.
Constraint AddVariableElement(IntVar index, absl::Span< const IntVar > variables, IntVar target)
Adds the element constraint: variables[index] == target.
BoolVar NewBoolVar()
Creates a Boolean variable.
void AddArc(int tail, int head, BoolVar literal)
Add an arc to the circuit.