Iterative approach to generate peak-timetable¶
The order in which files are to be executed (Input and Output Files of each program)
- The preprocess.py will tak OD.csv,Edge.csv,Stations.csv as input and will generate two files, i.e. up.csv,down.csv.
- After this the ampl_morning/evening.py code will take up.csv,down.csv,traversal_time.csv and preprocess.py as the input and will generate modelfile.mod which is given to Gurobi to solve.
- The modsample.run will take modelfile.mod as input and generate tt.txt,tt1.txt as the output.
- The output.py takes tt.txt,up.csv,down.csv and generate up1.csv,down1.csv that has the times of all the events.
The above four steps make a timetable without platform allocation. For the platform allocation, we uses iterative approach to satisfy the constraints.
5) The effort.py takes output.py,preprocess.py as input and generates samplefile.mod(Replace in modelfile.mod) Once we fix the train departure sequence at CST, the file effort3.py reads the timetable and find which arrival events are linked with these departure sequences.
The file effort.py reads the timetable entries and finds the sequencing of events at all stations. So, we are able to know which train will depart after a given train from a given station. For the platform allocation, we just fix only the headway sequence of departure events from CST Station. To accomodate these changes, we replace the headway1 constraint in modelfile.mod with (line no 3 and 4 from samplefile.mod). For instance:
Earlier .mod script contains:
set headway1 = {10000,10007,10014,10021,10028,10035,10042,10049,10056,10063,10070,10077,10084,10091,10098,10105,10112,10119,10126,10133,10280,10283,10286,10289,10292,10295,10298,10301,10508,10514,10520,10526,10532,10538,10544,10550,10556,10562,10638,10642,10646,10650,10654,10658,10662,10666,10670,10674,10678,10726,10728,10730,10732,10734,10736,10738,10740}; var pd1{i in headway1,j in headway1 : i<>j} binary; subject to con1{i in headway1,j in headway1:i<>j}:(dep[j]-dep[i]+423*pd1[i,j])>=3; subject to con2{i in headway1,j in headway1:i<>j}:(dep[j]-dep[i]+423*pd1[i,j])<=420;
We replace the above lines with the following two lines:
set headway1 = {(10042,10283),(10283,10646),(10646,10049),(10049,10650),(10650,10286),(10286,10526),(10526,10056),(10056,10654),(10654,10289),(10289,10063),(10063,10730),(10730,10658),(10658,10070),(10070,10532),(10532,10292),(10292,10077),(10077,10662),(10662,10295),(10295,10732),(10732,10084),(10084,10538),(10538,10091),(10091,10666),(10666,10298),(10298,10544),(10544,10098),(10098,10734),(10734,10670),(10670,10105),(10105,10550),(10550,10736),(10736,10112),(10112,10301),(10301,10556),(10556,10674),(10674,10119),(10119,10678),(10678,10738),(10738,10126),(10126,10562),(10562,10133),(10133,10740)}; subject to con1{(i,j) in headway1}:(dep[j]-dep[i])>=3;
Note that instead of replacing the code, you can also comment the code line by inserting “#” in the beginning.
6) The effort3.py takes up.csv,down.csv,output.py,tt1.txt as input and generates samplefile1.mod as output. Samplefile1.mod contains the platform constraints at CST which are to added at the end of modelfile.mod. Then the script write the platform constraints in samplefile1.mod. Eariler there are two types of platform constraints:
- Difference between next arrival on platform 1 after the departure from platform 1 - should be atleast 3 minutes
- Difference between next arrival on platform 2 after the departure from platform 2 - should be atleast 4 minutes
The following set of lines you will need to add at the last to your modelfile:
#Platform1 Constraints
set platform1 = {(246,10042),(845,10646),(406,10650),(267,10526),(274,10654),(789,10063),(685,10658),(793,10532),(691,10077),(797,10295),(697,10084),(295,10091),(801,10298),(805,10098),(418,10670),(809,10550),(316,10112),(813,10556),(709,10119),(424,10738),(337,10562),(427,10740)}; subject to con700{(i,j) in platform1 }:(arr[i]-dep[j])>=3;
#Platform2 Constraints
set platform2 = {(253,10283),(260,10049),(785,10286),(847,10056),(679,10289),(281,10730),(409,10070),(849,10292),(412,10662),(288,10732),(415,10538),(851,10666),(302,10544),(309,10734),(703,10105),(421,10736),(853,10301),(323,10674),(330,10678),(817,10126),(855,10133)}; subject to con701{(i,j) in platform2 }:(arr[i]-dep[j])>=4;
In the last meet (in which you were also there), one additional platform allocation constraint was added: (Departure from platform 2 - Arrival at platform 1) : either should be <= 0 or >= 4 To accomodate this constraint, the following lines are added in the modelfile.mod.
#Platform 1-2 Constraints
set arr1 = {673,246,845,406,267,274,789,685,793,691,797,697,295,801,805,418,809,316,813,709,424,337,427}; set dep2 = {10283,10049,10286,10056,10289,10730,10070,10292,10662,10732,10538,10666,10544,10734,10105,10736,10301,10674,10678,10126,10133}; var pdd {i in arr1,j in dep2} binary ;
subject to con702{i in arr1,j in dep2}:(arr[i]-dep[j] + 420*pdd[i,j]) >=0.5; subject to con703{i in arr1,j in dep2}:(arr[i]-dep[j] + 420*pdd[i,j]) <=420; subject to con704{i in arr1,j in dep2}:(arr[i]-dep[j] + 424*pdd[i,j]) >=4;
Soumya/Belur (with some contributions by Anurag) developed post-processing scripts which makes rakecycles files.
Iterative Approach:
- You do the step 5 once only.
- Then edit modelfile.mod
- Do Step 6 now.
- Edit modelfile.mod
- Run it now.
- If you get feasible solution – boom, you are done – but that is not the case always.
- So, you need to lower the platform bounds and then you will get feasible solution (valid new tt.txt and tt1.txt files)
- Now, you need to do step 4 and 6.