metro
Requirements
- Java 8
- json_pp command line tool to pretty print json.
Steps to Run Code
- Create package:
mvn package
Or use packaged jar file inside target directory - First run the spring boot application
java -jar target/metro-0.0.1-SNAPSHOT.jar
This will bring up a server on port 8080 by default. - To find paths run below command
curl -X POST http://localhost:8080/api/v1/train-path/ -H 'cache-control: no-cache' -H 'content-type: application/json' -H 'postman-token: a3ce4473-0292-42a2-e73d-7874c24945ad' -d '{ "sourceStationName": "Boon Lay", "destinationStationName": "Little India", "timeOfTravel": "2019-04-03T06:30", "json": false }' | json_pp
sourceStationName
: Starting StationdestinationStationName
: Station to reach totimeOfTravel
: Time of travel in SGT in formatyyyy-mm-ddThh:mm
- Output shows multiple paths with shortest path (in terms of time) at top.
Explanation
- If parameter
json
istrue
the output is a json output with all the paths in sorted order by time. The json output can be use by some client app to display information to user based on his own criteria. - I have solved it for
Bonus
points as well. So constraints mentioned underBonus
section in question are handled.
Assumptions
- Code finds all the paths and returns 5 most efficient paths.
- If we need to calculated only the shortest path then complexity of algorithm can be improved by using Dijkstras. But I assumed that we need to show multiple routes to user.