private static List <Node> DisplayBreadthFirstTraversal(GraphOperations graphOperations) { var path = graphOperations.BreadthFirstTraversal(); PrintPath(path); return(path); }
public void IsomorphismTest() { var graph1 = new UndirectedGraph(); var vertexA = new Vertex("A"); var vertexB = new Vertex("B"); var vertexC = new Vertex("C"); var vertexD = new Vertex("D"); var graph2 = new UndirectedGraph(); var vertex1 = new Vertex("1"); var vertex2 = new Vertex("2"); var vertex3 = new Vertex("3"); var vertex4 = new Vertex("4"); graph1.AddEdge(new UndirectedEdge(vertexB, vertexC)); graph2.AddEdge(new UndirectedEdge(vertex1, vertex3)); graph1.AddEdge(new UndirectedEdge(vertexC, vertexD)); graph2.AddEdge(new UndirectedEdge(vertex3, vertex4)); graph2.AddVertex(vertex1); graph2.AddVertex(vertex2); graph2.AddVertex(vertex3); graph2.AddVertex(vertex4); graph1.AddVertex(vertexA); graph1.AddVertex(vertexB); graph1.AddVertex(vertexC); graph1.AddVertex(vertexD); Assert.IsTrue(GraphOperations.CheckIsomorphism(graph1, graph2)); }
static int Execute(int maxLogsPerGraph, bool writeGraphviz, List <string> excludeVariants) { if (!Helper.TryFindRoot(out var rootDir)) { return(1); } if (maxLogsPerGraph == int.MaxValue) { Console.WriteLine($"The first {maxLogsPerGraph} restore logs will be used per request graph."); } else { Console.WriteLine($"No limit will be applied to the number of restore logs per request graph."); } var logDir = Path.Combine(rootDir, "out", "logs"); var graphs = RestoreLogParser.ParseAndMergeGraphs(logDir, excludeVariants.ToHashSet(), maxLogsPerGraph); var writtenNames = new HashSet <string>(); for (int index = 0; index < graphs.Count; index++) { var graph = graphs[index]; string fileName = Helper.GetGraphFileName(RequestGraph.Type, graph.VariantName, graph.SolutionName); if (writtenNames.Contains(fileName)) { Console.WriteLine($" WARNING: The output file {fileName} has already been written."); Console.WriteLine($" Consider including a variant name in the restore log file name to differentiate variants."); Console.WriteLine($" Output data is grouped by variant name, solution name, and set of package sources."); } Console.WriteLine($"Preparing {fileName}..."); GraphOperations.LazyTransitiveReduction(graph.Graph); var filePath = Path.Combine(rootDir, "out", "graphs", fileName); var outDir = Path.GetDirectoryName(filePath); Directory.CreateDirectory(outDir); if (writeGraphviz) { var gvPath = $"{filePath}.gv"; Console.WriteLine($" Writing {gvPath}..."); RequestGraphSerializer.WriteToGraphvizFile(gvPath, graph.Graph); } var jsonGzPath = $"{filePath}.json.gz"; Console.WriteLine($" Writing {jsonGzPath}..."); RequestGraphSerializer.WriteToFile(jsonGzPath, graph.Graph); writtenNames.Add(fileName); } return(0); }
void RelayoutDiagramItem(object sender, RoutedEventArgs e) { diagramControl.RelayoutDiagramItems(layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl))); diagramControl.Controller.RegisterRoutingStrategy(layout.GetDiagramConnectorType(), layout.GetDiagramRoutingStrategy()); diagramControl.Items.OfType <IDiagramConnector>().ForEach(connector => { connector.Type = layout.GetDiagramConnectorType(); connector.UpdateRoute(); }); diagramControl.FitToDrawing(); }
private static void SetupGraph(out GraphOperations graphOperations, out Node nodeA, out Node nodeH, out Node nodeX, out Node nodeY, out Node nodeZ) { graphOperations = new GraphOperations(); nodeA = new Node('A'); var nodeB = new Node('B'); var nodeC = new Node('C'); var nodeD = new Node('D'); var nodeE = new Node('E'); var nodeF = new Node('F'); var nodeG = new Node('G'); nodeH = new Node('H'); nodeX = new Node('X'); nodeY = new Node('Y'); nodeZ = new Node('Z'); /// Following Demonstrate A Bi-Directional Graph nodeA.AdjacentNodes.Enqueue(nodeG); nodeA.AdjacentNodes.Enqueue(nodeD); nodeA.AdjacentNodes.Enqueue(nodeB); nodeB.AdjacentNodes.Enqueue(nodeF); nodeB.AdjacentNodes.Enqueue(nodeE); nodeB.AdjacentNodes.Enqueue(nodeA); nodeC.AdjacentNodes.Enqueue(nodeH); nodeC.AdjacentNodes.Enqueue(nodeF); nodeD.AdjacentNodes.Enqueue(nodeF); nodeD.AdjacentNodes.Enqueue(nodeA); nodeE.AdjacentNodes.Enqueue(nodeG); nodeE.AdjacentNodes.Enqueue(nodeB); nodeF.AdjacentNodes.Enqueue(nodeD); nodeF.AdjacentNodes.Enqueue(nodeC); nodeF.AdjacentNodes.Enqueue(nodeB); nodeG.AdjacentNodes.Enqueue(nodeE); nodeG.AdjacentNodes.Enqueue(nodeA); nodeH.AdjacentNodes.Enqueue(nodeC); /// Following Demonstrate A Unidirectional Graph X -> Y -> Z nodeX.AdjacentNodes.Enqueue(nodeY); //nodeY.AdjacentNodes.Add(nodeX); nodeY.AdjacentNodes.Enqueue(nodeZ); //nodeZ.AdjacentNodes.Add(nodeY); }
static void Main(string[] args) { Graph g = new Graph(); Vertex a = new Vertex("A"); g.insertVertex(new Vertex("A")); Vertex b = new Vertex("B"); g.insertVertex(b); Vertex c = new Vertex("c"); g.insertVertex(c); Vertex d = new Vertex("D"); g.insertVertex(d); Vertex e = new Vertex("E"); g.insertVertex(e); g.insertEdge(a, b, 10); g.insertEdge(a, c, 3); g.insertEdge(b, c, 4); g.insertEdge(b, d, 2); g.insertEdge(c, e, 2); g.insertEdge(c, d, 8); g.insertEdge(d, e, 9); //GraphOperations.BFStraversal(g, a); Console.WriteLine("\t****************************************************\n"); GraphOperations.printShortestPath(g, a, d); Console.WriteLine("\n\t****************************************************\n"); /* * string m = "success"; * if (g.areAdjacent(b, e)) m = "fail"; * Console.WriteLine(m); */ }
public ActionResult UserProfile() { #if DEBUG ClaimsPrincipal.Current.DebugPrintAllClaims(); #endif string aadObjectIdOfUser = ClaimsPrincipal.Current.GetObjectId(); var graphOps = new GraphOperations(); graphOps.Initialize(); var user = graphOps.GetUser(aadObjectIdOfUser); var profile = new UserProfile() { DisplayName = user.DisplayName, GivenName = user.GivenName, Surname = user.Surname }; return(View(profile)); }
protected virtual IEnumerator Navigate(Vector3 destination) { Node srcNode = Navigation.Instance.NearestTo(transform.position); Node dstNode = Navigation.Instance.NearestTo(destination); _gizmoRealTarget = dstNode; Node reachedDst = srcNode; if (srcNode != dstNode) { rotateInPath = true; var path = GraphOperations.AStar(srcNode, dstNode).ToList(); if (path != null) { foreach (var next in path.Select(w => FloorPos(w.Content))) { RotateInPath(next); while ((next - FloorPos(this)).sqrMagnitude >= 0.05f) { _vel = (next - FloorPos(this)).normalized; yield return(null); } } } reachedDst = path.Last().Content; } if (reachedDst == dstNode) { rotateInPath = false; _vel = (FloorPos(destination) - FloorPos(this)).normalized; yield return(new WaitUntil(() => (FloorPos(destination) - FloorPos(this)).sqrMagnitude < 0.05f)); } _vel = Vector3.zero; OnReachDestination(reachedDst, reachedDst == dstNode); }
static void CreateDefaultMarkersFor(GraphEditor graphEditor, Type builderType) { // Remove unused nodes // Grab the names of all the markers nodes in the graph var markerNames = new List <string>(); foreach (var node in graphEditor.Graph.Nodes) { if (node is MarkerNode) { var markerNode = node as MarkerNode; markerNames.Add(markerNode.Caption); } } var unusedMarkers = new List <string>(markerNames.ToArray()); // Remove markers from the unused list that have child nodes attached to it foreach (var node in graphEditor.Graph.Nodes) { if (node is VisualNode) { var visualNode = node as VisualNode; foreach (var parentNode in visualNode.GetParentNodes()) { if (parentNode is MarkerNode) { var markerNode = parentNode as MarkerNode; unusedMarkers.Remove(markerNode.Caption); } } } } // Remove markers from the unused list that are referenced by other marker emitters foreach (var node in graphEditor.Graph.Nodes) { if (node is MarkerEmitterNode) { var emitterNode = node as MarkerEmitterNode; string markerName = emitterNode.Caption; // this marker is referenced by an emitter. Remove it from the unused list unusedMarkers.Remove(markerName); } } // Remove markers from the unused list that are required by the new builder type var defaultMarkerRepository = new DungeonBuilderDefaultMarkers(); var builderMarkers = defaultMarkerRepository.GetDefaultMarkers(builderType); foreach (var builderMarker in builderMarkers) { unusedMarkers.Remove(builderMarker); } // Remove all the unused markers var markerNodesToDelete = new List <MarkerNode>(); foreach (var node in graphEditor.Graph.Nodes) { if (node is MarkerNode) { var markerNode = node as MarkerNode; if (unusedMarkers.Contains(markerNode.Caption)) { markerNodesToDelete.Add(markerNode); } } } graphEditor.DeleteNodes(markerNodesToDelete.ToArray()); // Grab the names of all the markers nodes in the graph markerNames.Clear(); foreach (var node in graphEditor.Graph.Nodes) { if (node is MarkerNode) { var markerNode = node as MarkerNode; markerNames.Add(markerNode.Caption); } } var markersToCreate = new List <string>(); foreach (var builderMarker in builderMarkers) { if (!markerNames.Contains(builderMarker)) { markersToCreate.Add(builderMarker); } } var existingBounds = new List <Rect>(); foreach (var node in graphEditor.Graph.Nodes) { existingBounds.Add(node.Bounds); } // Add the new nodes const int INTER_NODE_X = 200; const int INTER_NODE_Y = 300; int itemsPerRow = 5; int positionIndex = 0; int ix, iy, x, y; var markerNodeSize = new Vector2(120, 50); for (int i = 0; i < markersToCreate.Count; i++) { bool overlaps; int numOverlapTries = 0; int MAX_OVERLAP_TRIES = 100; do { ix = positionIndex % itemsPerRow; iy = positionIndex / itemsPerRow; x = ix * INTER_NODE_X; y = iy * INTER_NODE_Y; positionIndex++; overlaps = false; var newNodeBounds = new Rect(x, y, markerNodeSize.x, markerNodeSize.y); foreach (var existingBound in existingBounds) { if (newNodeBounds.Overlaps(existingBound)) { overlaps = true; break; } } numOverlapTries++; } while (overlaps && numOverlapTries < MAX_OVERLAP_TRIES); var newNode = GraphOperations.CreateNode <MarkerNode>(graphEditor.Graph); DungeonEditorHelper.AddToAsset(graphEditor.Graph, newNode); newNode.Position = new Vector2(x, y); newNode.Caption = markersToCreate[i]; } }
public void RegularIsomorphismTest() { // Graph1 var graph1 = new UndirectedGraph(); var vertexA = new Vertex("A"); var vertexB = new Vertex("B"); var vertexC = new Vertex("C"); var vertexD = new Vertex("D"); var vertexG = new Vertex("G"); var vertexH = new Vertex("H"); var vertexI = new Vertex("I"); var vertexJ = new Vertex("J"); graph1.AddEdge(new UndirectedEdge(vertexA, vertexG)); graph1.AddEdge(new UndirectedEdge(vertexA, vertexH)); graph1.AddEdge(new UndirectedEdge(vertexA, vertexI)); graph1.AddEdge(new UndirectedEdge(vertexG, vertexB)); graph1.AddEdge(new UndirectedEdge(vertexG, vertexC)); graph1.AddEdge(new UndirectedEdge(vertexB, vertexH)); graph1.AddEdge(new UndirectedEdge(vertexB, vertexJ)); graph1.AddEdge(new UndirectedEdge(vertexH, vertexD)); graph1.AddEdge(new UndirectedEdge(vertexC, vertexI)); graph1.AddEdge(new UndirectedEdge(vertexC, vertexJ)); graph1.AddEdge(new UndirectedEdge(vertexD, vertexI)); graph1.AddEdge(new UndirectedEdge(vertexD, vertexJ)); graph1.AddVertex(vertexA); graph1.AddVertex(vertexB); graph1.AddVertex(vertexC); graph1.AddVertex(vertexD); graph1.AddVertex(vertexG); graph1.AddVertex(vertexH); graph1.AddVertex(vertexI); graph1.AddVertex(vertexJ); // Graph2 var graph2 = new UndirectedGraph(); var vertex1 = new Vertex("1"); var vertex2 = new Vertex("2"); var vertex3 = new Vertex("3"); var vertex4 = new Vertex("4"); var vertex5 = new Vertex("5"); var vertex6 = new Vertex("6"); var vertex7 = new Vertex("7"); var vertex8 = new Vertex("8"); graph2.AddEdge(new UndirectedEdge(vertex1, vertex2)); graph2.AddEdge(new UndirectedEdge(vertex1, vertex5)); graph2.AddEdge(new UndirectedEdge(vertex1, vertex4)); graph2.AddEdge(new UndirectedEdge(vertex4, vertex3)); graph2.AddEdge(new UndirectedEdge(vertex4, vertex8)); graph2.AddEdge(new UndirectedEdge(vertex3, vertex7)); graph2.AddEdge(new UndirectedEdge(vertex3, vertex2)); graph2.AddEdge(new UndirectedEdge(vertex2, vertex6)); graph2.AddEdge(new UndirectedEdge(vertex5, vertex6)); graph2.AddEdge(new UndirectedEdge(vertex5, vertex8)); graph2.AddEdge(new UndirectedEdge(vertex7, vertex6)); graph2.AddEdge(new UndirectedEdge(vertex7, vertex8)); graph2.AddVertex(vertex1); graph2.AddVertex(vertex2); graph2.AddVertex(vertex3); graph2.AddVertex(vertex4); graph2.AddVertex(vertex5); graph2.AddVertex(vertex6); graph2.AddVertex(vertex7); graph2.AddVertex(vertex8); Assert.IsTrue(GraphOperations.CheckIsomorphism(graph1, graph2)); }
static async Task <int> ExecuteAsync(string path, int iterations, int maxConcurrency, bool noDependencies) { if (!Helper.TryFindRoot(out var rootDir)) { return(1); } if (!path.EndsWith(GraphSerializer.FileExtension, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine($"The serialized graph must have the extension {GraphSerializer.FileExtension}"); return(1); } Console.WriteLine("Parsing the file name..."); if (!Helper.TryParseFileName(path, out var graphType, out var variantName, out var solutionName)) { graphType = null; variantName = null; solutionName = null; } Console.WriteLine($" Graph type: {graphType ?? "(none)"}"); Console.WriteLine($" Variant name: {variantName ?? "(none)"}"); Console.WriteLine($" Solution name: {solutionName ?? "(none)"}"); if (graphType != RequestGraph.Type) { Console.WriteLine($"The input graph type must be {RequestGraph.Type}."); return(1); } Console.WriteLine($"Reading {path}..."); var graph = RequestGraphSerializer.ReadFromFile(path); Console.WriteLine($"There are {graph.Nodes.Count} nodes in the graph."); Console.WriteLine($"There are {graph.Nodes.Sum(x => x.Dependencies.Count)} edges in the graph."); if (noDependencies) { Console.WriteLine("Clearing dependencies..."); foreach (var node in graph.Nodes) { node.Dependencies.Clear(); } } var resultsPath = Path.Combine(rootDir, "out", ResultFileName); Console.WriteLine($"Results will be writen to {resultsPath}."); using (var handler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip }) using (var httpClient = new HttpClient(handler)) { Console.WriteLine("Sorting the requests in topological order..."); var topologicalOrder = GraphOperations.TopologicalSort(graph); topologicalOrder.Reverse(); for (var iteration = 0; iteration <= iterations; iteration++) { await ExecuteIterationAsync( rootDir, resultsPath, variantName, solutionName, httpClient, iterations, maxConcurrency, topologicalOrder, iteration, noDependencies); } } return(0); }
void ApplyLayout(GraphLayout layout) { try { diagramControl.RelayoutDiagramItems(layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl))); diagramControl.Items.OfType <IDiagramConnector>().ForEach(connector => { connector.Type = layout.GetDiagramConnectorType(); connector.UpdateRoute(); }); diagramControl.FitToDrawing(); } catch (Exception e) { DXMessageBox.Show(string.Format("Error message: '{0}'", e.Message), "Error has been occurred"); } }
public void StartFloydWarshall() { GraphOperations.FloydWarshall(GraphManager.g, GraphManager.VertexList[SelectedIndexSource], GraphManager.VertexList[SelectedIndexDest]); SceneManager.LoadScene(GraphManager.ShortestPath[0].SceneNumber); }
public void StartBFS() { GraphOperations.BfsShotestPath(GraphManager.g, GraphManager.VertexList[SelectedIndexDest], GraphManager.VertexList[SelectedIndexSource]); SceneManager.LoadScene(GraphManager.ShortestPath[0].SceneNumber); }
public void StartBellManFord() { GraphOperations.BellmanFord(GraphManager.g, GraphManager.VertexList[SelectedIndexSource], GraphManager.VertexList[SelectedIndexDest]); SceneManager.LoadScene(GraphManager.ShortestPath[0].SceneNumber); }
public void StartDijkstra() { GraphManager.ShortestPath = GraphOperations.printShortestPath(GraphManager.g, GraphManager.VertexList[SelectedIndexSource], GraphManager.VertexList[SelectedIndexDest]); SceneManager.LoadScene(GraphManager.ShortestPath[0].SceneNumber); }