Iteration 1 - OR_EXPERT_REFINEMENT
Sequence: 3
Timestamp: 2025-07-25 22:32:36

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 political party aims to maximize its influence across regions by strategically allocating its members to events. The party wants to ensure that each region is adequately represented while minimizing the total cost of organizing these events.",
  "optimization_problem": "The optimization problem involves maximizing the total influence of the party across regions by assigning members to events, while ensuring that the total cost of organizing events does not exceed a predefined budget. The influence is measured by the number of members assigned to events in each region, and the cost is determined by the number of events organized.",
  "objective": "maximize \u2211(influence_coefficient[region] \u00d7 number_of_members_assigned[region])",
  "table_count": 3,
  "key_changes": [
    "Schema changes include creating new tables for decision variables and constraint bounds, and updating business configuration logic for scalar parameters and formulas."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Define and map the missing coefficients and constraints to the existing schema or business configuration logic.",
  "mapping_adequacy_summary": "needs_improvement"
}

CURRENT SCHEMA:
```sql
-- Iteration 1 Database Schema
-- Objective: Schema changes include creating new tables for decision variables and constraint bounds, and updating business configuration logic for scalar parameters and formulas.

CREATE TABLE region_members (
  region_id INTEGER,
  number_of_members INTEGER
);

CREATE TABLE region_events (
  region_id INTEGER,
  number_of_events INTEGER
);

CREATE TABLE region_constraints (
  region_id INTEGER,
  total_members_available INTEGER,
  max_events INTEGER,
  min_members INTEGER,
  min_events INTEGER,
  influence_coefficient FLOAT
);


```

CURRENT DATA DICTIONARY:
{
  "tables": {
    "region_members": {
      "business_purpose": "Number of members assigned to events in each region.",
      "optimization_role": "decision_variables",
      "columns": {
        "region_id": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for the region.",
          "optimization_purpose": "Index for decision variable.",
          "sample_values": "1, 2, 3"
        },
        "number_of_members": {
          "data_type": "INTEGER",
          "business_meaning": "Number of members assigned to events in the region.",
          "optimization_purpose": "Decision variable for optimization.",
          "sample_values": "10, 15, 20"
        }
      }
    },
    "region_events": {
      "business_purpose": "Number of events organized in each region.",
      "optimization_role": "decision_variables",
      "columns": {
        "region_id": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for the region.",
          "optimization_purpose": "Index for decision variable.",
          "sample_values": "1, 2, 3"
        },
        "number_of_events": {
          "data_type": "INTEGER",
          "business_meaning": "Number of events organized in the region.",
          "optimization_purpose": "Decision variable for optimization.",
          "sample_values": "2, 3, 4"
        }
      }
    },
    "region_constraints": {
      "business_purpose": "Constraints on members and events per region.",
      "optimization_role": "constraint_bounds",
      "columns": {
        "region_id": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for the region.",
          "optimization_purpose": "Index for constraint bounds.",
          "sample_values": "1, 2, 3"
        },
        "total_members_available": {
          "data_type": "INTEGER",
          "business_meaning": "Total number of members available in the region.",
          "optimization_purpose": "Upper bound for member assignment constraint.",
          "sample_values": "20, 25, 30"
        },
        "max_events": {
          "data_type": "INTEGER",
          "business_meaning": "Maximum number of events that can be organized in the region.",
          "optimization_purpose": "Upper bound for event organization constraint.",
          "sample_values": "5, 6, 7"
        },
        "min_members": {
          "data_type": "INTEGER",
          "business_meaning": "Minimum number of members that must be assigned to the region.",
          "optimization_purpose": "Lower bound for member assignment constraint.",
          "sample_values": "5, 6, 7"
        },
        "min_events": {
          "data_type": "INTEGER",
          "business_meaning": "Minimum number of events that must be organized in the region.",
          "optimization_purpose": "Lower bound for event organization constraint.",
          "sample_values": "1, 2, 3"
        },
        "influence_coefficient": {
          "data_type": "FLOAT",
          "business_meaning": "Impact of assigning a member to an event in the region.",
          "optimization_purpose": "Coefficient in the objective function.",
          "sample_values": "0.5, 0.6, 0.7"
        }
      }
    }
  }
}


