Beispiel #1
0
        static void loadGraph(ref GraphO g, string pdir, string rdir)
        {
            int    numNodes = 0; int numEdges = 0;
            string startingCity = "";

            Parser.readNodes(pdir, ref numNodes, ref startingCity, ref g);
            Parser.readEdges(rdir, ref numEdges, ref g);
            g.setStartNode(startingCity);
        }
Beispiel #2
0
        private void simulateGraph_click(object sender, RoutedEventArgs e)
        {
            //this.gViewer1.Graph = null;
            for (int i = 0; i < 1500; i++)
            {
                this.gViewer.Undo();
            }
            //this.gViewer1 = null;
            GraphO g     = new GraphO();
            Graph  graph = new Graph("graph");
            int    day   = Convert.ToInt32(InfectTime.Text);

            if (day != -999)
            {
                Keterangan.Text = "Waiting...";
                loadGraph(ref g, placedir, routedir);
                g.BFS(day);
                List <Node> nodes = new List <Node>();
                nodes = g.getListNode();
                List <Edge> edges = new List <Edge>();
                edges = g.getListEdge();
                List <Edge> path = new List <Edge>();
                path = g.getPath();

                Keterangan.Text = "";
                for (int i = 0; i < path.Count; i++)
                {
                    Keterangan.Text += (i + 1).ToString() + ".  " + path[i].getSourceNode() + "->" + path[i].getDestNode() + "\n\n";
                }

                for (int i = 0; i < edges.Count; i++)
                {
                    if (isEdgeExist(edges[i], path))
                    {
                        graph.AddEdge(edges[i].getSourceNode(), edges[i].getDestNode()).Attr.Color = Microsoft.Msagl.Drawing.Color.Chocolate;
                    }
                    else
                    {
                        graph.AddEdge(edges[i].getSourceNode(), edges[i].getDestNode());
                    }
                }

                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].getInfected())
                    {
                        graph.FindNode(nodes[i].getName()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Orange;
                        graph.FindNode(nodes[i].getName()).Attr.Color     = Microsoft.Msagl.Drawing.Color.Red;
                    }
                }

                this.gViewer.Graph = graph;
                g.resetGraph();
            }
        }
Beispiel #3
0
        static public void readEdges(string filename, ref int numEdges, ref GraphO g)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(@filename);

            string line = file.ReadLine();
            int    iter = 0;

            numEdges = Int32.Parse(getToken(ref iter, line));

            for (int i = 1; i <= numEdges; i++)
            {
                line = file.ReadLine();
                iter = 0;
                string fromNode = getToken(ref iter, line);
                string toNode   = getToken(ref iter, line);
                float  weight   = float.Parse(getToken(ref iter, line));

                Edge temp = new Edge(fromNode, toNode, weight);
                g.addEdge(temp);
            }
        }
Beispiel #4
0
        static public void readNodes(string filename, ref int numNodes, ref string startingCity, ref GraphO g)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(@filename);

            string line = file.ReadLine();
            int    iter = 0;

            numNodes     = Int32.Parse(getToken(ref iter, line));
            startingCity = getToken(ref iter, line);

            for (int i = 1; i <= numNodes; i++)
            {
                line = file.ReadLine();
                iter = 0;
                string nodeName = getToken(ref iter, line);
                int    pop      = Int32.Parse(getToken(ref iter, line));

                Node temp = new Node(nodeName, pop, 0, false);
                g.addNode(temp);
            }
        }