/// <summary> /// methode die de wereld opzet /// </summary> public World() { WorldManager.AddNodes(); Robot r0 = CreateRobot(0, 0, 0); Robot r1 = CreateRobot(0, 0, 0); Robot r2 = CreateRobot(0, 0, 0); Robot r3 = CreateRobot(0, 0, 0); Vrachtwagen = CreateLorry(0, 0, 0); r0.Move(2, 2, 1); r1.Move(2, 2, 2); r2.Move(2, 2, 3); r3.Move(2, 2, 4); Vrachtwagen.Move(0, 0, -2); foreach (var punt in WorldManager.Points()) { if (punt.Id.Length == 1) { Shelf s = CreateShelf(0, 0, 0); punt.Shelf = s; WorldManager.AddShelf(punt); s.Move(punt.X, 0, punt.Z); punt.ShelfStatus = true; } if (punt.Id.Length == 4) { punt.ShelfStatus = false; } } }
/// <summary> /// Berekent het kortste pad van start tot finish node /// </summary> /// <param name="start">start node</param> /// <param name="finish">finish node</param> /// <returns>list<node></returns> public List <Node> Shortest_path(string start, string finish) { var previous = new Dictionary <string, string>(); var distances = new Dictionary <string, int>(); var nodes = new List <string>(); List <Node> node = null; foreach (var vertex in Vertices) { if (vertex.Key == start) { distances[vertex.Key] = 0; } else { distances[vertex.Key] = int.MaxValue; } nodes.Add(vertex.Key); } while (nodes.Count != 0) { nodes.Sort((x, y) => distances[x] - distances[y]); var smallest = nodes[0]; nodes.Remove(smallest); if (smallest == finish) { node = new List <Node>(); while (previous.ContainsKey(smallest)) { Manager manager = new Manager(); foreach (Node n in manager.Points()) { if (smallest == n.Id) { node.Add(n); } } smallest = previous[smallest]; } break; } if (distances[smallest] == int.MaxValue) { break; } foreach (var neighbor in Vertices[smallest]) { var alt = distances[smallest] + neighbor.Value; if (alt < distances[neighbor.Key]) { distances[neighbor.Key] = alt; previous[neighbor.Key] = smallest; } } } node.Reverse(); return(node); }