choco.kernel.solver.constraints.global.matching
Class AbstractBipartiteGraph

java.lang.Object
  extended by choco.kernel.solver.propagation.Propagator
      extended by choco.kernel.solver.constraints.AbstractSConstraint<IntDomainVar>
          extended by choco.kernel.solver.constraints.integer.AbstractIntSConstraint
              extended by choco.kernel.solver.constraints.integer.AbstractLargeIntSConstraint
                  extended by choco.kernel.solver.constraints.global.matching.AbstractBipartiteGraph
All Implemented Interfaces:
IExtensionnable, IPretty, SConstraint<IntDomainVar>, IntPropagator, Cloneable, EventListener
Direct Known Subclasses:
AbstractBipartiteFlow, AbstractBipartiteMatching

public abstract class AbstractBipartiteGraph
extends AbstractLargeIntSConstraint

An abstract class encoding assignment graphs (matching each left vertex with one single right vertex) We consider a flow in the graph by adding a source linked to all right vertices and a sink linked to all left vertices

It is based on computing the strongly connected components of the residual graph, then remove arcs connecting two different strongly connected components

Computing the strongly connected components is done by an algorithm of Aho, Hopcroft, Ullman using depth first search (Cormen, Leiserson, p. 478, p. 489)

Note (EGA) on ice traduction from claire to java : class StrongConnectionDecomposition have been included in this one


Nested Class Summary
protected static class AbstractBipartiteGraph.IntQueue
           
 
Field Summary
protected  int[] component
           
protected  boolean[][] componentOrder
           
protected  int currentComponent
           
protected  int currentNode
           
protected  int[] finishDate
           
protected  int[] left2rightArc
           
protected  IStateInt matchingSize
           
protected  int maxValue
           
protected  int minValue
           
protected  int nbLeftVertices
           
protected  int nbRightVertices
           
protected  int nbVertices
           
protected  AbstractBipartiteGraph.IntQueue queue
           
protected  IStateIntVector refMatch
           
protected  int[] right2leftArc
           
protected  boolean[] seen
           
protected  int source
           
protected  int time
           
 
Fields inherited from class choco.kernel.solver.constraints.AbstractSConstraint
cIndices, constraintType, extensions, vars
 
Fields inherited from class choco.kernel.solver.propagation.Propagator
active, constAwakeEvent, priority, propagationEngine
 
Fields inherited from interface choco.kernel.solver.constraints.SConstraint
LOGGER
 
Constructor Summary
AbstractBipartiteGraph(IEnvironment environment, IntDomainVar[] vars, int nbLeft, int nbRight)
          Constructor
 
Method Summary
 void addComponentEdge(int compi, int compj)
          add an edge in the component graph between compi and compj: componentOrder stores the transitive closure of that graph
 void addComponentVertex()
          adds a new vertex to the component graph (= a component = a set of s. connected vertices in the original graph)
 void augment(int x)
          augment the matching along one alternating path note: throughout the following code, we assume (1 <= x <= c.nbLeftVertices), (1 <= y <= c.nbRightVertices)
 void augmentFlow()
          keeps augmenting the flow until a maximal flow is reached
abstract  void decreaseMatchingSize(int j)
          updates the matching size when one more left vertex is de-matched with j
abstract  void deleteEdgeAndPublish(int i, int j)
          two methods used for detecting that an edge should be removed from the bipartite assignment graph deleteMatch -> removes it from the graph data strutures deleteEdgeAndPublish -> same + publishes the information outside the constraint
abstract  void deleteMatch(int i, int j)
          removing the arc i-j from the reference matching & update matchingSize
 int findAlternatingPath()
          First pass: use Ford & Fulkerson algorithm to compute a reference flow (assignment) finds an augmenting path using a fifo queue
 void firstDFSearch(int i)
          the first search explores (DFS) the reduced graph
 void firstPassDFS()
          seen[i] = false <=> color[i] = white (in book) = true % {gray, black}
 int getNbComponents()
           
abstract  void increaseMatchingSize(int j)
          updates the matching size when one more left vertex is matched with j
protected  void init()
           
 void initSCCGraph()
          initialize the graph data structure storing the SCC decomposition
 int match(int i)
           
 boolean mayDiminishFlowBetween(int j, int i)
           
