Documentation ¶
Overview ¶
Package cpmodel offers a user-friendly API to build CP-SAT models.
The `Builder` struct wraps the CP-SAT model proto and provides helper methods for adding constraints and variables to the model. The `IntVar`, `BoolVar`, and `IntervalVar` structs are references to specific variables in the CP-SAT model proto and provide helpful methods for interacting with those variables. The `LinearExpr` struct provides helper methods for creating constraints and the objective from expressions with many variables and coefficients.
Example ¶
model := NewCpModelBuilder() x := model.NewIntVar(1, 3) y := model.NewIntVar(1, 3) b := model.NewBoolVar() model.AddLessOrEqual(x, NewConstant(1)).OnlyEnforceIf(b) model.AddLessOrEqual(y, NewConstant(1)).OnlyEnforceIf(b.Not()) obj := NewLinearExpr().AddSum(x, b.Not()).AddTerm(y, 5) model.Maximize(obj) m, err := model.Model() if err != nil { log.Fatalf("Building model returned with error %v", err) } res, err := SolveCpModel(m) if err != nil { log.Fatalf("CP solver returned with unexpected err %v", err) } if res.GetStatus() != cmpb.CpSolverStatus_FEASIBLE && res.GetStatus() != cmpb.CpSolverStatus_OPTIMAL { log.Fatalf("CP solver returned with status %v", res.GetStatus()) } fmt.Println("Objective:", res.GetObjectiveValue()) fmt.Println("x:", SolutionIntegerValue(res, x)) fmt.Println("y:", SolutionIntegerValue(res, y)) fmt.Println("Int b:", SolutionIntegerValue(res, b)) fmt.Println("Bool b:", SolutionBooleanValue(res, b))
Output: Objective: 16 x: 1 y: 3 Int b: 1 Bool b: true
Index ¶
- Variables
- func SolutionBooleanValue(r *cmpb.CpSolverResponse, bv BoolVar) bool
- func SolutionIntegerValue(r *cmpb.CpSolverResponse, la LinearArgument) int64_t
- func SolveCpModel(input *cmpb.CpModelProto) (*cmpb.CpSolverResponse, error)
- func SolveCpModelInterruptibleWithParameters(input *cmpb.CpModelProto, params *sppb.SatParameters, ...) (*cmpb.CpSolverResponse, error)
- func SolveCpModelWithParameters(input *cmpb.CpModelProto, params *sppb.SatParameters) (*cmpb.CpSolverResponse, error)
- type AutomatonConstraint
- type BoolVar
- type Builder
- func (cp *Builder) AddAbsEquality(target, expr LinearArgument) Constraint
- func (cp *Builder) AddAllDifferent(la ...LinearArgument) Constraint
- func (cp *Builder) AddAllowedAssignments(vars ...IntVar) TableConstraint
- func (cp *Builder) AddAssumption(lits ...BoolVar)
- func (cp *Builder) AddAtLeastOne(bvs ...BoolVar) Constraint
- func (cp *Builder) AddAtMostOne(bvs ...BoolVar) Constraint
- func (cp *Builder) AddAutomaton(transitionVars []IntVar, startState int64_t, finalStates []int64) AutomatonConstraint
- func (cp *Builder) AddBoolAnd(bvs ...BoolVar) Constraint
- func (cp *Builder) AddBoolOr(bvs ...BoolVar) Constraint
- func (cp *Builder) AddBoolXor(bvs ...BoolVar) Constraint
- func (cp *Builder) AddCircuitConstraint() CircuitConstraint
- func (cp *Builder) AddCumulative(capacity LinearArgument) CumulativeConstraint
- func (cp *Builder) AddDecisionStrategy(vars []IntVar, vs cmpb.DecisionStrategyProto_VariableSelectionStrategy, ...)
- func (cp *Builder) AddDivisionEquality(target, num, denom LinearArgument) Constraint
- func (cp *Builder) AddElement(ind IntVar, values []int64, target IntVar) Constraint
- func (cp *Builder) AddEquality(lhs LinearArgument, rhs LinearArgument) Constraint
- func (cp *Builder) AddExactlyOne(bvs ...BoolVar) Constraint
- func (cp *Builder) AddGreaterOrEqual(lhs LinearArgument, rhs LinearArgument) Constraint
- func (cp *Builder) AddGreaterThan(lhs LinearArgument, rhs LinearArgument) Constraint
- func (cp *Builder) AddImplication(a, b BoolVar) Constraint
- func (cp *Builder) AddInverseConstraint(vars []IntVar, inverseVars []IntVar) Constraint
- func (cp *Builder) AddLessOrEqual(lhs LinearArgument, rhs LinearArgument) Constraint
- func (cp *Builder) AddLessThan(lhs LinearArgument, rhs LinearArgument) Constraint
- func (cp *Builder) AddLinearConstraint(expr LinearArgument, lb, ub int64_t) Constraint
- func (cp *Builder) AddLinearConstraintForDomain(expr LinearArgument, domain Domain) Constraint
- func (cp *Builder) AddMaxEquality(target LinearArgument, exprs ...LinearArgument) Constraint
- func (cp *Builder) AddMinEquality(target LinearArgument, exprs ...LinearArgument) Constraint
- func (cp *Builder) AddModuloEquality(target, v, mod LinearArgument) Constraint
- func (cp *Builder) AddMultipleCircuitConstraint() MultipleCircuitConstraint
- func (cp *Builder) AddMultiplicationEquality(target LinearArgument, exprs ...LinearArgument) Constraint
- func (cp *Builder) AddNoOverlap(vars ...IntervalVar) Constraint
- func (cp *Builder) AddNoOverlap2D() NoOverlap2DConstraint
- func (cp *Builder) AddNotEqual(lhs LinearArgument, rhs LinearArgument) Constraint
- func (cp *Builder) AddReservoirConstraint(min, max int64_t) ReservoirConstraint
- func (cp *Builder) AddVariableElement(ind IntVar, vars []IntVar, target IntVar) Constraint
- func (cp *Builder) ClearAssumption()
- func (cp *Builder) ClearHint()
- func (cp *Builder) FalseVar() BoolVar
- func (cp *Builder) Maximize(obj LinearArgument)
- func (cp *Builder) Minimize(obj LinearArgument)
- func (cp *Builder) Model() (*cmpb.CpModelProto, error)
- func (cp *Builder) NewBoolVar() BoolVar
- func (cp *Builder) NewConstant(v int64_t) IntVar
- func (cp *Builder) NewFixedSizeIntervalVar(start LinearArgument, size int64_t) IntervalVar
- func (cp *Builder) NewIntVar(lb, ub int64_t) IntVar
- func (cp *Builder) NewIntVarFromDomain(d Domain) IntVar
- func (cp *Builder) NewIntervalVar(start, size, end LinearArgument) IntervalVar
- func (cp *Builder) NewOptionalFixedSizeIntervalVar(start LinearArgument, size int64_t, presence BoolVar) IntervalVar
- func (cp *Builder) NewOptionalIntervalVar(start, size, end LinearArgument, presence BoolVar) IntervalVar
- func (cp *Builder) SetHint(hint *Hint)
- func (cp *Builder) TrueVar() BoolVar
- type CircuitConstraint
- type ClosedInterval
- type ConstrIndex
- type Constraint
- type CumulativeConstraint
- type Domain
- type Hint
- type IntVar
- type IntervalVar
- type LinearArgument
- type LinearExpr
- func (l *LinearExpr) Add(la LinearArgument) *LinearExpr
- func (l *LinearExpr) AddConstant(c int64_t) *LinearExpr
- func (l *LinearExpr) AddSum(las ...LinearArgument) *LinearExpr
- func (l *LinearExpr) AddTerm(la LinearArgument, coeff int64_t) *LinearExpr
- func (l *LinearExpr) AddWeightedSum(las []LinearArgument, coeffs []int64) *LinearExpr
- type MultipleCircuitConstraint
- type NoOverlap2DConstraint
- type ReservoirConstraint
- type TableConstraint
- type VarIndex
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMixedModels = errors.New("elements are not part of the same model")
ErrMixedModels holds the error when elements added to a model are different.
Functions ¶
func SolutionBooleanValue ¶
func SolutionBooleanValue(r *cmpb.CpSolverResponse, bv BoolVar) bool
SolutionBooleanValue returns the value of BoolVar `bv` in the response.
func SolutionIntegerValue ¶
func SolutionIntegerValue(r *cmpb.CpSolverResponse, la LinearArgument) int64_t
SolutionIntegerValue returns the value of LinearArgument `la` in the response.
func SolveCpModel ¶
func SolveCpModel(input *cmpb.CpModelProto) (*cmpb.CpSolverResponse, error)
SolveCpModel solves a CP Model with the given input proto and returns a CPSolverResponse.
func SolveCpModelInterruptibleWithParameters ¶
func SolveCpModelInterruptibleWithParameters(input *cmpb.CpModelProto, params *sppb.SatParameters, interrupt <-chan struct{}) (*cmpb.CpSolverResponse, error)
SolveCpModelInterruptibleWithParameters solves a CP Model with the given input proto and parameters and returns a CPSolverResponse. The solve can be interrupted by triggering the `interrupt`.
func SolveCpModelWithParameters ¶
func SolveCpModelWithParameters(input *cmpb.CpModelProto, params *sppb.SatParameters) (*cmpb.CpSolverResponse, error)
SolveCpModelWithParameters solves a CP Model with the given input proto and solver parameters and returns a CPSolverResponse.
Types ¶
type AutomatonConstraint ¶
type AutomatonConstraint struct {
Constraint
}
AutomatonConstraint is a reference to a specialized automaton constraint that allows for adding transitions incrementally to the constraint.
func (*AutomatonConstraint) AddTransition ¶
func (ac *AutomatonConstraint) AddTransition(tail, head int64_t, label int64_t)
AddTransition adds a transition to the constraint. Both tail and head are states, label is any variable value. No two outgoing transitions from the same state can have the same label.
type BoolVar ¶
type BoolVar struct {
// contains filtered or unexported fields
}
BoolVar is a reference to a Boolean variable or the negation of a Boolean variable in the CP model.
func (BoolVar) Index ¶
Index returns the index of the variable. If the variable is a negation of a nother variable v, its index is `-1*v.index-1`.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a wrapper for the CpModelProto builder.
func NewCpModelBuilder ¶
func NewCpModelBuilder() *Builder
NewCpModelBuilder creates and returns a new CpModel Builder.
func (*Builder) AddAbsEquality ¶
func (cp *Builder) AddAbsEquality(target, expr LinearArgument) Constraint
AddAbsEquality adds the constraint: target == Abs(expr).
func (*Builder) AddAllDifferent ¶
func (cp *Builder) AddAllDifferent(la ...LinearArgument) Constraint
AddAllDifferent adds a constraint that forces all expressions to have different values.
func (*Builder) AddAllowedAssignments ¶
func (cp *Builder) AddAllowedAssignments(vars ...IntVar) TableConstraint
AddAllowedAssignments adds an allowed assignments constraint to the model. When all variables are fixed to a single value, it forces the corresponding list of values to be equal to one of the tuples added to the constraint.
func (*Builder) AddAssumption ¶
AddAssumption adds the literals to the model as assumptions.
func (*Builder) AddAtLeastOne ¶
func (cp *Builder) AddAtLeastOne(bvs ...BoolVar) Constraint
AddAtLeastOne adds the constraint that at least one of the literals must be true.
func (*Builder) AddAtMostOne ¶
func (cp *Builder) AddAtMostOne(bvs ...BoolVar) Constraint
AddAtMostOne adds the constraint that at most one of the literals must be true.
func (*Builder) AddAutomaton ¶
func (cp *Builder) AddAutomaton(transitionVars []IntVar, startState int64_t, finalStates []int64) AutomatonConstraint
AddAutomaton adds an automaton constraint.
An automaton constraint takes a list of variables (of size n), an initial state, a set of final states, and a set of transitions. A transition is a triplet ('tail', 'head', 'label'), where 'tail' and 'head' are states, and 'label' is the label of an arc from 'head' to 'tail', corresponding to the value of one variable in the list of variables.
This automaton will be unrolled into a flow with n + 1 phases. Each phase contains the possible states of the automaton. The first state contains the initial state. The last phase contains the final states.
Between two consecutive phases i and i + 1, the automaton creates a set of arcs. For each transition (tail, head, label), it will add an arc from the state 'tail' of phase i and the state 'head' of phase i + 1. This arc labeled by the value 'label' of the variables 'variables[i]'. That is, this arc can only be selected if 'variables[i]' is assigned the value 'label'. A feasible solution of this constraint is an assignment of variables such that, starting from the initial state in phase 0, there is a path labeled by the values of the variables that ends in one of the final states in the final phase.
It returns an AutomatonConstraint that allows adding transition incrementally after construction.
func (*Builder) AddBoolAnd ¶
func (cp *Builder) AddBoolAnd(bvs ...BoolVar) Constraint
AddBoolAnd adds the constraint that all of the literals must be true.
func (*Builder) AddBoolOr ¶
func (cp *Builder) AddBoolOr(bvs ...BoolVar) Constraint
AddBoolOr adds the constraint that at least one of the literals must be true.
func (*Builder) AddBoolXor ¶
func (cp *Builder) AddBoolXor(bvs ...BoolVar) Constraint
AddBoolXor adds the constraint that an odd number of the literals must be true.
func (*Builder) AddCircuitConstraint ¶
func (cp *Builder) AddCircuitConstraint() CircuitConstraint
AddCircuitConstraint adds a circuit constraint to the model. The circuit constraint is defined on a graph where the arcs are present if the corresponding literals are set to true.
func (*Builder) AddCumulative ¶
func (cp *Builder) AddCumulative(capacity LinearArgument) CumulativeConstraint
AddCumulative adds a cumulative constraint to the model that ensures that for any integer point, the sum of the demands of the intervals containging that point does not exceed the capacity.
func (*Builder) AddDecisionStrategy ¶
func (cp *Builder) AddDecisionStrategy(vars []IntVar, vs cmpb.DecisionStrategyProto_VariableSelectionStrategy, ds cmpb.DecisionStrategyProto_DomainReductionStrategy)
AddDecisionStrategy adds a decision strategy on a list of integer variables.
func (*Builder) AddDivisionEquality ¶
func (cp *Builder) AddDivisionEquality(target, num, denom LinearArgument) Constraint
AddDivisionEquality adds the constraint: target == num / denom.
func (*Builder) AddElement ¶
func (cp *Builder) AddElement(ind IntVar, values []int64, target IntVar) Constraint
AddElement adds the element constraint: values[ind] == target
func (*Builder) AddEquality ¶
func (cp *Builder) AddEquality(lhs LinearArgument, rhs LinearArgument) Constraint
AddEquality adds the linear constraint `lhs == rhs`.
func (*Builder) AddExactlyOne ¶
func (cp *Builder) AddExactlyOne(bvs ...BoolVar) Constraint
AddExactlyOne adds the constraint that exactly one of the literals must be true.
func (*Builder) AddGreaterOrEqual ¶
func (cp *Builder) AddGreaterOrEqual(lhs LinearArgument, rhs LinearArgument) Constraint
AddGreaterOrEqual adds the linear constraint `lhs >= rhs`.
func (*Builder) AddGreaterThan ¶
func (cp *Builder) AddGreaterThan(lhs LinearArgument, rhs LinearArgument) Constraint
AddGreaterThan adds the lienar constraints `lhs > rhs`.
func (*Builder) AddImplication ¶
func (cp *Builder) AddImplication(a, b BoolVar) Constraint
AddImplication adds the constraint a => b.
func (*Builder) AddInverseConstraint ¶
func (cp *Builder) AddInverseConstraint(vars []IntVar, inverseVars []IntVar) Constraint
AddInverseConstraint adds a constraint that enforces if `vars[i]` is assigned a value `j`, then `inverseVars[j]` is assigned a value `i`, and vice versa. The lengths of `vars` and `inverseVars` must be the same size.
func (*Builder) AddLessOrEqual ¶
func (cp *Builder) AddLessOrEqual(lhs LinearArgument, rhs LinearArgument) Constraint
AddLessOrEqual adds the linear constraint `lhs <= rhs`.
func (*Builder) AddLessThan ¶
func (cp *Builder) AddLessThan(lhs LinearArgument, rhs LinearArgument) Constraint
AddLessThan adds the linear constraint `lhs < rhs`.
func (*Builder) AddLinearConstraint ¶
func (cp *Builder) AddLinearConstraint(expr LinearArgument, lb, ub int64_t) Constraint
AddLinearConstraint adds the linear constraint `lb <= expr <= ub`
func (*Builder) AddLinearConstraintForDomain ¶
func (cp *Builder) AddLinearConstraintForDomain(expr LinearArgument, domain Domain) Constraint
AddLinearConstraintForDomain adds the linear constraint `expr` in `domain`.
func (*Builder) AddMaxEquality ¶
func (cp *Builder) AddMaxEquality(target LinearArgument, exprs ...LinearArgument) Constraint
AddMaxEquality adds the constraint: target == max(expr).
func (*Builder) AddMinEquality ¶
func (cp *Builder) AddMinEquality(target LinearArgument, exprs ...LinearArgument) Constraint
AddMinEquality adds the constraint: target == min(exprs).
func (*Builder) AddModuloEquality ¶
func (cp *Builder) AddModuloEquality(target, v, mod LinearArgument) Constraint
AddModuloEquality adds the constraint: target == v % mod.
func (*Builder) AddMultipleCircuitConstraint ¶
func (cp *Builder) AddMultipleCircuitConstraint() MultipleCircuitConstraint
AddMultipleCircuitConstraint adds a multiple circuit constraint to the model, aka the "VRP" (Vehicle Routing Problem) constraint.
func (*Builder) AddMultiplicationEquality ¶
func (cp *Builder) AddMultiplicationEquality(target LinearArgument, exprs ...LinearArgument) Constraint
AddMultiplicationEquality adds the constraint: target == Product(exprs).
func (*Builder) AddNoOverlap ¶
func (cp *Builder) AddNoOverlap(vars ...IntervalVar) Constraint
AddNoOverlap adds a constraint that ensures that all present intervals do not overlap in time.
func (*Builder) AddNoOverlap2D ¶
func (cp *Builder) AddNoOverlap2D() NoOverlap2DConstraint
AddNoOverlap2D adds a no_overlap2D constraint that prevents a set of boxes from overlapping.
func (*Builder) AddNotEqual ¶
func (cp *Builder) AddNotEqual(lhs LinearArgument, rhs LinearArgument) Constraint
AddNotEqual adds the linear constraint `lhs != rhs`.
func (*Builder) AddReservoirConstraint ¶
func (cp *Builder) AddReservoirConstraint(min, max int64_t) ReservoirConstraint
AddReservoirConstraint adds a reservoir constraint with optional refill/emptying events.
Maintain a reservoir level within bounds. The water level starts at 0, and at any time, it must be within [min_level, max_level].
Given an event (time, level_change, active), if active is true, and if time is assigned a value t, then the level of the reservoir changes by level_change (which is constant) at time t. Therefore, at any time t:
sum(level_changes[i] * actives[i] if times[i] <= t) in [min_level, max_level]
Note that min level must be <= 0, and the max level must be >= 0. Please use fixed level_changes to simulate an initial state.
It returns a ReservoirConstraint that allows adding optional and non optional events incrementally after construction.
func (*Builder) AddVariableElement ¶
func (cp *Builder) AddVariableElement(ind IntVar, vars []IntVar, target IntVar) Constraint
AddVariableElement adds the variable element constraint: vars[ind] == target.
func (*Builder) ClearAssumption ¶
func (cp *Builder) ClearAssumption()
ClearAssumption clears all the assumptions on the model.
func (*Builder) FalseVar ¶
FalseVar creates an always false Boolean variable. If this is called multiple times, the same variable will always be returned.
func (*Builder) Maximize ¶
func (cp *Builder) Maximize(obj LinearArgument)
Maximize adds a linear maximization objective.
func (*Builder) Minimize ¶
func (cp *Builder) Minimize(obj LinearArgument)
Minimize adds a linear minimization objective.
func (*Builder) Model ¶
func (cp *Builder) Model() (*cmpb.CpModelProto, error)
Model returns the built CP model proto. The proto returned is a pointer to the proto in Builder, and if modified, future calls to the Builder API can fail or result in an INVALID model.
The model returned is mutable and modifying any variables and constraints may result in unexpected changes to the model builder functionality. For example, multiple calls to `NewConstant()` will return the same variable even if the variable's domain has been changed to make it no longer a constant.
Model returns an error when invalid parameters have been used during model building (e.g. passing variables from other builders).
func (*Builder) NewBoolVar ¶
NewBoolVar creates a new BoolVar in the CpModel proto.
func (*Builder) NewConstant ¶
NewConstant creates a constant variable. If this is called multiple times, the same variable will always be returned.
func (*Builder) NewFixedSizeIntervalVar ¶
func (cp *Builder) NewFixedSizeIntervalVar(start LinearArgument, size int64_t) IntervalVar
NewFixedSizeIntervalVar creates a new interval variable with the fixed size.
func (*Builder) NewIntVarFromDomain ¶
NewIntVarFromDomain creates a new IntVar with the given domain in the CpModel proto.
func (*Builder) NewIntervalVar ¶
func (cp *Builder) NewIntervalVar(start, size, end LinearArgument) IntervalVar
NewIntervalVar creates a new interval variable from the three linear arguments. The interval variable enforces that `start` + `size` == `end`.
func (*Builder) NewOptionalFixedSizeIntervalVar ¶
func (cp *Builder) NewOptionalFixedSizeIntervalVar(start LinearArgument, size int64_t, presence BoolVar) IntervalVar
NewOptionalFixedSizeIntervalVar creates an optional interval variable with the fixed size. It only enforces that the interval is of the fixed size when the `presence` variable is true.
func (*Builder) NewOptionalIntervalVar ¶
func (cp *Builder) NewOptionalIntervalVar(start, size, end LinearArgument, presence BoolVar) IntervalVar
NewOptionalIntervalVar creates an optional interval variable from the three linear arguments and the Boolean variable. It only enforces that `start` + `size` = `end` if the `presence` variable is true.
type CircuitConstraint ¶
type CircuitConstraint struct {
Constraint
}
CircuitConstraint is a reference to a specialized circuit constraint that allows for adding arcs to the constraint incrementally.
func (*CircuitConstraint) AddArc ¶
func (cc *CircuitConstraint) AddArc(tail, head int32_t, literal BoolVar)
AddArc adds an arc to the circuit constraint. `tail` and `head` are the indices of the tail and head nodes, respectively, and `literal` is true if the arc is selected.
type ClosedInterval ¶
type ClosedInterval struct { Start int64_t End int64_t }
ClosedInterval stores the closed interval `[start,end]`. If the `Start` is greater than the `End`, the interval is considered empty.
func (ClosedInterval) Offset ¶
func (c ClosedInterval) Offset(delta int64_t) ClosedInterval
Offset adds an offset to both the `Start` and `End` of the ClosedInterval `c`. If the `Start` is equal to MinInt or if `End` is equal to MaxInt, the offset does not get added since those values represent an unbounded domain. Both `Start` and `End` are clamped at math.MinInt64 and Math.MaxInt64.
type ConstrIndex ¶
type ConstrIndex int32_t
ConstrIndex is the index of a constraint in the CP model proto.
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
Constraint is a reference to a constraint in the CP model.
func (Constraint) Index ¶
func (c Constraint) Index() ConstrIndex
Index returns the index of the constraint.
func (Constraint) OnlyEnforceIf ¶
func (c Constraint) OnlyEnforceIf(bvs ...BoolVar) Constraint
OnlyEnforceIf adds a condition on the constraint. This constraint is only enforced iff all literals given are true.
func (Constraint) WithName ¶
func (c Constraint) WithName(s string) Constraint
WithName sets the name of the constraint.
type CumulativeConstraint ¶
type CumulativeConstraint struct {
Constraint
}
CumulativeConstraint is a reference to a specialized cumulative constraint that allows for adding fixe or variable demands incrementally to the constraint.
func (*CumulativeConstraint) AddDemand ¶
func (cc *CumulativeConstraint) AddDemand(interval IntervalVar, demand LinearArgument)
AddDemand adds the demand to the constraint for the specified interval.
type Domain ¶
type Domain struct {
// contains filtered or unexported fields
}
Domain stores an ordered list of ClosedIntervals. This represents any subset of `[MinInt64,MaxInt64]`. This type can be used to represent such a set efficiently as a sorted and non-adjacent list of intervals. This is efficient as long as the size of such a list stays reasonable.
func FromFlatIntervals ¶
FromFlatIntervals creates a new domain from a flattened list of intervals. If there is an interval where the start is greater than the end, the interval is considered empty. Returns an error if the length of `values` is not even.
func FromIntervals ¶
func FromIntervals(intervals []ClosedInterval) Domain
FromIntervals creates a domain from the union of the set of unordered `intervals`. If an interval's `start` is greater than its `end`, the interval is considered empty.
func FromValues ¶
FromValues creates a new domain from `values`. `values` need not be sorted and can repeat.
func NewDomain ¶
func NewDomain(left, right int64_t) Domain
NewDomain creates a new domain of a single interval `[left,right]`. If `left > right`, an empty domain is returned.
func NewSingleDomain ¶
func NewSingleDomain(val int64_t) Domain
NewSingleDomain creates a new singleton domain `[val]`.
func (Domain) FlattenedIntervals ¶
FlattenedIntervals returns the flattened list of interval bounds of the domain. For example, if Domain d is equal to `[0,2][5,5][9,10]` will return `[0,2,5,5,9,10]`.
type IntVar ¶
type IntVar struct {
// contains filtered or unexported fields
}
IntVar is a reference to an integer variable in the CP model.
type IntervalVar ¶
type IntervalVar struct {
// contains filtered or unexported fields
}
IntervalVar is a reference to an interval variable in the CP model. An interval variable is both a variable and a constraint. It is defined by three elements (start, size, end) and enforces that start + size == end.
func (IntervalVar) Index ¶
func (iv IntervalVar) Index() ConstrIndex
Index returns the index of the interval variable.
func (IntervalVar) Name ¶
func (iv IntervalVar) Name() string
Name returns the name of the interval variable.
func (IntervalVar) WithName ¶
func (iv IntervalVar) WithName(s string) IntervalVar
WithName sets the name of the interval variable.
type LinearArgument ¶
type LinearArgument interface {
// contains filtered or unexported methods
}
LinearArgument provides an interface for BoolVar, IntVar, and LinearExpr.
type LinearExpr ¶
type LinearExpr struct {
// contains filtered or unexported fields
}
LinearExpr is a container for a linear expression.
func NewConstant ¶
func NewConstant(c int64_t) *LinearExpr
NewConstant creates and returns a LinearExpr containing the constant `c`.
func (*LinearExpr) Add ¶
func (l *LinearExpr) Add(la LinearArgument) *LinearExpr
Add adds the linear argument term to the LinearExpr and returns itself.
func (*LinearExpr) AddConstant ¶
func (l *LinearExpr) AddConstant(c int64_t) *LinearExpr
AddConstant adds the constant to the LinearExpr and returns itself.
func (*LinearExpr) AddSum ¶
func (l *LinearExpr) AddSum(las ...LinearArgument) *LinearExpr
AddSum adds the sum of the linear arguments to the LinearExpr and returns itself.
func (*LinearExpr) AddTerm ¶
func (l *LinearExpr) AddTerm(la LinearArgument, coeff int64_t) *LinearExpr
AddTerm adds the linear argument term with the given coefficient to the LinearExpr and returns itself.
func (*LinearExpr) AddWeightedSum ¶
func (l *LinearExpr) AddWeightedSum(las []LinearArgument, coeffs []int64) *LinearExpr
AddWeightedSum adds the linear arguments with the corresponding coefficients to the LinearExpr and returns itself.
type MultipleCircuitConstraint ¶
type MultipleCircuitConstraint struct {
Constraint
}
MultipleCircuitConstraint is a reference to a specialized circuit constraint that allows for adding arcs to the constraint incrementally.
func (*MultipleCircuitConstraint) AddRoute ¶
func (mc *MultipleCircuitConstraint) AddRoute(tail, head int32_t, literal BoolVar)
AddRoute adds an arc to the circuit constraint. `tail` and `head` and the indices of the tail and head nodes, respectively, and `literal` is true if the arc is selected.
type NoOverlap2DConstraint ¶
type NoOverlap2DConstraint struct {
Constraint
}
NoOverlap2DConstraint is a reference to a specialized no_overlap2D constraint that allows for adding rectangles to the constraint incrementally.
func (NoOverlap2DConstraint) AddRectangle ¶
func (noc NoOverlap2DConstraint) AddRectangle(xInterval, yInterval IntervalVar)
AddRectangle adds a rectangle (parallel to the axis) to the constraint.
type ReservoirConstraint ¶
type ReservoirConstraint struct { Constraint // contains filtered or unexported fields }
ReservoirConstraint is a reference to a specialized reservoir constraint that allows for adding emptying/refilling events incrementally to the constraint.
func (*ReservoirConstraint) AddEvent ¶
func (rc *ReservoirConstraint) AddEvent(time LinearArgument, levelChange LinearArgument)
AddEvent adds an event to the reservoir constraint. It will increase the used capacity by `levelChange` at time `time`.
type TableConstraint ¶
type TableConstraint struct {
Constraint
}
TableConstraint is a reference to a specialized assignment constraint that allows for adding tuples incrementally to the allowed/forbidden assignment constraint.
func (*TableConstraint) AddTuple ¶
func (tc *TableConstraint) AddTuple(tuple ...int64_t)
AddTuple adds a tuple of possible values to the table constraint.