Пример #1
0
    // Use this for initialization
    void Start()
    {
        Graph g = new Graph();

        for (int i = 1; i < 6; i++)
        {
            g.AddNode(i);
        }

        g.AddEdge(1, 2);
        g.AddEdge(1, 3);
        g.AddEdge(2, 4, 7);
        g.AddEdge(4, 5);
        g.AddEdge(3, 5, 5f);


        List <GraphEdge> path;

        GraphSearch.Dijkstra(g, g.GetNode(1), g.GetNode(5), out path);
        float cost = 0;

        foreach (GraphEdge e in path)
        {
            Debug.Log(e.from.index + " - " + e.to.index);
            cost += e.cost;
        }
        Debug.Log("Total Cost: " + cost);
    }
Пример #2
0
 private void MoveDroidToSecurityCheckpoint(Droid droid, ShipGraph shipGraph)
 {
     var(path, _) = GraphSearch.Dijkstra(shipGraph, droid.Room, "== Security Checkpoint ==");
     foreach (var nextRoom in path)
     {
         droid.TakeDoor((Direction)shipGraph.GetDoorDirection(droid.Room, nextRoom));
     }
 }
 public int GetDistance(string from, string to)
 {
     if (!distanceMatrix.TryGetValue(from, out var nextDict))
     {
         distanceMatrix[from] = new Dictionary <string, int>();
     }
     if (!distanceMatrix[from].TryGetValue(to, out var distance))
     {
         var(_, dist)             = GraphSearch.Dijkstra(this, from, to);
         distanceMatrix[from][to] = dist;
         return(dist);
     }
     else
     {
         return(distance);
     }
 }
Пример #4
0
 protected override void SolvePartOne()
 {
     var(path, dist) = GraphSearch.Dijkstra(graph, "AA:OUT", "ZZ:OUT");
     resultPartOne   = dist.ToString();
 }