Class AbstractGraphVar<E extends IGraph>

java.lang.Object
org.chocosolver.solver.variables.impl.AbstractVariable
org.chocosolver.solver.variables.impl.AbstractGraphVar<E>
All Implemented Interfaces:
Comparable<Variable>, Identity, GraphVar<E>, Variable
Direct Known Subclasses:
DirectedGraphVarImpl, UndirectedGraphVarImpl

public abstract class AbstractGraphVar<E extends IGraph> extends AbstractVariable implements GraphVar<E>
  • Field Details

    • UB

      protected E extends IGraph UB
    • LB

      protected E extends IGraph LB
    • delta

      protected GraphDelta delta
    • n

      protected int n
    • reactOnModification

      protected boolean reactOnModification
  • Constructor Details

    • AbstractGraphVar

      protected AbstractGraphVar(String name, Model solver, E LB, E UB)
      Creates a graph variable
      Parameters:
      solver -
  • Method Details

    • isInstantiated

      public boolean isInstantiated()
      Description copied from interface: Variable
      Indicates whether this is instantiated (see implementations to know what instantiation means).
      Specified by:
      isInstantiated in interface Variable
      Returns:
      true if this is instantiated
    • removeNode

      public boolean removeNode(int x, ICause cause) throws ContradictionException
      Remove node x from the domain Removes x from the upper bound graph
      Specified by:
      removeNode in interface GraphVar<E extends IGraph>
      Parameters:
      x - node's index
      cause - algorithm which is related to the removal
      Returns:
      true iff the removal has an effect
      Throws:
      ContradictionException
    • enforceNode

      public boolean enforceNode(int x, ICause cause) throws ContradictionException
      Enforce the node x to belong to any solution Adds x to the lower bound graph
      Specified by:
      enforceNode in interface GraphVar<E extends IGraph>
      Parameters:
      x - node's index
      cause - algorithm which is related to the modification
      Returns:
      true iff the enforcing has an effect
      Throws:
      ContradictionException
    • removeEdge

      public boolean removeEdge(int x, int y, ICause cause) throws ContradictionException
      Description copied from interface: GraphVar
      Removes edge (directed in case of directed graph variable) (x,y) from the upper bound
      Specified by:
      removeEdge in interface GraphVar<E extends IGraph>
      Parameters:
      x - node's index
      y - node's index
      cause - cause of edge removal
      Returns:
      true iff the edge has been removed from the upper bound
      Throws:
      ContradictionException - if the edge was mandatory
    • enforceEdge

      public boolean enforceEdge(int x, int y, ICause cause) throws ContradictionException
      Description copied from interface: GraphVar
      Adds edge (directed directed graph variable) (x,y) in the lower bound
      Specified by:
      enforceEdge in interface GraphVar<E extends IGraph>
      Parameters:
      x - node's index
      y - node's index
      cause - cause of edge addition
      Returns:
      true iff the edge has been add to the lower bound
      Throws:
      ContradictionException
    • getLB

      public E getLB()
      Description copied from interface: GraphVar
      Get GraphVar lower bound (or kernel): the graph which is a subgraph of any instantiation.
      Specified by:
      getLB in interface GraphVar<E extends IGraph>
      Returns:
      the lower bound graph (having mandatory nodes and edges)
    • getUB

      public E getUB()
      Description copied from interface: GraphVar
      Get GraphVar upper bound (or envelope): any instantiation of this GraphVar is a subgraph of the upper bound.
      Specified by:
      getUB in interface GraphVar<E extends IGraph>
      Returns:
      the upper bound graph (having possible nodes and edges)
    • getNbMaxNodes

      public int getNbMaxNodes()
      Specified by:
      getNbMaxNodes in interface GraphVar<E extends IGraph>
      Returns:
      the maximum number of node the graph variable may have. Nodes are comprised in the interval [0,getNbMaxNodes()] Therefore, any vertex should be strictly lower than getNbMaxNodes()
    • getDelta

      public GraphDelta getDelta()
      Description copied from interface: Variable
      Return the delta domain of this
      Specified by:
      getDelta in interface GraphVar<E extends IGraph>
      Specified by:
      getDelta in interface Variable
      Returns:
      the delta domain of the variable
    • getTypeAndKind

      public int getTypeAndKind()
      Description copied from interface: Variable
      Return a MASK composed of 2 main information: TYPE and KIND.
      TYPE is defined in the 3 first bits : VAR ( 1 invalid input: '<'invalid input: '<' 0), CSTE (1 invalid input: '<'invalid input: '<' 1) or VIEW (1 invalid input: '<'invalid input: '<' 2)
      KIND is defined on the other bits : INT (1 invalid input: '<'invalid input: '<' 3), BOOL (INT + 1 invalid input: '<'invalid input: '<' 4), GRAPH (1 invalid input: '<'invalid input: '<' 5) or META (1 invalid input: '<'invalid input: '<' 6)

      To get the TYPE of a variable:

       int type = var.getTypeAndKind() invalid input: '&' Variable.TYPE;
       

      To get the KIND of a variable:

       int kind = var.getTypeAndKind() invalid input: '&' Variable.KIND;
       

      To check a specific type or kind of a variable:

           boolean isVar = (var.getTypeAndKind() invalid input: '&' Variable.VAR) !=0;
           boolean isInt = (var.getTypeAndKind() invalid input: '&' Variable.INT) !=0;
       
      Specified by:
      getTypeAndKind in interface Variable
      Returns:
      an int representing the type and kind of the variable
    • createScheduler

      public EvtScheduler createScheduler()
      Specified by:
      createScheduler in class AbstractVariable
    • toString

      public String toString()
      Overrides:
      toString in class AbstractVariable
    • createDelta

      public void createDelta()
      Description copied from interface: Variable
      Create a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.
      Specified by:
      createDelta in interface Variable
    • notifyPropagators

      public void notifyPropagators(IEventType event, ICause cause) throws ContradictionException
      Description copied from interface: Variable
      If this has changed, then notify all of its observers.
      Each observer has its update method.
      Specified by:
      notifyPropagators in interface Variable
      Overrides:
      notifyPropagators in class AbstractVariable
      Parameters:
      event - event on this object
      cause - object which leads to the modification of this object
      Throws:
      ContradictionException - if a contradiction occurs during notification
    • instantiateTo

      public void instantiateTo(E value, ICause cause) throws ContradictionException
      Description copied from interface: GraphVar
      Instantiates this to value given in parameter. This method is not supposed to be used except for restoring solutions.
      Specified by:
      instantiateTo in interface GraphVar<E extends IGraph>
      Parameters:
      value - value of this
      cause -
      Throws:
      ContradictionException
    • getValueAsBoolMatrix

      public boolean[][] getValueAsBoolMatrix()
      Returns:
      the value of the graph variable represented through an adjacency matrix plus a set of nodes (last row of the matrix). This method is not supposed to be used except for restoring solutions.
    • instantiateTo

      public void instantiateTo(boolean[][] value, ICause cause) throws ContradictionException
      Instantiates this to value which represents an adjacency matrix plus a set of nodes (last row of the matrix). This method is not supposed to be used except for restoring solutions.
      Parameters:
      value - value of this
      cause -
      Throws:
      ContradictionException - if the edge was mandatory
    • monitorDelta

      public IGraphDeltaMonitor monitorDelta(ICause propagator)
      Description copied from interface: GraphVar
      Make the propagator 'prop' have an incremental filtering w.r.t. this graph variable
      Specified by:
      monitorDelta in interface GraphVar<E extends IGraph>
      Parameters:
      propagator - A propagator involving this graph variable
      Returns:
      A new instance of GraphDeltaMonitor to make incremental propagators