예제 #1
0
        public IGraph CreateGraph()
        {
            dagGraph = new DagGraph(engineXml.name.Name);

            foreach (var node in engineXml.node)
            {
                var nodeName = node.name.Name;
                engineNodes[nodeName] = node;

                var target = new Vertex(dagGraph, nodeName);
                dagGraph.Vertices.Add(target);

                if (node.inputs != null)
                {
                    foreach (var input in node.inputs)
                    {
                        var sourceName = [email protected];
                        var source = dagGraph.Vertices.First(x => x.Name == sourceName);

                        dagGraph.Edges.Add(new Edge(dagGraph, sourceName, source, target));
                    }
                }
            }

            return dagGraph;
        }
        public IGraph Generate(String graphName)
        {
            var graph = new DagGraph(graphName);
            var vertices = graph.Vertices.ToArray();

            Action endGraph = () =>
            {
                foreach (var v in vertices)
                {
                    var hasInEdges = v.InEdges.None();
                    var hasOutEdges = v.OutEdges.None();

                    if (hasInEdges && hasOutEdges)
                    {
                        graph.Vertices.Remove(v);
                        Console.WriteLine("Removed disconnected node: {0}", v.Name);
                    }
                    else if (hasInEdges)
                    {
                        Console.WriteLine("Active node: {0}", v.Name);
                    }
                    else if (hasOutEdges)
                    {
                        Console.WriteLine("Publisher node: {0}", v.Name);
                    }
                }
            };

            Action<int> createNode =
                v => graph.Vertices.Add(new Vertex(graph, v.ToString()));
            Action<int, int> createEdge =
                (s, t) => graph.Edges.Add(new Edge(graph, String.Format("{0}-{1}", s, t), s.ToString(), t.ToString()));

            generator.Generate(null, endGraph, createEdge, createNode);

            return graph;
        }