Cell shortest path algorithm written in java