Observers Concepts

Algorithms do not serialize any interesting data. They publish a set of standard events that an observer can listen to gather the data (algorithms and observers in QuickGraph implement the Observer Pattern). For example, one can attach an observer that records the vertex predecessors to algorithms that compute the shortest path.
  • VertexPredecessorRecorderObserver, creates a dictionary that links vertices to their parent edge,
  • EdgePredecessorRecorderObserver, create a dictionary that links vertices to their parent edge,
  • VertexDistanceRecorderObserver, stores the distance of vertices from the root vertex,
  • VertexTimeStamperObserver, stores the time instant where a vertex processing start and finishes
Using observers
Observer instance are to be 'attached' to algorithms during the computation. All observer implement an Attach method that returns a disposable instance. When disposing, this instance 'detached' the observer from the algorithm events.

    IVertexListGraph<TVertex,TEdge> g = ...; // some graph instance
    var dfs = new DepthFirstSearchAlgorithm<TVertex,TEdge>(g);
    var predecessorRecorder = new VertexPredecessorRecorderObserver<TVertex,TEdge>();

    using(predecessorRecorder.Attach(dfs)) // listen to dfs events, then unhook
        dfs.Compute();   

Last edited Mar 30, 2009 at 6:09 AM by pelikhan, version 4

Comments

topassi Feb 4, 2012 at 5:24 PM 
It's easy to deduce that the VertexPredecessorRecorderObserver creates a dictionary that links vertices to their parent VERTICE, and not "edge"...
Isn't it ???

km_waffle Jun 13, 2011 at 8:10 PM 
VertexPredecessorRecorderObserver, creates a dictionary that links vertices to their parent edge,
EdgePredecessorRecorderObserver, create a dictionary that links vertices to their parent edge,

those say the same thing.