integrated rule engine - VforVitorio/F1_Strat_Manager GitHub Wiki

Integrated Rule Engine

VforVitorio/F1_Strat_Manager

powered by

Devin

Integrated Rule Engine

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.

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.

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

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

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

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.

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.

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:

  1. Data Loading: Loads data from various sources
  2. Fact Transformation: Converts data into facts for the rule engine
  3. Rule Execution: Runs the integrated rule engine
  4. Recommendation Generation: Produces prioritized strategy recommendations

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...

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

  1. Maintaining Rule System Separation: Keep specialized rules in their respective classes to maintain modularity.

  2. Naming Convention for Rules: Use consistent prefixes for rule names (e.g., high_degradation_*) to ensure proper rule system tracking.

  3. Consistent Recommendation Structure: All recommendations should include action, confidence, explanation, and priority for proper conflict resolution.

  4. Updating Conflict Pairs: When adding new action types, update the conflicting_pairs list in _resolve_conflicts to define their relationships with existing actions.

  5. Fact Validation: Always validate facts before declaring them to the engine to avoid schema validation errors.

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