# Complete Optimization Problem and Solution: train_station

## 1. Problem Context and Goals

### Context  
The train station optimization problem focuses on efficiently assigning trains to stations to minimize passenger waiting times while adhering to operational constraints. The primary decision involves determining whether a specific train should be assigned to a particular station, represented as a binary choice. The operational parameters include the waiting time of passengers at each station for a specific train and the number of passengers waiting for that train. These parameters are used to calculate the total waiting time, which is the metric to be minimized.  

The business configuration includes a maximum allowed waiting time for passengers, set at 15 minutes, which serves as a constraint to ensure passenger satisfaction and operational efficiency. Additionally, the passenger waiting time is calculated based on the difference between the train's arrival and departure times at a station. This calculation is a linear relationship and is used to determine the coefficients in the optimization objective.  

The problem is designed to avoid nonlinear relationships, such as variable products or divisions, ensuring that the formulation remains linear. The data sources, including passenger waiting times, passenger counts, and station platform capacities, are mapped directly to the coefficients and constraints in the optimization problem.  

### Goals  
The primary goal of this optimization problem is to minimize the total passenger waiting time across all stations. This is achieved by optimally assigning trains to stations, considering the number of passengers and their waiting times. Success is measured by reducing the overall waiting time while ensuring that no station exceeds its platform capacity and that the maximum waiting time constraint is not violated. The optimization aligns with the business objective of improving passenger satisfaction and operational efficiency through linear decision-making.  

## 2. Constraints  

The optimization problem is subject to two key constraints:  

1. **Platform Capacity Constraint**: For each station, the total number of trains assigned must not exceed the number of available platforms. This ensures that stations do not become overcrowded and can handle the assigned trains efficiently.  

2. **Maximum Waiting Time Constraint**: For each train assigned to a station, the waiting time of passengers must not exceed the maximum allowed waiting time of 15 minutes. This constraint ensures that passenger satisfaction is maintained by preventing excessive delays.  

Both constraints are expressed in linear terms, avoiding any nonlinear relationships such as variable products or divisions. They are directly derived from the operational limitations and business configuration parameters.  

## 3. Available Data  

### Database Schema  
```sql
-- Iteration 2 Database Schema
-- Objective: Schema changes include creating a table for train assignments, updating existing tables to include train and station IDs, and moving passenger waiting time formula to configuration logic. Configuration logic updates include scalar parameters for maximum waiting time and formulas for passenger waiting time calculations.

CREATE TABLE passenger_waiting_time (
  Train_ID INTEGER,
  Station_ID INTEGER,
  Waiting_Time INTEGER
);

CREATE TABLE number_of_passengers (
  Train_ID INTEGER,
  Station_ID INTEGER,
  Passenger_Count INTEGER
);

CREATE TABLE station (
  Number_of_Platforms INTEGER
);

CREATE TABLE train_assignment (
  Train_ID INTEGER,
  Station_ID INTEGER,
  Assignment BOOLEAN
);
```

### Data Dictionary  
- **Passenger Waiting Time**:  
  - **Business Purpose**: Represents the waiting time in minutes for passengers at a specific station for a particular train.  
  - **Optimization Role**: Used as a coefficient in the objective function to calculate the total waiting time.  

- **Number of Passengers**:  
  - **Business Purpose**: Indicates the number of passengers waiting for a specific train at a station.  
  - **Optimization Role**: Used as a weight in the objective function to prioritize trains with higher passenger counts.  

- **Station**:  
  - **Business Purpose**: Contains information about the station, including the maximum number of platforms available.  
  - **Optimization Role**: Provides the constraint bound for the platform capacity constraint.  

- **Train Assignment**:  
  - **Business Purpose**: Represents the binary decision of whether a train is assigned to a station.  
  - **Optimization Role**: Serves as the decision variable in the optimization problem.  

### Current Stored Values  
```sql
-- Iteration 2 Realistic Data
-- Generated by triple expert (business + data + optimization)
-- Values were determined based on realistic train station operations, considering typical passenger counts, waiting times, and platform capacities. Data relationships were maintained to ensure consistency across tables.

-- Realistic data for passenger_waiting_time
INSERT INTO passenger_waiting_time (Train_ID, Station_ID, Waiting_Time) VALUES (1, 1, 5);
INSERT INTO passenger_waiting_time (Train_ID, Station_ID, Waiting_Time) VALUES (2, 2, 10);
INSERT INTO passenger_waiting_time (Train_ID, Station_ID, Waiting_Time) VALUES (3, 3, 15);

-- Realistic data for number_of_passengers
INSERT INTO number_of_passengers (Train_ID, Station_ID, Passenger_Count) VALUES (1, 1, 150);
INSERT INTO number_of_passengers (Train_ID, Station_ID, Passenger_Count) VALUES (2, 2, 100);
INSERT INTO number_of_passengers (Train_ID, Station_ID, Passenger_Count) VALUES (3, 3, 50);

-- Realistic data for station
INSERT INTO station (Number_of_Platforms) VALUES (4);
INSERT INTO station (Number_of_Platforms) VALUES (3);
INSERT INTO station (Number_of_Platforms) VALUES (2);

-- Realistic data for train_assignment
INSERT INTO train_assignment (Train_ID, Station_ID, Assignment) VALUES (1, 1, True);
INSERT INTO train_assignment (Train_ID, Station_ID, Assignment) VALUES (2, 2, True);
INSERT INTO train_assignment (Train_ID, Station_ID, Assignment) VALUES (3, 3, False);
```