private void onGraphClassify(object sender, EventArgs e) { if (CurrentGraphPanel == null) { return; } Graph g = CurrentGraphPanel.Graph; Output.WriteLine("[Vertex Classification Output]"); foreach (Vertex v in g.GetVertices()) { VertexClassification vc = GraphAlgorithms.ClassifyVertex(v); Output.WriteLine("Vertex " + v.ToString() + " is " + vc.ToString()); } Output.WriteLine("[End Vertex Classification Output]"); }
public static Graph GenerateRandomGraph(int n) { float prob = 0.2f; Graph g = new Graph(); g.Directed = false; for (int i = 0; i < n; i++) { Vertex v = new Vertex(); g.AddVertex(v); } Random r = new Random(); //Randomly decide when to add an edge between any two pairs foreach (Vertex v in g.GetVertices()) { foreach (Vertex u in g.GetVertices()) { if (!v.Equals(u)) { double random = r.NextDouble(); if (random >= 0 && random <= prob) { g.AddEdge(new Edge(v, u, (float)r.NextDouble())); } } } } foreach (Vertex v in g.GetVertices()) { VertexClassification vc = ClassifyVertex(v); Output.WriteLine("Vertex " + v.ToString() + " is " + vc.ToString()); } return(g); }