9. Best Practices, Common Pitfalls & Performance Tuning
Best Practices
- Exploit Static Monotonicity: Express upper-bound limitations using non-decreasing monotonic sums (\(S \le C\)) without surrounding them in
valid is_closed;. This allows the Rave compiler to classify them as Final Rules, maximizing search space pruning speed. - Isolate Domain Concepts: Avoid mixing structural level logic with financial calculations. Separate legality rules (
CONSTRAINT) from objective functions (PROPERTY cost). - Minimize Level Context Transitions: Prefer localized traversers (
sum(leg(duty), ...)) over multi-level nested traversers across entire rosters where possible.
Common Pitfalls
- Misusing
valid is_closed;on Final Rules: Wrapping a simple duty flight time rule (sum(leg(duty), leg.%time%) <= 08:00) invalid is_closed;neutralizes its ability to prune incomplete sub-trips, causing massive performance degradation. - Temporal Disdependencies: Subtracting times out of chronological order (e.g.,
start_time - end_time) breaks automatic non-negativity type inference, causing the rule classifier to fall back to unoptimized evaluation. - Implicit Universal Traversal: Calling unbounded
all()orany()traversers over large rosters inside inner generation loops instead of restricting evaluation to the current activeDutyorTrip.