Created
June 8, 2014 21:30
-
-
Save mattdeboard/22d8f9acc06a73f4a96a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| match (c1:City {name: "New York"}), | |
| (c2:City {name: "Seattle"}), | |
| p = allShortestPaths((c2)-[*]-(c1)) | |
| return distinct reduce(routeDesc = "", n in nodes(p) | | |
| routeDesc + n.name + " -> ") as routeDesc, | |
| reduce(totalCost = 0, r in relationships(p) | | |
| totalCost + r.cost) as routeCost; | |
| /* | |
| +---------------------------------------------------------------------------------------------+ | |
| | routeDesc | routeCost | | |
| +---------------------------------------------------------------------------------------------+ | |
| | "Seattle -> Helena -> Duluth -> Toronto -> Montreal -> New York -> " | 24 | | |
| | "Seattle -> Helena -> Winnipeg -> Sault St. Marie -> Montreal -> New York -> " | 24 | | |
| | "Seattle -> Calgary -> Winnipeg -> Sault St. Marie -> Montreal -> New York -> " | 24 | | |
| | "Seattle -> Helena -> Duluth -> Sault St. Marie -> Montreal -> New York -> " | 23 | | |
| | "Seattle -> Helena -> Omaha -> Chicago -> Pittsburgh -> New York -> " | 20 | | |
| | "Seattle -> Helena -> Duluth -> Chicago -> Pittsburgh -> New York -> " | 20 | | |
| +---------------------------------------------------------------------------------------------+ | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment