Skip to content

mamut_routing_tools.bks_campaign.archive

The run archive: one JSON record per run, written atomically, the unit of resumption.

Layout under campaign.out::

runs/<key>.json      one record per finished run (winner or not), schema_version 2
raw/<key>/           the solver's log and solution file (external solvers)
baseline.csv         the stored BKS before the campaign (``baseline``)
ledger.csv           one row per run (``report``)
cross-solver.csv     per instance: best per kind, gaps, seed spread (``report``)
harvest.json         what the last single-writer harvest did
harvests/NNNN-<time>.json  every harvest, numbered (the ledger's bks_action reads them all)
run.DONE             summary of the last ``run`` invocation

A run is done when its record exists; an interrupted run leaves no record and is picked up by the next run. The run key is <instance_id>__<objective>__<kind>__seed<S>__t<T>: the budget is part of it, so changing time_scale schedules new runs instead of mixing budgets.

group_runs

group_runs(
    out: Path, instance_id: str, objective: str
) -> list[dict[str, Any]]

The records of one instance and objective, read without scanning the whole archive.

Run keys start with <instance_id>__<objective>__, so the files are found by name; the records' own fields then decide (two ids can sanitise to the same key prefix).

Source code in MAMUT-routing-tools/src/mamut_routing_tools/bks_campaign/archive.py
def group_runs(out: Path, instance_id: str, objective: str) -> list[dict[str, Any]]:
    """The records of one instance and objective, read without scanning the whole archive.

    Run keys start with ``<instance_id>__<objective>__``, so the files are found by name; the
    records' own fields then decide (two ids can sanitise to the same key prefix).
    """
    directory = runs_dir(out)
    prefix = _UNSAFE.sub("-", f"{instance_id}__{objective}__")
    records = []
    for path in sorted(directory.glob(f"{prefix}*.json")) if directory.is_dir() else ():
        try:
            record = json.loads(path.read_text(encoding="utf-8"))
        except (OSError, ValueError):
            continue
        if isinstance(record, dict) and record.get("instance_id") == instance_id and record.get("objective_function") == objective:
            records.append(record)
    return records