Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

# FortSP example from its manual

By: a guest on Oct 1st, 2012  |  syntax: None  |  size: 2.54 KB  |  views: 325  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. set Crops;
2. scenarioset Scenarios;
3. probability P{Scenarios};
4. tree Tree := twostage;
5. param TotalArea; # acre
6. random param Yield{Crops, Scenarios}; # T/acre
7. param PlantingCost{Crops}; # \$/acre
8. param SellingPrice{Crops}; # \$/T
9. param ExcessSellingPrice; # \$/T
10. param PurchasePrice{Crops}; # \$/T
11. param MinRequirement{Crops}; # T
12. param BeetsQuota; # T
13. # Area in acres devoted to crop c
14. var area{c in Crops} >= 0;
15. # Tons of crop c sold (at favourable price in case of beets)
16. # under scenario s
17. var sell{c in Crops, s in Scenarios} >= 0, suffix stage 2;
18. # Tons of sugar beets sold in excess of the quota under
19. # scenario s
20. var sellExcess{s in Scenarios} >= 0, suffix stage 2;
21. # Tons of crop c bought under scenario s
22. var buy{c in Crops, s in Scenarios} >= 0, suffix stage 2;
23. maximize profit: sum{s in Scenarios} P[s] * (
24. ExcessSellingPrice * sellExcess[s] +
25. sum{c in Crops} (SellingPrice[c] * sell[c, s] -
26. PurchasePrice[c] * buy[c, s]) -
27. sum{c in Crops} PlantingCost[c] * area[c]);
28. s.t. totalArea: sum {c in Crops} area[c] <= TotalArea;
29. s.t. requirement{c in Crops, s in Scenarios}:
30. Yield[c, s] * area[c] - sell[c, s] + buy[c, s]
31. >= MinRequirement[c];
32. s.t. quota{s in Scenarios}: sell[’beets’, s] <= BeetsQuota;
33. s.t. beetsBalance{s in Scenarios}:
34. sell[’beets’, s] + sellExcess[s]
35. <= Yield[’beets’, s] * area[’beets’];
36. data;
37. set Crops := wheat corn beets;
38. set Scenarios := below average above;
39. param TotalArea := 500;
40. param P :=
41. below
42. 0.333333
43. average 0.333333
44. above
45. 0.333333;
46. param Yield:
47.           below average above :=
48.     wheat  2.0 2.5 3.0
49.     corn   2.4 3.0 3.6
50.     beets  16.0 20.0 24.0;
51. param PlantingCost :=
52. wheat 150
53. corn 230
54. beets 260;
55.
56. param SellingPrice :=
57. wheat 170
58. corn 150
59. beets 36;
60. param ExcessSellingPrice := 10;
61. param PurchasePrice :=
62. wheat 238
63. corn 210
64. beets 100; # Set to a high value to simplify the objective
65. param MinRequirement :=
66. wheat 200
67. corn 240
68. beets 0;
69. param BeetsQuota := 6000;
70.
71. # Read the model and data.
72. model farmer.mod;
73. data farmer.dat;
74. # Set options.
75. option solver fortsp;
76. # Instantiate and solve the problem.
77. solve;
78. # Print the results.
79. print ’Optimal value =’, profit;
80. print;
81. print ’First-stage solution:’;
82. print {c in Crops}: ’area[’, c, ’] =’, area[c], ’\
83. ’;
84. print ’totalArea =’, totalArea.body;
85.
86.
87. output:
88. ...
89. optimal solution; objective 108390.00000000003
90. Optimal value = 108390.00000000003
91. First-stage solution:
92. area[ wheat ] = 170.00000000000003
93. area[ corn ] = 79.99999999999997
94. area[ beets ] = 250.00000000000003
95. totalArea = 500
clone this paste RAW Paste Data
Top