{"id":13538041,"url":"https://github.com/metaory/mail-delivery-trains-challenge","last_synced_at":"2025-04-02T04:32:13.516Z","repository":{"id":227934085,"uuid":"667347669","full_name":"metaory/mail-delivery-trains-challenge","owner":"metaory","description":"autonomous mail delivery trains challenge","archived":true,"fork":false,"pushed_at":"2023-08-02T01:34:38.000Z","size":50176,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-03T03:30:34.677Z","etag":null,"topics":["challenge","coding-challenge"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metaory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-07-17T09:52:14.000Z","updated_at":"2024-07-16T14:20:27.000Z","dependencies_parsed_at":"2024-03-15T21:52:00.237Z","dependency_job_id":"3983dd0e-7bf0-4de8-99dc-0b5b480394b1","html_url":"https://github.com/metaory/mail-delivery-trains-challenge","commit_stats":null,"previous_names":["metaory/mail-delivery-trains-challenge"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaory%2Fmail-delivery-trains-challenge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaory%2Fmail-delivery-trains-challenge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaory%2Fmail-delivery-trains-challenge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaory%2Fmail-delivery-trains-challenge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metaory","download_url":"https://codeload.github.com/metaory/mail-delivery-trains-challenge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246757549,"owners_count":20828914,"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":["challenge","coding-challenge"],"created_at":"2024-08-01T09:01:06.014Z","updated_at":"2025-04-02T04:32:08.509Z","avatar_url":"https://github.com/metaory.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Mail delivery trains challenge\n\n## Related\n\n- [metaory/advent-of-code](https://github.com/metaory/advent-of-code)\n\n## Requirements\n\n- Node 16+\n\n## Dependencies\n\n- `Chalk` - Terminal string styling\n\n## How to run\n\n```bash\nnpm install\nnpm start\n# or\nnpm start assets/input-basic.json\nnpm start assets/input-edge.json\nnpm start assets/input-advance.json\n# or\nnpm start [path]\n```\n\n---\n\n## Generate random test input\n\nRandomly generate new test inputs:\n\n```bash\n# interactive mode to generate and run the solution\nnpm run generate\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/generate-mock.gif\" width=\"600\" /\u003e\n\u003c/p\u003e\n\n---\n\n```bash\n# non-interactive mode to generate and run the solution\nnpm run generate force [multiplier] [delay]\n\n# [multiplier]\n# for [distances, capacity, weight]\n# eg; multiplier of 5 gives: 5, 10, 15, 20, ...\n# default is 1\n\n# [delay]\n# delay in seconds\n# default is 3\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/generate-mock-force.gif\" width=\"600\" /\u003e\n\u003c/p\u003e\n\n---\n\n## Challenge\n\n_You have been asked to write a program to control a network of **autonomous mail delivery trains**_\n\nEach instance of this problem has:\n\n- [A network, consisting of a set of nodes, each described by a (string) name]\n\n- [A set of edges, each of which links two nodes and has journey time in seconds]\n- [Edges are undirected and\n  any number of trains can travel along any edge in any combination of orders\n  An edge is uniquely described by a pair of nodes]\n\n- [A set of trains in the network, each of which has a maximum total weight it can carry]\n\n- [All trains start off empty and each train has a node where it starts off]\n\n- [There is a set of packages in the network,\n  each of which has a weight and starts off located at a node,\n  and each of which has a destination node]\n\nThe problem is solved when all packages are **located at their destination nodes**\n\n_We would like you to write (or think about) a program which takes as input_:\n\n- [A list of node names, `[ Node1, Node2, .. ]`]\n- [A list of edges, `(Name, Node1, Node2, JourneyTimeInMinutes)`]\n- [A list of trains `(TrainName, CapacityInKg, StartingNode)`]\n- [A list of packages, `(PackageName, WeightInKg, StartingNode, DestinationNode)`]\n\n_And produces as output a list of moves. **Each move should contain**_:\n\n- [The time at which the move occurs, in seconds, `W`]\n- [The name of a train which moves, `T`]\n- [The node that the train starts at, `N1`]\n- [The names of the packages the train picks up at the start node, `P1`]\n- [The node that the train finishes at, `N2`]\n- [The names of the packages the train drops off at the finishing node, `P2`]\n\n_For clarity_:\n\n- [`P1` and `P2` may be empty]\n- [`N1` may be equal to `N2` No time is taken moving a train from a node to itself]\n- [No time is taken to load or drop off packages]\n- [No train may ever carry more than its capacity]\n- [There must be an edge (`N1`,`N2`)]\n- [The train will take the journey time for that edge to move from `N1` and `N2`\n  and may not do anything else whilst it is travelling]\n- [Any number of trains may travel down any edge in either direction at once]\n- [Any number of trains may be at any node at any time (nodes have no capacity limit)]\n- [Each train may carry any number of packages, long as it does not exceed capacity]\n- [Trains may end the sequence of moves anywhere]\n- [A train must start its next move at the destination node for its previous move\n  (or at its starting node if it has not yet moved) - trains cannot teleport]\n\n**At the end of your sequence of moves,\nall packages must have been dropped off at their destination node**\n\n**We define the solution time as the earliest time\nat which all packages have been dropped off at their destination node**\n\nSolution `S1` is better than `S2` if the solution time is lower in `S1` than in `S2`\n\n_We like the best solution possible, but correctness is more important than optimality_\n\n---\n\n`3` // number of stations\n\n`A` // station name\n\n`B` // station name\n\n`C` // station name\n\n---\n\n`2` // number of edges\n\n`E1,A,B,30` // route from `A` to `B` that takes `30` minutes\n\n`E2,B,C,10` // route from `B` to `C` that takes `10` minutes\n\n---\n\n`1` // number of deliveries to be performed\n\n`K1,5,A,C` // package `K1` with weight `5` located currently at station `A` that must be delivered to station `C`\n\n---\n\n`1` // number of trains\n\n`Q1,6,B` // train `Q1` with capacity `6` located at station `B`\n\n---\n\n// Move `Q1` to `A` via `E1`, takes `30` minutes\n\n`W=0, T=Q1, N1=B, P1=[], N2=A, P2=[]`\n\n// Now move back to `B` Takes `30` minutes\n\n`W=30, T=Q1, N1=A, P1=[K1], N2=B, P2=[]`\n\n// Move to `C` and drop off - takes `10` minutes\n\n`W=60, T=Q1, N1=B, P1=[], N2=C, P2=[K1]`\n\n---\n\n// Takes `70` minutes total\n\n---\n\n##### Input\n\n```javascript\n// input-edge.json\n{\n  stations: [ 'A', 'B', 'C', 'D', 'E' ],\n  edges: [ 'E1,A,B,30', 'E2,B,C,10', 'E3,C,D,40', 'E4,D,E,15' ],\n  deliveries: [ 'K1,1,A,D', 'K2,2,C,E', 'K3,4,B,D' ],\n  trains: [ 'Q1,4,C', 'Q2,5,B' ]\n}\n```\n\n---\n\n##### Initial reduced structures\n\n```javascript\n// positions\n{ A: 0, B: 1, C: 2, D: 3, E: 4 }\n\n// connections\n{ A: [ 'B' ], B: [ 'A', 'C' ], C: [ 'B', 'D' ], D: [ 'C', 'E' ], E: [ 'D' ] }\n\n// distances\n{ 'A-B': 30, 'B-A': 30, 'B-C': 10, 'C-B': 10, 'C-D': 40, 'D-C': 40, 'D-E': 15, 'E-D': 15 }\n\n// delivery status\n{ K1: Symbol(AT_PICKUP), K2: Symbol(AT_PICKUP), K3: Symbol(AT_PICKUP) }\n\n// train stations\n{ Q1: 'C', Q2: 'B' }\n\n// train capacities\n{ Q1: 4, Q2: 5 }\n\n// train loads\n{ Q1: [], Q2: [] }\n\n// train timeline\n{ Q1: 0, Q2: 0 }\n```\n\n---\n\n##### Outcome\n\n```javascript\n// moves\n// *L is train load\n[\n  'W=0, T=Q2, N1=B, P1=[K3], N2=A, P2=[], L=[K3]',\n  'W=30, T=Q2, N1=A, P1=[K1], N2=B, P2=[], L=[K3,K1]',\n  'W=60, T=Q2, N1=B, P1=[], N2=C, P2=[], L=[K3,K1]',\n  'W=70, T=Q2, N1=C, P1=[], N2=D, P2=[K3,K1], L=[]',\n  'W=0, T=Q1, N1=C, P1=[K2], N2=D, P2=[], L=[K2]',\n  'W=40, T=Q1, N1=D, P1=[], N2=E, P2=[K2], L=[]'\n]\n\n// input-edge.json\n// After adding the final leg of journey duration\n// The highest is Q2; 70 + 40(C-D is 40)\nSolution time is: 110\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetaory%2Fmail-delivery-trains-challenge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetaory%2Fmail-delivery-trains-challenge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetaory%2Fmail-delivery-trains-challenge/lists"}