You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
11 KiB

3 months ago
  1. # TRAIN, a model of railroad passenger car allocation
  2. #
  3. # References:
  4. # Robert Fourer, David M. Gay and Brian W. Kernighan, "A Modeling Language
  5. # for Mathematical Programming." Management Science 36 (1990) 519-554.
  6. ### SCHEDULE SETS AND PARAMETERS ###
  7. set cities;
  8. set links within {c1 in cities, c2 in cities: c1 <> c2};
  9. # Set of cities, and set of intercity links
  10. param last > 0 integer; # Number of time intervals in a day
  11. set times := 1..last; # Set of time intervals in a day
  12. set schedule within
  13. {c1 in cities, t1 in times,
  14. c2 in cities, t2 in times: (c1,c2) in links};
  15. # Member (c1,t1,c2,t2) of this set represents
  16. # a train that leaves city c1 at time t1
  17. # and arrives in city c2 at time t2
  18. ### DEMAND PARAMETERS ###
  19. param section > 0 integer;
  20. # Maximum number of cars in one section of a train
  21. param demand {schedule} > 0;
  22. # For each scheduled train:
  23. # the smallest number of cars that
  24. # can meet demand for the train
  25. param low {(c1,t1,c2,t2) in schedule} := ceil(demand[c1,t1,c2,t2]);
  26. # Minimum number of cars needed to meet demand
  27. param high {(c1,t1,c2,t2) in schedule}
  28. := max (2, min (ceil(2*demand[c1,t1,c2,t2]),
  29. section*ceil(demand[c1,t1,c2,t2]/section) ));
  30. # Maximum number of cars allowed on a train:
  31. # 2 if demand is for less than one car;
  32. # otherwise, lesser of
  33. # number of cars needed to hold twice the demand, and
  34. # number of cars in minimum number of sections needed
  35. ### DISTANCE PARAMETERS ###
  36. param dist_table {links} >= 0 default 0.0;
  37. param distance {(c1,c2) in links} > 0
  38. := if dist_table[c1,c2] > 0 then dist_table[c1,c2] else dist_table[c2,c1];
  39. # Inter-city distances: distance[c1,c2] is miles
  40. # between city c1 and city c2
  41. ### VARIABLES ###
  42. var U 'cars stored' {cities,times} >= 0;
  43. # u[c,t] is the number of unused cars stored
  44. # at city c in the interval beginning at time t
  45. var X 'cars in train' {schedule} >= 0;
  46. # x[c1,t1,c2,t2] is the number of cars assigned to
  47. # the scheduled train that leaves c1 at t1 and
  48. # arrives in c2 at t2
  49. ### OBJECTIVES ###
  50. minimize cars:
  51. sum {c in cities} U[c,last] +
  52. sum {(c1,t1,c2,t2) in schedule: t2 < t1} X[c1,t1,c2,t2];
  53. # Number of cars in the system:
  54. # sum of unused cars and cars in trains during
  55. # the last time interval of the day
  56. minimize miles:
  57. sum {(c1,t1,c2,t2) in schedule} distance[c1,c2] * X[c1,t1,c2,t2];
  58. # Total car-miles run by all scheduled trains in a day
  59. ### CONSTRAINTS ###
  60. account {c in cities, t in times}:
  61. U[c,t] = U[c, if t > 1 then t-1 else last] +
  62. sum {(c1,t1,c,t) in schedule} X[c1,t1,c,t] -
  63. sum {(c,t,c2,t2) in schedule} X[c,t,c2,t2];
  64. # For every city and time:
  65. # unused cars in the present interval must equal
  66. # unused cars in the previous interval,
  67. # plus cars just arriving in trains,
  68. # minus cars just leaving in trains
  69. satisfy {(c1,t1,c2,t2) in schedule}:
  70. low[c1,t1,c2,t2] <= X[c1,t1,c2,t2] <= high[c1,t1,c2,t2];
  71. # For each scheduled train:
  72. # number of cars must meet demand,
  73. # but must not be so great that unnecessary
  74. # sections are run
  75. ### DATA ###
  76. data;
  77. set cities := BO NY PH WA ;
  78. set links := (BO,NY) (NY,PH) (PH,WA)
  79. (NY,BO) (PH,NY) (WA,PH) ;
  80. param dist_table := [*,*] BO NY 232
  81. NY PH 90
  82. PH WA 135 ;
  83. param last := 48 ;
  84. param section := 14 ;
  85. set schedule :=
  86. (WA,*,PH,*) 2 5 6 9 8 11 10 13
  87. 12 15 13 16 14 17 15 18
  88. 16 19 17 20 18 21 19 22
  89. 20 23 21 24 22 25 23 26
  90. 24 27 25 28 26 29 27 30
  91. 28 31 29 32 30 33 31 34
  92. 32 35 33 36 34 37 35 38
  93. 36 39 37 40 38 41 39 42
  94. 40 43 41 44 42 45 44 47
  95. 46 1
  96. (PH,*,NY,*) 1 3 5 7 9 11 11 13
  97. 13 15 14 16 15 17 16 18
  98. 17 19 18 20 19 21 20 22
  99. 21 23 22 24 23 25 24 26
  100. 25 27 26 28 27 29 28 30
  101. 29 31 30 32 31 33 32 34
  102. 33 35 34 36 35 37 36 38
  103. 37 39 38 40 39 41 40 42
  104. 41 43 42 44 43 45 44 46
  105. 45 47 47 1
  106. (NY,*,BO,*) 10 16 12 18 14 20 15 21
  107. 16 22 17 23 18 24 19 25
  108. 20 26 21 27 22 28 23 29
  109. 24 30 25 31 26 32 27 33
  110. 28 34 29 35 30 36 31 37
  111. 32 38 33 39 34 40 35 41
  112. 36 42 37 43 38 44 39 45
  113. 40 46 41 47 42 48 43 1
  114. 44 2 45 3 46 4 48 6
  115. (BO,*,NY,*) 7 13 9 15 11 17 12 18
  116. 13 19 14 20 15 21 16 22
  117. 17 23 18 24 19 25 20 26
  118. 21 27 22 28 23 29 24 30
  119. 25 31 26 32 27 33 28 34
  120. 29 35 30 36 31 37 32 38
  121. 33 39 34 40 35 41 36 42
  122. 37 43 38 44 39 45 40 46
  123. 41 47 43 1 45 3 47 5
  124. (NY,*,PH,*) 1 3 12 14 13 15 14 16
  125. 15 17 16 18 17 19 18 20
  126. 19 21 20 22 21 23 22 24
  127. 23 25 24 26 25 27 26 28
  128. 27 29 28 30 29 31 30 32
  129. 31 33 32 34 33 35 34 36
  130. 35 37 36 38 37 39 38 40
  131. 39 41 40 42 41 43 42 44
  132. 43 45 44 46 45 47 46 48
  133. 47 1
  134. (PH,*,WA,*) 1 4 14 17 15 18 16 19
  135. 17 20 18 21 19 22 20 23
  136. 21 24 22 25 23 26 24 27
  137. 25 28 26 29 27 30 28 31
  138. 29 32 30 33 31 34 32 35
  139. 33 36 34 37 35 38 36 39
  140. 37 40 38 41 39 42 40 43
  141. 41 44 42 45 43 46 44 47
  142. 45 48 46 1 47 2 ;
  143. param demand :=
  144. [WA,*,PH,*] 2 5 .55 6 9 .01 8 11 .01
  145. 10 13 .13 12 15 1.59 13 16 1.69
  146. 14 17 5.19 15 18 3.55 16 19 6.29
  147. 17 20 4.00 18 21 5.80 19 22 3.40
  148. 20 23 4.88 21 24 2.92 22 25 4.37
  149. 23 26 2.80 24 27 4.23 25 28 2.88
  150. 26 29 4.33 27 30 3.11 28 31 4.64
  151. 29 32 3.44 30 33 4.95 31 34 3.73
  152. 32 35 5.27 33 36 3.77 34 37 4.80
  153. 35 38 3.31 36 39 3.89 37 40 2.65
  154. 38 41 3.01 39 42 2.04 40 43 2.31
  155. 41 44 1.52 42 45 1.75 44 47 1.88
  156. 46 1 1.05
  157. [PH,*,NY,*] 1 3 1.05 5 7 .43 9 11 .20
  158. 11 13 .21 13 15 .40 14 16 6.49
  159. 15 17 16.40 16 18 9.48 17 19 17.15
  160. 18 20 9.31 19 21 15.20 20 22 8.21
  161. 21 23 13.32 22 24 7.35 23 25 11.83
  162. 24 26 6.61 25 27 10.61 26 28 6.05
  163. 27 29 9.65 28 30 5.61 29 31 9.25
  164. 30 32 5.40 31 33 8.24 32 34 4.84
  165. 33 35 7.44 34 36 4.44 35 37 6.80
  166. 36 38 4.11 37 39 6.25 38 40 3.69
  167. 39 41 5.55 40 42 3.29 41 43 4.77
  168. 42 44 2.91 43 45 4.19 44 46 2.53
  169. 45 47 4.00 47 1 1.65
  170. [NY,*,BO,*] 10 16 1.23 12 18 3.84 14 20 4.08
  171. 15 21 1.47 16 22 2.96 17 23 1.60
  172. 18 24 2.95 19 25 1.71 20 26 2.81
  173. 21 27 1.77 22 28 2.87 23 29 1.84
  174. 24 30 2.95 25 31 1.91 26 32 3.12
  175. 27 33 1.93 28 34 3.31 29 35 2.00
  176. 30 36 3.40 31 37 2.08 32 38 3.41
  177. 33 39 2.69 34 40 4.45 35 41 2.32
  178. 36 42 3.40 37 43 1.80 38 44 2.63
  179. 39 45 1.52 40 46 2.23 41 47 1.25
  180. 42 48 1.79 43 1 .97 44 2 1.28
  181. 45 3 .48 46 4 .68 48 6 .08
  182. [BO,*,NY,*] 7 13 .03 9 15 1.29 11 17 4.59
  183. 12 18 2.56 13 19 3.92 14 20 2.37
  184. 15 21 3.81 16 22 2.24 17 23 3.51
  185. 18 24 2.13 19 25 3.28 20 26 2.05
  186. 21 27 3.15 22 28 1.99 23 29 3.09
  187. 24 30 1.93 25 31 3.19 26 32 1.91
  188. 27 33 3.21 28 34 1.85 29 35 3.21
  189. 30 36 1.71 31 37 3.04 32 38 2.08
  190. 33 39 3.13 34 40 1.96 35 41 2.53
  191. 36 42 1.43 37 43 2.04 38 44 1.12
  192. 39 45 1.71 40 46 .91 41 47 1.32
  193. 43 1 1.80 45 3 1.13 47 5 .23
  194. [NY,*,PH,*] 1 3 .04 12 14 4.68 13 15 5.61
  195. 14 16 3.56 15 17 5.81 16 18 3.81
  196. 17 19 6.31 18 20 4.07 19 21 7.33
  197. 20 22 4.55 21 23 7.37 22 24 4.73
  198. 23 25 7.61 24 26 4.92 25 27 7.91
  199. 26 28 5.19 27 29 8.40 28 30 5.53
  200. 29 31 9.32 30 32 5.51 31 33 10.33
  201. 32 34 9.21 33 35 18.95 34 36 11.23
  202. 35 37 16.85 36 38 7.29 37 39 10.89
  203. 38 40 5.41 39 41 8.21 40 42 4.52
  204. 41 43 6.99 42 44 3.92 43 45 6.21
  205. 44 46 3.44 45 47 5.17 46 48 2.55
  206. 47 1 1.24
  207. [PH,*,WA,*] 1 4 .20 14 17 4.49 15 18 3.53
  208. 16 19 2.67 17 20 3.83 18 21 3.01
  209. 19 22 4.12 20 23 3.15 21 24 4.67
  210. 22 25 3.20 23 26 4.23 24 27 2.87
  211. 25 28 3.84 26 29 2.60 27 30 3.80
  212. 28 31 2.77 29 32 4.31 30 33 3.16
  213. 31 34 4.88 32 35 3.45 33 36 5.55
  214. 34 37 3.52 35 38 6.11 36 39 3.32
  215. 37 40 5.53 38 41 3.03 39 42 4.51
  216. 40 43 2.53 41 44 3.39 42 45 1.93
  217. 43 46 2.52 44 47 1.20 45 48 1.75
  218. 46 1 .88 47 2 .87 ;
  219. end;