integrated rule engine - VforVitorio/F1_Strat_Manager GitHub Wiki
Integrated Rule Engine
- Overview
- System Architecture
- Installation and Setup
- Streamlit Dashboard
- Strategy Recommendations View
- Gap Analysis View
- Radio Analysis View
- Time Predictions View
- Strategy Chat Interface
- Machine Learning Models
- Lap Time Prediction
- Tire Degradation Modeling
- Vision-based Gap Calculation
- NLP Pipeline
- Radio Transcription
- Sentiment and Intent Analysis
- Named Entity Recognition
- Expert System
- Degradation Rules
- Gap Analysis Rules
- Radio Message Rules
- Integrated Rule Engine
- Developer Guide
- API Reference
- Integration Guide
Integrated Rule Engine
- scripts/IS_agent/N06_rule_merging.ipynb
- scripts/IS_agent/utils/N06_rule_merging.py
- scripts/app/app_modules/agent/N01_agent_setup.py
- scripts/app/app_modules/agent/N02_degradation_time_rules.py
- scripts/app/app_modules/agent/N03_lap_time_rules.py
- scripts/app/app_modules/agent/N04_nlp_rules.py
- scripts/app/app_modules/agent/N05_gap_rules.py
- scripts/app/app_modules/agent/N06_rule_merging.py
- scripts/app/components/strategy_overview.py
The Integrated Rule Engine is the central component of the F1 Strategy Manager that combines all specialized rule systems into a unified decision-making framework. It integrates separate rule engines for tire degradation, lap time prediction, gap analysis, and radio communication analysis, while providing sophisticated conflict resolution capabilities to ensure consistent and coherent strategy recommendations.
For information about specific rule systems, see Degradation Rules, Gap Analysis Rules, and Radio Message Rules.
Architecture Overview
The Integrated Rule Engine follows a multiple inheritance pattern where the main F1CompleteStrategyEngine
class inherits from all specialized rule engines. This allows the integrated engine to access and utilize rules from all domains while providing enhanced coordination and conflict resolution.
- scripts/IS_agent/N06_rule_merging.ipynb122-133
- scripts/app/app_modules/agent/N06_rule_merging.py78-89
- scripts/IS_agent/N06_rule_merging.ipynb281-357
Fact Types and Knowledge Representation
The rule engine operates on various fact types that represent different aspects of race strategy. These facts are created from raw data and serve as the input to the rule engine.
- scripts/app/app_modules/agent/N01_agent_setup.py14-102
- scripts/app/app_modules/agent/N06_rule_merging.py238-431
Core Components
F1CompleteStrategyEngine Class
The F1CompleteStrategyEngine
class is the central component that inherits from all specialized rule engines and adds conflict resolution capabilities.
Key features:
- Multiple Inheritance: Inherits all rules from specialized engines
- Active Systems Tracking: Monitors which rule systems have fired rules
- Enhanced Recommendation Processing: Adds conflict resolution to recommendations
- scripts/app/app_modules/agent/N06_rule_merging.py78-101
- scripts/IS_agent/N06_rule_merging.ipynb129-144
Active Systems Tracking
The integrated engine tracks which specialized rule systems have fired rules. This information is valuable for:
- Debugging which parts of the system are active
- Providing context for recommendations
- Understanding the basis for strategic decisions
- scripts/app/app_modules/agent/N06_rule_merging.py217-235
- scripts/IS_agent/N06_rule_merging.ipynb264-283
Conflict Resolution Mechanism
A key feature of the integrated engine is its ability to resolve conflicting recommendations. This is critical in F1 strategy where different data sources might suggest contradictory actions.
Conflict Resolution Process
- scripts/app/app_modules/agent/N06_rule_merging.py102-144
- scripts/IS_agent/N06_rule_merging.ipynb145-192
Conflicting Action Pairs
The engine defines specific pairs of actions that are considered mutually exclusive:
Action Pair | Conflict Reason |
---|---|
extend_stint + pit_stop |
Cannot extend stint and pit at the same time |
extend_stint + prioritize_pit |
Cannot extend stint and prioritize pitting |
extend_stint + defensive_pit |
Cannot extend stint and make a defensive pit |
extend_stint + consider_pit |
Cannot extend stint and consider pitting |
prepare_pit + pit_stop |
No need to prepare if immediate pit is recommended |
prepare_pit + prioritize_pit |
No need to prepare if prioritized pit is recommended |
perform_undercut + perform_overcut |
Cannot do undercut and overcut simultaneously |
When conflicting recommendations are detected, the engine selects the one with higher priority and confidence.
- scripts/app/app_modules/agent/N06_rule_merging.py165-178
- scripts/IS_agent/N06_rule_merging.ipynb214-228
Fact Transformation Pipeline
The integrated engine requires properly formatted facts. The transform_all_facts
function serves as a comprehensive pipeline for converting raw data into facts.
- scripts/app/app_modules/agent/N06_rule_merging.py238-431
- scripts/IS_agent/N06_rule_merging.ipynb366-431
Complete Strategy Analysis Pipeline
The analyze_strategy
function provides an end-to-end pipeline for F1 strategy analysis. It integrates all components of the system:
- Data Loading: Loads data from various sources
- Fact Transformation: Converts data into facts for the rule engine
- Rule Execution: Runs the integrated rule engine
- Recommendation Generation: Produces prioritized strategy recommendations
- scripts/app/app_modules/agent/N06_rule_merging.py522-639
- scripts/IS_agent/utils/N06_rule_merging.py522-639
Example Usage
The Integrated Rule Engine can be used through the analyze_strategy
function, which provides a complete pipeline from raw data to strategy recommendations:
The output is a list of prioritized strategy recommendations that have been processed through the conflict resolution mechanism:
Recommendation 1:
Action: pit_stop
Confidence: 0.85
Priority: 3
Explanation: Tire performance cliff detected. Model predicts 0.75s slowdown...
Recommendation 2:
Action: defensive_pit
Confidence: 0.80
Priority: 2
Explanation: Defensive pit stop strongly recommended in mid stint...
- scripts/app/app_modules/agent/N06_rule_merging.py522-639
- scripts/app/components/strategy_overview.py7-42
Integration with UI
The Integrated Rule Engine is accessed from the Streamlit dashboard via components that call the analyze_strategy
function or related utilities:
In the Streamlit dashboard, the "Run Strategy Analysis for All Drivers" button triggers the integrated rule engine for all drivers, generating comprehensive strategy recommendations that are displayed in the UI.
Best Practices for Extending the Rule Engine
-
Maintaining Rule System Separation: Keep specialized rules in their respective classes to maintain modularity.
-
Naming Convention for Rules: Use consistent prefixes for rule names (e.g.,
high_degradation_*
) to ensure proper rule system tracking. -
Consistent Recommendation Structure: All recommendations should include
action
,confidence
,explanation
, andpriority
for proper conflict resolution. -
Updating Conflict Pairs: When adding new action types, update the
conflicting_pairs
list in_resolve_conflicts
to define their relationships with existing actions. -
Fact Validation: Always validate facts before declaring them to the engine to avoid schema validation errors.
- scripts/app/app_modules/agent/N06_rule_merging.py102-214
- scripts/IS_agent/N06_rule_merging.ipynb147-264
Conclusion
The Integrated Rule Engine is the cornerstone of the F1 Strategy Manager, providing a unified framework for evaluating diverse sources of race information and generating coherent strategy recommendations. By combining specialized rule systems with sophisticated conflict resolution, it enables comprehensive strategy analysis that considers tire degradation, lap times, gaps between cars, and radio communications. The modular architecture allows for easy extension with new rule systems while maintaining a consistent recommendation framework.
On this page
- Integrated Rule Engine
- Architecture Overview
- Fact Types and Knowledge Representation
- Core Components
- F1CompleteStrategyEngine Class
- Active Systems Tracking
- Conflict Resolution Mechanism
- Conflict Resolution Process
- Conflicting Action Pairs
- Fact Transformation Pipeline
- Complete Strategy Analysis Pipeline
- Example Usage
- Integration with UI
- Best Practices for Extending the Rule Engine
- Conclusion