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.

72 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 "iODBC"
  15. 'DSN=glpk;UID=glpk;PWD=gnu'
  16. 'SELECT PLANT, CAPA AS CAPACITY'
  17. 'FROM transp_capa' :
  18. I <- [ PLANT ], a ~ CAPACITY;
  19. set J;
  20. /* markets */
  21. param b{j in J};
  22. /* demand at market j in cases */
  23. table markets IN "iODBC"
  24. 'DSN=glpk;UID=glpk;PWD=gnu'
  25. 'transp_demand' :
  26. J <- [ MARKET ], b ~ DEMAND;
  27. param d{i in I, j in J};
  28. /* distance in thousands of miles */
  29. table dist IN "iODBC"
  30. 'DSN=glpk;UID=glpk;PWD=gnu'
  31. 'transp_dist' :
  32. [ LOC1, LOC2 ], d ~ DIST;
  33. param f;
  34. /* freight in dollars per case per thousand miles */
  35. param c{i in I, j in J} := f * d[i,j] / 1000;
  36. /* transport cost in thousands of dollars per case */
  37. var x{i in I, j in J} >= 0;
  38. /* shipment quantities in cases */
  39. minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
  40. /* total transportation costs in thousands of dollars */
  41. s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
  42. /* observe supply limit at plant i */
  43. s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
  44. /* satisfy demand at market j */
  45. solve;
  46. table result{i in I, j in J: x[i,j]} OUT "iODBC"
  47. 'DSN=glpk;UID=glpk;PWD=gnu'
  48. 'DELETE FROM transp_result;'
  49. 'INSERT INTO transp_result VALUES (?,?,?)' :
  50. i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY;
  51. data;
  52. param f := 90;
  53. end;