Module org.maxicp

Class Factory

java.lang.Object
org.maxicp.modeling.Factory

public final class Factory extends Object
Modeling factory providing static helper methods to create model dispatchers, objectives, symbolic integer/boolean/cumulative expressions, and high-level modeling constraints.
  • Method Details

    • makeModelDispatcher

      public static ModelDispatcher makeModelDispatcher()
      Creates a new ModelDispatcher to build and solve constraint programming models.
      Returns:
      a new ModelDispatcher instance
    • minimize

      public static Objective minimize(IntExpression x, boolean shared)
      Creates a minimization objective for the given integer expression.
      Parameters:
      x - the expression to minimize
      shared - true if the objective bound should be shared across parallel searches
      Returns:
      the minimization Objective
    • minimize

      public static Objective minimize(IntExpression x)
      Creates a minimization objective for the given integer expression.
      Parameters:
      x - the expression to minimize
      Returns:
      the minimization Objective
    • maximize

      public static Objective maximize(IntExpression x, boolean shared)
      Creates a maximization objective for the given integer expression.
      Parameters:
      x - the expression to maximize
      shared - true if the objective bound should be shared across parallel searches
      Returns:
      the maximization Objective
    • maximize

      public static Objective maximize(IntExpression x)
      Creates a maximization objective for the given integer expression.
      Parameters:
      x - the expression to maximize
      Returns:
      the maximization Objective
    • cst

      public static IntExpression cst(ModelProxy modelProxy, int v)
      Creates a constant integer expression with value v.
      Parameters:
      modelProxy - the model proxy
      v - the constant integer value
      Returns:
      a constant IntExpression equal to v
    • plus

      public static IntExpression plus(IntExpression a, int v)
      Returns an integer expression representing a + v.
      Parameters:
      a - an integer expression
      v - a constant offset
      Returns:
      the expression a + v
    • plus

      public static IntExpression plus(IntExpression a, IntExpression b)
      Returns an integer expression representing a + b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      the expression a + b
    • minus

      public static IntExpression minus(IntExpression a, int v)
      Returns an integer expression representing a - v.
      Parameters:
      a - an integer expression
      v - a constant offset to subtract
      Returns:
      the expression a - v
    • minus

      public static IntExpression minus(IntExpression a, IntExpression b)
      Returns an integer expression representing a - b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      the expression a - b
    • minus

      public static IntExpression minus(IntExpression a)
      Returns an integer expression representing the unary negation -a.
      Parameters:
      a - an integer expression
      Returns:
      the expression -a
    • mul

      public static IntExpression mul(IntExpression a, int b)
      Returns an integer expression representing a * b.
      Parameters:
      a - an integer expression
      b - a constant multiplier
      Returns:
      the expression a * b
    • div

      public static IntExpression div(IntExpression a, int b)
      Returns an integer expression representing the integer division a / b.
      Parameters:
      a - the dividend expression
      b - the constant divisor
      Returns:
      the expression a / b
    • mul

      public static IntExpression mul(int b, IntExpression a)
      Returns an integer expression representing b * a.
      Parameters:
      b - a constant multiplier
      a - an integer expression
      Returns:
      the expression b * a
    • mul

      public static IntExpression mul(IntExpression x, BoolExpression b)
      Returns an integer expression representing x * b where b is a boolean expression.
      Parameters:
      x - an integer expression
      b - a boolean expression (0 or 1)
      Returns:
      the expression x * b
    • mul

      public static IntExpression mul(IntExpression... x)
      Returns an integer expression representing the product of the given expressions.
      Parameters:
      x - the integer expressions to multiply
      Returns:
      the product expression x[0] * x[1] * ... * x[n-1]
    • abs

      public static IntExpression abs(IntExpression x)
      Returns an integer expression representing the absolute value |x|.
      Parameters:
      x - an integer expression
      Returns:
      the expression |x|
    • div

      public static IntExpression div(IntExpression x, IntExpression y)
      Returns an integer expression representing the integer division x / y.
      Parameters:
      x - the dividend expression
      y - the divisor expression
      Returns:
      the expression x / y
    • sum

      public static IntExpression sum(IntExpression... x)
      Returns an integer expression representing the sum of the given expressions.
      Parameters:
      x - the integer expressions to sum
      Returns:
      the sum expression x[0] + x[1] + ... + x[n-1]
    • max

      public static IntExpression max(IntExpression... x)
      Returns an integer expression representing the maximum of the given expressions.
      Parameters:
      x - the integer expressions
      Returns:
      the maximum expression max(x)
    • min

      public static IntExpression min(IntExpression... x)
      Returns an integer expression representing the minimum of the given expressions.
      Parameters:
      x - the integer expressions
      Returns:
      the minimum expression min(x)
    • eq

      public static BoolExpression eq(IntExpression a, int b)
      Returns a boolean expression representing a == b.
      Parameters:
      a - an integer expression
      b - a constant value
      Returns:
      a boolean expression true iff a == b
    • eq

      public static BoolExpression eq(int a, IntExpression b)
      Returns a boolean expression representing a == b.
      Parameters:
      a - a constant value
      b - an integer expression
      Returns:
      a boolean expression true iff a == b
    • eq

      public static BoolExpression eq(IntExpression a, IntExpression b)
      Returns a boolean expression representing a == b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      a boolean expression true iff a == b
    • neq

      public static BoolExpression neq(IntExpression a, int b)
      Returns a boolean expression representing a != b.
      Parameters:
      a - an integer expression
      b - a constant value
      Returns:
      a boolean expression true iff a != b
    • neq

      public static BoolExpression neq(int a, IntExpression b)
      Returns a boolean expression representing a != b.
      Parameters:
      a - a constant value
      b - an integer expression
      Returns:
      a boolean expression true iff a != b
    • neq

      public static BoolExpression neq(IntExpression a, IntExpression b)
      Returns a boolean expression representing a != b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      a boolean expression true iff a != b
    • le

      public static BoolExpression le(IntExpression a, int b)
      Returns a boolean expression representing a <= b.
      Parameters:
      a - an integer expression
      b - a constant value
      Returns:
      a boolean expression true iff a <= b
    • le

      public static BoolExpression le(int a, IntExpression b)
      Returns a boolean expression representing a <= b.
      Parameters:
      a - a constant value
      b - an integer expression
      Returns:
      a boolean expression true iff a <= b
    • le

      public static BoolExpression le(IntExpression a, IntExpression b)
      Returns a boolean expression representing a <= b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      a boolean expression true iff a <= b
    • lt

      public static BoolExpression lt(int a, IntExpression b)
      Returns a boolean expression representing a < b.
      Parameters:
      a - a constant value
      b - an integer expression
      Returns:
      a boolean expression true iff a < b
    • lt

      public static BoolExpression lt(IntExpression a, int b)
      Returns a boolean expression representing a < b.
      Parameters:
      a - an integer expression
      b - a constant value
      Returns:
      a boolean expression true iff a < b
    • lt

      public static BoolExpression lt(IntExpression a, IntExpression b)
      Returns a boolean expression representing a < b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      a boolean expression true iff a < b
    • ge

      public static BoolExpression ge(IntExpression a, int b)
      Returns a boolean expression representing a >= b.
      Parameters:
      a - an integer expression
      b - a constant value
      Returns:
      a boolean expression true iff a >= b
    • ge

      public static BoolExpression ge(int a, IntExpression b)
      Returns a boolean expression representing a >= b.
      Parameters:
      a - a constant value
      b - an integer expression
      Returns:
      a boolean expression true iff a >= b
    • ge

      public static BoolExpression ge(IntExpression a, IntExpression b)
      Returns a boolean expression representing a >= b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      a boolean expression true iff a >= b
    • gt

      public static BoolExpression gt(IntExpression a, int b)
      Returns a boolean expression representing a > b.
      Parameters:
      a - an integer expression
      b - a constant value
      Returns:
      a boolean expression true iff a > b
    • gt

      public static BoolExpression gt(int a, IntExpression b)
      Returns a boolean expression representing a > b.
      Parameters:
      a - a constant value
      b - an integer expression
      Returns:
      a boolean expression true iff a > b
    • gt

      public static BoolExpression gt(IntExpression a, IntExpression b)
      Returns a boolean expression representing a > b.
      Parameters:
      a - the first integer expression
      b - the second integer expression
      Returns:
      a boolean expression true iff a > b
    • not

      public static BoolExpression not(BoolExpression a)
      Returns the logical negation !a.
      Parameters:
      a - a boolean expression
      Returns:
      the negated boolean expression !a
    • and

      public static BoolExpression and(BoolExpression... t)
      Returns the logical conjunction (AND) of the given boolean expressions.
      Parameters:
      t - the boolean expressions
      Returns:
      a boolean expression true iff all expressions in t are true
    • or

      public static BoolExpression or(BoolExpression... t)
      Returns the logical disjunction (OR) of the given boolean expressions.
      Parameters:
      t - the boolean expressions
      Returns:
      a boolean expression true iff at least one expression in t is true
    • implies

      public static BoolExpression implies(BoolExpression a, BoolExpression b)
      Returns the logical implication of a and b
      Parameters:
      a - a boolean expression
      b - a boolean expression
      Returns:
      a => b
    • endBeforeStart

      public static BoolExpression endBeforeStart(IntervalVar a, IntervalVar b)
      Returns a boolean expression representing whether interval a ends at or before the start of b.
      Parameters:
      a - the first interval variable
      b - the second interval variable
      Returns:
      a boolean expression true iff end(a) <= start(b) when both are present
    • get

      public static IntExpression get(int[] T, IntExpression y)
      Returns an integer expression representing T[y].
      Parameters:
      T - the array of constant values
      y - the index expression
      Returns:
      the element expression T[y]
    • get

      public static IntExpression get(IntExpression[] T, IntExpression y)
      Returns an integer expression representing T[y].
      Parameters:
      T - the array of integer expressions
      y - the index expression
      Returns:
      the element expression T[y]
    • get

      public static IntExpression get(int[][] T, IntExpression x, IntExpression y)
      Returns an integer expression representing T[x][y].
      Parameters:
      T - the 2D matrix of constant values
      x - the row index expression
      y - the column index expression
      Returns:
      the element expression T[x][y]
    • get

      public static IntExpression get(IntExpression[][] T, IntExpression x, IntExpression y)
      Returns an integer expression representing T[x][y].
      Parameters:
      T - the 2D matrix of integer expressions
      x - the row index expression
      y - the column index expression
      Returns:
      the element expression T[x][y]
    • lexLe

      public static Constraint lexLe(IntExpression[] x, IntExpression[] y)
      Creates a non-strict lexicographic ordering constraint x <=_lex y.
      Parameters:
      x - the first array of integer expressions
      y - the second array of integer expressions
      Returns:
      a LexLe constraint enforcing x <=_lex y
    • lexLt

      public static Constraint lexLt(IntExpression[] x, IntExpression[] y)
      Creates a strict lexicographic ordering constraint x <_lex y.
      Parameters:
      x - the first array of integer expressions
      y - the second array of integer expressions
      Returns:
      a LexLe constraint enforcing x <_lex y
    • among

      public static Constraint among(IntExpression[] x, Set<Integer> values, IntExpression count)
      Creates an Among constraint ensuring that count expressions in x take a value in values.
      Parameters:
      x - the array of integer expressions
      values - the set of target values
      count - the expression counting how many elements of x belong to values
      Returns:
      an Among constraint
    • subCircuit

      public static Constraint subCircuit(IntExpression... x)
      Creates a SubCircuit constraint ensuring that the successor array x forms at most one circuit.
      Parameters:
      x - the array of successor expressions
      Returns:
      a SubCircuit constraint
    • cardinalityMin

      public static Constraint cardinalityMin(IntExpression[] x, int[] minCard)
      Creates a CardinalityMin constraint ensuring that each value v appears at least minCard[v] times in x.
      Parameters:
      x - the array of integer expressions
      minCard - the minimum number of occurrences for each value 0..minCard.length - 1
      Returns:
      a CardinalityMin constraint
    • cardinalityMax

      public static Constraint cardinalityMax(IntExpression[] x, int[] maxCard)
      Creates a CardinalityMax constraint ensuring that each value v appears at most maxCard[v] times in x.
      Parameters:
      x - the array of integer expressions
      maxCard - the maximum number of occurrences for each value 0..maxCard.length - 1
      Returns:
      a CardinalityMax constraint
    • allDifferent

      public static Constraint allDifferent(IntExpression... x)
      Creates an AllDifferent constraint ensuring that all expressions in x take pairwise distinct values.
      Parameters:
      x - the integer expressions that must be pairwise distinct
      Returns:
      an AllDifferent constraint
    • binPacking

      public static Constraint binPacking(IntExpression[] x, int[] weights, IntExpression[] loads)
      Creates a BinPacking constraint linking item bin assignments x and item weights to bin loads.
      Parameters:
      x - the bin assignment expression for each item
      weights - the weight of each item
      loads - the total load expression for each bin
      Returns:
      a BinPacking constraint
    • circuit

      public static Constraint circuit(IntExpression... x)
      Creates a Circuit constraint ensuring that the successor array x forms a single Hamiltonian circuit.
      Parameters:
      x - the array of successor expressions
      Returns:
      a Circuit constraint
    • table

      public static Constraint table(IntExpression[] x, int[][] array, Optional<Integer> starred)
      Creates a positive Table constraint ensuring that the tuple assigned to x belongs to array.
      Parameters:
      x - the array of integer expressions
      array - the table of allowed tuples
      starred - optional wildcard value representing any value in a tuple
      Returns:
      a Table constraint
    • negTable

      public static Constraint negTable(IntExpression[] x, int[][] array, Optional<Integer> starred)
      Creates a negative NegTable constraint ensuring that the tuple assigned to x does not match any tuple in array.
      Parameters:
      x - the array of integer expressions
      array - the table of forbidden tuples
      starred - optional wildcard value representing any value in a tuple
      Returns:
      a NegTable constraint
    • cumulative

      public static Constraint cumulative(IntExpression[] start, int[] duration, int[] demand, int capa)
      Creates a Cumulative scheduling constraint with constant durations, demands, and capacity.
      Parameters:
      start - the start time expressions of the activities
      duration - the durations of the activities
      demand - the resource demands of the activities
      capa - the resource capacity
      Returns:
      a Cumulative constraint
    • cumulative

      public static Constraint cumulative(IntExpression[] start, IntExpression[] duration, IntExpression[] end, IntExpression[] demand, IntExpression capa)
      Creates a Cumulative scheduling constraint with variable durations, ends, demands, and capacity.
      Parameters:
      start - the start time expressions of the activities
      duration - the duration expressions of the activities
      end - the end time expressions of the activities
      demand - the resource demand expressions of the activities
      capa - the resource capacity expression
      Returns:
      a Cumulative constraint
    • disjunctive

      public static Constraint disjunctive(IntExpression[] start, int[] duration)
      Creates a Disjunctive scheduling constraint with constant activity durations.
      Parameters:
      start - the start time expressions of the activities
      duration - the durations of the activities
      Returns:
      a Disjunctive constraint
    • disjunctive

      public static Constraint disjunctive(IntExpression[] start, IntExpression[] duration)
      Creates a Disjunctive scheduling constraint with variable activity durations.
      Parameters:
      start - the start time expressions of the activities
      duration - the duration expressions of the activities
      Returns:
      a Disjunctive constraint
    • distance

      public static Constraint distance(SeqVar seqVar, int[][] distanceMatrix, IntExpression distance)
      Creates a Distance constraint on a sequence variable maintaining the total travel distance.
      Parameters:
      seqVar - the sequence variable
      distanceMatrix - the distance matrix between nodes
      distance - the total distance expression
      Returns:
      a Distance constraint
    • require

      public static Constraint require(SeqVar seqVar, int node)
      Creates a Require constraint forcing node to be visited in seqVar.
      Parameters:
      seqVar - the sequence variable
      node - the node to require
      Returns:
      a Require constraint
    • insert

      public static Constraint insert(SeqVar seqVar, int prev, int node)
      Creates an Insert constraint inserting node immediately after prev in seqVar.
      Parameters:
      seqVar - the sequence variable
      prev - the predecessor node
      node - the node to insert
      Returns:
      an Insert constraint
    • exclude

      public static Constraint exclude(SeqVar seqVar, int node)
      Creates an Exclude constraint excluding node from seqVar.
      Parameters:
      seqVar - the sequence variable
      node - the node to exclude
      Returns:
      an Exclude constraint
    • notBetween

      public static Constraint notBetween(SeqVar seqVar, int pred, int node, int succ)
      Creates a NotBetween constraint forbidding node from being placed immediately between pred and succ in seqVar.
      Parameters:
      seqVar - the sequence variable
      pred - the predecessor node
      node - the node whose insertion is forbidden
      succ - the successor node
      Returns:
      a NotBetween constraint
    • transitionTimes

      public static Constraint transitionTimes(SeqVar seqVar, IntExpression[] time, int[][] dist)
      Creates a TransitionTimes constraint linking visit times with transition distances in seqVar.
      Parameters:
      seqVar - the sequence variable
      time - the visit time expression for each node
      dist - the transition distance matrix between nodes
      Returns:
      a TransitionTimes constraint
    • transitionTimes

      public static Constraint transitionTimes(SeqVar seqVar, IntExpression[] time, int[][] dist, int[] serviceTime)
      Creates a TransitionTimes constraint linking visit times with transition distances and service durations in seqVar.
      Parameters:
      seqVar - the sequence variable
      time - the visit time expression for each node
      dist - the transition distance matrix between nodes
      serviceTime - the service duration at each node
      Returns:
      a TransitionTimes constraint
    • cumulative

      public static Constraint cumulative(SeqVar seqVar, int[] starts, int[] ends, int[] load, int capacity)
      Creates a Cumulative constraint on a sequence variable.
      Parameters:
      seqVar - the sequence variable
      starts - the start nodes of the activities
      ends - the end nodes of the activities
      load - the load of each activity
      capacity - the maximum resource capacity along the sequence
      Returns:
      a sequence Cumulative constraint
    • noOverlap

      public static Constraint noOverlap(IntervalVar... intervals)
      Creates a NoOverlap constraint ensuring that the given interval variables do not overlap in time.
      Parameters:
      intervals - the interval variables
      Returns:
      a NoOverlap constraint
    • noOverlap

      public static Constraint noOverlap(IntervalVar[] intervals, IntExpression[] posOfInterval, IntExpression[] intervalInPos)
      Creates a noOverlap constraint with position variables and zero transition times.
      Parameters:
      intervals - the interval variables
      posOfInterval - position of each interval
      intervalInPos - interval at each position
      Returns:
      a NoOverlapWithPosition constraint
    • noOverlap

      public static Constraint noOverlap(IntervalVar[] intervals, IntExpression[] posOfInterval, IntExpression[] intervalInPos, int[][] minTransition)
      Creates a noOverlap constraint with position variables and minimum transition times.
      Parameters:
      intervals - the interval variables
      posOfInterval - position of each interval
      intervalInPos - interval at each position
      minTransition - n×n transition time matrix
      Returns:
      a NoOverlapWithPosition constraint with transition times
    • alternative

      public static Constraint alternative(IntervalVar real, IntervalVar... alternatives)
    • alternative

      public static Constraint alternative(IntervalVar real, IntExpression n, IntervalVar... alternatives)
    • length

      public static Constraint length(IntervalVar var, int length)
    • present

      public static BoolExpression present(IntervalVar var)
    • start

      public static Constraint start(IntervalVar var, int start)
    • startOr

      public static IntExpression startOr(IntervalVar interval, int v)
    • start

      public static IntExpression start(IntervalVar interval)
    • endOr

      public static IntExpression endOr(IntervalVar interval, int v)
    • end

      public static IntExpression end(IntervalVar interval)
    • length

      public static IntExpression length(IntervalVar interval)
    • lengthOr

      public static IntExpression lengthOr(IntervalVar interval, int v)
    • endBefore

      public static BoolExpression endBefore(IntervalVar intervalVar, IntExpression value)
    • endAfter

      public static BoolExpression endAfter(IntervalVar intervalVar, IntExpression value)
    • endAfter

      public static BoolExpression endAfter(IntervalVar intervalVar, int value)
    • startBefore

      public static BoolExpression startBefore(IntervalVar intervalVar, IntExpression value)
    • startBefore

      public static BoolExpression startBefore(IntervalVar intervalVar, int value)
    • startAfter

      public static BoolExpression startAfter(IntervalVar intervalVar, IntExpression value)
    • startAfter

      public static BoolExpression startAfter(IntervalVar intervalVar, int value)
    • flat

      public static CumulFunction flat()
    • pulse

      public static CumulFunction pulse(IntervalVar interval, int height)
    • pulse

      public static CumulFunction pulse(IntervalVar interval, int hMin, int hMax)
    • pulse

      public static CumulFunction pulse(IntervalVar interval, IntExpression height)
    • sum

      public static CumulFunction sum(CumulFunction... functions)
    • minus

      public static CumulFunction minus(CumulFunction left, CumulFunction right)
    • stepAtEnd

      public static CumulFunction stepAtEnd(IntervalVar interval, int hMin, int hMax)
    • stepAtEnd

      public static CumulFunction stepAtEnd(IntervalVar interval, int height)
    • step

      public static CumulFunction step(ModelDispatcher m, int from, int h)
    • stepAtStart

      public static CumulFunction stepAtStart(IntervalVar interval, int hMin, int hMax)
    • stepAtStart

      public static CumulFunction stepAtStart(IntervalVar interval, int height)
    • le

      public static Constraint le(CumulFunction function, int limit)
    • alwaysIn

      public static Constraint alwaysIn(CumulFunction expression, int heightMin, int heightMax)