コード例 #1
0
    // Use this for initialization
    void Start()
    {
        Node a = new Node("A");
        Node b = new Node("B");
        Node c = new Node("C");
        Node d = new Node("D");
        Node e = new Node("E");
        Node f = new Node("F");

        a.AddOutgoingEdge(new Edge(a, b, 4));
        a.AddOutgoingEdge(new Edge(a, c, 2));
        a.AddOutgoingEdge(new Edge(a, f, 50));
        b.AddOutgoingEdge(new Edge(b, c, 5));
        b.AddOutgoingEdge(new Edge(b, d, 10));
        c.AddOutgoingEdge(new Edge(c, e, 3));
        e.AddOutgoingEdge(new Edge(e, d, 4));
        d.AddOutgoingEdge(new Edge(d, f, 11));

        var pathfinder = new AstarPathfinder <Node>(Heuristic);
        var timer      = new SystemExecutionTimer();
        var path       = pathfinder.FindPath(a, f);

        print(string.Format("In {1} seconds found the following path with cost {0} from A to F:", path.Cost, timer.ElapsedSeconds));
        print(path.Edges.Aggregate("", (soFar, edge) => soFar + (soFar.Length > 0 ? " -> " : "") + edge.ToString()));
    }