private void ThenToStringContainsStartPositionString() { string vertexString = _vertex.ToString(); string expected = _startPosition.ToString(); Assert.True(vertexString.Contains(expected)); }
public void HighlightCycles_OnClick(Vertex vertex) { if (vertex is Vertex) { ///Highlight cycles MainWindow.RemoveCustomHighlights(); int v = Convert.ToInt32(vertex.ToString()); int count = 0; foreach (var cycle in MainWindow.GraphFromLibrary.minimumCycleBasis) { foreach (var edgeRef in cycle.Select((value, idx) => new { value, idx })) { var edge = MainWindow.GraphFromLibrary.EdgesReference[edgeRef.idx]; if ((edgeRef.value == 1) && (edge.Item1 == v || edge.Item2 == v)) { int[] data = cycle; Color color = MainWindow.GetSequentialColor(count++, false, 0); MainWindow.HighlightPath(ref data, 0, 1, 1, true, false, color); break; } } } /// Highlight selected vertex //Color vcolor = (Color)Application.Current.Resources["VertexHighlighted"]; Color vcolor = Colors.Black; MainWindow.HighlightVertex(vertex.ToString(), false, vcolor); } }
public void doIDS(Vertex <char> start, Vertex <char> goal, int numOfNodes) { openList = new Stack <Vertex <char> >(); closedList = ""; // loops through until a goal node is found for (int _depth = 1; _depth < numOfNodes; _depth++) { Clear(); bool found = DLS(start, goal, _depth); if (found) { sb.Append(goal.ToString() + " was found."); AISearchLog.Text = sb.ToString(); break; } } // this will never be reached as it // loops forever until goal is found if (!Found) { sb.Append(goal.ToString() + "was not found."); AISearchLog.Text = sb.ToString(); } }
public override string ToString() { if (vertex.IsDisposed) { return("Disposed " + vertex.ToString()); } return(vertex.ToString()); }
private void PrintNodeValue(Vertex node) { _sb.AppendLine((node == null) ? "<null>" : (_original.Key == node.Key) ? "[o]" + node.ToString() : node.ToString() ); }
private string GetPath(Vertex start, Vertex endVertex) { var path = endVertex.ToString(); while (start != endVertex) { endVertex = GetVertexInfo(endVertex).PreviousVertex; path = endVertex.ToString() + path; } return(path); }
/// <summary> /// Führt eine Tiefensuche in dem Graphen durch.s /// </summary> /// <typeparam name="T">Der Datentyp der Werte in den Vertices.</typeparam> /// <param name="graph">Der Graph, der durchsucht werden soll.</param> /// <param name="start">Der Start-Vertex, von dem aus gesucht werden soll.</param> /// <param name="goal">Der gesuchte Vertex.</param> /// <returns>True, wenn die Suche erfolgreich war, false sonst.</returns> public static bool DepthFirstSearch <T>(this Graph <T> graph, Vertex <T> start, Vertex <T> goal, out List <Edge <T> > path) { Stack <Vertex <T> > stack = new Stack <Vertex <T> >(); graph.ResetVisitedProperty(); start = graph.GetVertex(start); if (!graph.HasVertex(start)) { throw new ArgumentException($"Der Graph enthält den StartKnoten({start}) nicht."); } if (!graph.HasVertex(goal)) { throw new ArgumentException($"Der Graph enthält den Zielknoten({goal}) nicht."); } bool sucess = SearchHelper <T>(graph, ref stack, start, goal); // Die Liste mit Kanten auf dem Pfad initialisieren. path = new List <Edge <T> >(); if (sucess) { Vertex <T> previous = stack.Pop(); string output = previous.ToString(); while (stack.Count > 0) { Vertex <T> actual = stack.Pop(); if (graph.HasEdge(actual, previous) && actual.IsVisited) { // Die Kante dem Pfad hinzufügen. path.Add(graph.GetEdge(actual, previous)); previous = actual; output = previous.ToString() + " -> " + output; } } // Die Liste mit Kanten auf dem Pfad wird in falscher Reihenfolge befüllt, hier die richtige Reihenfolge herstellen. path.Reverse(); // Console.WriteLine("DepthFirstSearch was successful!: "); // Console.WriteLine(output); } else { // Console.WriteLine("DepthFirstSearch wasn't successful!"); } return(sucess); }
public string GetTriangleLabels(Vertex vertex) { using (new OperationContextScope(InnerChannel)) { return(TryCatchEndpointException(() => Channel.GetTriangleLabels(vertex.ToString()))); } }
void Start() { pq = new Heap(); pq.BuildMinHeap(); GameObject[] t = GameObject.FindGameObjectsWithTag("Waypoint"); Vertexes = new ArrayList(); int j = 0; foreach (var g in t) { Vertex tmp = new Vertex(); tmp.position = g.transform.position; tmp.val = Vector2.SqrMagnitude(tmp.position - (Vector2)transform.position); pq.Insert(tmp); Debug.Log(tmp.ToString()); j++; } Vertex tmp1 = new Vertex(); tmp1.position = transform.position; tmp1.val = 0; pq.Insert(tmp1); Debug.Log("Output"); for (int i = 0; i <= j; i++) { Debug.Log(pq.ExtractMin().val); } }
public void ShouldReturnCommonStringRepresentationForToString() { var vertex = new Vertex(12345); var vertexString = vertex.ToString(); Assert.Equal("v[12345]", vertexString); }
public void ToStringTest() { Vertex testVertex = new Vertex("Address0", 0, 0); var expected = "Address0 X:0 Y:0"; var actual = testVertex.ToString(); Assert.AreEqual(expected, actual); }
private void colorNodeInUI(Vertex <char> node, int step) { Thread thread = new Thread(delegate() { Thread.CurrentThread.IsBackground = true; Thread.Sleep(1000); graph2.FindNode(node.ToString()).LabelText = node.ToString() + ": Step " + step; //step++; graph2.FindNode(node.ToString()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; //highlight a visited node, so it's different from other children viewer2.Graph = graph2; }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } }
public void VertexWithTwoNeighboursToStringTest() { var v1 = new Vertex(1); var v2 = new Vertex(2); var v3 = new Vertex(3); v1.AddDoublyLinkedNeighbour(v2); v1.AddDoublyLinkedNeighbour(v3); Assert.AreEqual("1 : 2, 3", v1.ToString()); Assert.AreEqual("2 : 1", v2.ToString()); Assert.AreEqual("3 : 1", v3.ToString()); }
public void ToString_TestValue1_TestValue1() { //Arrange var sut = new Vertex <string>(TestValue1); //Act var result = sut.ToString(); //Assert Assert.Equal(TestValue1, result); }
public void HighlightCliques_OnClick(Vertex vertex) { if (vertex is Vertex) { ///Highlight ciques MainWindow.RemoveCustomHighlights(); int count = 0; foreach (var clique in MainWindow.GraphFromLibrary.maximalCliqueSet) { if (clique.ToList().Contains(Convert.ToInt32(vertex.ToString()))) { int[] data = clique; Color color = MainWindow.GetSequentialColor(count++, false, 0); MainWindow.HighlightPath(ref data, 2, 1, 1, true, false, color); } } /// Highlight selected vertex //Color vcolor = (Color)Application.Current.Resources["VertexHighlighted"]; Color vcolor = Colors.Black; MainWindow.HighlightVertex(vertex.ToString(), false, vcolor); } }
private string GetPath(Vertex startVertex, Vertex endVertex) { var path = endVertex.ToString(); PathWeight = GetVertexInfo(endVertex).EdgeWeightSum; while (startVertex != endVertex) { if (endVertex == null) { path = "Маршрут не найден"; break; } endVertex = GetVertexInfo(endVertex).PreviousVertex; path = $"{endVertex}-{path}"; } return($"{path} | {PathWeight}"); }
public void ShowEdge(EdgeLine edge) { #if DEBUG HasDebugMark = false; //reset for this //--------------- if (_testEdgeCount == _addDebugMarkOnEdgeNo) { HasDebugMark = true; } _testEdgeCount++; if (!_clearInfoView) { return; } Vertex pnt_P = edge.P; Vertex pnt_Q = edge.Q; //------------------------------- NodeInfo nodeInfo = new NodeInfo(NodeInfoKind.TessEdge, edge, _edgeLines.Count); TreeNode nodeEdge = new TreeNode(); nodeEdge.Tag = nodeInfo; nodeEdge.Text = "e id=" + edge.dbugId + ",count=" + _testEdgeCount + " : " + pnt_P.ToString() + "=>" + pnt_Q.ToString(); if (edge.dbugNoPerpendicularBone) { nodeEdge.Text += "_X_ (no perpendicular_bone)"; } _tessEdgesNode.Nodes.Add(nodeEdge); //------------------------------- _edgeLines.Add(edge); #endif }
public static void bfsUsingQueue(Vertex node) { Queue <Vertex> queue = new Queue <Vertex>(); queue.Enqueue(node); node.Visited = true; while (queue.Count != 0) { Vertex element = queue.Dequeue(); Console.WriteLine(element.ToString() + " "); List <Vertex> neighbours = element.adj; for (int i = 0; i < neighbours.Count; i++) { Vertex n = neighbours[i]; if (n != null && !n.Visited) { queue.Enqueue(n); n.Visited = true; } } } }
//public static void dfs_recursive(Vertex node) //{ // Console.WriteLine(node.ToString()); // var neighbours = node.adj; // node.Visited = true; // for (int i = 0; i < neighbours.Count; i++) // { // Vertex n = neighbours[i]; // if (n != null && !n.Visited) // { // dfs_recursive(n); // } // } //} /// <summary> /// Time Complexity: O(V+E) where V is number of vertices in the graph and E is number of edges in the graph. /// </summary> /// <param name="node"></param> public static void dfsUsingStack(Vertex node) { Stack <Vertex> stack = new Stack <Vertex>(); stack.Push(node); node.Visited = true; while (stack.Count != 0) { Vertex element = stack.Pop(); Console.WriteLine(element.ToString() + " "); List <Vertex> neighbours = element.adj; for (int i = 0; i < neighbours.Count; i++) { Vertex n = neighbours[i]; if (n != null && !n.Visited) { stack.Push(n); n.Visited = true; } } } }
public void ToStringShouldReturnExpandedFormAsAppropriate() { var vertex = new Vertex(2, 3, 4); Assert.Equal("2(x - 3)² + 4", vertex.ToString()); }
public void ToStringShouldReturnStandardOnSimpleSquare() { var vertex = new Vertex(1, 0, 0); Assert.Equal("x²", vertex.ToString()); }
public override string ToString() { String str = source.ToString() + " " + target.ToString(); return(str); }
private void btnInitVertices_Click(object sender, EventArgs e) { vertices = new List<Vertex>(); edges = new List<Edge>(); tbVertices.Clear(); tbEdges.Clear(); for(int i = 1; i <= numVerticesSum.Value; i++) { Vertex newVertex = new Vertex(i, 0); vertices.Add(newVertex); tbVertices.AppendText(newVertex.ToString() + "\r\n"); } btnAddEge.Enabled = true; btnCreateGraph.Enabled = true; tbRegularExpression.Enabled = true; numInitVertex.Enabled = true; numFinalVertex.Enabled = true; numStartGraphVertex.Enabled = true; numFinishGraphVertex.Enabled = true; numInitVertex.Maximum = numVerticesSum.Value; numFinalVertex.Maximum = numVerticesSum.Value; numStartGraphVertex.Maximum = numVerticesSum.Value; numFinishGraphVertex.Maximum = numVerticesSum.Value; numStartGraphVertex.Value = 1; numFinishGraphVertex.Value = numVerticesSum.Value; }
public void doDFS(Vertex <char> startNode, Vertex <char> goalNode) { bool found = false; openStackList = new Stack <Vertex <char> >(); closedStackList = ""; openStackList.Push(startNode); //initialize int step = 1; //algorithm step StringBuilder sb = new StringBuilder(); while (openStackList.Count > 0 && !found) //open is not empty { sb.Append("\n\nOpen:"); AISearchLog.Text = sb.ToString(); foreach (Vertex <char> n in openStackList) { sb.Append(" " + n.Data.ToString()); //print out open set(stack) AISearchLog.Text = sb.ToString(); } Vertex <char> node = openStackList.Pop(); //pop node, to push children of node colorNodeInUI(node, step); step++; closedStackList = closedStackList + " " + node.Data.ToString(); //if N is goal node if (node.Data.ToString() == goalNode.Data.ToString()) { //use multithreading to update the GUI (for the visualization effect. //change the shape of the goal node to a diamond #region Maniplate UI Thread for animation effect Thread thread2 = new Thread(delegate() { Thread.CurrentThread.IsBackground = true; Thread.Sleep(1000); graph2.FindNode(node.ToString()).Attr.Shape = Shape.Diamond; //change goal node's shape, so it's different from other nodes viewer2.Graph = graph2; }); thread2.Start(); while (thread2.IsAlive) { Application.DoEvents(); } #endregion Debug.Write("Success"); sb.Append("\nNode " + goalNode.Data.ToString() + " found!"); AISearchLog.Text = sb.ToString(); found = true; break; } sb.Append("\n\nOpen:"); AISearchLog.Text = sb.ToString(); foreach (Vertex <char> n in openStackList) { sb.Append(" " + n.Data.ToString()); AISearchLog.Text = sb.ToString(); } sb.Append("\nClosed: " + closedStackList + "\nFound? : " + found + "\nCurrent Node : " + node.Data.ToString()); //print out DFS properties. closed set, state and current node AISearchLog.Text = sb.ToString(); sb.Append("\nNode's Unvisited Children :"); if (node.WeightedNeighbors != null) { foreach (KeyValuePair <Vertex <char>, int> n in node.WeightedNeighbors) { if (!closedStackList.Contains(n.Key.Data.ToString())) { sb.Append(" " + n.Key.Data.ToString()); //print out current node neighbors (that have not been visited) AISearchLog.Text = sb.ToString(); } } } Dictionary <Vertex <char>, int> neighbours = node.WeightedNeighbors; //find neighbors (children) if (neighbours != null) { foreach (KeyValuePair <Vertex <char>, int> neighbour in neighbours) { if (!closedStackList.Contains(neighbour.Key.ToString())) { openStackList.Push(neighbour.Key); //put the children (unvisited) of n into open } } Debug.Write("Failure"); } } sb.Append("\nClosed set: " + closedStackList); AISearchLog.Text = sb.ToString(); }
public void TestToString() { var vertex = new Vertex(12.34f, -98.7f, 54); Assert.Equal("[12.34, -98.7, 54]", vertex.ToString()); }
public override string ToString() { return("start point: " + startPoint.ToString() + System.Environment.NewLine + "second point: " + secondPoint.ToString() + System.Environment.NewLine + "end point: " + endPoint.ToString()); }
/// <summary> /// </summary> /// <returns></returns> public override string ToString() { return(Vertex.ToString()); }
public override string ToString() { string boardString = ""; for (int col = 0; col < this.GetColCount(); col++) { for (int row = 0; row < this.GetRowCount(); row++) { // This' properties Face face = this.GetFace(col, row); Vertex vertexL = this.GetVertex(col, row, VertexSpecifier.L); Vertex vertexR = this.GetVertex(col, row, VertexSpecifier.R); Edge edgeW = this.GetEdge(col, row, EdgeSpecifier.W); Edge edgeN = this.GetEdge(col, row, EdgeSpecifier.N); Edge edgeE = this.GetEdge(col, row, EdgeSpecifier.E); // Face exists? if (face != null) { // Face col, row boardString += "( " + col + "," + row + " ) " + face.ToString(); boardString += "\n"; } // Vertex L exists? if (vertexL != null) { boardString += "( " + col + "," + row + ", L " + " ) " + vertexL.ToString(); boardString += "\n"; } // Vertex R exists? if (vertexR != null) { boardString += "( " + col + "," + row + ", R " + " ) " + vertexR.ToString(); boardString += "\n"; } // Edge W exists? if (edgeW != null) { boardString += "( " + col + "," + row + ", W " + " ) " + edgeW.ToString(); boardString += "\n"; } // Edge N exists? if (edgeN != null) { boardString += "( " + col + "," + row + ", N " + " ) " + edgeN.ToString(); boardString += "\n"; } // Edge E exists? if (edgeE != null) { boardString += "( " + col + "," + row + ", E " + " ) " + edgeE.ToString(); boardString += "\n"; } } } return(boardString); }
public void VertexWithoutNeighboursToStringTest() { var v = new Vertex(1); Assert.AreEqual("1 : ", v.ToString()); }
public bool DLS(Vertex <char> start, Vertex <char> goal, int _maximumDepth) { openList.Push(start); //initialize while (openList.Count > 0 && !Found) //open is not empty and maximum depth hasn't been reached { Vertex <char> node = openList.Pop(); //pop node, to push children of node colorNodeInUI(node, step); step++; closedList = closedList + " " + node.Data.ToString(); if (node.Data.ToString() == goal.Data.ToString()) { //use multithreading to update the GUI (for the visualization effect. //change the shape of the goal node to a diamond #region Maniplate UI Thread for animation effect Thread thread2 = new Thread(delegate() { Thread.CurrentThread.IsBackground = true; Thread.Sleep(1000); graph2.FindNode(node.ToString()).Attr.Shape = Shape.Diamond; //change goal node's shape, so it's different from other nodes viewer2.Graph = graph2; }); thread2.Start(); while (thread2.IsAlive) { Application.DoEvents(); } #endregion Debug.Write("Success"); Found = true; break; } if (depth < _maximumDepth) { Dictionary <Vertex <char>, int> neighbours = node.WeightedNeighbors; //find neighbors (children) if (neighbours != null) { depth++; //increment depth since children are deeper into the tree (graph) foreach (Vertex <char> neighbour in neighbours.Keys) { if (!closedList.Contains(neighbour.ToString())) { openList.Push(neighbour); //put the children (unvisited) of n into open } } Debug.Write("Failure"); } } } sb.Append("\nAt depth: " + _maximumDepth); sb.Append("\nClose List: " + closedList + "\n"); AISearchLog.Text = sb.ToString(); return(Found); }
public void doDLS(Vertex <char> startNode, Vertex <char> goalNode, int maxDepth) { StringBuilder sb = new StringBuilder(); int step = 1; bool found = false; openStackList = new Stack <Vertex <char> >(); closedStackList = ""; openStackList.Push(startNode); //initialize int depth = 0; while (openStackList.Count > 0 && !found && depth < maxDepth) //open is not empty and maximum depth hasn't been reached { Vertex <char> node = openStackList.Pop(); //pop node, to push children of node colorNodeInUI(node, step); step++; closedStackList = closedStackList + " " + node.Data.ToString(); if (node.Data.ToString() == goalNode.Data.ToString()) { //use multithreading to update the GUI (for the visualization effect. //change the shape of the goal node to a diamond #region Maniplate UI Thread for animation effect Thread thread2 = new Thread(delegate() { Thread.CurrentThread.IsBackground = true; Thread.Sleep(1000); graph2.FindNode(node.ToString()).Attr.Shape = Shape.Diamond; //change goal node's shape, so it's different from other nodes viewer2.Graph = graph2; }); thread2.Start(); while (thread2.IsAlive) { Application.DoEvents(); } #endregion Debug.Write("Success"); sb.Append("\nNode " + goalNode.Data.ToString() + " found at level " + depth + "!"); //print that node is found AISearchLog.Text = sb.ToString(); found = true; break; } sb.Append("\nNode " + node.Data.ToString() + " at level " + depth + ", " + goalNode.Data.ToString() + " not yet found at this level"); //print out properties AISearchLog.Text = sb.ToString(); Dictionary <Vertex <char>, int> neighbours = node.WeightedNeighbors; //find neighbors (children) if (neighbours != null) { depth++; //increment depth since children are deeper into the tree (graph) foreach (Vertex <char> neighbour in neighbours.Keys) { if (!closedStackList.Contains(neighbour.ToString())) { openStackList.Push(neighbour); //put the children (unvisited) of n into open } } Debug.Write("Failure"); } } sb.Append("\nClosed set: " + closedStackList); AISearchLog.Text = sb.ToString(); }
private static int _ShortestPathLength(Vertex from, Vertex to, ref ArrayList visitedNodes) { if (from == null || to == null) { return(int.MaxValue); } if (s_diagnostics) { _Debug.WriteLine(String.Format("\t\tProbing outward from {0}, looking for {1}.", from, to)); } if (from == to) { if (s_diagnostics) { _Debug.WriteLine("Probe found {0}! Returning pathlength.", from.ToString()); } return(0); } if (visitedNodes.Contains(from)) { if (s_diagnostics) { _Debug.WriteLine("Located a cycle"); } return(int.MaxValue); } visitedNodes.Add(from); int shortestPathLength = int.MaxValue; if (s_diagnostics) { /***************************************************************************************/ _Debug.WriteLine(String.Format("\t\t{0} has {1} successor edges...", from, from.SuccessorEdges.Count)); _Debug.Write("\t\t"); foreach (Edge edge in from.SuccessorEdges) { _Debug.Write("\t" + edge); } _Debug.WriteLine(""); _Debug.WriteLine(String.Format("\t\t{0} has {1} predecessor edges...", from, from.PredecessorEdges.Count)); _Debug.Write("\t\t"); foreach (Edge edge in from.PredecessorEdges) { _Debug.Write("\t" + edge); } _Debug.WriteLine(""); /****************************************************************************************/ } foreach (Edge edge in from.SuccessorEdges) { int pathLength = _ShortestPathLength(edge.PostVertex, to, ref visitedNodes); if (pathLength < shortestPathLength) { shortestPathLength = pathLength; } } if (shortestPathLength == int.MaxValue) { return(int.MaxValue); } return(shortestPathLength + 1); }
public override string ToString() { return("Node:" + node?.ToString() + " g:" + costSoFar + " rhs:" + rightHandSide + " Key:" + key?.ToString()); }
/// <summary> /// Override of ToString method. /// </summary> /// <returns></returns> public override string ToString() { return(String.Format("EdgeKey: (gEdge={0}, centre={1}, vertex={2})", Edge.ToString(), Centre.ToString(), Vertex.ToString())); }