{"id":18309107,"url":"https://github.com/typicalam/np-combinatorics","last_synced_at":"2026-04-30T15:31:22.267Z","repository":{"id":152899267,"uuid":"551507220","full_name":"TypicalAM/NP-Combinatorics","owner":"TypicalAM","description":"Creating a Travelling Salesman Problem solver","archived":false,"fork":false,"pushed_at":"2022-12-02T11:46:32.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T11:48:43.750Z","etag":null,"topics":["golang","python3","tsp-solver"],"latest_commit_sha":null,"homepage":"","language":"Go","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/TypicalAM.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}},"created_at":"2022-10-14T14:28:46.000Z","updated_at":"2023-04-20T16:19:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"5615e751-0b36-4d42-907f-1db81801d574","html_url":"https://github.com/TypicalAM/NP-Combinatorics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TypicalAM/NP-Combinatorics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2FNP-Combinatorics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2FNP-Combinatorics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2FNP-Combinatorics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2FNP-Combinatorics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TypicalAM","download_url":"https://codeload.github.com/TypicalAM/NP-Combinatorics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypicalAM%2FNP-Combinatorics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32469344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","python3","tsp-solver"],"created_at":"2024-11-05T16:10:16.757Z","updated_at":"2026-04-30T15:31:22.262Z","avatar_url":"https://github.com/TypicalAM.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Combinatorial Optimization Project (NP-Complete problem solver)\n\nA program by Adam Piaseczny (L12) which allows the user to\n- Generate a weighted graph using `python3`\n- Solve the TSP problem using `golang`\n\n## What is the TSP problem?\n\nThe travelling salesman problem asks the following question: \"Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?\". This can be formally expressed as finding the shortest hamiltonian circuit in a complete weighted graph.\n\n## What are the implemented strategies\n\nThe implemented solvers are the following\n- Bruteforce\n\t- The bruteforce approach generates all possible permutations of the set of vertices ($n!$) and then computes the total distance of every one of them, keeping the smallest one in a variable\n- Greedy\n\t- The greedy solver always takes the nearest unvisited vertex and \"jumps to it\" until all the vertices are exhausted, this allows for a fast approximation for a rather expensive problem.\n- Backtracking\n\t- Check every path, but when the path is bigger than an already discovered minimal path, discard it\n\n## Usage of the program\n\nThe generator is written in `python3` while the `solver` is written in `golang`. First, clone the repository:\n\n```bash\ngit clone https://github.com/TypicalAM/NP-Combinatorics/ \u0026\u0026 cd NP-Combinatorics\n```\n\n### Generator (`python3`)\n\nTo use the generator (on a linux machine)\n\n```bash\ncd generator\n# python3 -m pip install --user virtualenv\nvirtualenv --no-vcs-ignore venv\nsource venv/bin/activate\npip3 install -r requirements.txt\npython3 generate.py --help\n```\n\nNow you can run the generator, for this projects complete graphs were used, so the density should stay at 100. An example generation of a graph using the erdos renyi model would look something like this:\n\n```bash\npython3 generate.py \\\n\t--size 15 \\\n\t--density 100 \\\n\t--min_weight 20 \\\n\t--max_weight 50 \\\n\t--path ../solver/data/15_vertices.json\n```\n\nThe generator will dump a `json` file looking a little bit like example.json.\n\n### Solver (`golang`)\n\nTo use the solver on a linux machine (needs `go` to be installed)\n\n```bash\ncd solver\ngo build -o solver main.go\n./solver --help\n```\n\nExamples of generation and solving could be\n\n```bash\n# in solver dir\npython3 ../generator/generate.py --path ../solver/data/10_vertices.json\n./solver --load data/10_vertices.json\n```\n\n```bash\n# in solver dir\npython3 ../generator/generate.py --path ../solver/data/10_vertices.json\n./solver --load data/10_vertices.json\n```\n\n```bash\n# in solver dir\npython3 ../generator/generate.py \\\n\t--size 30 \\\n\t--density 100 \\\n\t--min_weight 2 \\\n\t--max_weight 15 \\\n\t--path ../solver/data/30_vertices.json\n./solver \\\n\t--load data/30_vertices.json \\\n\t--solvers greedy \\\n\t--show=false\n```\n\n```bash\n# in solver dir\npython3 ../generator/generate.py \\\n\t--size 10 \\\n\t--min_weight 1 \\\n\t--max_weight 200 \\\n\t--path ../solver/data/10_vertices.json\n./solver \\\n\t--load data/10_vertices.json \\\n\t--solvers bruteforce,backtracking \\\n\t--show=true\n```\n\n## Testing (solver)\n\nTo test the solver run the following commands in the solver directory:\n\n```bash\ngo test ./src/solutions\n```\n\nor to see a more verbose output\n\n```bash\ngo test -v ./src/solutions\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicalam%2Fnp-combinatorics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypicalam%2Fnp-combinatorics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicalam%2Fnp-combinatorics/lists"}