{"id":17933644,"url":"https://github.com/keyan/metro_coloring","last_synced_at":"2025-07-13T15:34:22.131Z","repository":{"id":87742729,"uuid":"249255833","full_name":"keyan/metro_coloring","owner":"keyan","description":"Generating vertex colorings of metro networks for safe parallelization of RAPTOR","archived":false,"fork":false,"pushed_at":"2020-03-23T04:46:40.000Z","size":22999,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T11:26:49.286Z","etag":null,"topics":["algorithms","graph-coloring","graph-theory","gtfs","mapping","public-transit"],"latest_commit_sha":null,"homepage":"","language":"Python","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/keyan.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,"publiccode":null,"codemeta":null}},"created_at":"2020-03-22T19:21:39.000Z","updated_at":"2020-11-14T17:01:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"64d6d217-6bb0-4861-a61e-81871a1f42cd","html_url":"https://github.com/keyan/metro_coloring","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/keyan/metro_coloring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyan%2Fmetro_coloring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyan%2Fmetro_coloring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyan%2Fmetro_coloring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyan%2Fmetro_coloring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keyan","download_url":"https://codeload.github.com/keyan/metro_coloring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyan%2Fmetro_coloring/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265163706,"owners_count":23721017,"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":["algorithms","graph-coloring","graph-theory","gtfs","mapping","public-transit"],"created_at":"2024-10-28T21:41:02.551Z","updated_at":"2025-07-13T15:34:22.091Z","avatar_url":"https://github.com/keyan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# metro_coloring\n\nLimited implementation of the parallelization techniques discussed in Section 3.3 of the [original RAPTOR paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2012/01/raptor_alenex.pdf).\n\nBriefly, the goal is to create an undirected \"conflict graph\" of all transit routes in a network and output a [graph coloring](https://en.wikipedia.org/wiki/Graph_coloring) (specifically a vertex coloring) of the graph such that all transit routes that share a stop are colored differently.\n\nThe resulting graph coloring can be used to determine an ordering to safely traverse routes (Algorithm 1 L15) in parallel without worrying about shared memory corruption.\n\nA selection of the NYC MTA subway vertex coloring (See below for more details):\n![Sample section of MTA vertex coloring](https://raw.githubusercontent.com/keyan/metro_coloring/master/output/mta_demo.png)\n\n## Usage\n\nFunctions for computing the constraint graph and coloring are in `src/color.py` and require no external dependencies.\n\nIn order to generate png output graphs you will need to install the `graphviz` library:\n```\npip install -r requirements.txt\n```\n\nRunning tests will also output the png graph, this can be done with:\n```\nmake\n```\n\n## Problem overview\nGiven a limited set of RAPTOR data structures, provide a vertex coloring for the network. Here each Route is a vertex and an edge to another Route exists iff both Routes share a stop.\n\nThe output should be a color for each Route.\n\nA test network is defined as follows:\n```\nroute_1        3\n               |\nroute_0   0 -- 1    2\n               |    |\n               4    5 - 7  route_3\n                    |\nroute_2             6\n```\n\nThe list at index i indicates which routes touch stop_i. Therefore `len(routes_for_stops) == # stops`.\n```\nroutes_for_stops: [[0], [0, 1], [2], [1], [1], [2, 3], [2], [3]]\n```\n\nThe list at index i indicates which stops are on route_i. Therefore `len(stops_for_routes) == # routes`.\n```\nstops_for_routes: [[0, 1], [3, 1, 4], [2, 5, 6], [5, 7]]\n```\n\nWhich routes share stops?\n```\nroute_0 and route_1\nroute_2 and route_3\n```\n\nSo a possible accurate coloring would be:\n```\nroute_colors: [0, 1, 0, 1]\n```\n\nThe example happens to be bipartite and the example coloring is chromatic, but the input need not be and this algorithm will still handle it correctly.\n\nWe can visualize the output for the example data above using `src/draw.py`. The uncolored constraint graph is:\n\n![constraintgraph](https://raw.githubusercontent.com/keyan/metro_coloring/master/output/uncolored.gv.png)\n\nAfter running the constraint graph through vertex coloring we get:\n\n![coloredgraph](https://raw.githubusercontent.com/keyan/metro_coloring/master/output/colored.gv.png)\n\n## Real world (NYC MTA Subway) Network\n\nThere are an additional set of utilities provided to process raw agency GTFS and output the vertex coloring. As a demonstration the directory `gtfs/` contains NYC MTA subway GTFS data from [transitfeeds](https://transitfeeds.com/p/mta/79) which can be loaded into a local SQLite database for graph generation.\n\nThe processing time for this operation is high due to the size of the MTA network, but should you be interested in generating the graph be patient and run:\n```\nmake load_and_draw\n```\n\nThe MTA subway network only has 30 \"GTFS routes\", but RAPTOR defines routes differently resulting in 215 routes/vertices in the final network. This creates a very large graph which is hard to visually inspect in its entirety, but if you are interested it is included here: https://github.com/keyan/metro_coloring/blob/master/output/mta_colored.gv.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeyan%2Fmetro_coloring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeyan%2Fmetro_coloring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeyan%2Fmetro_coloring/lists"}