public void GraphWithSelfEdgesPUT1(int v, int e, bool self) { AdjacencyGraph g = null; RandomGraph.Graph(g, v, e, new Random(), self); DepthFirstSearchAlgorithm bfs = new DepthFirstSearchAlgorithm(g); }
public void GraphWithoutSelfEdges() { AdjacencyGraph g = new AdjacencyGraph( new QuickGraph.Providers.VertexAndEdgeProvider(), true); RandomGraph.Graph(g, 20, 100, new Random(), false); DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g); dfs.StartVertex += new VertexHandler(this.StartVertex); dfs.DiscoverVertex += new VertexHandler(this.DiscoverVertex); dfs.ExamineEdge += new EdgeHandler(this.ExamineEdge); dfs.TreeEdge += new EdgeHandler(this.TreeEdge); dfs.BackEdge += new EdgeHandler(this.BackEdge); dfs.ForwardOrCrossEdge += new EdgeHandler(this.FowardOrCrossEdge); dfs.FinishVertex += new VertexHandler(this.FinishVertex); Parents.Clear(); DiscoverTimes.Clear(); FinishTimes.Clear(); m_Time = 0; foreach (IVertex v in g.Vertices) { Parents[v] = v; } // compute dfs.Compute(); CheckDfs(g, dfs); }
protected override bool ContainsOption(RandomGraph.Common.Model.AnalyseOptions option) { switch (option) { case AnalyseOptions.ClusteringCoefficient: return assemblyToAnalyze[0].CoefficientsLocal.Keys.Count != 0; case AnalyseOptions.DegreeDistribution: return assemblyToAnalyze[0].VertexDegreeLocal.Keys.Count != 0; case AnalyseOptions.ConnSubGraph: return assemblyToAnalyze[0].SubgraphsLocal.Keys.Count != 0; case AnalyseOptions.MinPathDist: return assemblyToAnalyze[0].DistanceBetweenVerticesLocal.Count != 0; case AnalyseOptions.EigenValue: return assemblyToAnalyze[0].Results[0].EigenVector.Count != 0; case AnalyseOptions.DistEigenPath: return assemblyToAnalyze[0].DistancesBetweenEigenValuesLocal.Count != 0; case AnalyseOptions.Cycles: return assemblyToAnalyze[0].Results[0].Cycles.Count != 0; case AnalyseOptions.TriangleCountByVertex: return assemblyToAnalyze[0].Results[0].TriangleCount.Count != 0; case AnalyseOptions.TriangleTrajectory: return assemblyToAnalyze[0].TriangleTrajectoryLocal.Count != 0; default: return assemblyToAnalyze[0].Results[0].Result.Keys.Contains(option); } }
/// Summary /// Time: 4 min 52 sec /// Pattern: Parameterized stub public void RemoveEdgeIf(BidirectionalGraph g) { IEdge e = RandomGraph.Edge(g, Rnd); g.RemoveEdgeIf(new DummyEdgeEqualPredicate(e, false)); g.RemoveEdgeIf(new DummyEdgeEqualPredicate(e, true)); }
public void RemoveEdgeIf() { IMutableEdgeListGraph g = Graph; IEdge e = RandomGraph.Edge(g, Rnd); g.RemoveEdgeIf(new DummyEdgeEqualPredicate(e, false)); g.RemoveEdgeIf(new DummyEdgeEqualPredicate(e, true)); }
private void AddRandom_Click(object sender, RoutedEventArgs e) { ViewModel.Current.Graphs.Add(RandomGraph.Get()); //for (int i = 0; i < 10; i++) //{ // graphs.Add(new RandomGraph()); //} }
/// Summary /// Time: 1 min 59 sec /// Pattern: AAAA, AllowedException public void AddRemoveVertexNotFound([PexAssumeUnderTest] AdjacencyGraph g) { IVertex v = RandomGraph.Vertex(g, new Random()); g.RemoveVertex(v); PexAssert.IsFalse(g.ContainsVertex(v)); g.RemoveVertex(v); PexAssert.IsTrue(false, "ArgumentNullException was expected"); }
public Result Test(StreamWriter tw, int graphSize, double saturation, bool useBrute) { Result res = new Result(); Graph graph = RandomGraph.GenerateGraph(graphSize, saturation); res.vertices = graphSize; res.edges = graph.EdgesCount; int[] result; long elapsedMs; Stopwatch watch; if (useBrute) { watch = System.Diagnostics.Stopwatch.StartNew(); result = BruteForce.Solve(ref graph); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; bool tmp = graph.IsColoringValid(); res.bruteChromaticNum = graph.ChromaticNumber(); res.bruteTimeMs = elapsedMs; res.bruteValid = graph.IsColoringValid(); } watch = System.Diagnostics.Stopwatch.StartNew(); result = SmallestLast.Solve(ref graph); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; res.smallestlastChromaticNum = graph.ChromaticNumber(); res.smallestlastTimeMs = elapsedMs; res.smallestlastValid = graph.IsColoringValid(); watch = System.Diagnostics.Stopwatch.StartNew(); result = DSatur.Solve(ref graph); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; res.dsaturChromaticNum = graph.ChromaticNumber(); res.dsaturTimeMs = elapsedMs; res.dsaturValid = graph.IsColoringValid(); watch = System.Diagnostics.Stopwatch.StartNew(); result = BFSColoring.Solve(ref graph); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; res.bfsChromaticNum = graph.ChromaticNumber(); res.bfsTimeMs = elapsedMs; res.bfsValid = graph.IsColoringValid(); tw.WriteLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12};{13};", res.bruteTimeMs, res.bruteChromaticNum, res.bruteValid, res.smallestlastTimeMs, res.smallestlastChromaticNum, res.smallestlastValid, res.smallestlastChromaticNum - res.bruteChromaticNum, res.bfsTimeMs, res.bfsChromaticNum, res.bfsValid, res.bfsChromaticNum - res.bruteChromaticNum, res.dsaturTimeMs, res.dsaturChromaticNum, res.dsaturValid, res.dsaturChromaticNum - res.bruteChromaticNum)); return(res); }
/// Summary /// Time: 1 min 8 sec /// Pattern: AAAA, Allowed Exception public void AddEdgeTargetNotFound([PexAssumeUnderTest] AdjacencyGraph g) { IVertex v = RandomGraph.Vertex(g, new Random()); IVertex target = RandomGraph.Vertex(g, new Random()); PexAssume.IsTrue(v != target); g.RemoveVertex(target); IEdge e = g.AddEdge(v, target); PexAssert.IsTrue(false); //Should not be reached }
/// Summary /// Time: 1 min 3 sec /// Pattern: AAAA, Allowed Exception public void AddEdgeSourceNotFound([PexAssumeUnderTest] AdjacencyGraph g) { IVertex v = RandomGraph.Vertex(g, new Random()); IVertex source = RandomGraph.Vertex(g, new Random()); PexAssume.IsTrue(v != source); g.RemoveVertex(source); IEdge e = g.AddEdge(source, v); PexAssert.IsTrue(false); //Should not be reached }
public void tooManyConnectionsTest() { Graph g = RandomGraph.Generate(20, 1.1, 1); Assert.AreEqual(20, g.GetMap().Count); foreach (KeyValuePair <int, List <int> > entry in g.GetMap()) { Assert.AreEqual(19, entry.Value.Count); } }
public void normalTest() { Graph g = RandomGraph.Generate(20, 0.5, 1); Assert.AreEqual(20, g.GetMap().Count); foreach (KeyValuePair <int, List <int> > entry in g.GetMap()) { Assert.IsNotNull(entry.Value); } }
public void RemoveEdgeIf(IMutableEdgeListGraph g) { if (g.EdgesEmpty) { return; } IEdge e = RandomGraph.Edge(g, Rnd); g.RemoveEdgeIf(new DummyEdgeEqualPredicate(e, false)); g.RemoveEdgeIf(new DummyEdgeEqualPredicate(e, true)); }
public static int RunTest(int n) { IRandomGraph g = new RandomGraph(n); int c = 0; while (!g.IsConnected()) { c++; g.NextEdge(); } return(c); }
public void GraphWithoutSelfEdges() { RandomGraph.Graph(g, 20, 100, new Random(), false); foreach (IVertex v in g.Vertices) { Parents[v] = v; } // compute dfs.Compute(); CheckDfs(); }
private void gerarAlternativo(out List <GameObject> thisLevelNodes) { thisLevelNodes = new List <GameObject>(); RandomGraph rg = new RandomGraph(numPoints, maxDistance, minDistance); foreach (var v in rg.PopulateVertices()) { var go = fac.SpawnNetworkNode(Random.Range(3, 6), Random.Range(0, 6) * 15, NetworkNode.NodeState.NS_Visible, getPosition(v.x, v.y)); thisLevelNodes.Add(go); v.tag = go; } // gerar arestas int numcons = 0; foreach (var e in rg.PopulateEdges(forgiveDistance)) { numcons++; fac.CreateConnection((GameObject)e.A.tag, (GameObject)e.B.tag); } // gerar nos 0 - 2 NetworkNode inputNode = null; for (int i = 0; i < 3; i++) { RandomGraph.Vertex p; var v = rg.CreateNew(out p); var go = fac.SpawnNetworkNode(i, Random.Range(0, 6) * 15, NetworkNode.NodeState.NS_Visible, getPosition(v.x, v.y)); thisLevelNodes.Add(go); v.tag = go; fac.CreateConnection((GameObject)v.tag, (GameObject)p.tag); if (i == 0) { inputNode = go.GetComponent <NetworkNode>(); } } // ativar nos conectados foreach (var conn in inputNode.Connetions) { var other = conn.nodes[0].netnode == inputNode ? conn.nodes[1].netnode : conn.nodes[0].netnode; other.State = NetworkNode.NodeState.NS_Active; } Debug.Log("LEVEL GERADO COM ALGORITMO RESERVA!!!"); }
public void concurrencyRandomGraphTest() { int size = 60; foreach (SCCDetector detector in this.concurrentDetectors) { Graph g = RandomGraph.Generate(size, 0.05, 4); Graph original = new Graph(g.GetMap()); ResultSet results = detector.Compute(g); for (int i = 0; i < results.List.Count; i++) { Assert.IsTrue(original.IsSCC(results.List[i])); } } }
/// Summary /// Time: 8 min 17 sec /// Pattern: AAAA, Parameterized stub /// Pex Limitations - Not able to generate any test due to the following issue: /// <boundary> maxbranches - 40000 (maximum number of branches exceeded) /// [execution] Please notice: A branch in the method System.Collections.Hashtable+HashtableEnumerator.MoveNext was executed 5777 times; /// please check that the code is not stuck in an infinite loop. /// [test] (run 1) GraphWithoutSelfEdgesPUT01, pathboundsexceeded (duplicate) /// [execution] Please notice: A branch in the method System.Collections.Hashtable+HashtableEnumerator.MoveNext was executed 4344 times; /// please check that the code is not stuck in an infinite loop. /// [test] (run 2) GraphWithoutSelfEdgesPUT01, pathboundsexceeded (duplicate) /// <summary> /// @Author:Madhuri /// </summary> public void GraphWithSelfEdgesPUT(AdjacencyGraph g, int loopBound) { Random rnd = new Random(); Init(); for (int i = 0; i < loopBound; ++i) { for (int j = 0; j < i * i; ++j) { RandomGraph.Graph(g, i, j, rnd, true); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(g); bfs.InitializeVertex += new VertexHandler(this.InitializeVertex); bfs.DiscoverVertex += new VertexHandler(this.DiscoverVertex); bfs.ExamineEdge += new EdgeHandler(this.ExamineEdge); bfs.ExamineVertex += new VertexHandler(this.ExamineVertex); bfs.TreeEdge += new EdgeHandler(this.TreeEdge); bfs.NonTreeEdge += new EdgeHandler(this.NonTreeEdge); bfs.GrayTarget += new EdgeHandler(this.GrayTarget); bfs.BlackTarget += new EdgeHandler(this.BlackTarget); bfs.FinishVertex += new VertexHandler(this.FinishVertex); Parents.Clear(); Distances.Clear(); m_CurrentDistance = 0; m_SourceVertex = RandomGraph.Vertex(g, rnd); var choose = PexChoose.FromCall(this); if (choose.ChooseValue <bool>("to add a self ede")) { IVertex selfEdge = RandomGraph.Vertex(g, rnd); g.AddEdge(selfEdge, selfEdge); } // g.RemoveEdge(RandomGraph.Edge(g, rnd)); foreach (IVertex v in g.Vertices) { Distances[v] = int.MaxValue; Parents[v] = v; } Distances[SourceVertex] = 0; bfs.Compute(SourceVertex); CheckBfs(g, bfs); } } }
public void GraphWithSelfEdgesPUT(AdjacencyGraph g, int loopBound, bool self) { Random rnd; //new Random(); var choose1 = PexChoose.FromCall(this); rnd = choose1.ChooseValue <Random>("Random object"); Init(); for (int i = 0; i < loopBound; ++i) { for (int j = 0; j < i * i; ++j) { RandomGraph.Graph(g, i, j, rnd, true); Init(); DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g); dfs.StartVertex += new VertexHandler(this.StartVertex); dfs.DiscoverVertex += new VertexHandler(this.DiscoverVertex); dfs.ExamineEdge += new EdgeHandler(this.ExamineEdge); dfs.TreeEdge += new EdgeHandler(this.TreeEdge); dfs.BackEdge += new EdgeHandler(this.BackEdge); dfs.ForwardOrCrossEdge += new EdgeHandler(this.FowardOrCrossEdge); dfs.FinishVertex += new VertexHandler(this.FinishVertex); Parents.Clear(); DiscoverTimes.Clear(); FinishTimes.Clear(); m_Time = 0; foreach (IVertex v in g.Vertices) { Parents[v] = v; } var choose = PexChoose.FromCall(this); if (choose.ChooseValue <bool>("to add a self ede")) { IVertex selfEdge = RandomGraph.Vertex(g, rnd); g.AddEdge(selfEdge, selfEdge); } // compute dfs.Compute(); CheckDfs(g, dfs); } } }
public void GraphWithSelfEdges() { Random rnd = new Random(); for (int i = 0; i < 10; ++i) { for (int j = 0; j < i * i; ++j) { AdjacencyGraph g = new AdjacencyGraph( new QuickGraph.Providers.VertexProvider(), new QuickGraph.Providers.EdgeProvider(), true); RandomGraph.Graph(g, i, j, rnd, true); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(g); bfs.InitializeVertex += new VertexEventHandler(this.InitializeVertex); bfs.DiscoverVertex += new VertexEventHandler(this.DiscoverVertex); bfs.ExamineEdge += new EdgeEventHandler(this.ExamineEdge); bfs.ExamineVertex += new VertexEventHandler(this.ExamineVertex); bfs.TreeEdge += new EdgeEventHandler(this.TreeEdge); bfs.NonTreeEdge += new EdgeEventHandler(this.NonTreeEdge); bfs.GrayTarget += new EdgeEventHandler(this.GrayTarget); bfs.BlackTarget += new EdgeEventHandler(this.BlackTarget); bfs.FinishVertex += new VertexEventHandler(this.FinishVertex); Parents.Clear(); Distances.Clear(); m_CurrentDistance = 0; m_SourceVertex = RandomGraph.Vertex(g, rnd); foreach (IVertex v in g.Vertices) { Distances[v] = int.MaxValue; Parents[v] = v; } Distances[SourceVertex] = 0; bfs.Compute(SourceVertex); CheckBfs(g, bfs); } } }
static void Main(string[] args) { try { /* * VertexStringDictionary verticesNames = new VertexStringDictionary(); * EdgeStringDictionary edgesNames = new EdgeStringDictionary(); * EdgeDoubleDictionary edgesWeights = new EdgeDoubleDictionary(); * IncidenceGraph g = new IncidenceGraph(true); * * // adding vertex * Vertex u = g.AddVertex(); * verticesNames[u]="u"; * Vertex v = g.AddVertex(); * verticesNames[v]="v"; * Vertex w = g.AddVertex(); * verticesNames[w]="w"; * Vertex x = g.AddVertex(); * verticesNames[x]="x"; * Vertex y = g.AddVertex(); * verticesNames[y]="y"; * Vertex z = g.AddVertex(); * verticesNames[z]="z"; * * // adding edges * Edge uv = g.AddEdge(u,v); * edgesNames[uv]="uv"; * edgesWeights[uv]=1; * Edge ux = g.AddEdge(u,x); * edgesNames[ux]="ux"; * edgesWeights[ux]=0.8; * Edge wu = g.AddEdge(w,u); * g.AddEdge(w,u); * edgesNames[wu]="wu"; * edgesWeights[wu]=0.2; * Edge xv = g.AddEdge(x,v); * edgesNames[xv]="xv"; * edgesWeights[xv]=1.1; * Edge vy = g.AddEdge(v,y); * edgesNames[vy]="vy"; * edgesWeights[vy]=2.0; * Edge wy = g.AddEdge(w,y); * edgesNames[wy]="wy"; * edgesWeights[wy]=1.5; * Edge yw = g.AddEdge(y,w); * edgesNames[yw]="yw"; * edgesWeights[yw]=0.2; * Edge wz = g.AddEdge(w,z); * edgesNames[wz]="wz"; * edgesWeights[wz]=0.1; * * RandomGraph.Graph(g, 20,50,new Random(),true); * * /* * // do a dfs serach * Console.WriteLine("---- DepthFirstSearch"); * DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g); * //TestDepthFirstSearchVisitor dfsVis = * // new TestDepthFirstSearchVisitor(dfs,verticesNames); * AlgorithmTracerVisitor dfstracer = new * AlgorithmTracerVisitor(g,"dfs",".",GraphvizImageType.Png); * dfstracer.VertexLabels = verticesNames; * dfstracer.RegisterVertexHandlers(dfs); * dfstracer.RegisterEdgeHandlers(dfs); * * dfs.Compute(); */ Vertex source = u; source = RandomGraph.Vertex(g, new Random()); Console.WriteLine("source: {0}", source.GetHashCode()); Console.WriteLine("---- BreathFirstSearch"); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(g); TestBreadthFirstSearchVisitor bfsVis = new TestBreadthFirstSearchVisitor(bfs, verticesNames, source); AlgorithmTracerVisitor bfstracer = new AlgorithmTracerVisitor(g, "bfs", ".", GraphvizImageType.Png); // bfstracer.VertexLabels = verticesNames; bfs.RegisterTreeEdgeBuilderHandlers(bfsTracer); bfs.RegisterVertexColorizeHandlers(bfsTracer); bfs.Compute(source); /* * Console.WriteLine("---- Dijkstra"); * DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm( * g, * edgesWeights * ); * TestDijkstraShortestPathVisitor dijVis = new TestDijkstraShortestPathVisitor(dij,verticesNames); * AlgorithmTracerVisitor dijtracer = new * AlgorithmTracerVisitor(g,"dij",".",GraphvizImageType.Png); * dijtracer.VertexLabels = verticesNames; * dijtracer.EdgeLabels = edgesWeights; * dijtracer.RegisterVertexHandlers(dij); * // dijtracer.RegisterEdgeHandlers(dij); * dij.Compute(g.Vertex(0)); * * Console.WriteLine("Distance from {0}", verticesNames[g.Vertex(0)]); * foreach(DictionaryEntry de in dij.Distances) * { * * Console.WriteLine("\t-> {0}, {1}", * verticesNames[(Vertex)de.Key], * de.Value.ToString() * ); * } * * Console.WriteLine("---- Topological sort"); * VertexCollection vs = new VertexCollection(); * TopologicalSortAlgorithm tps= new TopologicalSortAlgorithm(g); * tps.Compute(vs); * foreach(Vertex ve in vs) * { * Console.WriteLine("v - {0}",verticesNames[ve]); * } * * Console.WriteLine("--- graphviz output"); * GraphvizWriterAlgorithm gw = new GraphvizWriterAlgorithm( * g,"dotgenerator",".",GraphvizImageType.Png); * TestGraphvizVertex gv = new TestGraphvizVertex(verticesNames); * gw.WriteVertex += new VertexHandler( gv.WriteVertex ); * gw.WriteEdge+= new EdgeHandler( gv.WriteEdge ); * gw.Write(GraphvizImageType.Png); * gw.Write(GraphvizImageType.Svg); * gw.Write(GraphvizImageType.Svgz); * gw.Write(GraphvizImageType.Gif); * gw.Write(GraphvizImageType.Jpeg); */ Console.WriteLine("Test finished"); String s2 = Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); String s = Console.ReadLine(); } }
// Use this for initialization void Start() { MyGraph = new RandomGraph(maxX, maxY, desiredNodes, TravelCostMin, TravelCostMax); MyGraph.PopulateGraph(); }
private static Graph CreateRandomGraph(int n, double p, SCCDetector[] detectors, int threads) { return(RandomGraph.Generate(n, p, threads)); }
public void emptyTest() { Graph g = RandomGraph.Generate(0, 0, 1); Assert.AreEqual(0, g.GetMap().Count); }
private void GenerateRandomLevel() { List <GameObject> thisLevelNodes = new List <GameObject>(); bool hiddenLevel = Random.value > 0.7f; int iterations = 0; while (thisLevelNodes.Count <= 0) // repetir até haver um nível corretamente mapeado { iterations++; if (iterations > maxIterations) { gerarAlternativo(out thisLevelNodes); break; } RandomGraph rg = new RandomGraph(numPoints, maxDistance, minDistance); var vertices = new List <RandomGraph.Vertex>(rg.PopulateVertices()); var edges = rg.PopulateEdges(forgiveDistance); var hanging = vertices.FindAll(test => test.edges.Count == 1); Debug.Log("Pendurados: " + hanging.Count + " Tentativas " + iterations); if (hanging.Count < 3) // ao menos tres pendurados { continue; } NetworkNode inputNode = null; for (int i = 0; i < 3; i++) { var go = fac.SpawnNetworkNode(i, Random.Range(0, 7) * 15, NetworkNode.NodeState.NS_Visible, getPosition(hanging[i].x, hanging[i].y)); hanging[i].tag = go; thisLevelNodes.Add(go); if (i == 0) { inputNode = go.GetComponent <NetworkNode>(); } } // coloar input firewall e registro foreach (var v in vertices) { if (v.tag != null) { continue; } var go = fac.SpawnNetworkNode(Random.Range(3, 7), Random.Range(0, 6) * 15, hiddenLevel ? NetworkNode.NodeState.NS_Hidden : NetworkNode.NodeState.NS_Visible, getPosition(v.x, v.y)); thisLevelNodes.Add(go); v.tag = go; } // gerar arestas foreach (var e in edges) { fac.CreateConnection((GameObject)e.A.tag, (GameObject)e.B.tag); } foreach (var conn in inputNode.Connetions) { var other = conn.nodes[0].netnode == inputNode ? conn.nodes[1].netnode : conn.nodes[0].netnode; other.State = NetworkNode.NodeState.NS_Active; } } GameManager.listOfNodesAdd(thisLevelNodes.ToArray()); }