Class COptQuestAssignmentVariable


public final class COptQuestAssignmentVariable extends COptQuestManifoldVariable
An assignment variable. Its value is an assignment of each of m items to one of n bins. Use an assignment variable when the decision is an assignment of items to bins, such as jobs to machines or tasks to workers.

The engine adds the assignment rules to the model as constraints, so a solution that does not meet a rule is infeasible. An item that must be in a bin is in exactly one bin, and any other item is in at most one bin. Each bin holds from its smallest to its largest number of items.

Variable names: <name>@1 to <name>@m, one for each item. The value of each name is the number of the bin that the item is in, counted from 1, or 0 when the item is in no bin.

In a suggested solution, the engine rounds each value to the nearest bin index, and it puts an item whose value is outside 1 to n in no bin. The engine can then change the assignment so that it meets the rules.

In most programs, you add this variable with one of the OptQuestModel.AddAssignmentVariable methods and read its values with OptQuestSolution.GetValue(String) and the generated names. Construct this class only when you add the variable with COptQuestOptimization.AddVariable(COptQuestVariable).

See Also:
  • OptQuestModel.AddAssignmentVariable(String, int, int)
  • OptQuestModel.AddAssignmentVariable(String, int, int, boolean, int, int)
  • OptQuestModel.AddAssignmentVariable(String, int, int, boolean[], int[], int[])
  • Constructor Details

    • COptQuestAssignmentVariable

      public COptQuestAssignmentVariable(String name, int m, int n, boolean[] mustAssign, int[] binCapacitiesMin, int[] binCapacitiesMax) throws COptQuestException
      Creates an assignment variable with separate rules for each item and each bin. Item i is in exactly one bin when mustAssign[i] is true, and in at most one bin when it is false. Bin j holds from binCapacitiesMin[j] to binCapacitiesMax[j] items.
      Parameters:
      name - base name of the variable
      m - number of items; must be at least 1
      n - number of bins; must be at least 1
      mustAssign - one entry for each item: true if the item must be in a bin, false if it can be in no bin
      binCapacitiesMin - one entry for each bin: the smallest number of items in the bin
      binCapacitiesMax - one entry for each bin: the largest number of items in the bin
      Throws:
      COptQuestException - if m or n is less than 1, if an array is null or does not have one entry for each item or bin, if a bin maximum is negative or less than its minimum, if the bin minimums add up to more than m items, or if the bins cannot hold every item that must be assigned
    • COptQuestAssignmentVariable

      public COptQuestAssignmentVariable(String name, int m, int n, boolean mustAssign, int binCapacityMin, int binCapacityMax) throws COptQuestException
      Creates an assignment variable with the same rules for every item and every bin. When mustAssign is true, every item is in exactly one bin. When it is false, every item is in at most one bin. Every bin holds from binCapacityMin to binCapacityMax items.
      Parameters:
      name - base name of the variable
      m - number of items; must be at least 1
      n - number of bins; must be at least 1
      mustAssign - true if every item must be in a bin, false if an item can be in no bin
      binCapacityMin - smallest number of items in each bin
      binCapacityMax - largest number of items in each bin
      Throws:
      COptQuestException - if m or n is less than 1, if binCapacityMax is negative or less than binCapacityMin, if the bin minimums add up to more than m items, or if mustAssign is true and the bins cannot hold every item
    • COptQuestAssignmentVariable

      public COptQuestAssignmentVariable(String name, int m, int n) throws COptQuestException
      Creates an assignment variable in which every item is in exactly one bin, and a bin can hold any number of items.
      Parameters:
      name - base name of the variable
      m - number of items; must be at least 1
      n - number of bins; must be at least 1
      Throws:
      COptQuestException - if m or n is less than 1
  • Method Details

    • getInputVariables

      public List<COptQuestVariable> getInputVariables()
      Returns an empty list, because an assignment variable has no ordinary input variables.

      The values of an assignment variable are in the list that getProjectedInputVariables() returns. That list has the variables <name>@1 to <name>@m, one for each item.

      Returns:
      an empty list
    • getOutputVariables

      public List<COptQuestUserControlledVariable> getOutputVariables()
      Returns an empty list, because an assignment variable has no output variables.

      The values of an assignment variable are in the list that getProjectedInputVariables() returns. That list has the variables <name>@1 to <name>@m, one for each item.

      Returns:
      an empty list
    • getProjectedInputVariables

      public List<COptQuestUserControlledVariable> getProjectedInputVariables()
      Description copied from class: COptQuestManifoldVariable
      Returns the decision values of this manifold variable that are not ordinary decision variables.

      For example, an angle variable returns angle@theta, and a mixture variable returns one mix@<component> name for each component. In every solution that the engine generates, and in every suggested solution, these values are inside the set of the variable. Your evaluator reads them as inputs: OptQuestSolution.GetInputNames() returns them.

      A constraint that uses one of these names is checked after the evaluation, like a constraint on an output. Your evaluator can receive values that break the constraint, and the solution is then infeasible.

      Specified by:
      getProjectedInputVariables in class COptQuestManifoldVariable
      Returns:
      fixed-size or immutable list of these variables; never null
    • getConstraints

      public List<COptQuestStringConstraint> getConstraints()
      Description copied from class: COptQuestManifoldVariable
      Returns the constraints that this manifold variable adds to the model.

      The engine adds these constraints to the model when the variable is added. Most manifold variable types add no constraints and return an empty list.

      Overrides:
      getConstraints in class COptQuestManifoldVariable
      Returns:
      list of constraints; never null