set Crops;
scenarioset Scenarios;
probability P{Scenarios};
tree Tree := twostage;
param TotalArea; # acre
random param Yield{Crops, Scenarios}; # T/acre
param PlantingCost{Crops}; # $/acre
param SellingPrice{Crops}; # $/T
param ExcessSellingPrice; # $/T
param PurchasePrice{Crops}; # $/T
param MinRequirement{Crops}; # T
param BeetsQuota; # T
# Area in acres devoted to crop c
var area{c in Crops} >= 0;
# Tons of crop c sold (at favourable price in case of beets)
# under scenario s
var sell{c in Crops, s in Scenarios} >= 0, suffix stage 2;
# Tons of sugar beets sold in excess of the quota under
# scenario s
var sellExcess{s in Scenarios} >= 0, suffix stage 2;
# Tons of crop c bought under scenario s
var buy{c in Crops, s in Scenarios} >= 0, suffix stage 2;
maximize profit: sum{s in Scenarios} P[s] * (
ExcessSellingPrice * sellExcess[s] +
sum{c in Crops} (SellingPrice[c] * sell[c, s] -
PurchasePrice[c] * buy[c, s]) -
sum{c in Crops} PlantingCost[c] * area[c]);
s.t. totalArea: sum {c in Crops} area[c] <= TotalArea;
s.t. requirement{c in Crops, s in Scenarios}:
Yield[c, s] * area[c] - sell[c, s] + buy[c, s]
>= MinRequirement[c];
s.t. quota{s in Scenarios}: sell[’beets’, s] <= BeetsQuota;
s.t. beetsBalance{s in Scenarios}:
sell[’beets’, s] + sellExcess[s]
<= Yield[’beets’, s] * area[’beets’];
data;
set Crops := wheat corn beets;
set Scenarios := below average above;
param TotalArea := 500;
param P :=
below
0.333333
average 0.333333
above
0.333333;
param Yield:
below average above :=
wheat 2.0 2.5 3.0
corn 2.4 3.0 3.6
beets 16.0 20.0 24.0;
param PlantingCost :=
wheat 150
corn 230
beets 260;
param SellingPrice :=
wheat 170
corn 150
beets 36;
param ExcessSellingPrice := 10;
param PurchasePrice :=
wheat 238
corn 210
beets 100; # Set to a high value to simplify the objective
param MinRequirement :=
wheat 200
corn 240
beets 0;
param BeetsQuota := 6000;
# Read the model and data.
model farmer.mod;
data farmer.dat;
# Set options.
option solver fortsp;
# Instantiate and solve the problem.
solve;
# Print the results.
print ’Optimal value =’, profit;
print;
print ’First-stage solution:’;
print {c in Crops}: ’area[’, c, ’] =’, area[c], ’\
’;
print ’totalArea =’, totalArea.body;
output:
...
optimal solution; objective 108390.00000000003
Optimal value = 108390.00000000003
First-stage solution:
area[ wheat ] = 170.00000000000003
area[ corn ] = 79.99999999999997
area[ beets ] = 250.00000000000003
totalArea = 500