public void BuildRandomGraph(FlockGraph Graph, int NumberOfVertexes, int NumberOfEdges) { Random r = new Random(DateTime.Now.Millisecond); //Build Vertexes for (int i = 0; i < NumberOfVertexes; i++) { FlockVertex v = new FlockVertex(i); Graph.AddVertex(v); } //Build Edges double vc = Graph.VertexCount; int flock1 = (int)Math.Round(vc / 3); int flock2 = flock1 * 2; int flock3 = Graph.VertexCount - 1; int flocks = (int)Math.Round((double)(NumberOfEdges / 3)); FlockVertex s = Graph.Vertices.ElementAt(1); FlockVertex t = Graph.Vertices.ElementAt(flock2); Graph.AddEdge(new FlockEdge(s, t)); s = Graph.Vertices.ElementAt(flock2); t = Graph.Vertices.ElementAt(flock3); Graph.AddEdge(new FlockEdge(s, t)); for (int i = 0; i < flocks; i++) { FlockVertex source = Graph.Vertices.ElementAt(r.Next(1, flock1)); FlockVertex target = Graph.Vertices.ElementAt(r.Next(1, flock1)); Graph.AddEdge(new FlockEdge(source, target)); } for (int i = 0; i < flocks; i++) { FlockVertex source = Graph.Vertices.ElementAt(r.Next(flock1, flock2)); FlockVertex target = Graph.Vertices.ElementAt(r.Next(flock1, flock2)); Graph.AddEdge(new FlockEdge(source, target)); } for (int i = 0; i < flocks; i++) { FlockVertex source = Graph.Vertices.ElementAt(r.Next(flock2, flock3)); FlockVertex target = Graph.Vertices.ElementAt(r.Next(flock2, flock3)); Graph.AddEdge(new FlockEdge(source, target)); } }
private void BuildFlockGraph() { flockGraph = new FlockGraph(); foreach (long friendUid in FriendsList) { flockGraph.AddVertex(new FlockVertex(friendUid)); } foreach (KeyValuePair<long, List<long>> kvp in EdgeMap) { long source = kvp.Key; foreach (long target in kvp.Value) { //Error at 20% if ((flockGraph.VertexDictionary.ContainsKey(source)) && (flockGraph.VertexDictionary.ContainsKey(target))) flockGraph.AddEdge(new FlockEdge(flockGraph.VertexDictionary[source], flockGraph.VertexDictionary[target])); else Debug.WriteLine("Edge Dropped"); } } }