Class COptQuestMultiChoiceVariable


public class COptQuestMultiChoiceVariable extends COptQuestManifoldVariable
A multi-choice variable. Its value is a subset of the choices that has from minSelect to maxSelect members. Use a multi-choice variable when the decision is an unordered selection of several items, such as which sensors to turn on or which assets to include.

In every solution that the engine generates, each choice is either selected or not, and the number of selected choices is from minSelect to maxSelect.

Variable names: <name>@<choice> for each choice, in the order of choices. The value of each name is 1 if the choice is selected and 0 if it is not.

In a suggested solution, the engine selects each choice whose value is greater than 0.5. If more than maxSelect choices are then selected, the engine keeps the selected choices that come first in choices. If fewer than minSelect are selected, the engine adds the unselected choices that come first.

In most programs, you add this variable with OptQuestModel.AddMultiChoiceVariable 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.AddMultiChoiceVariable(String, String[], int, int)
  • Constructor Details

    • COptQuestMultiChoiceVariable

      public COptQuestMultiChoiceVariable(String name, String[] choices, int minSelect, int maxSelect) throws COptQuestException
      Creates a multi-choice variable.
      Parameters:
      name - base name of the variable
      choices - names of the choices; each must be unique and must not contain whitespace, a semicolon, a comma or @
      minSelect - smallest number of selected choices; must be at least 0
      maxSelect - largest number of selected choices; must be at least minSelect and at most the number of choices
      Throws:
      COptQuestException - if choices is null or empty or holds a name that is not valid, or if minSelect and maxSelect are not valid
  • Method Details

    • getInputVariables

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

      The values of a multi-choice variable are in the list that getProjectedInputVariables() returns. That list has one variable <name>@<choice> for each choice.

      Returns:
      an empty list
    • getOutputVariables

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

      The values of a multi-choice variable are in the list that getProjectedInputVariables() returns. That list has one variable <name>@<choice> for each choice.

      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