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.

71 lines
1.6 KiB

  1. # A TRANSPORTATION PROBLEM
  2. #
  3. # This problem finds a least cost shipping schedule that meets
  4. # requirements at markets and supplies at factories.
  5. #
  6. # References:
  7. # Dantzig G B, "Linear Programming and Extensions."
  8. # Princeton University Press, Princeton, New Jersey, 1963,
  9. # Chapter 3-3.
  10. set I;
  11. /* canning plants */
  12. param a{i in I};
  13. /* capacity of plant i in cases */
  14. table plants IN "MySQL"
  15. 'Database=glpk;UID=glpk;PWD=gnu'
  16. 'SELECT PLANT, CAPA AS CAPACITY FROM transp_capa' :
  17. I <- [ PLANT ], a ~ CAPACITY;
  18. set J;
  19. /* markets */
  20. param b{j in J};
  21. /* demand at market j in cases */
  22. table markets IN "MySQL"
  23. 'Database=glpk;UID=glpk;PWD=gnu'
  24. 'transp_demand' :
  25. J <- [ MARKET ], b ~ DEMAND;
  26. param d{i in I, j in J};
  27. /* distance in thousands of miles */
  28. table dist IN "MySQL"
  29. 'Database=glpk;UID=glpk;PWD=gnu'
  30. 'transp_dist' :
  31. [ LOC1, LOC2 ], d ~ DIST;
  32. param f;
  33. /* freight in dollars per case per thousand miles */
  34. param c{i in I, j in J} := f * d[i,j] / 1000;
  35. /* transport cost in thousands of dollars per case */
  36. var x{i in I, j in J} >= 0;
  37. /* shipment quantities in cases */
  38. minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
  39. /* total transportation costs in thousands of dollars */
  40. s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
  41. /* observe supply limit at plant i */
  42. s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
  43. /* satisfy demand at market j */
  44. solve;
  45. table result{i in I, j in J: x[i,j]} OUT "MySQL"
  46. 'Database=glpk;UID=glpk;PWD=gnu'
  47. 'DELETE FROM transp_result;'
  48. 'INSERT INTO transp_result VALUES (?,?,?)' :
  49. i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY;
  50. data;
  51. param f := 90;
  52. end;