-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kibaekkim/dev
Dev
- Loading branch information
Showing
6 changed files
with
371 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Kibaek Kim - ANL MCS 2016 | ||
# Farmer example from Birge and Louveaux book. | ||
# | ||
# To use MPI, add MPI.Init() and MPI.Finalize() around the scritp lines. | ||
|
||
using MPI, JuMP, Dsp | ||
|
||
MPI.Init() | ||
|
||
NS = 3; # number of scenarios | ||
probability = [1/3, 1/3, 1/3]; # probability | ||
|
||
CROPS = 1:3 # set of crops (wheat, corn and sugar beets, resp.) | ||
PURCH = 1:2 # set of crops to purchase (wheat and corn, resp.) | ||
SELL = 1:4 # set of crops to sell (wheat, corn, sugar beets under 6K and those over 6K) | ||
|
||
Cost = [150 230 260] # cost of planting crops | ||
Budget = 500 # budget capacity | ||
Purchase = [238 210]; # purchase price | ||
Sell = [170 150 36 10] # selling price | ||
Yield = [3.0 3.6 24.0; | ||
2.5 3.0 20.0; | ||
2.0 2.4 16.0] | ||
Minreq = [200 240 0] # minimum crop requirement | ||
|
||
# JuMP model | ||
m = Model(NS) | ||
|
||
@variable(m, x[i=CROPS] >= 0, Int) | ||
@objective(m, Min, sum{Cost[i] * x[i], i=CROPS}) | ||
@constraint(m, const_budget, sum{x[i], i=CROPS} <= Budget) | ||
|
||
for s in 1:NS | ||
blk = Model(m, s, probability[s]) | ||
|
||
@variable(blk, y[j=PURCH] >= 0) | ||
@variable(blk, w[k=SELL] >= 0) | ||
|
||
@objective(blk, Min, sum{Purchase[j] * y[j], j=PURCH} - sum{Sell[k] * w[k], k=SELL}) | ||
|
||
@constraint(blk, const_minreq[j=PURCH], Yield[s,j] * x[j] + y[j] - w[j] >= Minreq[j]) | ||
@constraint(blk, const_minreq_beets, Yield[s,3] * x[3] - w[3] - w[4] >= Minreq[3]) | ||
@constraint(blk, const_aux, w[3] <= 6000) | ||
end | ||
|
||
MPI.Finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.