{"id":22828570,"url":"https://github.com/sandyspiers/branch_and_bound_template","last_synced_at":"2026-07-18T21:32:55.263Z","repository":{"id":194001125,"uuid":"689872305","full_name":"sandyspiers/branch_and_bound_template","owner":"sandyspiers","description":"A structured and quick-to-implement template for your branch and bound prototypes!","archived":false,"fork":false,"pushed_at":"2023-09-13T07:29:12.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T06:16:32.598Z","etag":null,"topics":["branch-and-bound","integer-programming","mixed-integer-programming","optimisation-algorithms","template"],"latest_commit_sha":null,"homepage":"","language":"Python","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/sandyspiers.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":"2023-09-11T04:54:29.000Z","updated_at":"2024-04-21T01:58:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"bbe67420-49e0-4a5c-8e9f-66d442ce6c35","html_url":"https://github.com/sandyspiers/branch_and_bound_template","commit_stats":null,"previous_names":["sandyspiers/branch_and_bound_template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sandyspiers/branch_and_bound_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandyspiers%2Fbranch_and_bound_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandyspiers%2Fbranch_and_bound_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandyspiers%2Fbranch_and_bound_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandyspiers%2Fbranch_and_bound_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandyspiers","download_url":"https://codeload.github.com/sandyspiers/branch_and_bound_template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandyspiers%2Fbranch_and_bound_template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000850,"owners_count":26082950,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["branch-and-bound","integer-programming","mixed-integer-programming","optimisation-algorithms","template"],"created_at":"2024-12-12T19:10:35.387Z","updated_at":"2025-10-09T06:16:35.970Z","avatar_url":"https://github.com/sandyspiers.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Branch and Bound Template\n\nThis repository contains a structured template for a branch and bound algorithm.\nThis allows for rapid testing and experimentation of your B\u0026B ideas.\n\n**The purpose is not for performance! The purpose is quick implementation for prototyping branch and bound ideas!**\n\nSo copy or fork this repo, and apply it to your own problem by filling in the blank lines.\n\n\u003e *fail fast* -someone clever\n\n## Contents\n\nThe main part of the code consists 5 Python classes within `branch_and_bound.py`.\nHere is a brief introduction, however for more information please read the documentation within `branch_and_bound.py`.\n\n### 1. `Problem`\n\n`Problem` should contain all the relevant information for you specific problem instance.\nThis includes all parameters required to generate \u0026 solve an instance of this problem.\nFor ease of use, consider using this object in one of the following ways:\n\n1. As an inheritance of a common algebraic modelling package, such as a `docplex.mp.model.Model` object.\nSee [example here](https://github.com/sandyspiers/euclidean_maximisation/blob/main/emsca/model.py).\n2. Use class methods as instance generators.\nGreat for generating instances of a particular structure.\n\n### 2. `Solution`\n\nThis should just be a basic container for a solution.\nCan be considered as only a dataclass if need.\nBut it **must** always contain feasible solution!\nAnd it **must** always have an `objective_value` attribute!\n\n### 3. `RootProblem`\n\nIn many cases, implementation is far easier when we have a so called *root problem*.\nThis is essentially an optimisation problem formulation of the problem instance, before any variable fixings.\nThis class shall handle that model, and then also has a `solve(fixings)` method that can solve the root problem, with given variable fixings.\nFor example, this could be the base MIP created from a problem instance.\nThen variable fixings are added based on the branch and bound tree.\nAfter the node problem is solved, these fixings are removed from the root problem.\n\n### 4. `Node`\n\nThe node object contains all information to generate a specific node.\nThis includes which variables are fixed, which are free etc.\nThis could either contain itself an entire model, or simply a reference to the root problem.\n\n### 5. `Solver`\n\nThis is the main part of the code.\nRealistically, any user of this code should only ever interface with this object to either\n\n1. Set any `parameters`,\n2. Call the `solve()` method,\n3. Retrieve the `solution`.\n\nEverything else should be considered as private.\n\nFor the branch and bound process, the object has the following important attributes,\n\n* `_node_list`\n* `_incumbent_solution`\n\nThe main branch and bound iterations are handled inside `solve()`.\nWithin these iterations, we call the following important methods,\n\n* `_get_next_node()`\n* `_heuristic_repair()`\n* `_make_children()`\n\nAll should be self explanatory, however for more information on the purpose of each method see documentation inside `branch_and_bound.py`.\n\n## Usage\n\nThis repo is designed as a template.\nTherefore, the idea is to grab the code within `branch_and_bound.py`, and fill in the blanks for your own purpose.\nAn example of this is shown in `knapsack_example.py`, where we fill in the branch and bound solver to solve a basic 0-1 knapsack problem.\nThe implementation simply fills in the code from `branch_and_bound.py`.\n\n## Tests\n\nThere are several test provided in `test_bnb_solver.py`.\nThese should be appropriate for any implementation, and can be used to ensure you don't break any of the code when adjusting for your own implementation.\nIt's a good idea to also check your implementation against another method to solve the problem.  For the knapsack example, we test that the branch and bound solver matches the solution found from `cplex`.\n\n## Contributions\n\nWe welcome and appreciate all contributions!\nEspecially any changes that might make the template easier to understand / use / implement / extend.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandyspiers%2Fbranch_and_bound_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandyspiers%2Fbranch_and_bound_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandyspiers%2Fbranch_and_bound_template/lists"}