예제 #1
0
        internal GraphWriter ToGraph(IList <IStatement> pretasks, IList <IStatement> looptasks)
        {
            GraphWriter g = new DotGraphWriter("Model");

            Count = 1;
            if (ShowNonIterativeTaskNodes)
            {
                foreach (IStatement ist in pretasks)
                {
                    AddNode(g, ist, Stage.Initialisation);
                }
            }
            foreach (IStatement ist in looptasks)
            {
                AddNode(g, ist, Stage.Update);
            }
            foreach (IStatement ist in pretasks)
            {
                AddEdges(g, ist, Stage.Initialisation);
            }
            Set <IStatement> edgesDone = new Set <IStatement>(new IdentityComparer <IStatement>());

            foreach (IStatement ist in looptasks)
            {
                if (edgesDone.Contains(ist))
                {
                    continue;
                }
                edgesDone.Add(ist);
                AddEdges(g, ist, Stage.Update);
            }
            return(g);
        }
예제 #2
0
        internal GraphWriter ToGraph(ModelBuilder mb)
        {
            GraphWriter g = new DotGraphWriter("Model");

            Count = 0;
            if (mb == null)
            {
                return(g);
            }
            foreach (IModelExpression me in mb.ModelExpressions)
            {
                if (me is MethodInvoke)
                {
                    AddFactorEdges(g, (MethodInvoke)me);
                }
            }
            // connect nodes that represent the same variable with undirected edges
            Dictionary <Variable, List <Node> > nodesOfVariable = new Dictionary <Variable, List <Node> >();

            foreach (KeyValuePair <IModelExpression, Node> entry in nodeOfExpr)
            {
                if (!(entry.Key is Variable))
                {
                    continue;
                }
                Variable v = (Variable)entry.Key;
                v = GetBaseVariable(v);
                List <Node> nodes;
                if (!nodesOfVariable.TryGetValue(v, out nodes))
                {
                    nodes = new List <Node>();
                    nodesOfVariable[v] = nodes;
                }
                nodes.Add(entry.Value);
            }
            foreach (List <Node> nodes in nodesOfVariable.Values)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    for (int j = 0; j < nodes.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        // Glee uses the edge direction as a layout hint, so only use child nodes as sources
                        if (!childNodes.Contains(nodes[i]))
                        {
                            continue;
                        }
                        Edge edge = g.AddEdge(nodes[i].ID, nodes[j].ID);
                        edge.ArrowheadAtTarget = ArrowheadStyle.None;
                    }
                }
            }
            return(g);
        }
예제 #3
0
        /// <summary>
        /// Write the graph to a file in DOT format
        /// </summary>
        /// <param name="path"></param>
        public void WriteDot(string path)
        {
            // References:
            // https://en.wikipedia.org/wiki/DOT_(graph_description_language)

            GraphWriter g = new DotGraphWriter("Model");

            GraphBuilder.Add(g, modelBuilder, true);
            g.Write(path);
        }
        protected void AddEdges(DotGraphWriter g, NodeIndex index)
        {
            Node nd = nodeOf[index];

            if (nd == null)
            {
                return;
            }
            foreach (EdgeIndex edge in dg.EdgesInto(index))
            {
                NodeIndex sourceIndex = dg.SourceOf(edge);
                Node      nd2         = nodeOf[sourceIndex];
                if (nd2 == null)
                {
                    continue;
                }
                GVEdgeStyle style = GetEdgeStyle(edge);
                Edge        e;
                if ((style & GVEdgeStyle.Back) > 0)
                {
                    e                   = g.AddEdge(nd.ID, nd2.ID);
                    e.Color             = Color.Red;
                    e.ArrowheadAtSource = ArrowheadStyle.Normal;
                    e.ArrowheadAtTarget = ArrowheadStyle.None;
                    if ((style & GVEdgeStyle.Blue) > 0)
                    {
                        e.Color = Color.Purple;
                    }
                }
                else
                {
                    e = g.AddEdge(nd2.ID, nd.ID);
                    if ((style & GVEdgeStyle.Blue) > 0)
                    {
                        e.Color = Color.Blue;
                    }
                    if ((style & GVEdgeStyle.Dimmed) > 0)
                    {
                        e.Color = Color.LightGray;
                    }
                }
                if (edgeName != null)
                {
                    e.Label = edgeName(edge);
                }
                if ((style & GVEdgeStyle.Bold) > 0)
                {
                    e.Width = 2;
                }
                if ((style & GVEdgeStyle.Dashed) > 0)
                {
                    e.Style = DOTEdgeStyle.Dashed;
                }
            }
        }
        internal DotGraphWriter ToGraph(IndexedGraph dg)
        {
            DotGraphWriter g = new DotGraphWriter("Model");

            Count = 1;
            foreach (NodeIndex index in dg.Nodes)
            {
                AddNode(g, index);
            }
            foreach (NodeIndex index in dg.Nodes)
            {
                AddEdges(g, index);
            }
            return(g);
        }
        protected Node AddNode(DotGraphWriter g, NodeIndex index)
        {
            Node nd = nodeOf[index];

            if (nd != null)
            {
                return(nd);
            }
            string s = (nodeName != null) ? nodeName(index) : index.ToString(CultureInfo.InvariantCulture);

            nd            = g.AddNode("node" + Count);
            nd.UserData   = Count++;
            nodeOf[index] = nd;
            nd.Label      = s;
            nd.Shape      = ShapeStyle.Box;
            nd.FontSize   = 9;
            return(nd);
        }
 protected void OnGraphChanged()
 {
     graph = ToGraph(dg);
 }