Class COptQuestItemSelectionVariable


public final class COptQuestItemSelectionVariable extends COptQuestManifoldVariable
An item selection variable. Its value is a selection of candidates, and the number of selected candidates is from kMin to kMax. Use an item selection variable when the decision is which candidates to include, such as which sites to open.

The engine adds the selection rule to the model as a constraint, so a solution that selects fewer than kMin or more than kMax candidates is infeasible.

Variable names: <name>@1 to <name>@n, one for each candidate. These are ordinary binary inputs. The value of each name is 1 if the candidate is selected and 0 if it is not.

In most programs, you add this variable with one of the OptQuestModel.AddItemSelectionVariable 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.AddItemSelectionVariable(String, int, int)
  • OptQuestModel.AddItemSelectionVariable(String, int, int, int)
  • Constructor Details

    • COptQuestItemSelectionVariable

      public COptQuestItemSelectionVariable(String name, int n, int kMin, int kMax) throws COptQuestException
      Creates an item selection variable that selects from kMin to kMax of n candidates.
      Parameters:
      name - base name of the variable
      n - number of candidates; must be at least 1
      kMin - smallest number of candidates to select; must be at least 0
      kMax - largest number of candidates to select; must be from kMin to n
      Throws:
      COptQuestException - if n is less than 1, or if no selection has from kMin to kMax candidates
    • COptQuestItemSelectionVariable

      public COptQuestItemSelectionVariable(String name, int n, int k) throws COptQuestException
      Creates an item selection variable that selects exactly k of n candidates.
      Parameters:
      name - base name of the variable
      n - number of candidates; must be at least 1
      k - number of candidates to select; must be from 0 to n
      Throws:
      COptQuestException - if n is less than 1, or if k is less than 0 or greater than n
  • Method Details

    • getProjectedInputVariables

      public List<COptQuestUserControlledVariable> getProjectedInputVariables()
      Returns an empty list, because the values of an item selection variable are ordinary inputs.

      The values are in the list that getInputVariables() returns. That list has the variables <name>@1 to <name>@n, one for each candidate.

      Returns:
      an empty list
    • getOutputVariables

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

      The values of an item selection variable are ordinary inputs, so they are in the list that getInputVariables() returns. That list has the variables <name>@1 to <name>@n, one for each candidate.

      Returns:
      an empty list
    • getInputVariables

      public List<COptQuestVariable> getInputVariables()
      Description copied from class: COptQuestManifoldVariable
      Returns the ordinary decision variables of this manifold variable.

      The engine chooses these values directly. Your evaluator reads them as inputs. The item selection and budgeted selection types use this list, and so do the vector, matrix and N-dimensional types of continuous, integer, discrete and binary variables. For every other type, the list is empty.

      Specified by:
      getInputVariables in class COptQuestManifoldVariable
      Returns:
      fixed-size or immutable list of input 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