SmartGraph.Engine An implementation of a dependency graph
manager.
Contents
-
Introduction
-
The Engine implemenation
-
How to use?
The SmartGraph.Engine library contains classes for building and managing
Directed Acyclic Graphs (or DAGs).
A dependency engine is an active task which is bound to a
DAG graph. The engine is an event handler. The event handling policy
determines how 'dirty node' events are handled. The scheduling policy
determines in what order (if at all) dirty nodes (corresponding to the graph's
vertices) should be updated. Once a node has been updated if its state (or
value) has changed the engine can publish a 'clean node' event.
The design of the engine is similar to a pipeline of processing. The various
engine policies are connected with queues. Dirty nodes are queued for the
scheduler. The scheduler queues a list of nodes for the calculation policy. The
calculation policy queues clean nodes for the publisher which raises clean node
events.
Node types:
-
INode - a basic node which does not raise the dirty node event. A node will be
updated.
-
IActiveNode - not just a basic node. Active nodes can raise the dirty node
event. They are not updated.
-
IInvariantNode - not just a basic node. Invariant nodes do not change an will
not be updated. These nodes do not raise the dirty node event. Can be used to
optimize graph updates.
Some suggestions for when to use a SmartGraph.Engine follow.
Scheduling
A simple graph can model a set of tasks which must be performed in certain order
(remember - no cycles in the DAG). It defines a sequential flow of control
acting on the nodes. A simple application of the engine is to create tasks
which must be performed periodically.
The TickingHelloWorld sample
shows how to set-up a graph and an engine to perform a string concatenation on
3 nodes:
-
a value node holding the string "hello"
-
a value node holding the string "world"
-
the current time, as given by a Ticker node which raises an event with a
configurable frequency (sample's freq=1sec). Its output value is DateTime.Now.
The graph can be foung in TickingHelloWorld.xml.
The following is a drawing of it:

The concatenated value is available after the publisher raises the clean node
event from the Concat node.
To load the engine you need the following code:
public void TickingHelloWorld_WatchOutItBlocks()
{
XmlEngineBuilder engineBuilder =
new XmlEngineBuilder( Helpers.DataDir( "TickingHelloWorld.xml" ) );
String engineName = "TickingHelloWorld";
using ( Engine engine = new Engine( engineName, engineBuilder ) )
{
engine.Start();
ManualResetEvent endevent = new ManualResetEvent(false);
endevent.WaitOne();
}
}
|