Class COptQuestTreeVariable


public class COptQuestTreeVariable extends COptQuestManifoldVariable
A tree variable. Its value is a directed spanning tree over the given nodes: one node is the root, every other node has exactly one incoming edge, and every node can be reached from the root. Use a tree variable when the decision is a hierarchy that connects every node, such as a cueing network or a reporting structure.

In every solution that the engine generates, the edges form a spanning tree. The tree has exactly n - 1 edges and no cycle. Any node can be the root.

Variable names: <name>@<nodeFrom>,<nodeTo> for every ordered pair of nodes, including a node paired with itself: the full n by n adjacency matrix, row by row in the order of nodeNames. The value of each name is 1 if the edge from nodeFrom to nodeTo is present and 0 if it is not. The diagonal is always 0. Each name contains a comma, so write it in brackets in an expression: [<name>@A,B].

In a suggested solution, a value greater than 0.5 is an edge. The engine keeps a suggested tree as it is. Otherwise, the engine keeps one incoming edge for each node other than the root, and it uses a suggested edge where it can.

In most programs, you add this variable with OptQuestModel.AddTreeVariable 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:
  • Constructor Details

    • COptQuestTreeVariable

      public COptQuestTreeVariable(String name, String[] nodeNames) throws COptQuestException
      Creates a tree variable over the given nodes.
      Parameters:
      name - base name of the variable
      nodeNames - names of the nodes; there must be at least one, and each must be unique and must not contain whitespace, a semicolon, a comma or @
      Throws:
      COptQuestException - if nodeNames is null or empty, or holds a name that is not valid
    • COptQuestTreeVariable

      public COptQuestTreeVariable(String name, String[] nodeNames, String rootNode, Map<String,List<String>> predecessors) throws COptQuestException
      Creates a tree variable over the given nodes, with an optional fixed root and optional precedences.
      Parameters:
      name - base name of the variable
      nodeNames - names of the nodes; there must be at least one, and each must be unique and must not contain whitespace, a semicolon, a comma or @
      rootNode - the node that is the root of every tree, or null or empty to let any node be the root
      predecessors - map from a node to the nodes that must come before it, or null. A node never comes above one of its predecessors in the tree. Names that are not nodes are ignored.
      Throws:
      COptQuestException - if nodeNames is null or empty, holds a name that is not valid, if rootNode is not one of the nodes, if the root node has a predecessor, if a node lists itself as a predecessor, or if the precedences form a cycle
  • Method Details

    • getInputVariables

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

      The values of a tree variable are in the list that getProjectedInputVariables() returns. That list has one variable <name>@<nodeFrom>,<nodeTo> for every ordered pair of nodes.

      Returns:
      an empty list
    • getOutputVariables

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

      The values of a tree variable are in the list that getProjectedInputVariables() returns. That list has one variable <name>@<nodeFrom>,<nodeTo> for every ordered pair of nodes.

      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