abstract  boolean mayDiminishFlowFromSource(int j)
           
 boolean mayGrowFlowBetween(int j, int i)
           
abstract  boolean mayGrowFlowFromSource(int j)
           
 boolean mayGrowFlowToSink(int i)
           
 int[] mayInverseMatch(int j)
          reverse, access from the right vertex set: iterating over the variables (left vertex set) and reading their domains
 int[] mayMatch(int i)
          Accessing the edges of the bipartite graph access from the left vertex set: reading domains of modeling variables
abstract  boolean mustGrowFlowFromSource(int j)
           
 void prettyPrintForDebug()
           
 void propagate()
          Achieves generalized arc consistency in one call
abstract  void putRefMatch(int i, int j)
          adding the arc i-j in the reference matching without any updates
 void refreshSCC()
           
protected  void removeUselessEdges()
          remove arcs connecting two different strongly connected components the event generated by the flow algorithm: discovering that an edge is no longer valid, and posting this event to the constraint strategy: since we are already achieving GAC consistency in one single loop, there is no need to post a constAwake
 void secondDFSearch(int i)
          the second search explores (DFS) the inverse of the reduced graph
 void secondPassDFS()
           
abstract  void setMatch(int i, int j)
          adding the arc i-j in the reference matching & update matchingSize
 
Methods inherited from class choco.kernel.solver.constraints.integer.AbstractIntSConstraint
awakeOnBounds, awakeOnInf, awakeOnInst, awakeOnRem, awakeOnRemovals, awakeOnSup, getConstraintType, isConsistent, isSatisfied, isSatisfied
 
Methods inherited from class choco.kernel.solver.constraints.AbstractSConstraint
addExtension, addListener, clone, getAbstractSConstraintExtensionNumber, getConstraintIdx, getExtension, getFineDegree, getNbVarNotInst, getNbVars, getVar, getVarQuick, isCompletelyInstantiated, isEntailed, opposite, pretty, setConstraintIndex, setExtension, setVar, toString
 
Methods inherited from class choco.kernel.solver.propagation.Propagator
activate, awake, constAwake, fail, getEvent, getFilteredEventMask, getPriority, isActive, setActive, setActiveSilently, setEntailed, setPassive, setPropagationEngine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nbLeftVertices

protected int nbLeftVertices

nbRightVertices

protected int nbRightVertices

nbVertices

protected int nbVertices

minValue

protected int minValue

maxValue

protected int maxValue

source

protected int source

refMatch

protected IStateIntVector refMatch

matchingSize

protected IStateInt matchingSize

left2rightArc

protected int[] left2rightArc

right2leftArc

protected int[] right2leftArc

queue

protected AbstractBipartiteGraph.IntQueue queue

time

protected int time

finishDate

protected int[] finishDate

seen

protected boolean[] seen

currentNode

protected int currentNode

currentComponent

protected int currentComponent

component

protected int[] component

componentOrder

protected boolean[][] componentOrder
Constructor Detail

AbstractBipartiteGraph

public AbstractBipartiteGraph(IEnvironment environment,
                              IntDomainVar[] vars,
                              int nbLeft,
                              int nbRight)
Constructor

Parameters:
environment -
vars - the graph, a left vextex per vars, a right vertex per domain value
nbLeft - number of left nodes, = vars.length
nbRight - number of right nodes, domain values of vars
Method Detail

init

protected void init()

mayMatch

public final int[] mayMatch(int i)
Accessing the edges of the bipartite graph access from the left vertex set: reading domains of modeling variables

Parameters:
i - the left vertex
Returns:
the set of right vertices that can be matched to i

mayInverseMatch

public final int[] mayInverseMatch(int j)
reverse, access from the right vertex set: iterating over the variables (left vertex set) and reading their domains

Parameters:
j - the right vertex
Returns:
the set of left vertices that can be matched to j

match

public final int match(int i)
Parameters:
i - left vextex index
Returns:
accessing the right vertex matched to i

mayGrowFlowToSink

public final boolean mayGrowFlowToSink(int i)
Parameters:
i - a left vertex
Returns:
whether the flow from i to the sink may be increased

mayGrowFlowBetween

public final boolean mayGrowFlowBetween(int j,
                                        int i)
