Iteration 1 - OR_EXPERT_REFINEMENT
Sequence: 3
Timestamp: 2025-07-25 22:47:17

Prompt:
You are an Operations Research (OR) expert in iteration 1 of an alternating optimization process. The algorithm alternates between OR expert analysis and data engineering implementation until convergence.

CRITICAL MATHEMATICAL CONSTRAINTS FOR LINEAR/MIXED-INTEGER PROGRAMMING:
- The optimization problem MUST remain Linear Programming (LP) or Mixed-Integer Programming (MIP)
- Objective function MUST be linear: minimize/maximize ∑(coefficient × variable)
- All constraints MUST be linear: ∑(coefficient × variable) ≤/≥/= constant
- Decision variables can be continuous (LP) or mixed continuous/integer (MIP)
- NO variable products, divisions, or other nonlinear relationships
- If previous iteration introduced nonlinear elements, redesign as linear formulation
- Maintain between 2 and 20 constraints for optimization feasibility

YOUR SCOPE: Focus exclusively on optimization modeling and mapping analysis. Do NOT propose database changes.
ROW COUNT AWARENESS: Understand that data engineer applies 3-row minimum rule - insufficient table data gets moved to business_configuration_logic.json.


DATA AVAILABILITY CHECK: 
Before listing missing requirements, verify:
- Check current schema for required data columns
- Check business configuration logic for required parameters  
- Only list as "missing" if data is truly unavailable
- If all mappings are "good", missing_requirements should be []

CONSISTENCY RULES:
- IF all mapping_adequacy == "good" THEN missing_optimization_requirements = []
- IF missing_optimization_requirements = [] THEN complete CAN be true
- IF complete == true THEN confidence should be "high"

SELF-CHECK: Before responding, verify:
1. Does current schema contain the data I claim is missing?
2. Are my mapping assessments consistent with missing requirements?
3. Is my complete status consistent with missing requirements?

MAPPING COMPLETENESS CHECK: Ensure logical consistency between:
- All objective coefficients mapped with adequacy evaluation
- All constraint bounds mapped with adequacy evaluation  
- All decision variables mapped with adequacy evaluation
- Missing requirements list matches inadequate mappings only


CRITICAL: Respond with ONLY a valid JSON object. No explanations, no markdown, no extra text.



CURRENT STATE (iteration 0):
{
  "iteration": 1,
  "converged": false,
  "business_context": "A debate organization wants to maximize the total audience engagement across multiple debates by strategically assigning participants from different districts and parties, ensuring diversity and fairness in representation.",
  "optimization_problem": "The goal is to maximize the total audience engagement by assigning participants to debates in a way that ensures diversity in district and party representation, while respecting constraints on the number of debates each participant can join and the balance between affirmative and negative sides.",
  "objective": "maximize \u2211(Audience_Engagement[Debate_ID] \u00d7 Num_of_Audience[Debate_ID])",
  "table_count": 1,
  "key_changes": [
    "Schema changes include creating a new table for decision variables, updating the people table to include age constraints, and adding a business configuration logic file for audience engagement metrics and formulas."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Refine constraints to ensure diversity and fairness in participant assignments.",
  "mapping_adequacy_summary": "mostly_good"
}

CURRENT SCHEMA:
```sql
-- Iteration 1 Database Schema
-- Objective: Schema changes include creating a new table for decision variables, updating the people table to include age constraints, and adding a business configuration logic file for audience engagement metrics and formulas.

CREATE TABLE participant_assignment (
  Debate_ID INTEGER,
  People_ID INTEGER,
  Side STRING
);

CREATE TABLE people (
  People_ID INTEGER,
  District STRING,
  Party STRING,
  Age INTEGER
);


```

CURRENT DATA DICTIONARY:
{
  "tables": {
    "participant_assignment": {
      "business_purpose": "Represents the assignment of participants to debates on specific sides.",
      "optimization_role": "decision_variables",
      "columns": {
        "Debate_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Identifier for the debate.",
          "optimization_purpose": "Used to link participants to specific debates.",
          "sample_values": "1, 2, 3"
        },
        "People_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Identifier for the participant.",
          "optimization_purpose": "Used to link participants to specific debates.",
          "sample_values": "101, 102, 103"
        },
        "Side": {
          "data_type": "STRING",
          "business_meaning": "The side (Affirmative/Negative) the participant is assigned to.",
          "optimization_purpose": "Used to ensure balance between sides in debates.",
          "sample_values": "Affirmative, Negative"
        }
      }
    },
    "people": {
      "business_purpose": "Represents the participants in the debates.",
      "optimization_role": "business_data",
      "columns": {
        "People_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Identifier for the participant.",
          "optimization_purpose": "Used to link participants to specific debates.",
          "sample_values": "101, 102, 103"
        },
        "District": {
          "data_type": "STRING",
          "business_meaning": "The district the participant represents.",
          "optimization_purpose": "Used to ensure diversity in district representation.",
          "sample_values": "District A, District B, District C"
        },
        "Party": {
          "data_type": "STRING",
          "business_meaning": "The party the participant represents.",
          "optimization_purpose": "Used to ensure diversity in party representation.",
          "sample_values": "Party X, Party Y, Party Z"
        },
        "Age": {
          "data_type": "INTEGER",
          "business_meaning": "The age of the participant.",
          "optimization_purpose": "Used to limit the number of debates a participant can join.",
          "sample_values": "25, 30, 35"
        }
      }
    }
  }
}


