expert system - VforVitorio/F1_Strat_Manager GitHub Wiki

Expert System

VforVitorio/F1_Strat_Manager

powered by

Devin

Expert System

The F1 Strategy Manager's Expert System is a rule-based decision-making component that evaluates race telemetry, prediction model outputs, and team radio communications to generate strategic recommendations for Formula 1 racing. This page documents the architecture, components, and operation of the Expert System, which serves as the analytical core of the strategy platform.

For information on the machine learning models that feed into this system, see Machine Learning Models. For details on the specific rule types implemented, see Degradation Rules, Gap Analysis Rules, Radio Message Rules, and Integrated Rule Engine.

Expert System Architecture

The Expert System is built on the Experta library, which implements the RETE algorithm for efficient rule matching. The system follows a declarative programming paradigm where race conditions and strategy decisions are expressed as pattern-matching rules operating on a knowledge base of facts.

Core Components and Data Flow

The Expert System processes data through several stages before producing recommendations:

Fact Classes

The Expert System operates on a set of well-defined fact classes that represent different aspects of race state and analysis:

Fact Class Purpose Key Fields
TelemetryFact Car performance data lap_time, predicted_lap_time, tire_age, compound_id, position, driver_number
DegradationFact Tire condition degradation_rate, predicted_rates, previous_rates
GapFact Gaps to other cars gap_ahead, gap_behind, in_undercut_window, consistent_gap_ahead_laps
RadioFact NLP-analyzed team radio sentiment, intent, entities (WEATHER, PIT_CALL, etc.)
RaceStatusFact Overall race state lap, total_laps, race_phase (start/mid/end), track_status
StrategyRecommendation Generated advice action, confidence, explanation, priority

The fact classes form the data model that rules operate on, with each rule pattern-matching against specific fact attributes.

Specialized Rule Systems

The Expert System is modularized into four specialized rule systems, each focusing on a specific aspect of race strategy:

Degradation Rules System

Evaluates tire performance and degradation patterns to recommend pit stops or stint extensions. Key rules include:

  • high_degradation_pit_stop: Triggers when degradation rates exceed safe thresholds
  • stint_extension_recommendation: Suggests extending stint when tires perform better than expected
  • early_degradation_warning: Provides early warnings for preparing pit stops

Lap Time Rules System

Analyzes current and predicted lap times to identify performance patterns. Key rules include:

  • optimal_performance_window: Identifies periods of peak performance for push strategies
  • performance_cliff_detection: Detects sudden performance drops requiring immediate action
  • post_traffic_recovery: Suggests recovery strategies after being in traffic

Radio Analysis Rules System

Interprets team radio messages using NLP for strategic insights. Key rules include:

  • grip_issue_response: Responds to driver reports of grip problems
  • weather_information_adjustment: Adjusts strategy based on weather reports
  • incident_reaction: Adapts to incidents reported on track

Gap Analysis Rules System

Examines the gaps between cars to identify strategic opportunities. Key rules include:

Integrated Strategy Engine

The F1CompleteStrategyEngine class inherits from all specialized rule systems, creating a comprehensive strategy engine that can apply rules from any domain. This integrated approach allows for holistic race strategy evaluation.

The integrated engine also tracks which specialized systems are active during each analysis:

This tracking helps with conflict resolution and understanding which aspects of the strategy are most influential.

Conflict Resolution

A key feature of the F1CompleteStrategyEngine is its ability to resolve conflicting recommendations. When multiple rules fire and suggest contradictory actions, the conflict resolution system determines the optimal strategy.

The conflict resolution follows these steps:

  1. Group recommendations by driver number

  2. For each driver's recommendations:

    • Identify conflicting action pairs (e.g., can't both extend stint and pit)
    • For each conflict, compare priority and confidence values
    • Select the recommendation with higher priority/confidence
    • Enhance the explanation of selected recommendations

This approach ensures that drivers receive consistent, logical strategy advice even when multiple rules are triggered.

Data Transformation

Before rules can be applied, raw data must be transformed into fact objects. The transform_all_facts() function converts various data sources into fact instances:

  1. Tire prediction data: Converted to DegradationFact and TelemetryFact
  2. Lap time prediction data: Primarily affects TelemetryFact
  3. Gap data: Transformed into GapFact with consistency metrics
  4. Radio analysis: Converted to RadioFact
  5. Race status: Creates RaceStatusFact

Each transformation handles error conditions and ensures data consistency before creating fact objects.

End-to-End System Operation

The complete operation of the Expert System typically follows this sequence:

The analyze_strategy() function in scripts/IS_agent/utils/N06_rule_merging.py522-639 orchestrates this process, providing a complete pipeline from raw data to strategic recommendations.

Expert System Implementation and Integration

The Expert System is implemented across several Python files with the core components being:

  1. Base Engine and Facts: Defined in scripts/IS_agent/utils/N01_agent_setup.py

  2. Specialized Rule Systems: Defined in separate modules:

  3. Integrated Engine: Defined in scripts/IS_agent/utils/N06_rule_merging.py

The system is designed for flexibility, allowing it to be used with different data sources and in various contexts. It can be run on historical race data for analysis or in real-time during races to provide ongoing strategic guidance.

Strategic Actions and Prioritization

The Expert System generates recommendations with the following key action types:

Action Type Description Source Rule System
pit_stop Immediate pit stop needed Degradation/Lap Time
extend_stint Continue on current tires Degradation
prepare_pit Begin preparations for pit Degradation
consider_pit Evaluate pit stop options Degradation
push_strategy Increase pace for advantage Lap Time
recovery_push Push after traffic Lap Time
prioritize_pit Urgent pit stop Radio
prepare_rain_tires Ready for weather change Radio
perform_undercut Pit early to pass Gap
defensive_pit Pit to defend position Gap
perform_overcut Stay out longer to pass Gap

Each recommendation includes:

  • Action: What to do
  • Confidence: How certain the system is (0.0-1.0)
  • Explanation: Human-readable justification
  • Priority: Urgency level (higher = more urgent)

The get_recommendations() method sorts recommendations by priority and confidence, ensuring the most important actions are considered first.

Benefits of the Expert System Approach

The Expert System offers several advantages for F1 strategy management:

  1. Explainability: Rules provide clear explanations for recommendations
  2. Integration of Diverse Inputs: Combines numerical data with natural language information
  3. Domain Knowledge Encoding: Captures F1 strategic expertise in explicit rules
  4. Conflict Management: Resolves contradictory advice through principled prioritization
  5. Modularity: Specialized rule systems can be developed and maintained independently

These characteristics make the Expert System an ideal complement to the machine learning models, combining data-driven predictions with expert knowledge.

On this page