Decision Engineο
Overviewο
The Decision Engine is the unified abstraction layer that wraps existing policy functions with rich metadata.
Instead of returning bare zone IDs:
[132, 236, 237] # Old: just zone IDs
It returns:
Recommendation(
vehicle_id="demo_vehicle",
recommended_zone=132,
ranked_zones=[
RankedZone(zone_id=132, score=0.91, expected_demand=41.7, ...),
RankedZone(zone_id=236, score=0.85, expected_demand=38.2, ...),
RankedZone(zone_id=237, score=0.78, expected_demand=35.1, ...),
],
confidence=0.87,
model_version="two-step-v1",
explanations=["high predicted demand", "low predicted supply"],
)
Architectureο
Prediction (forecast demand/supply)
β
Candidate Generation (zone filtering)
β
Optimization (score each candidate)
β
Constraint Filter (safety, business rules)
β
Recommendation (ranked zones + metadata)
Schemaο
Recommendationο
Field |
Type |
Description |
|---|---|---|
|
str |
Unique vehicle identifier |
|
datetime |
When recommendation was generated |
|
int |
Zone the vehicle is in |
|
int |
Top recommended zone |
|
list[RankedZone] |
Full ranked list with scores |
|
float? |
Heuristic confidence score |
|
str |
Model/policy identifier |
|
str |
Version string |
RankedZoneο
Field |
Type |
Description |
|---|---|---|
|
int |
Zone ID |
|
float |
Modelβs score for this zone |
|
float? |
Predicted demand |
|
float? |
Predicted supply |
|
float? |
Expected revenue |
|
float? |
Travel time from current zone |
All Optional fields are None when not computable β never fabricated.
Policiesο
Policy |
Strategy |
Description |
|---|---|---|
|
Historical demand ranking |
Recommends zones with highest historical pickup counts |
|
Greedy utility maximization |
Best immediate expected value (fare / travel_time) |
|
Finite-horizon planning |
Considers continuation value after first trip (default) |
|
Deep Q-Network |
RL policy trained in simulator |
Constraintsο
The ConstraintAwarePolicy wrapper applies safety and business constraints:
from src.decision.policies.constraints import ZoneConstraints, make_constrained
constraints = ZoneConstraints(
max_reposition_distance_minutes=15.0,
max_airport_exposure_ratio=0.3,
)
constrained = make_constrained(two_step_policy, constraints)
Constraints are soft: if all candidates are filtered, falls back to original recommendation.
Usageο
from src.decision.engine import build_recommendation, compute_confidence
rec = build_recommendation(
vehicle_id="v001",
current_time=datetime.now(),
current_zone=161,
ranked_zone_ids=[132, 236, 237],
model_name="two_step",
model_version="v1",
)
rec.confidence = compute_confidence(rec.ranked_zones)
Important Notesο
All fields are computed from real data/model outputs
confidenceis a heuristic diagnostic, not a calibrated probabilityField availability depends on what the underlying model provides