CURRENT BUSINESS CONFIGURATION LOGIC:
{
  "audience_engagement_metric": {
    "sample_value": 0.75,
    "data_type": "FLOAT",
    "business_meaning": "Represents the engagement level of the audience for each debate.",
    "optimization_role": "Used to weight the audience size in the objective function.",
    "configuration_type": "scalar_parameter"
  },
  "age_constraint_formula": {
    "formula_expression": "Age / 20",
    "data_type": "STRING",
    "business_meaning": "Limits the number of debates a participant can join based on their age.",
    "optimization_role": "Used in the age constraint to limit debate participation.",
    "configuration_type": "business_logic_formula"
  }
}


TASK: Refine the optimization problem formulation by analyzing current data schema mapping and identifying requirements while maintaining LINEAR structure.

JSON STRUCTURE REQUIRED:

{
  "database_id": "debate",
  "iteration": 1,
  "business_context": "Updated realistic business scenario description that supports linear optimization",
  "optimization_problem_description": "Refined description of LINEAR optimization problem", 
  "optimization_formulation": {
    "objective": "refined linear minimize/maximize with mathematical precision (sum of weighted variables only)",
    "decision_variables": "clearly defined controllable linear variables (continuous or integer)",
    "constraints": "mathematically precise LINEAR constraint definitions (no variable products or divisions) - maintain 2 to 20 constraints"
  },
  
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "coefficient_name[indices]": {
        "currently_mapped_to": "table.column OR business_configuration_logic.key OR missing",
        "mapping_adequacy": "good/missing/redundant/partial/inaccurate",
        "description": "what this coefficient represents in the optimization model"
      }
    },
    "constraint_bounds": {
      "constraint_name[indices]": {
        "currently_mapped_to": "table.column OR business_configuration_logic.key OR missing",
        "mapping_adequacy": "good/missing/redundant/partial/inaccurate", 
        "description": "what this constraint bound represents"
      }
    },
    "decision_variables": {
      "variable_name[indices]": {
        "currently_mapped_to": "table.column OR business_configuration_logic.key OR missing",
        "mapping_adequacy": "good/missing/redundant/partial/inaccurate",
        "description": "what this decision variable represents",
        "variable_type": "continuous/integer/binary"
      }
    }
  },
  
  "missing_optimization_requirements": [
    "List what data/parameters are still needed for linear formulation (should be [] if all mappings are good)"
  ],
  
  "iteration_status": {
    "complete": true/false based on linear formulation completeness,
    "confidence": "updated confidence level",
    "next_focus": "What needs refinement for linear optimization OR 'Ready for convergence'"
  }
}

Response:
{
  "database_id": "debate",
  "iteration": 1,
  "business_context": "A debate organization aims to maximize total audience engagement by strategically assigning participants from various districts and parties to debates, ensuring diversity and fairness in representation while adhering to constraints on participant age and debate side balance.",
  "optimization_problem_description": "Maximize total audience engagement by assigning participants to debates, ensuring diversity in district and party representation, and balancing affirmative and negative sides, while respecting age-based constraints on the number of debates each participant can join.",
  "optimization_formulation": {
    "objective": "maximize \u2211(Audience_Engagement[Debate_ID] \u00d7 Num_of_Audience[Debate_ID])",
    "decision_variables": "participant_assignment[Debate_ID, People_ID, Side] (binary)",
    "constraints": [
      "\u2211(participant_assignment[Debate_ID, People_ID, Side]) \u2264 Age[People_ID] / 20 for each People_ID",
      "\u2211(participant_assignment[Debate_ID, People_ID, 'Affirmative']) = \u2211(participant_assignment[Debate_ID, People_ID, 'Negative']) for each Debate_ID",
      "\u2211(participant_assignment[Debate_ID, People_ID, Side]) \u2264 1 for each People_ID",
      "\u2211(participant_assignment[Debate_ID, People_ID, Side]) \u2265 1 for each Debate_ID"
    ]
  },
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "Audience_Engagement[Debate_ID]": {
        "currently_mapped_to": "business_configuration_logic.audience_engagement_metric",
        "mapping_adequacy": "good",
        "description": "Engagement level of the audience for each debate."
      },
      "Num_of_Audience[Debate_ID]": {
        "currently_mapped_to": "missing",
        "mapping_adequacy": "missing",
        "description": "Number of audience members for each debate."
      }
    },
    "constraint_bounds": {
      "Age[People_ID] / 20": {
        "currently_mapped_to": "people.Age",
        "mapping_adequacy": "good",
        "description": "Age-based limit on the number of debates a participant can join."
      },
      "1": {
        "currently_mapped_to": "missing",
        "mapping_adequacy": "missing",
        "description": "Limit on the number of debates a participant can join."
      }
    },
    "decision_variables": {
      "participant_assignment[Debate_ID, People_ID, Side]": {
        "currently_mapped_to": "participant_assignment.Debate_ID, participant_assignment.People_ID, participant_assignment.Side",
        "mapping_adequacy": "good",
        "description": "Assignment of participants to debates on specific sides.",
        "variable_type": "binary"
      }
    }
  },
  "missing_optimization_requirements": [
    "Num_of_Audience[Debate_ID]",
    "1 (constraint bound)"
  ],
  "iteration_status": {
    "complete": false,
    "confidence": "medium",
    "next_focus": "Identify and map the missing data for Num_of_Audience[Debate_ID] and the constraint bound '1' to ensure a complete linear formulation."
  }
}
