Iteration 2 - OR_EXPERT_REFINEMENT
Sequence: 5
Timestamp: 2025-07-25 22:31:46

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": "An orchestra management company aims to maximize total attendance across all shows by optimizing the number of performances each orchestra conducts, while adhering to constraints on conductor availability and minimum performance ratings.",
  "optimization_problem": "Maximize total attendance by determining the optimal number of performances for each orchestra, subject to constraints on conductor availability, minimum performance ratings, and performance limits per orchestra.",
  "objective": "maximize \u2211(Attendance \u00d7 Number_of_Performances)",
  "table_count": 1,
  "key_changes": [
    "Added attendance table to map attendance data per performance for each orchestra, ensuring the objective function is complete. No tables were deleted or modified as existing tables adequately map to the optimization requirements."
  ],
  "math_consistency": "high",
  "next_iteration_focus": "Identify and map attendance data for each orchestra to complete the objective function",
  "mapping_adequacy_summary": "mostly_good"
}

CURRENT SCHEMA:
```sql
-- Iteration 2 Database Schema
-- Objective: Added attendance table to map attendance data per performance for each orchestra, ensuring the objective function is complete. No tables were deleted or modified as existing tables adequately map to the optimization requirements.

CREATE TABLE attendance (
  Orchestra_ID INTEGER,
  Attendance INTEGER
);

CREATE TABLE conductor_availability (
  Conductor_ID INTEGER,
  Total_Availability INTEGER
);

CREATE TABLE performance_ratings (
  Performance_ID INTEGER,
  Minimum_Rating FLOAT
);

CREATE TABLE performance_limits (
  Orchestra_ID INTEGER,
  Maximum_Performances INTEGER,
  Minimum_Performances INTEGER,
  Number_of_Performances INTEGER
);


```

CURRENT DATA DICTIONARY:
{
  "tables": {
    "attendance": {
      "business_purpose": "Attendance per performance for each orchestra",
      "optimization_role": "objective_coefficients",
      "columns": {
        "Orchestra_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each orchestra",
          "optimization_purpose": "Index for attendance data",
          "sample_values": [
            1,
            2,
            3
          ]
        },
        "Attendance": {
          "data_type": "INTEGER",
          "business_meaning": "Attendance per performance for the orchestra",
          "optimization_purpose": "Coefficient for objective function",
          "sample_values": [
            500,
            600,
            450
          ]
        }
      }
    },
    "conductor_availability": {
      "business_purpose": "Total availability of each conductor",
      "optimization_role": "constraint_bounds",
      "columns": {
        "Conductor_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each conductor",
          "optimization_purpose": "Index for conductor availability constraint",
          "sample_values": [
            1,
            2,
            3
          ]
        },
        "Total_Availability": {
          "data_type": "INTEGER",
          "business_meaning": "Total availability hours for the conductor",
          "optimization_purpose": "Constraint bound for conductor availability",
          "sample_values": [
            100,
            120,
            80
          ]
        }
      }
    },
    "performance_ratings": {
      "business_purpose": "Minimum required rating for each performance",
      "optimization_role": "constraint_bounds",
      "columns": {
        "Performance_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each performance",
          "optimization_purpose": "Index for performance rating constraint",
          "sample_values": [
            1,
            2,
            3
          ]
        },
        "Minimum_Rating": {
          "data_type": "FLOAT",
          "business_meaning": "Minimum required rating for the performance",
          "optimization_purpose": "Constraint bound for performance ratings",
          "sample_values": [
            5.0,
            6.0,
            4.5
          ]
        }
      }
    },
    "performance_limits": {
      "business_purpose": "Maximum and minimum number of performances allowed per orchestra",
      "optimization_role": "constraint_bounds",
      "columns": {
        "Orchestra_ID": {
          "data_type": "INTEGER",
          "business_meaning": "Unique identifier for each orchestra",
          "optimization_purpose": "Index for performance limits constraint",
          "sample_values": [
            1,
            2,
            3
          ]
        },
        "Maximum_Performances": {
          "data_type": "INTEGER",
          "business_meaning": "Maximum number of performances allowed per orchestra",
          "optimization_purpose": "Constraint bound for performance limits",
          "sample_values": [
            10,
            12,
            8
          ]
        },
        "Minimum_Performances": {
          "data_type": "INTEGER",
          "business_meaning": "Minimum number of performances required per orchestra",
          "optimization_purpose": "Constraint bound for performance limits",
          "sample_values": [
            1,
            2,
            1
          ]
        },
        "Number_of_Performances": {
          "data_type": "INTEGER",
          "business_meaning": "Number of performances each orchestra should conduct",
          "optimization_purpose": "Decision variable for optimization",
          "sample_values": [
            5,
            6,
            4
          ]
        }
      }
    }
  }
}



TASK: Refine the optimization problem formulation by analyzing current data schema mapping and identifying requirements while maintaining LINEAR structure.

JSON STRUCTURE REQUIRED:

{
  "database_id": "orchestra",
  "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": "orchestra",
  "iteration": 2,
  "business_context": "An orchestra management company aims to maximize total attendance across all shows by optimizing the number of performances each orchestra conducts, while adhering to constraints on conductor availability, minimum performance ratings, and performance limits per orchestra.",
  "optimization_problem_description": "Maximize total attendance by determining the optimal number of performances for each orchestra, subject to constraints on conductor availability, minimum performance ratings, and performance limits per orchestra.",
  "optimization_formulation": {
    "objective": "maximize \u2211(Attendance[Orchestra_ID] \u00d7 Number_of_Performances[Orchestra_ID])",
    "decision_variables": "Number_of_Performances[Orchestra_ID] (integer)",
    "constraints": [
      "\u2211(Number_of_Performances[Orchestra_ID]) \u2264 Total_Availability[Conductor_ID]",
      "Number_of_Performances[Orchestra_ID] \u2265 Minimum_Performances[Orchestra_ID]",
      "Number_of_Performances[Orchestra_ID] \u2264 Maximum_Performances[Orchestra_ID]"
    ]
  },
  "current_optimization_to_schema_mapping": {
    "objective_coefficients": {
      "Attendance[Orchestra_ID]": {
        "currently_mapped_to": "attendance.Attendance",
        "mapping_adequacy": "good",
        "description": "Attendance per performance for each orchestra"
      }
    },
    "constraint_bounds": {
      "Total_Availability[Conductor_ID]": {
        "currently_mapped_to": "conductor_availability.Total_Availability",
        "mapping_adequacy": "good",
        "description": "Total availability hours for each conductor"
      },
      "Minimum_Performances[Orchestra_ID]": {
        "currently_mapped_to": "performance_limits.Minimum_Performances",
        "mapping_adequacy": "good",
        "description": "Minimum number of performances required per orchestra"
      },
      "Maximum_Performances[Orchestra_ID]": {
        "currently_mapped_to": "performance_limits.Maximum_Performances",
        "mapping_adequacy": "good",
        "description": "Maximum number of performances allowed per orchestra"
      }
    },
    "decision_variables": {
      "Number_of_Performances[Orchestra_ID]": {
        "currently_mapped_to": "performance_limits.Number_of_Performances",
        "mapping_adequacy": "good",
        "description": "Number of performances each orchestra should conduct",
        "variable_type": "integer"
      }
    }
  },
  "missing_optimization_requirements": [],
  "iteration_status": {
    "complete": true,
    "confidence": "high",
    "next_focus": "Ready for convergence"
  }
}
