Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 46
load('/home/user/lenprogram.sage')
# P = Protien # C = Carbohydrates # F = Fat # Fr = Fruit, servings # M = Meat, servings # V = Vegetable, servings # FrC = Cost per serving of fruit, dollars # MC = Cost per serving of meat, dollars # VC = Cost per serving of vegetable, dollars # FrP = Protein in 1 serving of fruit, grams # FrC = Carbs in 1 serving of fruit, grams # FrF = Fat in 1 serving of fruit, grams # MP = protein in 1 serving of meat, grams # MC = carbs in 1 serving of meat, grams # MF = fat in 1 serving of meat, grams # VP = protein in 1 serving of vegetable, grams # VC = carbs in 1 serving of vegetable, grams # VF = fat in 1 serving of vegetable, grams # Constraints # FrP + MP + VP >= 56 # FrC + MC + VC >= 130 # FrF + MF + VF >= 65 # FrCa + Mca + Vca >= 100 # Objective Minimize the cost applesauce = [0,27,0,0] # item = [protein, carbs, fat, calcium] applesauce_p = 3.5 applesauce_servings = 11 applesauce_c = applesauce_p/applesauce_servings applesauce_c_serving = [applesauce_c / x for x in applesauce] # applesauce_c/x applesauce_c_serving
[+infinity, 0.0117845117845118, +infinity, +infinity]
spinach = [2, 3, 0, 8] spinach_p = 1.54 spinach_servings = 3.5 spinach_c = spinach_p / spinach_servings spinach_c_serving = [spinach_c / x for x in spinach] # spinach_c/x spinach_c_serving
[0.220000000000000, 0.146666666666667, +infinity, 0.0550000000000000]
groundbeef = [21, 0, 17, 0] groundbeef_p = 3.86 groundbeef_servings = 4 groundbeef_c = groundbeef_p / groundbeef_servings groundbeef_c_serving = [groundbeef_c / x for x in groundbeef] #groundbeef_c/x groundbeef_c_serving
[0.0459523809523810, +infinity, 0.0567647058823529, +infinity]
protein = [applesauce[0], spinach[0], groundbeef[0]] # I guess this are the M the matrix of coefficients of each row carbs = [applesauce[1], spinach[1], groundbeef[1]] fat = [applesauce[2], spinach[2], groundbeef[2]]
var = ['fruit (servings)', 'veg (servings)', 'meat (servings)'] #con = ['protein', 'carbs', 'fat'] #ob = [applesauce, spinach, groundbeef] #M= [[1,1,1],[1,1,1],[1,1,1]] #inq = [-1,-1,-1] #bnd = [56,130,65] #lp(var,con,ob,M,inq,bnd, mx = False) constraint = ['protein', 'carbs', 'fat'] objective = [applesauce_c, spinach_c, groundbeef_c] coeffs = [protein,carbs,fat] ineqality = [-1, -1, -1] bound = [56, 130, 65] lp( var, constraint, objective, coeffs, ineqality, bound, mx = False)
GLPK 4.60 - SENSITIVITY ANALYSIS REPORT Page 1 Problem: Objective: 5.221692414 (MINimum) No. Row name St Activity Slack Lower bound Activity Obj coef Obj value at Limiting Marginal Upper bound range range break point variable ------ ------------ -- ------------- ------------- ------------- ------------- ------------- ------------- ------------ 1 protein BS 80.29412 -24.29412 56.00000 +Inf -.04595 1.53199 fat . +Inf 80.29412 +Inf +Inf 2 carbs NL 130.00000 . 130.00000 . -.01178 3.68971 fruit (servings) .01178 +Inf +Inf +Inf +Inf 3 fat NL 65.00000 . 65.00000 45.33333 -.05676 4.10532 protein .05676 +Inf +Inf +Inf +Inf GLPK 4.60 - SENSITIVITY ANALYSIS REPORT Page 2 Problem: Objective: 5.221692414 (MINimum) No. Column name St Activity Obj coef Lower bound Activity Obj coef Obj value at Limiting Marginal Upper bound range range break point variable ------ ------------ -- ------------- ------------- ------------- ------------- ------------- ------------- ------------ 1 fruit (servings) BS 4.81481 .31818 . +Inf . 3.68971 carbs . +Inf -Inf 3.96000 22.75637 veg (servings) 2 veg (servings) NL . .44000 . -12.14706 .03535 .30643 protein .40465 +Inf 43.33333 +Inf 22.75637 fruit (servings) 3 meat (servings) BS 3.82353 .96500 . +Inf . 1.53199 fat . +Inf 3.82353 +Inf +Inf End of report