Parameters:
j - a right vertex
i - a left vertex
Returns:
whether the flow from j to i may be increased (meaning whether that the additional flow is able to arrive to j, we don't care yet whether it will be able to leave i)

mayDiminishFlowBetween

public final boolean mayDiminishFlowBetween(int j,
                                            int i)
Parameters:
j - a right vertex
i - a left vertex
Returns:
whether the flow from j to i may be decreased

increaseMatchingSize

public abstract void increaseMatchingSize(int j)
updates the matching size when one more left vertex is matched with j

Parameters:
j - a right vertex

decreaseMatchingSize

public abstract void decreaseMatchingSize(int j)
updates the matching size when one more left vertex is de-matched with j

Parameters:
j - a right vertex

deleteMatch

public abstract void deleteMatch(int i,
                                 int j)
removing the arc i-j from the reference matching & update matchingSize

Parameters:
i - a left vertex
j - a right vertex

putRefMatch

public abstract void putRefMatch(int i,
                                 int j)
adding the arc i-j in the reference matching without any updates

Parameters:
i - a left vertex
j - a right vertex

setMatch

public abstract void setMatch(int i,
                              int j)
adding the arc i-j in the reference matching & update matchingSize

Parameters:
i - a left vertex
j - a right vertex

mayDiminishFlowFromSource

public abstract boolean mayDiminishFlowFromSource(int j)
Parameters:
j - a right vertex
Returns:
whether the flow from the source to j may be decreased

mayGrowFlowFromSource

public abstract boolean mayGrowFlowFromSource(int j)
Parameters:
j - a right vertex
Returns:
whether the flow from the source to j may be increased

mustGrowFlowFromSource

public abstract boolean mustGrowFlowFromSource(int j)
Parameters:
j - a right vertex
Returns:
whether the flow from the source to j must be increased in order to get a maximal (sink/left vertex set saturating) flow

deleteEdgeAndPublish

public abstract void deleteEdgeAndPublish(int i,
                                          int j)
                                   throws ContradictionException
two methods used for detecting that an edge should be removed from the bipartite assignment graph deleteMatch -> removes it from the graph data strutures deleteEdgeAndPublish -> same + publishes the information outside the constraint

Parameters:
i - a left vertex
j - a right vertex
Throws:
ContradictionException

findAlternatingPath

public int findAlternatingPath()
First pass: use Ford & Fulkerson algorithm to compute a reference flow (assignment) finds an augmenting path using a fifo queue

Returns:
0 if none found, otherwise the end of the path

augment

public void augment(int x)
augment the matching along one alternating path note: throughout the following code, we assume (1 <= x <= c.nbLeftVertices), (1 <= y <= c.nbRightVertices)

Parameters:
x -

augmentFlow

public final void augmentFlow()
                       throws ContradictionException
keeps augmenting the flow until a maximal flow is reached

Throws:
ContradictionException

initSCCGraph

public final void initSCCGraph()
initialize the graph data structure storing the SCC decomposition


addComponentVertex

public final void addComponentVertex()
adds a new vertex to the component graph (= a component = a set of s. connected vertices in the original graph)


getNbComponents

public final int getNbComponents()

addComponentEdge

public final void addComponentEdge(int compi,
                                   int compj)
add an edge in the component graph between compi and compj: componentOrder stores the transitive closure of that graph

Parameters:
compi -
compj -

firstPassDFS

public final void firstPassDFS()
seen[i] = false <=> color[i] = white (in book) = true % {gray, black}


firstDFSearch

public final void firstDFSearch(int i)
the first search explores (DFS) the reduced graph

Parameters:
i -

secondPassDFS

public final void secondPassDFS()

secondDFSearch

public final void secondDFSearch(int i)
the second search explores (DFS) the inverse of the reduced graph

Parameters:
i -

removeUselessEdges

protected void removeUselessEdges()
                           throws ContradictionException
remove arcs connecting two different strongly connected components the event generated by the flow algorithm: discovering that an edge is no longer valid, and posting this event to the constraint strategy: since we are already achieving GAC consistency in one single loop, there is no need to post a constAwake

Throws:
ContradictionException

refreshSCC

public final void refreshSCC()

propagate

public void propagate()
               throws ContradictionException
Achieves generalized arc consistency in one call

Specified by:
propagate in class Propagator
Throws:
ContradictionException

prettyPrintForDebug

public final void prettyPrintForDebug()


Copyright © 2012. All Rights Reserved.