public void GraphWithVertexEdgePropertiesTest() { var graph = new AdjacencyListGraph <int, int>(); var v0 = new Vertex(0, 0); var v1 = graph.AddVertex(new Vertex(1, 1)); graph.AddVertex(v0); Assert.AreEqual(default(int), graph.GetVertexProp(v0)); graph.SetVertexProp(v0, 1); Assert.AreEqual(1, graph.GetVertexProp(v0)); Assert.AreEqual(default(int), graph.GetVertexProp(v1)); graph.SetVertexProp(v1, -5); Assert.AreEqual(-5, graph.GetVertexProp(v1)); graph.Clear(); Assert.Throws <GeomException>(() => graph.GetVertexProp(v1)); graph.AddVertex(v0); graph.AddVertex(v1); var e = new Edge(v0, v1); graph.AddEdge(e); Assert.AreEqual(default(int), graph.GetEdgeProp(e)); graph.SetEdgeProp(e, int.MaxValue); Assert.AreEqual(int.MaxValue, graph.GetEdgeProp(e)); graph.Clear(); Assert.Throws <GeomException>(() => graph.GetEdgeProp(e)); }
private void LineAction(string line) { // si la ligne contient des entités CDP on ne la traite pas Regex regex = new Regex("&CDP-[0-9|A-F]+;"); if (regex.IsMatch(line)) { return; } string[] parts = line.Split('\t'); if (parts.Length < 3) { return; } // on supprime la portion 2 l'éventuelle partie entre crochets if (parts[2].IndexOf('[') > 0) { parts[2] = parts[2].Substring(0, parts[2].IndexOf('[')); } IEnumerable <char> components = parts[2].ToCharArray().Where(c => c <'⿰' || c> '⿻'); foreach (char c in components) { if (!parts[1].Equals(c.ToString())) { DGraph.AddVertex(parts[1], c.ToString()); CGraph.AddVertex(c.ToString(), parts[1]); } } }
// Use this for initialization void Start() { Cursor.lockState = CursorLockMode.Locked; cc = GetComponent <CharacterController>(); floorGraph = new AdjacencyListGraph <string, Edge <string> >(); floorGraph.AddVertex("Start"); }
public void DFS_1Vertex_SmallGraphTest() { var graph = new AdjacencyListGraph <int>(); graph.AddVertex(1); foreach (var vertex in graph.DFS(1)) { Assert.AreEqual(1, vertex); } }
public void BFSWithAction_1Vertex_SmallGraphTest() { var graph = new AdjacencyListGraph <int>(); graph.AddVertex(1); foreach (var vertex in graph.BFS(1, v => Assert.AreEqual(1, v))) { Assert.AreEqual(1, vertex); } }
public void IsHamiltonianTest() { Assert.True(TSP.IsHamiltonian(m_graph)); Assert.False(TSP.IsHamiltonian(m_complete4)); // check edge case with <= 1 vertex var smallGraph = new AdjacencyListGraph(); smallGraph.AddVertex(new Vertex()); Assert.IsTrue(TSP.IsHamiltonian(smallGraph)); }
private void OnControllerColliderHit(ControllerColliderHit hit) { GameObject body = hit.gameObject; if (lastHit == body) { return; } lastHit = body; if (body.tag == "Floor" || body.tag == "End") { Floor floor = body.GetComponent <Floor>(); if (floor.active == false) { foreach (GameObject element in floor.adjacents) { if (element != null) { Floor adjacent = element.GetComponent <Floor>(); if (adjacent.active == true) { floorGraph.AddVertex(body.name); floorGraph.AddBidirectionalEdge(new Edge <string>(body.name, element.name)); floor.active = true; Material mat = body.GetComponent <Renderer>().material; if (body.tag == "Floor") { mat.color = new Color(255, 255, 0); } else { mat.color = new Color(0, 255, 0); } break; } } } } } else if (body.tag == "Switch") { body.SendMessage("StartSwitch"); } }
/// <summary> /// 这样插入vertex,只有上面,左边,左上,右上4种vertex可能有边。 /// </summary> /// <param name="vertexIndex"></param> private void AddVertex(int xDimension, int yDimension) { var key = GetVertexIndex(xDimension, yDimension) + 1; var vertex = _graph.CreateVertex(key); _graph.AddVertex(vertex); var count = 0; var upperLeft = GetVertex(xDimension - 1, yDimension - 1); if (upperLeft != null) { count++; _graph.AddEdge(vertex, upperLeft); } var upper = GetVertex(xDimension, yDimension - 1); if (upper != null) { count++; _graph.AddEdge(vertex, upper); } var upperRight = GetVertex(xDimension + 1, yDimension - 1); if (upperRight != null) { count++; _graph.AddEdge(vertex, upperRight); } var left = GetVertex(xDimension - 1, yDimension); if (left != null) { count++; _graph.AddEdge(vertex, left); } Console.WriteLine($"vertex:{key} legeCount:{count}"); }
public void CreateMap() { int tileID = 0; foreach (int x in Enumerable.Range(0, mapSize)) { foreach (int y in Enumerable.Range(0, mapSize)) { GameObject tile = (GameObject)Instantiate(mapTileSprite, new Vector3(x, y, 0f), Quaternion.identity); var vertex = new Vertex(tile, tileID); mapTiles[x, y] = vertex; mapGraph.AddVertex(vertex); tileID++; } } foreach (int x in Enumerable.Range(0, mapSize)) { foreach (int y in Enumerable.Range(0, mapSize)) { if (x > 0) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x - 1, y])); } if (y > 0) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x, y - 1])); } if (x < mapSize - 1) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x + 1, y])); } if (y < mapSize - 1) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x, y + 1])); } } } }
public BreathFirstSearchTest() { _graph = new AdjacencyListGraph <int>(); _graph.AddVertex(0); _graph.AddVertex(1); _graph.AddVertex(2); _graph.AddVertex(3); _graph.AddVertex(4); _graph.AddVertex(5); _graph.AddVertex(6); _graph.AddVertex(7); _graph.AddVertex(8); _graph.AddVertex(9); _graph.AddVertex(10); _graph.AddVertex(11); _graph.AddVertex(12); _graph.AddEdge(0, 1); _graph.AddEdge(0, 2); _graph.AddEdge(0, 5); _graph.AddEdge(0, 6); _graph.AddEdge(3, 4); _graph.AddEdge(3, 5); _graph.AddEdge(4, 5); _graph.AddEdge(4, 6); _graph.AddEdge(7, 8); _graph.AddEdge(9, 10); _graph.AddEdge(9, 11); _graph.AddEdge(9, 12); _graph.AddEdge(11, 12); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); }
public void SetUp() { _graph = new AdjacencyListGraph <int>(); _graph.AddVertex(0); _graph.AddVertex(1); _graph.AddVertex(2); _graph.AddVertex(3); _graph.AddVertex(4); _graph.AddVertex(5); _graph.AddVertex(6); _graph.AddVertex(7); _graph.AddVertex(8); _graph.AddVertex(9); _graph.AddVertex(10); _graph.AddVertex(11); _graph.AddVertex(12); _graph.AddEdge(0, 1); _graph.AddEdge(0, 2); _graph.AddEdge(0, 5); _graph.AddEdge(0, 6); _graph.AddEdge(3, 4); _graph.AddEdge(3, 5); _graph.AddEdge(4, 5); _graph.AddEdge(4, 6); _graph.AddEdge(7, 8); _graph.AddEdge(9, 10); _graph.AddEdge(9, 11); _graph.AddEdge(9, 12); _graph.AddEdge(11, 12); }