PyPE solution to PE problem 82

Registered by Scott Armitage

PyPE solution to PE problem 82

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Scott Armitage
Completed by
Scott Armitage

Related branches

Sprints

Whiteboard

    ProjectEuler.net problem 82
    ===========================

    NOTE: This problem is a more challenging version of Problem 81.

    The minimal path sum in the 5 by 5 matrix below, by starting in any cell
    in the left column and finishing in any cell in the right column, and only
    moving up, down, and right, is indicated in red and bold; the sum is equal
    to 994.

        131 673 234 103 18
        201 96 342 965 150
        630 803 746 422 111
        537 699 497 121 956
        805 732 524 37 331

    Find the minimal path sum, in matrix.txt (right click and 'Save Link/Target
    As...'), a 31K text file containing a 80 by 80 matrix, from the left column
    to the right column.

    Solution
    --------

    While the grid represents a similar triangle as problem 81, the additional
    possible move (i.e. "UP") greatly increases the number of possible paths
    from the starting node to the ending node. Furthermore, there are multiple
    starting and ending nodes that we must compare against in order to select
    the minimum path from left-hand column to right-hand column.

    Instead of a simple depth-first recursive search, as was employed for
    problem 81, an A* path-finding algorithm has been implemented in
    PyPE.algorithms.astar. This algorithm holds a list of "frontier-nodes" in
    the grid, i.e. those that it is preparing to check next, and estimates the
    cost of getting from each of the frontier nodes to the goal. It then chooses
    the node with the minimum estimated cost and then evaluates the actual cost
    in getting /to/ that node. It then addes all of the neighbouring nodes to
    the set of frontier nodes. This could be considered a "best-first, breadth-
    first" algorithm.

    The A* path-finding algorithm relies on a single starting and ending node.
    To handle multiple starting nodes, we simply add a new node to the grid at
    position (-1,-1) which is connected with a cost of 0 to all of the possible
    starting nodes. Therefore, the actual starting node that the algorithm
    selects will be the first visited node in the returned path. A similar
    solution is employed for multiple goal nodes, positioned at (m,n) (outside
    of the regular grid).

    Answer
    ------

    260324

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.