from pathlib import Path
from typing import Tuple

def find_project_root() -> Path:
    """Find project root by looking for a marker file."""
    current = Path().resolve()
    for parent in [current] + list(current.parents):
        if (parent / "pyproject.toml").exists():  # or setup.py, .git, etc.
            return parent
    raise FileNotFoundError("Could not find project root")

PROJECT_ROOT = find_project_root()

DATA_DIR = PROJECT_ROOT / "data"

instances_base = DATA_DIR / "instances"
cache_base = DATA_DIR / "instances" / "caches"

Run 3D4L on a Single InstanceΒΆ

This example shows how to define a custom pipeline runner to execute automated pipeline synthesis for a single instance. We utilize the FoodmartLoader class from ware_ops_algos to translate the instance file into a domain object compatible with 3D4L.

from ware_ops_algos.domain_models import BaseWarehouseDomain
from ware_ops_algos.data_loaders import FoodmartLoader
from ware_ops_pipes.utils.experiment_utils import PipelineRunner, RankingEvaluatorDistance


class SimpleRunner(PipelineRunner):
    def __init__(self, instance_set_name: str, 
                 instances_dir: Path, 
                 cache_dir: Path, 
                 project_root: Path):
        super().__init__(instance_set_name, 
                         instances_dir, 
                         cache_dir, 
                         project_root)
        
        self.loader = FoodmartLoader(str(instances_dir), 
                                     str(cache_dir))
        self.ranker = RankingEvaluatorDistance
        
    def discover_instances(self) -> list[Tuple[str, list[Path]]]:
        pass
    
    def load_domain(self, instance_name: str, 
                    file_paths: list[Path]) -> BaseWarehouseDomain:
        return self.loader.load(file_paths[0].name, use_cache=True)

runner = SimpleRunner("FoodmartData", instances_base / "FoodmartData",
                        cache_base / "FoodmartData", PROJECT_ROOT)

runner.run_instance(instance_name="instances_d5_ord5_MAL.txt", file_paths=[Path("data/instances/FoodmartData/instances_d5_ord5_MAL.txt")])
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 from ware_ops_algos.domain_models import BaseWarehouseDomain
      2 from ware_ops_algos.data_loaders import FoodmartLoader
      3 from ware_ops_pipes.utils.experiment_utils import PipelineRunner, RankingEvaluatorDistance
      4 

ModuleNotFoundError: No module named 'ware_ops_algos'

As the ranker shows, the best pipeline is the combination of GreedyItemAssignment, Local Search Batching with a RandomBatching component for constructing the initial solution and NearestNeighbourhoodRouting as the routing component