Created
September 11, 2013 20:54
-
-
Save larryv/6529641 to your computer and use it in GitHub Desktop.
The diet problem in GNU MathProg.
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
set Foods := Rice Quinoa Tortilla Lentils Broccoli; | |
set NutrientTypes := Carbs Proteins Fat; | |
param Nutrients: | |
Carbs Proteins Fat := | |
Rice 53 4.4 0.4 | |
Quinoa 40 8 3.6 | |
Tortilla 12 3 2 | |
Lentils 53 12 0.9 | |
Broccoli 6 1.9 0.3 | |
; | |
param Costs := | |
Rice 0.5 | |
Quinoa 0.9 | |
Tortilla 0.1 | |
Lentils 0.6 | |
Broccoli 0.4 | |
; | |
param Bounds: 1 2 := | |
Carbs 100 1000 | |
Proteins 10 100 | |
Fat 0 100 | |
; | |
end; |
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
set Foods; | |
set NutrientTypes; | |
param Nutrients{i in Foods, j in NutrientTypes}; | |
param Costs{i in Foods}; | |
param Bounds{i in NutrientTypes, j in 1..2}; | |
var x{i in Foods} >= 0; | |
maximize protein: sum{i in Foods} Nutrients[i,'Proteins'] * x[i]; | |
s.t. | |
bndConstr{k in NutrientTypes}: | |
Bounds[k,1] <= sum{i in Foods} Nutrients[i,k] * x[i] <= Bounds[k,2]; | |
costConstr: | |
sum{i in Foods} Costs[i] * x[i] <= 2; | |
solve; | |
display protein; | |
display x; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment