Class COptQuestMixtureVariable


public class COptQuestMixtureVariable extends COptQuestManifoldVariable
A mixture variable. Its value is a set of continuous weights, one for each component, and the weights sum to sumTo. Use a mixture variable when the decision is a set of proportions, such as portfolio weights, blend fractions or allocation ratios.

In every solution that the engine generates, the weights sum to sumTo within 1e-12, and each weight is within the bounds of its component.

Variable names: <name>@<component> for each component, in the order of components. The value of each name is the weight of that component. The constructors that take k name the components 1 to k.

With a negative lower bound, a weight can be below zero, down to that bound.

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

    • COptQuestMixtureVariable

      public COptQuestMixtureVariable(String name, int k) throws COptQuestException
      Creates a mixture variable with k components named 1 to k. The weights sum to 1.0, every lower bound is 0, and there are no upper bounds.
      Parameters:
      name - base name of the variable
      k - number of components; must be at least 1
      Throws:
      COptQuestException - if k is less than 1
    • COptQuestMixtureVariable

      public COptQuestMixtureVariable(String name, String[] components) throws COptQuestException
      Creates a mixture variable with the given component names. The weights sum to 1.0, every lower bound is 0, and there are no upper bounds.
      Parameters:
      name - base name of the variable
      components - names of the components; each must be unique and must not contain whitespace, a semicolon, a comma or @
      Throws:
      COptQuestException - if components is null or empty, or holds a name that is not valid
    • COptQuestMixtureVariable

      public COptQuestMixtureVariable(String name, int k, double[] lowerBounds, double[] upperBounds, double sumTo) throws COptQuestException
      Creates a mixture variable with k components named 1 to k, optional bounds for each component, and the sum of the weights.
      Parameters:
      name - base name of the variable
      k - number of components; must be at least 1
      lowerBounds - lower bound of each component, or null for a lower bound of 0 on every component
      upperBounds - upper bound of each component, or null for no upper bounds
      sumTo - sum of the weights; must be greater than 0
      Throws:
      COptQuestException - if k is less than 1, if sumTo is not greater than 0, if a bound array does not have k entries, if a lower bound is greater than its upper bound, or if no set of weights within the bounds sums to sumTo
    • COptQuestMixtureVariable

      public COptQuestMixtureVariable(String name, String[] components, double[] lowerBounds, double[] upperBounds, double sumTo) throws COptQuestException
      Creates a mixture variable with the given component names, optional bounds for each component, and the sum of the weights.
      Parameters:
      name - base name of the variable
      components - names of the components; each must be unique and must not contain whitespace, a semicolon, a comma or @
      lowerBounds - lower bound of each component, or null for a lower bound of 0 on every component
      upperBounds - upper bound of each component, or null for no upper bounds
      sumTo - sum of the weights; must be greater than 0
      Throws:
      COptQuestException - if components is null or empty or holds a name that is not valid, if sumTo is not greater than 0, if a bound array does not have one entry for each component, if a lower bound is greater than its upper bound, or if no set of weights within the bounds sums to sumTo
  • Method Details

    • getInputVariables

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

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

      Returns:
      an empty list
    • getOutputVariables

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

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

      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