public void Save(Graph graph)
        {
            using (StreamWriter writer = File.CreateText(outputFile))
            {
                writer.WriteLine("digraph G {");
                writer.WriteLine(@"node [label="""",shape=""point"",style=""filled"",fillcolor=""gray"",width=""0.1""];");
                writer.WriteLine(@"edge [arrowhead=""none""];");

                //                foreach (Vertex v in graph.EnumerateVertices().Where(vertex => (bool)vertex["IsForwarder"]))
                foreach (Vertex v in graph.EnumerateVertices())
                {
                    var data = (GraphAnnotationData)v["N"];
                    var node = data.Node;
                    var elems = data.Elems;
                    var invoc = data.CallNode;
                    var deletions = data.DeletedElems;
                    //var node = (N)v["N"] ;
                    //var elems = v["Elems"] as ISet<T>;
                    //var invoc = v["Call"];

                    string elemsStr = ElemsToStr(elems);
                    string deletionsStr = ElemsToStr(deletions);

                    if (invoc == null)
                    {
                        var nodeStr = node.ToString();
                        writer.WriteLine(@"{0} [shape=""box"",label=""{1}:[{2}]-[{3}]"",fillcolor=""gray""];", v.Id, nodeStr, elemsStr, deletionsStr);
                    }
                    else
                    {

                        if (invoc is CallInfo)
                        {
                            var callNode = invoc as CallInfo;
                            var lhsStr = callNode.LHS == null ? "$" : callNode.LHS.ToString();
                            var recStr = callNode.Receiver == null ? "[]" : callNode.Receiver.ToString(); ;
                            writer.WriteLine(@"{0} [shape=""circle"",label=""{1}:{2}, lhs={3} rec={4}"",fillcolor=""blue""];", v.Id, callNode.Callee.ToString(), elemsStr, lhsStr, recStr);
                        }
                        if (invoc is DelegateCallInfo)
                        {
                            var deleNode = invoc as DelegateCallInfo;
                            writer.WriteLine(@"{0} [shape=""circle"",label=""{1}:[{2}]"",fillcolor=""brown""];", v.Id, deleNode.CalleeDelegate.ToString(), elemsStr);

                        }
                    }

                }

                foreach (Edge e in graph.EnumerateEdges())
                {
            //					string elemsStr = ElemsToStr((Bag<TypeDescriptor>)e["Types"]);
                    string elemsStr = ElemsToStr((HashSet<TypeDescriptor>)e["Types"]);

                    writer.WriteLine("{0}: [{1}];", e, elemsStr);
                }
                writer.WriteLine("}");
            }
        }
Пример #2
0
 static void graphTest()
 {
     Graph g = new Graph();
     for (int i = 0; i < 10000; i++) { }
         //g.RandomNode().InvestMoney().TakeProfitAndPayInvestors();
     g.FullyConnectedGraph(10);
     g.ToString().PrintToOutputWindow();
     //Distribute profit according to asset rank
     g.DistributeAssetsByRank(100);
     g.ToString().PrintToOutputWindow();
     //Redistribute profit based on investment connections
     g.PayInvestors();
     //Reinvest the net profit into new investments
 }
 internal PropagationGraph()
 {
     graph = new Graph();
     vIndex = new Dictionary<PropGraphNodeDescriptor, int>();
     callNodes = new HashSet<AnalysisCallNode>();
 }
Пример #4
0
        public void Graph(double start, double end, double dx)
        {
            Series series = new Series();
            for (double x = start; x < end; x += dx) {
                double y = Evaluate(x);
                Debug.Print(x.ToString() + ", " + y.ToString());
                if (!double.IsNaN(y) && y < 1.0e10 && y > -1.0e10) {
                    series.Points.Add(new DataPoint(x, y));
                } else Debug.Print(x.ToString() + ", " + y.ToString() + ", " + "could not be graphed");
            }
            series.ChartType = SeriesChartType.Line;
            series.XAxisType = AxisType.Primary;
            series.YAxisType = AxisType.Primary;

            series.ChartArea = "ChartArea1";
            series.Legend = "Legend1";
            Graph graph = new Graph(series);
            graph.ShowDialog();
        }