Iteration 2 - OR_EXPERT_REFINEMENT
Sequence: 5
Timestamp: 2025-07-25 22:47:17

Prompt:
You are an Operations Research (OR) expert in iteration 2 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 1):
{
  "iteration": 2,
  "converged": false,
  "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": "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.",
  "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 audience size, updating business configuration logic to include missing scalar parameters, and ensuring all optimization requirements are mapped correctly."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Identify and map the missing data for Num_of_Audience[Debate_ID] and the constraint bound '1' to ensure a complete linear formulation.",
  "mapping_adequacy_summary": "partially_adequate"
}

CURRENT SCHEMA:
```sql
-- Iteration 2 Database Schema
-- Objective: Schema changes include creating a new table for audience size, updating business configuration logic to include missing scalar parameters, and ensuring all optimization requirements are mapped correctly.

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

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

CREATE TABLE audience_size (
  Debate_ID INTEGER,
  Num_of_Audience 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"
        }
      }
    },
    "audience_size": {
      "business_purpose": "Represents the number of audience members for each debate.",
      "optimization_role": "objective_coefficients",
      "columns": {
        "Debate_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Identifier for the debate.",
          "optimization_purpose": "Used to link audience size to specific debates.",
          "sample_values": "1, 2, 3"
        },
        "Num_of_Audience": {
          "data_type": "INTEGER",
          "business_meaning": "Number of audience members for the debate.",
          "optimization_purpose": "Used to weight the audience engagement in the objective function.",
          "sample_values": "100, 150, 200"
        }
      }
    }
  }
}


CURRENT BUSINESS CONFIGURATION LOGIC:
{
  "num_of_audience": {
    "sample_value": 100,
    "data_type": "INTEGER",
    "business_meaning": "Number of audience members for each debate.",
    "optimization_role": "Used to weight the audience engagement in the objective function.",
    "configuration_type": "scalar_parameter"
  },
  "constraint_bound_1": {
    "sample_value": 1,
    "data_type": "INTEGER",
    "business_meaning": "Limit on the number of debates a participant can join.",
    "optimization_role": "Used in the constraint to limit debate participation.",
    "configuration_type": "scalar_parameter"
  }
}


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": 2,
  "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": 2,
  "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(Num_of_Audience[Debate_ID] \u00d7 Assignment[Debate_ID, People_ID, Side])",
    "decision_variables": "Assignment[Debate_ID, People_ID, Side] (binary: 1 if participant is assigned to debate on a specific side, 0 otherwise)",
    "constraints": [
      "\u2211(Assignment[Debate_ID, People_ID, Side]) \u2264 1 for each People_ID (limit on number of debates per participant)",
      "\u2211(Assignment[Debate_ID, People_ID, 'Affirmative']) = \u2211(Assignment[Debate_ID, People_ID, 'Negative']) for each Debate_ID (balance between sides)",
      "\u2211(Assignment[Debate_ID, People_ID, Side]) \u2265 1 for each Debate_ID (ensure at least one participant per debate)",
      "\u2211(Assignment[Debate_ID, People_ID, Side]) \u2264 Age[People_ID] / 25 for each People_ID (age-based constraint)"
    ]
  },
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "Num_of_Audience[Debate_ID]": {
        "currently_mapped_to": "audience_size.Num_of_Audience",
        "mapping_adequacy": "good",
        "description": "Number of audience members for each debate, used to weight the audience engagement in the objective function."
      }
    },
    "constraint_bounds": {
      "constraint_bound_1[People_ID]": {
        "currently_mapped_to": "business_configuration_logic.constraint_bound_1",
        "mapping_adequacy": "good",
        "description": "Limit on the number of debates a participant can join."
      }
    },
    "decision_variables": {
      "Assignment[Debate_ID, People_ID, Side]": {
        "currently_mapped_to": "participant_assignment",
        "mapping_adequacy": "good",
        "description": "Binary decision variable indicating whether a participant is assigned to a specific debate on a specific side.",
        "variable_type": "binary"
      }
    }
  },
  "missing_optimization_requirements": [],
  "iteration_status": {
    "complete": true,
    "confidence": "high",
    "next_focus": "Ready for convergence"
  }
}
