Exemple #1
0
        public void ProcessSortedNodes()
        {
            var sort = new QuickGraph.Algorithms.TopologicalSort.TopologicalSortAlgorithm <Vertex, Edge <Vertex> >(this.graph);

            sort.Compute();
            var r = sort.SortedVertices;

            Console.WriteLine("TopologicalSort");
            foreach (Vertex v in r)
            {
                Console.Write("Vertex: ");
                Console.WriteLine(v);
                var inEdges = graph.InEdges(v);
                foreach (var edge in inEdges)
                {
                    Console.Write("Edge: ");
                    Console.WriteLine(edge);
                }
            }
        }
Exemple #2
0
        public Workflow()
        {
            this.graph    = new BidirectionalGraph <Vertex, Edge <Vertex> >(true);
            this.edgeList = new Dictionary <Edge <Vertex>, string>();
            this.edgeMap  = new Dictionary <string, Edge <Vertex> >();
            this.nodeMap  = new Dictionary <string, Vertex>();

            // Define some weights to the edges
            this.edgeCostList = new Dictionary <Edge <Vertex>, double>();

            this.edgeState = new Dictionary <string, bool>();
            this.nodeState = new Dictionary <string, bool>();

            string json = @"{
                'NodeList': {
                    'A': { 'Name':'A', 'NodeType':'Pass' },
                    'B': { 'Name':'B', 'NodeType':'Pass' },
                    'C': { 'Name':'C', 'NodeType':'Pass' },
                    'D': { 'Name':'D', 'NodeType':'Pass' },
                    'E': { 'Name':'E', 'NodeType':'Pass' },
                    'Z': { 'Name':'Z', 'NodeType':'Pass' }
                },
                'TaskList': {
                    'a1': { 'Id':'a1', 'Src': 'A', 'Dst':'B', 'TaskType':'Assign', 'Est':24 },
                    'b1': { 'Id':'b1', 'Src': 'B', 'Dst':'C', 'TaskType':'Choose', 'Est':24 },
                    'b2': { 'Id':'b2', 'Src': 'B', 'Dst':'C', 'TaskType':'Accept', 'Est':4 },
                    'c1': { 'Id':'c1', 'Src': 'C', 'Dst':'D', 'TaskType':'Approve', 'Est':48 },
                    'c2': { 'Id':'c2', 'Src': 'C', 'Dst':'D', 'TaskType':'Wire', 'Est':24 },
                    'c3': { 'Id':'c3', 'Src': 'C', 'Dst':'D', 'TaskType':'Sign', 'Est':1 },
                    'd1': { 'Id':'d1', 'Src': 'D', 'Dst':'E', 'TaskType':'CloseOut', 'Est':24 },
                    'd2': { 'Id':'d2', 'Src': 'D', 'Dst':'E', 'TaskType':'Sign', 'Est':12 },
                    'd3': { 'Id':'d3', 'Src': 'D', 'Dst':'Z', 'TaskType':'Sign', 'Est':6 },
                    'e1': { 'Id':'e1', 'Src': 'E', 'Dst':'Z', 'TaskType':'Sign', 'Est':24 }
                }
            }";

            WorkflowJson wf = JsonConvert.DeserializeObject <WorkflowJson>(json);

            foreach (KeyValuePair <string, Vertex> kvp in wf.NodeList)
            {
                Vertex v = kvp.Value;
                AddVertex(v);
            }

            foreach (KeyValuePair <string, Task> kvp in wf.TaskList)
            {
                Task t = kvp.Value;
                AddTask(t);
            }

            // Add some vertices to the graph
            //var a = AddVertex("A", NodeType.Start);
            //var b = AddVertex("B", NodeType.Link);
            //var c = AddVertex("C", NodeType.Link);
            //var d = AddVertex("D", NodeType.Link);
            //var e = AddVertex("E", NodeType.Link);
            //var z = AddVertex("Z", NodeType.End);

            // Add the edges
            //AddEdge("a1", a, b);
            //AddEdge("b1", b, c);
            //AddEdge("b2", b, c);
            //AddEdge("c1", c, d);
            //AddEdge("c2", c, d);
            //AddEdge("c3", c, d);
            //AddEdge("d1", d, e);
            //AddEdge("d2", d, e);
            //AddEdge("d3", d, z);
            //AddEdge("e1", e, z);

            // Perform a topological sort of the directed acycle graph
            // This gives us the tasks and nodes in a time and dependent order.
            var sort = new QuickGraph.Algorithms.TopologicalSort.TopologicalSortAlgorithm <Vertex, Edge <Vertex> >(this.graph);

            sort.Compute();
            this.sortedVertexList = sort.SortedVertices;

            // Initialize our starting node
            nodeState["A"] = true;
        }