{"id":18526978,"url":"https://github.com/mandrenkov/compile-time-graph-library","last_synced_at":"2025-06-24T15:08:13.102Z","repository":{"id":59495302,"uuid":"155892083","full_name":"Mandrenkov/Compile-Time-Graph-Library","owner":"Mandrenkov","description":"C++17 library that implements the execution of graph algorithms during compilation.","archived":false,"fork":false,"pushed_at":"2023-01-17T13:38:59.000Z","size":98,"stargazers_count":18,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T04:41:24.287Z","etag":null,"topics":["graph-library","template-metaprogramming"],"latest_commit_sha":null,"homepage":"","language":"C++","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/Mandrenkov.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}},"created_at":"2018-11-02T16:20:54.000Z","updated_at":"2024-07-27T18:30:31.000Z","dependencies_parsed_at":"2023-02-10T09:45:40.433Z","dependency_job_id":null,"html_url":"https://github.com/Mandrenkov/Compile-Time-Graph-Library","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Mandrenkov/Compile-Time-Graph-Library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mandrenkov%2FCompile-Time-Graph-Library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mandrenkov%2FCompile-Time-Graph-Library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mandrenkov%2FCompile-Time-Graph-Library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mandrenkov%2FCompile-Time-Graph-Library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mandrenkov","download_url":"https://codeload.github.com/Mandrenkov/Compile-Time-Graph-Library/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mandrenkov%2FCompile-Time-Graph-Library/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261700839,"owners_count":23196504,"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":["graph-library","template-metaprogramming"],"created_at":"2024-11-06T17:52:57.122Z","updated_at":"2025-06-24T15:08:13.076Z","avatar_url":"https://github.com/Mandrenkov.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compile Time Graph Library ![Travis Status](https://travis-ci.org/Mandrenkov/Compile-Time-Graph-Library.svg?branch=master)\nThe *Compile Time Graph Library* (CTGL) is a C++ header-only library that implements `constexpr` graph algorithms.\n\n## Setup\nTo integrate CTGL with your project, add the files in the [header](src/h) directory to your include path.  Then, include [`ctgl.h`](src/h/ctgl.h) in the source files of your choice!\n\n**Note:** This library uses C++17 features.\n\n## Examples\nThe first example finds the shortest distance between two nodes in a graph.\n```C++\n// The nodes of a CTGL graph are ctgl::Node\u003c\u003e types with unique ID parameters.\nusing n1 = ctgl::Node\u003c1\u003e;\nusing n2 = ctgl::Node\u003c2\u003e;\nusing n3 = ctgl::Node\u003c3\u003e;\nusing nodes = ctgl::List\u003cn1, n2, n3\u003e;\n\n// The directed, weighted edges of a CTGL graph are ctgl::Edge\u003c\u003e types.\n// 1 --(4)--\u003e 2 --(4)--\u003e 3\n// '---------(9)---------^\nusing e12 = ctgl::Edge\u003cn1, n2, 4\u003e;\nusing e13 = ctgl::Edge\u003cn1, n3, 9\u003e;\nusing e23 = ctgl::Edge\u003cn2, n3, 4\u003e;\nusing edges = ctgl::List\u003ce12, e13, e23\u003e;\n\n// By definition, a Graph is a composition of Nodes and Edges.\nusing graph = ctgl::Graph\u003cnodes, edges\u003e;\n\n// |distance| represents the (shortest) distance between Node 1 and Node 3.\n// In this case, the value of |distance| will be 8.\nconstexpr int distance = ctgl::algorithm::findDistance(graph{}, n1{}, n3{});\n```\n\nThe second example solves the [Travelling Salesman Problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem) in O(1) running time.\n```C++\n// Nodes represent cities in the TSP instance.\nusing dubai = ctgl::Node\u003c1\u003e;\nusing miami = ctgl::Node\u003c2\u003e;\nusing paris = ctgl::Node\u003c3\u003e;\nusing tokyo = ctgl::Node\u003c4\u003e;\nusing cities = ctgl::List\u003cdubai, miami, paris, tokyo\u003e;\n\n// Edges represent unidirectional routes between cities.\n//                  .-------------(1)-------------v\n// Dubai --(1)--\u003e Miami --(2)--\u003e Paris --(1)--\u003e Tokyo\n// ^   ^-----------(3)-----------'   ^---(4)----'   |\n// '----------------------(3)-----------------------'\nusing routes = ctgl::List\u003cctgl::Edge\u003cdubai, miami, 1\u003e,\n                          ctgl::Edge\u003cmiami, paris, 2\u003e,\n                          ctgl::Edge\u003cmiami, tokyo, 1\u003e,\n                          ctgl::Edge\u003cparis, dubai, 3\u003e,\n                          ctgl::Edge\u003cparis, tokyo, 1\u003e,\n                          ctgl::Edge\u003ctokyo, dubai, 3\u003e,\n                          ctgl::Edge\u003ctokyo, paris, 4\u003e\u003e;\n\n// |circuit| represents an optimal solution to the TSP instance from Dubai.\n// The type of |circuit| will express Dubai --\u003e Miami --\u003e Paris --\u003e Tokyo --\u003e Dubai.\nusing world = ctgl::Graph\u003ccities, routes\u003e;\nconstexpr auto circuit = ctgl::algorithm::findShortestRoute(world{}, dubai{}, cities{});\n```\n\nThe third example detects opportunities for arbitrage in a foreign exchange market.\n```C++\n// Nodes represent currencies in the foreign exchange market.\nusing aud = ctgl::Node\u003c1\u003e;\nusing cad = ctgl::Node\u003c2\u003e;\nusing nzd = ctgl::Node\u003c3\u003e;\nusing usd = ctgl::Node\u003c4\u003e;\nusing currencies = ctgl::List\u003caud, cad, nzd, usd\u003e;\n\n// Edges represent logarithmic exchange rates between currencies. Why? If the\n// product of the exchange rates along a cycle is less than one, then the sum\n// of the logarithmic exchanges rates along that cycle must be less than zero.\n//                v----------(-2)----------.\n// NZD --(1)--\u003e AUD --(-3)--\u003e CAD --(3)--\u003e USD\nusing log_rates = ctgl::List\u003cctgl::Edge\u003cnzd, aud,  1\u003e,\n                             ctgl::Edge\u003caud, cad, -3\u003e,\n                             ctgl::Edge\u003ccad, usd,  3\u003e,\n                             ctgl::Edge\u003cusd, aud, -2\u003e\u003e;\n\n// |arbitrage| represents the possibility of arbitrage in the currency market.\n// Here, |arbitrage| will be set to true because AUD --\u003e CAD --\u003e USD --\u003e AUD\n// forms a negative cycle.\nusing market = ctgl::Graph\u003ccurrencies, log_rates\u003e;\nconstexpr bool arbitrage = ctgl::graph::hasNegativeCycle(market{});\n```\n\n## Development\n| Command      | Description                        |\n|---           |---                                 |\n| `make all`   | Build and run the CTGL examples.   |\n| `make test`  | Build and run the CTGL test suite. |\n| `make clean` | Clean the current directory.       |\n\nYou can provide a `COMPILER` or `FLAGS` argument to any of the build commands to select a different compiler or add custom flags to a compiler invocation. For example, to build the test suite using Clang, use `make test COMPILER=clang++`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmandrenkov%2Fcompile-time-graph-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmandrenkov%2Fcompile-time-graph-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmandrenkov%2Fcompile-time-graph-library/lists"}