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.

70 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. set J;
  13. /* markets */
  14. set K dimen 2;
  15. /* transportation lane */
  16. set L;
  17. /* parameters */
  18. param a{i in I};
  19. /* capacity of plant i in cases */
  20. param b{j in J};
  21. /* demand at market j in cases */
  22. param d{i in I, j in J};
  23. /* distance in thousands of miles */
  24. param e{l in L};
  25. /* parameters */
  26. param f;
  27. /* freight in dollars per case per thousand miles */
  28. table tab_plant IN "CSV" "plants.csv" :
  29. I <- [plant], a ~ capacity;
  30. table tab_market IN "CSV" "markets.csv" :
  31. J <- [market], b ~ demand;
  32. table tab_distance IN "CSV" "distances.csv" :
  33. K <- [plant, market], d ~ distance;
  34. table tab_parameter IN "CSV" "parameters.csv" :
  35. L <- [parameter], e ~ value ;
  36. param c{i in I, j in J} := e['transport cost'] * d[i,j] / 1000;
  37. /* transport cost in thousands of dollars per case */
  38. var x{(i,j) in K} >= 0;
  39. /* shipment quantities in cases */
  40. minimize cost: sum{(i,j) in K} c[i,j] * x[i,j];
  41. /* total transportation costs in thousands of dollars */
  42. s.t. supply{i in I}: sum{(i,j) in K} x[i,j] <= a[i];
  43. /* observe supply limit at plant i */
  44. s.t. demand{j in J}: sum{(i,j) in K} x[i,j] >= b[j];
  45. /* satisfy demand at market j */
  46. solve;
  47. table tab_result{(i,j) in K} OUT "CSV" "result.csv" :
  48. i ~ plant, j ~ market, x[i,j] ~ shipment;
  49. end;