if tracktype[r,s] == "0" then 1/60 * speedmult[i] * maxspeedeast

else if tracktype[r,s] == "S" then 1/60 * speedmult[i] * maxspeedsl

else if tracktype[r,s] == "SW" then 1/60 * speedmult[i] * maxspeedsw;

+set S := {(r,s) in E: tracktype[r,s] == "S"};

# if i immediately precedes j on track (r,s)

var x {i in T, j in T, (r,s) in E: i <> j} binary;

s.t. entry_time_east {i in I, (r,s) in E: r == orig[i]}: a[i,r,s] >= entrytime[i];

s.t. entry_time_west {i in J, (r,s) in W: r == orig[i]}: a[i,s,r] >= entrytime[i];

# long train and sliding track

-s.t. long_train {i in ~~I~~, (r,s) in ~~E: tracktype[r,s] == "S"~~}:

+s.t. long_train {i in T, (r,s) in S}:

trackleng[r,s] >= trainleng[i] - (1 - y[i,r,s]) * L;

# inhalation hazard train

-s.t. hazard_train {i in ~~I~~, (r,s) in ~~E~~: hazard[i] == 1~~ and tracktype[r,s] == "S"~~}: y[i,r,s] = 0;

+s.t. hazard_train {i in T, (r,s) in S: hazard[i] == 1}: y[i,r,s] = 0;