Iteration 2 - OR_EXPERT_REFINEMENT
Sequence: 5
Timestamp: 2025-07-27 23:24:02

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 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": "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": 1,
  "key_changes": [
    "Schema adjustments include adding tables for minimum and maximum maintenance hours constraints, updating business configuration logic for scalar parameters and formulas, and ensuring all mappings are complete and adequate."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Gather missing data for minimum and maximum maintenance hour constraints",
  "mapping_adequacy_summary": "partially_adequate"
}

CURRENT SCHEMA:
```sql
-- Iteration 2 Database Schema
-- Objective: Schema adjustments include adding tables for minimum and maximum maintenance hours constraints, updating business configuration logic for scalar parameters and formulas, and ensuring all mappings are complete and adequate.

CREATE TABLE roller_coaster_maintenance (
  roller_coaster_id INTEGER,
  hours FLOAT
);

CREATE TABLE downtime_coefficients (
  roller_coaster_id INTEGER,
  coefficient FLOAT
);

CREATE TABLE maintenance_constraints (
  roller_coaster_id INTEGER,
  minimum_hours FLOAT,
  maximum_hours 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"
        }
      }
    },
    "maintenance_constraints": {
      "business_purpose": "Stores minimum and maximum maintenance hours constraints for each roller coaster",
      "optimization_role": "constraint_bounds",
      "columns": {
        "roller_coaster_id": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each roller coaster",
          "optimization_purpose": "Identifies the roller coaster for constraint application",
          "sample_values": "1, 2, 3"
        },
        "minimum_hours": {
          "data_type": "FLOAT",
          "business_meaning": "Minimum maintenance hours required for safety",
          "optimization_purpose": "Lower bound constraint for maintenance hours",
          "sample_values": "2.0, 3.0, 4.0"
        },
        "maximum_hours": {
          "data_type": "FLOAT",
          "business_meaning": "Maximum maintenance hours that can be allocated",
          "optimization_purpose": "Upper bound constraint for maintenance hours",
          "sample_values": "8.0, 10.0, 12.0"
        }
      }
    }
  }
}


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": 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": "roller_coaster",
  "iteration": 2,
  "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, continuous",
    "constraints": [
      "\u2211(maintenance_hours[i]) <= total_available_hours",
      "maintenance_hours[i] >= minimum_hours[i] for each roller coaster i",
      "maintenance_hours[i] <= maximum_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_hours[i]": {
        "currently_mapped_to": "maintenance_constraints.minimum_hours",
        "mapping_adequacy": "good",
        "description": "Minimum maintenance hours required for safety for each roller coaster"
      },
      "maximum_hours[i]": {
        "currently_mapped_to": "maintenance_constraints.maximum_hours",
        "mapping_adequacy": "good",
        "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": [],
  "iteration_status": {
    "complete": true,
    "confidence": "high",
    "next_focus": "Ready for convergence"
  }
}
