P4Learned Delivery Routing
1 Codebase

conftest.py

tests/conftest.py · 34 lines · Download

1import sys2from pathlib import Path3 4import numpy as np5import pytest6 7sys.path.insert(0, str(Path(__file__).resolve().parent.parent))8 9from delivery.travel_time import TimeModel  # noqa: E40210 11 12def synthetic_matrix(Z=8, seed=0, rush=True):13    """Time-dependent synthetic matrix: zones in the plane, rush hours slower."""14    rng = np.random.default_rng(seed)15    xy = rng.uniform(0, 5, size=(Z, 2))16    d = np.linalg.norm(xy[:, None] - xy[None], axis=2)17    base = 4.0 + 3.0 * d18    mult = np.ones(24)19    if rush:20        mult[7:10] = 1.3521        mult[16:19] = 1.422        mult[0:6] = 0.823    return base[None] * mult[:, None, None]24 25 26@pytest.fixture27def tm():28    return TimeModel(synthetic_matrix(), factor=1.0, name="synthetic")29 30 31def line_tm(n=5, per_step=5.0, plus=1.0):32    idx = np.arange(n)33    M = per_step * np.abs(idx[:, None] - idx[None]) + plus34    return TimeModel(M, factor=1.0, name="line")