Iteration 1 - OR_EXPERT_REFINEMENT
Sequence: 3
Timestamp: 2025-07-27 23:24:02

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 theme park company wants to optimize the allocation of maintenance resources across its roller coasters to minimize downtime while ensuring safety standards are met. The company needs to decide how many maintenance hours to allocate to each roller coaster, considering constraints like maximum available maintenance hours and minimum safety requirements.",
  "optimization_problem": "The goal is to minimize the total downtime of roller coasters by optimally allocating maintenance hours. Each roller coaster has a specific maintenance requirement to ensure safety, and there is a limited number of maintenance hours available. The optimization will determine the number of maintenance hours allocated to each roller coaster to minimize downtime while meeting safety requirements.",
  "objective": "minimize total_downtime = \u2211(downtime_coefficient[i] \u00d7 maintenance_hours[i])",
  "table_count": 2,
  "key_changes": [
    "Schema changes include creating tables for decision variables, objective coefficients, and constraint bounds. Business configuration logic is updated to include scalar parameters and formulas for optimization constraints."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Gather missing data for downtime coefficients and maintenance hour constraints",
  "mapping_adequacy_summary": "needs_improvement"
}

CURRENT SCHEMA:
```sql
-- Iteration 1 Database Schema
-- Objective: Schema changes include creating tables for decision variables, objective coefficients, and constraint bounds. Business configuration logic is updated to include scalar parameters and formulas for optimization constraints.

CREATE TABLE roller_coaster_maintenance (
  roller_coaster_id INTEGER,
  hours FLOAT
);

CREATE TABLE downtime_coefficients (
  roller_coaster_id INTEGER,
  coefficient FLOAT
);


```

CURRENT DATA DICTIONARY:
{
  "tables": {
    "roller_coaster_maintenance": {
      "business_purpose": "Stores maintenance hours allocated to each roller coaster",
      "optimization_role": "decision_variables",
      "columns": {
        "roller_coaster_id": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each roller coaster",
          "optimization_purpose": "Identifies the roller coaster for maintenance allocation",
          "sample_values": "1, 2, 3"
        },
        "hours": {
          "data_type": "FLOAT",
          "business_meaning": "Number of maintenance hours allocated",
          "optimization_purpose": "Decision variable for maintenance allocation",
          "sample_values": "5.0, 10.0, 15.0"
        }
      }
    },
    "downtime_coefficients": {
      "business_purpose": "Represents downtime impact per maintenance hour for each roller coaster",
      "optimization_role": "objective_coefficients",
      "columns": {
        "roller_coaster_id": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each roller coaster",
          "optimization_purpose": "Identifies the roller coaster for downtime coefficient",
          "sample_values": "1, 2, 3"
        },
        "coefficient": {
          "data_type": "FLOAT",
          "business_meaning": "Impact of maintenance hours on downtime",
          "optimization_purpose": "Coefficient in the objective function",
          "sample_values": "0.5, 0.3, 0.2"
        }
      }
    }
  }
}


CURRENT BUSINESS CONFIGURATION LOGIC:
{
  "total_available_hours": {
    "sample_value": 100,
    "data_type": "INTEGER",
    "business_meaning": "Total number of maintenance hours available across all roller coasters",
    "optimization_role": "Constraint bound for total maintenance hours",
    "configuration_type": "scalar_parameter"
  },
  "minimum_required_hours_formula": {
    "formula_expression": "maintenance_hours[i] >= minimum_required_hours[i]",
    "data_type": "STRING",
    "business_meaning": "Ensures each roller coaster receives minimum maintenance hours for safety",
    "optimization_role": "Constraint formula for minimum maintenance hours",
    "configuration_type": "business_logic_formula"
  },
  "maximum_possible_hours_formula": {
    "formula_expression": "maintenance_hours[i] <= maximum_possible_hours[i]",
    "data_type": "STRING",
    "business_meaning": "Limits the maximum maintenance hours that can be allocated to each roller coaster",
    "optimization_role": "Constraint formula for maximum maintenance hours",
    "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": "roller_coaster",
  "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": "roller_coaster",
  "iteration": 1,
  "business_context": "A theme park company aims to optimize the allocation of maintenance resources across its roller coasters to minimize downtime while ensuring safety standards are met. The company needs to decide how many maintenance hours to allocate to each roller coaster, considering constraints like maximum available maintenance hours and minimum safety requirements.",
  "optimization_problem_description": "The goal is to minimize the total downtime of roller coasters by optimally allocating maintenance hours. Each roller coaster has a specific maintenance requirement to ensure safety, and there is a limited number of maintenance hours available. The optimization will determine the number of maintenance hours allocated to each roller coaster to minimize downtime while meeting safety requirements.",
  "optimization_formulation": {
    "objective": "minimize total_downtime = \u2211(downtime_coefficient[i] \u00d7 maintenance_hours[i])",
    "decision_variables": "maintenance_hours[i] for each roller coaster i, where maintenance_hours[i] is continuous",
    "constraints": [
      "\u2211(maintenance_hours[i]) <= total_available_hours",
      "maintenance_hours[i] >= minimum_required_hours[i] for each roller coaster i",
      "maintenance_hours[i] <= maximum_possible_hours[i] for each roller coaster i"
    ]
  },
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "downtime_coefficient[i]": {
        "currently_mapped_to": "downtime_coefficients.coefficient",
        "mapping_adequacy": "good",
        "description": "Impact of maintenance hours on downtime for each roller coaster"
      }
    },
    "constraint_bounds": {
      "total_available_hours": {
        "currently_mapped_to": "business_configuration_logic.total_available_hours",
        "mapping_adequacy": "good",
        "description": "Total number of maintenance hours available across all roller coasters"
      },
      "minimum_required_hours[i]": {
        "currently_mapped_to": "business_configuration_logic.minimum_required_hours_formula",
        "mapping_adequacy": "missing",
        "description": "Minimum maintenance hours required for safety for each roller coaster"
      },
      "maximum_possible_hours[i]": {
        "currently_mapped_to": "business_configuration_logic.maximum_possible_hours_formula",
        "mapping_adequacy": "missing",
        "description": "Maximum maintenance hours that can be allocated to each roller coaster"
      }
    },
    "decision_variables": {
      "maintenance_hours[i]": {
        "currently_mapped_to": "roller_coaster_maintenance.hours",
        "mapping_adequacy": "good",
        "description": "Number of maintenance hours allocated to each roller coaster",
        "variable_type": "continuous"
      }
    }
  },
  "missing_optimization_requirements": [
    "minimum_required_hours[i]",
    "maximum_possible_hours[i]"
  ],
  "iteration_status": {
    "complete": false,
    "confidence": "medium",
    "next_focus": "Gather missing data for minimum and maximum maintenance hour constraints"
  }
}
