{"id":18836336,"url":"https://github.com/obitech/ds_shortest_path","last_synced_at":"2025-06-24T07:07:57.660Z","repository":{"id":144377671,"uuid":"95587784","full_name":"obitech/ds_shortest_path","owner":"obitech","description":"Shortest path in a directed graph with edge weight and acceleration","archived":false,"fork":false,"pushed_at":"2017-06-27T18:51:24.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-22T18:34:51.933Z","etag":null,"topics":["algorithm","java"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/obitech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-06-27T18:18:04.000Z","updated_at":"2017-11-12T15:35:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"50eb4f8b-60be-4052-acab-d57beae05c04","html_url":"https://github.com/obitech/ds_shortest_path","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/obitech/ds_shortest_path","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obitech%2Fds_shortest_path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obitech%2Fds_shortest_path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obitech%2Fds_shortest_path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obitech%2Fds_shortest_path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obitech","download_url":"https://codeload.github.com/obitech/ds_shortest_path/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obitech%2Fds_shortest_path/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261624959,"owners_count":23186118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","java"],"created_at":"2024-11-08T02:21:33.664Z","updated_at":"2025-06-24T07:07:57.653Z","avatar_url":"https://github.com/obitech.png","language":"Java","readme":"## Shortest path in a directed graph with edge weight and acceleration\nThis is a custom algorithm implemented in Java. In this form it only works on a specific graph (see below), but could be easily customized to work on other graphs as well.\n\n### Data Model\nThe Graph is read in by arces.csv and nodes.csv, stored in the util package.\n\n* Each vertex has an ID and a speed modifier\n* Start has ID = 0, End has ID = 21\n* Vertices are connected with directed edges\n* Edges have distance\n* Vertex with ID = 0 sets speed to 1\n* Passing a vertex will modify current speed according to his modification\n* Time to pass an edge = distance / current speed at vertex\n\n![A bi-directional graph with weighted edges and acceleration](https://github.com/obitech/ds_shortest_path/blob/master/graph.png \"A bi-directional graph with weighted edges and acceleration\")\n\n### Task\nFind the path with the shortest time from 0 to 21. Travel speed can't fall below 0.\n\n### Algorithm\nThe algorithm calculates the shortest path from 0 to 21. It uses a breadth-first search approach to dynamically adjust time \u0026 speed for all connected vertices for the currently visited node, very similar to Bellman-Ford's SP algorithm.  It optimizes for time decrease or speed improvement from a vertex to its neighbours. Additionally there is a limit of how many times a vertex can be passed each iteration. \n\nAt the beginning each vertex only gets passed once, the final time for the end vertex will then be compared against the previous final time (Infinity for the first iteration). If time improves, we restart the algorithm but now allow each vertex to be visited one more time. This gets repeated until there is no more measurable improvement in time.\n\n The optimal path for each vertex is stored in the HashMap 'pathMap' and are updated dynamically. The paths for each iteration are saved in the ArrayList 'results' and can be accessed via showResult()\n \n#### Starting conditions\n * initialize endTime to Inf\n * all vertices initialized to: time = Inf, speed = 0\n * v0: time = 0, speed = 1\n *  nMax (max times each vertex can get visited in this iteration) = 1\n\n#### Process \n1. vertex with id = 0 gets queued\n2. Remove top vertex from queue\n3. Check all connected vertices if either time or speed improves (speed can't be \u003c 0) AND if number of times visited for destination would still be \u003c= nMax:\n    * adjust time \u0026 speed for destination\n    * update path for destination vertex\n    * add vertex to queue (except if it's 21 and/or already in queue)\n 4. If queue has items left, go to 2)\n 5. If final time for v21 \u003c endTime:\n    * nMax++ (vertices can be visited an additional time)\n    * Set endTime to v21.time\n    * Reset all vertices to starting conditions\n    * Go back to 1)\n    * **If false**: Time improvements from nMax - 1 to nMax are too small to keep track of -\u003e Algorithm is finished\n 6. The optimal path can be found via results.get(nMax - 1)\n\n ### Result\n The shortest path from 0 to 21 is: \n1) 0 -\u003e 7 with speed 1.0 in 30.0 time. Arrival time: 30.0\n2) 7 -\u003e 13 with speed 4.0 in 12.5 time. Arrival time: 42.5\n3) 13 -\u003e 7 with speed 4000.0 in 0.0125 time. Arrival time: 42.5125\n4) 7 -\u003e 13 with speed 4003.0 in 0.012490632025980514 time. Arrival time: 42.52499063202598\n5) 13 -\u003e 7 with speed 4003000.0 in 1.2490632025980514E-5 time. Arrival time: 42.525003122658006\n6) 7 -\u003e 13 with speed 4003003.0 in 1.2490622665034226E-5 time. Arrival time: 42.52501561328067\n7) 13 -\u003e 7 with speed 4.003003E9 in 1.2490622665034225E-8 time. Arrival time: 42.525015625771296\n8) 7 -\u003e 13 with speed 4.003003003E9 in 1.2490622655673287E-8 time. Arrival time: 42.52501563826192\n9) 13 -\u003e 7 with speed 4.003003003E12 in 1.2490622655673286E-11 time. Arrival time: 42.52501563827441\n10) 7 -\u003e 13 with speed 4.003003003003E12 in 1.2490622655663925E-11 time. Arrival time: 42.5250156382869\n11) 13 -\u003e 7 with speed 4.003003003003E15 in 1.2490622655663926E-14 time. Arrival time: 42.525015638286916\n12) 7 -\u003e 23 with speed 4.003003003003003E15 in 1.2490622655663916E-14 time. Arrival time: 42.52501563828693\n13) 23 -\u003e 12 with speed 4.003003003002998E15 in 1.249062265566393E-15 time. Arrival time: 42.52501563828693\n14) 12 -\u003e 21 with speed 4.003003003003001E15 in 2.4981245311327843E-16 time. Arrival time: 42.52501563828693\n\nTotal time travelled from 0 to 21 is 42.52501563828693","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobitech%2Fds_shortest_path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobitech%2Fds_shortest_path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobitech%2Fds_shortest_path/lists"}