"""File optima_variables.py

Michel Bierlaire, EPFL
Sun Aug 03 2025, 12:00:56

 Specification of a logit model, that will be estimated, and
 used for simulation.

"""

import pandas as pd
from biogeme.database import Database
from biogeme.expressions import Variable

# Read the data
df = pd.read_csv('optima.dat', sep='\t')
database = Database('optima', df)

# Variables from the data
Choice = Variable('Choice')
TimePT = Variable('TimePT')
TimeCar = Variable('TimeCar')
MarginalCostPT = Variable('MarginalCostPT')
CostCarCHF = Variable('CostCarCHF')
distance_km = Variable('distance_km')
Gender = Variable('Gender')
OccupStat = Variable('OccupStat')
Weight = Variable('Weight')
NbTransf = Variable('NbTransf')

# Exclude observations such that the chosen alternative is -1
database.remove(Choice == -1.0)

# Normalize the weights
sumWeight = database.dataframe['Weight'].sum()
numberOfRows = database.dataframe.shape[0]
normalizedWeight = Weight * numberOfRows / sumWeight

# Definition of variables:
# For numerical reasons, it is good practice to scale the data to
# that the values of the parameters are around 1.0.

TimePT_scaled = TimePT / 200
TimeCar_scaled = TimeCar / 200
CostCarCHF_scaled = CostCarCHF / 10
distance_km_scaled = distance_km / 5
male = Gender == 1
female = Gender == 2
unreportedGender = Gender == -1

fulltime = OccupStat == 1
notfulltime = OccupStat != 1
