Created
April 18, 2014 17:15
-
-
Save cshjin/11054755 to your computer and use it in GitHub Desktop.
AMPL learning
This file contains hidden or 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
data; | |
set Crops := wheat corn beets; | |
param TotalArea:=500; | |
param BeetsQuota:=6000; | |
param Yield := | |
wheat 2.5 | |
corn 3.0 | |
beets 20.0; | |
param MinRequirement := | |
wheat 200 | |
corn 240 | |
beets 0; | |
param PlantingCost := | |
wheat 150 | |
corn 230 | |
beets 260; | |
param SellingPrice := | |
wheat 170 | |
corn 150 | |
beets 36; | |
param ExcessSellingPrice := 10; | |
param BuyingPrice := | |
wheat 238 | |
corn 210 | |
beets 100; |
This file contains hidden or 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
reset; | |
model; | |
set Crops; | |
param TotalArea; | |
param Yield{Crops}; | |
param PlantingCost{Crops}; | |
param SellingPrice{Crops}; | |
param ExcessSellingPrice; | |
param BuyingPrice{Crops}; | |
param MinRequirement{Crops}; | |
param BeetsQuota; | |
var area{c in Crops} >= 0; | |
var sell{c in Crops} >= 0; | |
var sellExcess >=0; | |
var buy{c in Crops} >=0; | |
maximize profit: | |
ExcessSellingPrice * sellExcess + | |
sum{c in Crops} (SellingPrice[c] * sell[c] - | |
BuyingPrice[c] * buy[c] - | |
PlantingCost[c] * area[c]); | |
subject to totalArea: | |
sum {c in Crops} area[c] <= TotalArea; | |
subject to requirement{c in Crops}: | |
Yield[c] * area[c] - sell[c] + buy[c] | |
>=MinRequirement[c]; | |
subject to quota: sell['beets'] <=BeetsQuota; | |
subject to sellBeets: sell['beets'] + sellExcess | |
<=Yield['beets'] * area['beets']; |
This file contains hidden or 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
#---------------------------------------- | |
# FARMAR RUN COMMEND | |
#---------------------------------------- | |
reset; | |
option solver CPLEX; | |
option presolve 1; | |
option cplex_options 'sensitivity'; | |
include farmer1.mod; | |
include farmer1.dat; | |
solve; | |
display _objname, _obj; | |
# Print out the value of the objective function | |
display _varname, _var, _var.lb,_var.ub, _var.rc ; | |
# Print out names, values and reduced costs | |
display _varname, _var.down, _var.current, _var.up ; | |
# Print out names, objective function coefficients | |
# together with what can be changed without causing | |
# a base change | |
# down = lower limit, up = upper limit | |
display _conname, _con.slack, _con.dual; | |
# Print out constraint name, slack and shadow price | |
display _conname,_con.down,_con.current,_con.up ; | |
# Print out constraint name, right-hand side coefficient | |
# together with what can be changed without causing | |
# a base change |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_var
can have a bunch of suffixes, the following list is from help docFor
_con
which is the constraints suffix:for
_obj
, which is object suffix: