Skip to content

mamut_routing_tools.bks_campaign.spec

BKS campaign specification (TOML, validated with pydantic).

.. code-block:: toml

[campaign]
name = "mamut2026-bks-4"
out = "runs/mamut2026-bks-4"        # relative to this file; never inside a benchmark collection
authors = "Jane Doe (jdoe)"         # credited in every BKS the harvest writes
# solvers_config = "solvers.toml"   # default: the user's solvers config

[select]
benchmarks_dir = "../benchmarks"
problem_types = ["CVRP"]
families = ["Mamut2026"]
metrics = ["euclidean"]
min_n = 700
# max_n, name_regex, instance_ids
# [select.objective]                # per problem type; default: the family's published objective
# VRPTW = "HierarchicalVehicleCost"

[budget]                            # T(n) = clamp(per_customer_s * n, min_s, max_s) * time_scale
per_customer_s = 21.6
min_s = 7200
max_s = 86400
# fixed_s = 600                     # instead of per_customer_s
time_scale = 1.0

[[runs]]
solver = "filo2"
seeds = "1-5"

[[runs]]
solver = "pyvrp"
kind = "pyvrp-polish"
seeds = "3000-3003"
budget_factor = 1.5
warm_start = "best"                 # from the best archived run or the stored BKS, looked up
                                    # when the run starts: after the other runs of its instance

[resources]
workers = 90
memory_gb = "auto"                  # 80 % of MemAvailable, or a number
nice = 5

BudgetSpec

Bases: _Strict

seconds

seconds(num_customers: int, factor: float = 1.0) -> int

The wall-clock budget for an instance with num_customers customers.

Source code in MAMUT-routing-tools/src/mamut_routing_tools/bks_campaign/spec.py
def seconds(self, num_customers: int, factor: float = 1.0) -> int:
    """The wall-clock budget for an instance with ``num_customers`` customers."""
    if self.fixed_s is not None:
        base = self.fixed_s
    else:
        base = float(self.per_customer_s) * num_customers
        base = max(base, self.min_s)
        if self.max_s is not None:
            base = min(base, self.max_s)
    return max(1, int(round(base * self.time_scale * factor)))

parse_seeds

parse_seeds(value: str | int | list[int]) -> list[int]

"1-5,7" -> [1, 2, 3, 4, 5, 7]; a list or an int passes through.

Source code in MAMUT-routing-tools/src/mamut_routing_tools/bks_campaign/spec.py
def parse_seeds(value: str | int | list[int]) -> list[int]:
    """``"1-5,7"`` -> ``[1, 2, 3, 4, 5, 7]``; a list or an int passes through."""
    if isinstance(value, int):
        return [value]
    if isinstance(value, list):
        return list(dict.fromkeys(int(item) for item in value))
    seeds: list[int] = []
    for part in str(value).split(","):
        part = part.strip()
        if not part:
            continue
        if "-" in part:
            low, high = part.split("-", 1)
            if int(high) < int(low):
                raise ValueError(f"empty seed range {part!r}")
            seeds.extend(range(int(low), int(high) + 1))
        else:
            seeds.append(int(part))
    if not seeds:
        raise ValueError(f"no seeds in {value!r}")
    return list(dict.fromkeys(seeds))  # "1-3,2" is seeds 1, 2, 3: a repeated seed would be a duplicate run

load_spec

load_spec(path: str | Path) -> CampaignSpec

Read and validate a campaign spec; paths become absolute, out is refused inside a collection.

Source code in MAMUT-routing-tools/src/mamut_routing_tools/bks_campaign/spec.py
def load_spec(path: str | Path) -> CampaignSpec:
    """Read and validate a campaign spec; paths become absolute, ``out`` is refused inside a collection."""
    from mamut_routing_lib.sidecars import find_collection_root

    spec_path = Path(path).resolve()
    data = tomllib.loads(spec_path.read_text(encoding="utf-8"))
    spec = CampaignSpec.model_validate({**data, "path": spec_path}).resolved(spec_path.parent)
    out = spec.campaign.out
    try:
        inside = find_collection_root(out)
    except Exception:  # noqa: BLE001 - no collection marker above the out directory
        inside = None
    benchmarks = spec.select.benchmarks_dir
    if inside is not None or (benchmarks is not None and _is_within(out, benchmarks)):
        raise ValueError(f"campaign.out ({out}) must not lie inside a benchmark tree: workers never write next to instances")
    if not math.isfinite(spec.budget.time_scale) or spec.budget.time_scale <= 0:
        raise ValueError("budget.time_scale must be positive")
    return spec