Iteration 1 - OR_EXPERT_REFINEMENT
Sequence: 3
Timestamp: 2025-07-27 22:09:50

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 campaign wants to optimize the allocation of resources to maximize the overall support rate for their candidate across different poll sources. The campaign can decide how much effort to allocate to each poll source to influence the support rate.",
  "optimization_problem": "The goal is to maximize the total support rate for a candidate by optimally allocating resources across different poll sources. The decision variables represent the level of effort allocated to each poll source, which influences the support rate. Constraints include budget limits, minimum and maximum effort levels, and ensuring that the total effort does not exceed available resources.",
  "objective": "maximize total_support_rate = \u2211(effort[i] * support_rate[i])",
  "table_count": 2,
  "key_changes": [
    "Schema changes include creating new tables for decision variables and constraint bounds, modifying existing tables to fill mapping gaps, and moving scalar parameters to configuration logic."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Refine the mapping of decision variables and constraints to existing schema or identify additional data requirements",
  "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, modifying existing tables to fill mapping gaps, and moving scalar parameters to configuration logic.

CREATE TABLE EffortAllocation (
  poll_source_id INTEGER,
  effort FLOAT
);

CREATE TABLE PollConstraints (
  poll_source_id INTEGER,
  min_effort FLOAT,
  max_effort FLOAT
);


```

CURRENT DATA DICTIONARY:
{
  "tables": {
    "EffortAllocation": {
      "business_purpose": "Stores the level of effort allocated to each poll source",
      "optimization_role": "decision_variables",
      "columns": {
        "poll_source_id": {
          "data_type": "INTEGER",
          "business_meaning": "Identifier for each poll source",
          "optimization_purpose": "Links effort to specific poll sources",
          "sample_values": "1, 2, 3"
        },
        "effort": {
          "data_type": "FLOAT",
          "business_meaning": "Level of effort allocated to the poll source",
          "optimization_purpose": "Decision variable in optimization",
          "sample_values": "10.5, 20.0, 15.0"
        }
      }
    },
    "PollConstraints": {
      "business_purpose": "Stores constraints for effort allocation to poll sources",
      "optimization_role": "constraint_bounds",
      "columns": {
        "poll_source_id": {
          "data_type": "INTEGER",
          "business_meaning": "Identifier for each poll source",
          "optimization_purpose": "Links constraints to specific poll sources",
          "sample_values": "1, 2, 3"
        },
        "min_effort": {
          "data_type": "FLOAT",
          "business_meaning": "Minimum effort required for the poll source",
          "optimization_purpose": "Lower bound constraint",
          "sample_values": "5.0, 10.0, 7.5"
        },
        "max_effort": {
          "data_type": "FLOAT",
          "business_meaning": "Maximum effort allowed for the poll source",
          "optimization_purpose": "Upper bound constraint",
          "sample_values": "20.0, 25.0, 30.0"
        }
      }
    }
  }
}


CURRENT BUSINESS CONFIGURATION LOGIC:
{
  "total_available_resources": {
    "sample_value": "1000",
    "data_type": "INTEGER",
    "business_meaning": "The total resources available for allocation",
    "optimization_role": "Used as a constraint in the optimization model",
    "configuration_type": "scalar_parameter"
  },
  "min_effort_formula": {
    "formula_expression": "effort[i] >= min_effort[i]",
    "data_type": "STRING",
    "business_meaning": "Ensures minimum effort is allocated to each poll source",
    "optimization_role": "Used as a constraint in the optimization model",
    "configuration_type": "business_logic_formula"
  },
  "max_effort_formula": {
    "formula_expression": "effort[i] <= max_effort[i]",
    "data_type": "STRING",
    "business_meaning": "Ensures maximum effort is not exceeded for each poll source",
    "optimization_role": "Used as a constraint in the optimization model",
    "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": "candidate_poll",
  "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": "candidate_poll",
  "iteration": 1,
  "business_context": "A political campaign is optimizing resource allocation to maximize support rates across different poll sources, ensuring efficient use of limited resources.",
  "optimization_problem_description": "Maximize the total support rate by allocating resources to various poll sources, subject to budget constraints and effort limits.",
  "optimization_formulation": {
    "objective": "maximize total_support_rate = \u2211(effort[i] * support_rate[i])",
    "decision_variables": "effort[i] for each poll source i, representing the level of effort allocated (continuous)",
    "constraints": [
      "\u2211(effort[i]) <= total_available_resources",
      "effort[i] >= min_effort[i] for each poll source i",
      "effort[i] <= max_effort[i] for each poll source i"
    ]
  },
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "support_rate[i]": {
        "currently_mapped_to": "missing",
        "mapping_adequacy": "missing",
        "description": "The support rate coefficient for each poll source, needed to calculate the weighted sum in the objective function"
      }
    },
    "constraint_bounds": {
      "total_available_resources": {
        "currently_mapped_to": "business_configuration_logic.total_available_resources",
        "mapping_adequacy": "good",
        "description": "The total resources available for allocation"
      },
      "min_effort[i]": {
        "currently_mapped_to": "PollConstraints.min_effort",
        "mapping_adequacy": "good",
        "description": "Minimum effort required for each poll source"
      },
      "max_effort[i]": {
        "currently_mapped_to": "PollConstraints.max_effort",
        "mapping_adequacy": "good",
        "description": "Maximum effort allowed for each poll source"
      }
    },
    "decision_variables": {
      "effort[i]": {
        "currently_mapped_to": "EffortAllocation.effort",
        "mapping_adequacy": "good",
        "description": "Level of effort allocated to each poll source",
        "variable_type": "continuous"
      }
    }
  },
  "missing_optimization_requirements": [
    "support_rate[i] for each poll source"
  ],
  "iteration_status": {
    "complete": false,
    "confidence": "medium",
    "next_focus": "Identify and map support_rate[i] for each poll source to complete the linear formulation"
  }
}