CURRENT BUSINESS CONFIGURATION LOGIC:
{
  "total_budget": {
    "sample_value": 100000,
    "data_type": "INTEGER",
    "business_meaning": "The total budget available for organizing events.",
    "optimization_role": "Upper bound for total cost constraint.",
    "configuration_type": "scalar_parameter"
  },
  "cost_per_event": {
    "sample_value": 5000,
    "data_type": "INTEGER",
    "business_meaning": "The cost of organizing a single event in a region.",
    "optimization_role": "Used in total cost constraint calculation.",
    "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": "party_people",
  "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": "party_people",
  "iteration": 1,
  "business_context": "A political party aims to maximize its influence across regions by strategically allocating its members to events. The party wants to ensure that each region is adequately represented while minimizing the total cost of organizing these events. Influence is measured by the number of members assigned to events in each region, and the cost is determined by the number of events organized.",
  "optimization_problem_description": "Maximize the total influence of the party across regions by assigning members to events, while ensuring that the total cost of organizing events does not exceed a predefined budget. The problem is formulated as a linear optimization problem with linear objective and constraints.",
  "optimization_formulation": {
    "objective": "maximize \u2211(influence_coefficient[region] \u00d7 number_of_members_assigned[region])",
    "decision_variables": {
      "number_of_members_assigned[region]": "Number of members assigned to events in each region (integer)",
      "number_of_events[region]": "Number of events organized in each region (integer)"
    },
    "constraints": [
      "\u2211(cost_per_event \u00d7 number_of_events[region]) \u2264 total_budget",
      "number_of_members_assigned[region] \u2264 total_members_available[region] for all regions",
      "number_of_members_assigned[region] \u2265 min_members[region] for all regions",
      "number_of_events[region] \u2264 max_events[region] for all regions",
      "number_of_events[region] \u2265 min_events[region] for all regions"
    ]
  },
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "influence_coefficient[region]": {
        "currently_mapped_to": "region_constraints.influence_coefficient",
        "mapping_adequacy": "good",
        "description": "Impact of assigning a member to an event in the region."
      }
    },
    "constraint_bounds": {
      "total_budget": {
        "currently_mapped_to": "business_configuration_logic.total_budget",
        "mapping_adequacy": "good",
        "description": "Upper bound for total cost constraint."
      },
      "total_members_available[region]": {
        "currently_mapped_to": "region_constraints.total_members_available",
        "mapping_adequacy": "good",
        "description": "Upper bound for member assignment constraint."
      },
      "min_members[region]": {
        "currently_mapped_to": "region_constraints.min_members",
        "mapping_adequacy": "good",
        "description": "Lower bound for member assignment constraint."
      },
      "max_events[region]": {
        "currently_mapped_to": "region_constraints.max_events",
        "mapping_adequacy": "good",
        "description": "Upper bound for event organization constraint."
      },
      "min_events[region]": {
        "currently_mapped_to": "region_constraints.min_events",
        "mapping_adequacy": "good",
        "description": "Lower bound for event organization constraint."
      }
    },
    "decision_variables": {
      "number_of_members_assigned[region]": {
        "currently_mapped_to": "region_members.number_of_members",
        "mapping_adequacy": "good",
        "description": "Number of members assigned to events in the region.",
        "variable_type": "integer"
      },
      "number_of_events[region]": {
        "currently_mapped_to": "region_events.number_of_events",
        "mapping_adequacy": "good",
        "description": "Number of events organized in the region.",
        "variable_type": "integer"
      }
    }
  },
  "missing_optimization_requirements": [],
  "iteration_status": {
    "complete": true,
    "confidence": "high",
    "next_focus": "Ready for convergence"
  }
}
