This release is a pre-release and may not be stable for production use.
treebo
treebo is a library for combinatorial tree searches. It is designed to
make it quick to prototype algorithms whose search state can be compared using
several kinds of logic, including single-objective (SO) and multi-objective
(MO) comparisons.
The main algorithmic frameworks are beam search and its derived lazy-race tree search modules. A smaller branch-and-bound module is also available and is still under development. The library provides the containers, comparison strategies, tree/archive infrastructure, and extension points needed to design and test new search algorithms.
Installation
treebo requires Python 3.12 or newer. From the repository root, install it
in editable mode inside a virtual environment:
pip install -e .
Optional extras are available for plotting (plot), the repository examples
(examples), the test suite (test), or all of them (dev):
pip install -e ".[dev]" # equivalent to: pip install -r requirements.txt
The repository is organised as follows:
src/treebo/: the installable library.docs/: the user guide (not installed).example/: runnable examples (not installed).test/: the test suite (not installed).
Run the tests from the repository root with either of:
pytest
python -m unittest discover -s test -t .
Documentation
The user guide covers installation, basic usage, setting a comparison, creating a tree, running a search, setting a callback and restarting a search.
Core Model
A problem is expressed through a Node subclass. A node stores the current
state and its objective values, and implements how children are generated.
Tree owns the active population and optional archive. An Algorithm expands,
compares, prunes, and archives those nodes.
The main problem-specific business logic lives in two node methods: branch
creates the next candidate states, while compute derives the partial solution
objective values and other state-dependent fields used by the search. A small
root classmethod is often useful for constructing and evaluating the tree
roots fed to the search.
The two conventional objective fields are:
fitness: the objective value used to evaluate a search node internally during the search. It may be a scalar or an objective vector.jay: the main problem objective, often used as the archive sorting key. When it is not set explicitly, it falls back tofitness. To archive byjay, configureTreeStorage(archive_key="jay")when constructing the tree.
Comparison rules are configured through Comparison and can be selected by
node field. This lets one search use ordinary scalar ordering for one field and
multi-objective or Pareto logic for another.
Atomic Beam Search
The following complete example searches for the lowest-sum sequence of six values. Each node represents a partial sequence; beam search expands one level at a time and keeps only the four best partial sequences.
from treebo.algorithms.beam_search import BeamSearch
from treebo import Node, Tree
class SumNode(Node):
VALUES = (1, 4, 7, 12)
@classmethod
def root(cls, first_value):
root = cls(path=[first_value])
root.compute()
return root
def compute(self):
self["depth"] = len(self["path"])
self.fitness = sum(self["path"])
def branch(self, br=None):
values = self.VALUES if br is None else self.VALUES[:br]
children = []
for value in values:
child = SumNode(path=self["path"] + [value])
child.compute()
children.append(child)
return children
root = SumNode.root(first_value=1)
tree = Tree([root], archive_size=1)
algorithm = BeamSearch(br=3, be=4)
tree = algorithm.grow(tree, depth=5)
print(f"Best solution found after {tree.node_count} evaluations:\n",
tree.archive.best.pretty())
The same example is available as
example/beam_sum.py. Once treebo is installed, it
can be run from the repository root with:
python example/beam_sum.py
The detailed guides are indexed in docs/README.md.
The important boundary is the node subclass: the framework does not need to
know what a partial solution means. The node's branch and compute
methods contain the problem-specific business logic, while Tree and
BeamSearch handle population management, comparison, pruning, and archiving.
Search Frameworks
Beam search
BeamSearch expands the entire active population by one depth, optionally
archives the branch or the pruned level, and retains the configured beam. The
low-memory variant performs prune-add-prune steps while branching so that large
intermediate levels do not all remain live at once. Besides space complexity,
this can also reduce the time complexity of searches with expensive pruning, e.g.
with MO fitness.
Channeled beam search temporarily groups candidates by a channel field and prunes each channel independently. This is useful when diversity or resource classes should be preserved during selection.
All beam search variants allow for parallel branching, while pruning remains sequential.
Lazy-race tree search
LazyRaceTreeSearch groups nodes into slots and expands one slot at a time.
By default it selects the minimum slot key. Pruning is also independent within
each slot.
Slots often represent solution timeline slices. Lazy-race tree search mitigates the unfair comparison of same-depth partial solutions of different duration incurred by beam searches.
Its multi-index mode can select among non-dominated slot keys, making it suitable for searches where the exploration rhythm must be controlled over budgets other than time. Channeled and low-memory variants are also provided.
Lazy-race tree search variants allow for parallel branching and pruning steps. The same multiprocessing pool is used for both.
Branch and bound
BnB is a smaller branch-and-bound framework that relies on the node subclass
to implement branch_and_bound, which takes the entire tree as argument.
It is useful for experimentation, but its API and behavior are less mature than
the beam search and lazy-race tree search modules.
Containers and Comparisons
The core containers include:
NodeList: flat list storage.NodeSet: identity-based storage with fast membership checks.NodeDict: buckets nodes by a node field. Values can be any container.Archive: bounded storage that retains selected nodes.MultiHashed: synchronized capacity-bounded indexes over several node fields (experimental).
Tree hashing means that nodes are grouped into bounded buckets by a hash/index field, so pruning can preserve representation across categories instead of selecting only from one global population. Experimental multi-hashing applies that idea across several fields at once; a node is retained only while it survives every configured index.
Comparison strategies include scalar/lexicographic ordering, multi-objective ordering, Pareto selection, and preshuffled variants. Custom comparison classes can implement the common sorting, selection, pruning, and reference interface.
Repository Examples
example/tsp/tsp.py: compact combinatorial TSP node model.example/beam_sum.py: atomic beam-search walkthrough.example/kro/: a KRO/TSP-style benchmark example.
The test suite under test/ contains smaller examples of tree
hashing, channeling, slots, comparisons, archives, and multi-hash containers.
License
This project is licensed under the Mozilla Public License 2.0. See the
LICENSE file for the full text.
Copyright
Copyright © 2026 Carlos Ortega Absil.
For copyright and attribution information, see NOTICE.md.
Citation
If you use this software in academic research, scientific publications, or other scholarly work, please cite it using its DOI.
For the recommended citation format, see NOTICE.md.
Metadata
Release files for treebo 0.1.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| treebo-0.1.0b1.tar.gz | 341.7 kB | Without provenance | Details for treebo-0.1.0b1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| treebo-0.1.0b1-py3-none-any.whl | Python 3 | none | any | Details for treebo-0.1.0b1-py3-none-any.whl |
Total release size: 391.3 kB
Release files / treebo-0.1.0b1.tar.gz
| Download URL | treebo-0.1.0b1.tar.gz |
|---|---|
| Size | 341.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b01a66242ed04462646140cca5a43adcc57871a552cbb259c3a0a4b1d08cda19
|
|
BLAKE2b-256 checksum How to use checksums |
0e864210bb566ade6bc7606221f594e8f58b8e239b3765e44bff3d553b477329
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / treebo-0.1.0b1-py3-none-any.whl
| Download URL | treebo-0.1.0b1-py3-none-any.whl |
|---|---|
| Size | 49.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ec309721cc63e4101aa5c5b69cd0251f0d276f9fca95896bf5a2172e833dffd
|
|
BLAKE2b-256 checksum How to use checksums |
830ae96813fd63c5c4b915a55540059948a8c8135ad36a3dd3cc6089ac6ad1f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for treebo 0.1.0b1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.