Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 46
Kernel: SageMath (stable)

Chipotle!!!!!!!!!!!!!!!!!!!!!!!!!

The matrix M has rows for each ingredient and columns for attributes. The ingredients have different sections The attributes of the ingredients are as follows: Taste Rank (1-100), Cost, Calories, Total Fat (G), Sodium (MG), Protein (G), and Sugar (G).

Mfood=["chicken", "steak", "Carnitas", "Barbacoa", "Sofritas", "Veggies with Guac", "White Rice", "Brown Rice", "Black Beans", "Pinto Beans", "Fajita Veggies", "Queso", "Tomato salsa", "Chilicorn salsa", "Tomatillo green", "Tomatillo-red", "Sour cream", "Cheese", "Guacamole", "Lettuce"]
M=[[98,6.85,180,7,310,32,0],[90,7.85,150,6,330,21,0],[40,7.3,210,12,450,23,0],[40,7.85,170,7,530,24,0],[50,6.85,150,10,560,8,5],[60,4.8,40,0,300,2,4],[65,0,210,4,350,4,0],[55,0,210,6,190,4,0],[65,0,130,1.5,210,8,2],[50,0,130,1.5,210,8,1],[7,0,20,0,150,1,2],[80,1.25,120,8,200,6,1],[65,0,25,0,550,0,1],[50,0,80,1.5,330,3,4],[25,0,15,0,260,0,2],[65,0,30,0,500,0,0],[58,0,110,9,30,2,2],[79,0,110,8,190,6,0],[93,2.05,230,22,370,2,1],[50,0,5,0,0,0,0]] show(matrix(RDF,M))
(98.06.85180.07.0310.032.00.090.07.85150.06.0330.021.00.040.07.3210.012.0450.023.00.040.07.85170.07.0530.024.00.050.06.85150.010.0560.08.05.060.04.840.00.0300.02.04.065.00.0210.04.0350.04.00.055.00.0210.06.0190.04.00.065.00.0130.01.5210.08.02.050.00.0130.01.5210.08.01.07.00.020.00.0150.01.02.080.01.25120.08.0200.06.01.065.00.025.00.0550.00.01.050.00.080.01.5330.03.04.025.00.015.00.0260.00.02.065.00.030.00.0500.00.00.058.00.0110.09.030.02.02.079.00.0110.08.0190.06.00.093.02.05230.022.0370.02.01.050.00.05.00.00.00.00.0)\renewcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrrrrr} 98.0 & 6.85 & 180.0 & 7.0 & 310.0 & 32.0 & 0.0 \\ 90.0 & 7.85 & 150.0 & 6.0 & 330.0 & 21.0 & 0.0 \\ 40.0 & 7.3 & 210.0 & 12.0 & 450.0 & 23.0 & 0.0 \\ 40.0 & 7.85 & 170.0 & 7.0 & 530.0 & 24.0 & 0.0 \\ 50.0 & 6.85 & 150.0 & 10.0 & 560.0 & 8.0 & 5.0 \\ 60.0 & 4.8 & 40.0 & 0.0 & 300.0 & 2.0 & 4.0 \\ 65.0 & 0.0 & 210.0 & 4.0 & 350.0 & 4.0 & 0.0 \\ 55.0 & 0.0 & 210.0 & 6.0 & 190.0 & 4.0 & 0.0 \\ 65.0 & 0.0 & 130.0 & 1.5 & 210.0 & 8.0 & 2.0 \\ 50.0 & 0.0 & 130.0 & 1.5 & 210.0 & 8.0 & 1.0 \\ 7.0 & 0.0 & 20.0 & 0.0 & 150.0 & 1.0 & 2.0 \\ 80.0 & 1.25 & 120.0 & 8.0 & 200.0 & 6.0 & 1.0 \\ 65.0 & 0.0 & 25.0 & 0.0 & 550.0 & 0.0 & 1.0 \\ 50.0 & 0.0 & 80.0 & 1.5 & 330.0 & 3.0 & 4.0 \\ 25.0 & 0.0 & 15.0 & 0.0 & 260.0 & 0.0 & 2.0 \\ 65.0 & 0.0 & 30.0 & 0.0 & 500.0 & 0.0 & 0.0 \\ 58.0 & 0.0 & 110.0 & 9.0 & 30.0 & 2.0 & 2.0 \\ 79.0 & 0.0 & 110.0 & 8.0 & 190.0 & 6.0 & 0.0 \\ 93.0 & 2.05 & 230.0 & 22.0 & 370.0 & 2.0 & 1.0 \\ 50.0 & 0.0 & 5.0 & 0.0 & 0.0 & 0.0 & 0.0 \end{array}\right)
costs=[M[i][1] for i in range(20)] costs
[6.85000000000000, 7.85000000000000, 7.30000000000000, 7.85000000000000, 6.85000000000000, 4.80000000000000, 0, 0, 0, 0, 0, 1.25000000000000, 0, 0, 0, 0, 0, 0, 2.05000000000000, 0]
tr=[M[i][0] for i in range(20)] #taste rank tr
[98, 90, 40, 40, 50, 60, 65, 55, 65, 50, 7, 80, 65, 50, 25, 65, 58, 79, 93, 50]
# objective for taste rank. We want to maximize objtaste=0 for i in range(20): objtaste+=M[i][0]*x[i] objtaste
98*x_0 + 90*x_1 + 40*x_2 + 40*x_3 + 50*x_4 + 60*x_5 + 65*x_6 + 55*x_7 + 65*x_8 + 50*x_9 + 7*x_10 + 80*x_11 + 65*x_12 + 50*x_13 + 25*x_14 + 65*x_15 + 58*x_16 + 79*x_17 + 93*x_18 + 50*x_19
# objective for cost. We want to minimize objcost=0 for i in range(20): objcost+=M[i][1]*x[i] objcost
6.85*x_0 + 7.85*x_1 + 7.3*x_2 + 7.85*x_3 + 6.85*x_4 + 4.8*x_5 + 1.25*x_11 + 2.05*x_18

x[i]=the item that we include in the bowl x[taste rank, cost,calories,fat,sodium,protein, sugar] x[i,j,k,l,m,n,o]

Parameters

p=MixedIntegerLinearProgram(maximization=True) x=p.new_variable(binary=True) #Calories constraint min p.add_constraint(add([x[i]*M[i][2] for i in range(20)]) >= 750) #Calories constraint max p.add_constraint(add([x[i]*M[i][2] for i in range(20)]) <= 1000) #Fat constraint min p.add_constraint(add([x[i]*M[i][3] for i in range(20)]) >= 15) #Fat constraint max p.add_constraint(add([x[i]*M[i][3] for i in range(20)]) <= 32) #Sodium p.add_constraint(add([x[i]*M[i][4] for i in range(20)]) <= 940) ##OG sodium constraint was 500. Had to increase for a feasible sol'n #Protein constraint Min p.add_constraint(add([x[i]*M[i][5] for i in range(20)]) >= 18) #Sugar constraint p.add_constraint(add([x[i]*M[i][6] for i in range(20)]) <= 10) #Must have 1 meat in the bowl p.add_constraint(add([x[k] for k in range(6)]) == 1) p.add_constraint(x[6]+x[7]<=1) #rice constraint p.add_constraint(x[8]+x[9]<=1) #beans constraint, can only have 1 type max #when we order veggies, it comes with guac #p.add_constraint(x[5]+x[18]==0%2) p.set_objective(objtaste-objcost) p.show() p.solve() soln=p.get_values(x) soln
Maximization: 91.15 x_0 + 82.15 x_1 + 32.7 x_2 + 32.15 x_3 + 43.15 x_4 + 55.2 x_5 + 65.0 x_6 + 55.0 x_7 + 65.0 x_8 + 50.0 x_9 + 7.0 x_10 + 78.75 x_11 + 65.0 x_12 + 50.0 x_13 + 25.0 x_14 + 65.0 x_15 + 58.0 x_16 + 79.0 x_17 + 90.95 x_18 + 50.0 x_19 Constraints: -180.0 x_0 - 150.0 x_1 - 210.0 x_2 - 170.0 x_3 - 150.0 x_4 - 40.0 x_5 - 210.0 x_6 - 210.0 x_7 - 130.0 x_8 - 130.0 x_9 - 20.0 x_10 - 120.0 x_11 - 25.0 x_12 - 80.0 x_13 - 15.0 x_14 - 30.0 x_15 - 110.0 x_16 - 110.0 x_17 - 230.0 x_18 - 5.0 x_19 <= -750.0 180.0 x_0 + 150.0 x_1 + 210.0 x_2 + 170.0 x_3 + 150.0 x_4 + 40.0 x_5 + 210.0 x_6 + 210.0 x_7 + 130.0 x_8 + 130.0 x_9 + 20.0 x_10 + 120.0 x_11 + 25.0 x_12 + 80.0 x_13 + 15.0 x_14 + 30.0 x_15 + 110.0 x_16 + 110.0 x_17 + 230.0 x_18 + 5.0 x_19 <= 1000.0 -7.0 x_0 - 6.0 x_1 - 12.0 x_2 - 7.0 x_3 - 10.0 x_4 - 4.0 x_6 - 6.0 x_7 - 1.5 x_8 - 1.5 x_9 - 8.0 x_11 - 1.5 x_13 - 9.0 x_16 - 8.0 x_17 - 22.0 x_18 <= -15.0 7.0 x_0 + 6.0 x_1 + 12.0 x_2 + 7.0 x_3 + 10.0 x_4 + 4.0 x_6 + 6.0 x_7 + 1.5 x_8 + 1.5 x_9 + 8.0 x_11 + 1.5 x_13 + 9.0 x_16 + 8.0 x_17 + 22.0 x_18 <= 32.0 310.0 x_0 + 330.0 x_1 + 450.0 x_2 + 530.0 x_3 + 560.0 x_4 + 300.0 x_5 + 350.0 x_6 + 190.0 x_7 + 210.0 x_8 + 210.0 x_9 + 150.0 x_10 + 200.0 x_11 + 550.0 x_12 + 330.0 x_13 + 260.0 x_14 + 500.0 x_15 + 30.0 x_16 + 190.0 x_17 + 370.0 x_18 <= 940.0 -32.0 x_0 - 21.0 x_1 - 23.0 x_2 - 24.0 x_3 - 8.0 x_4 - 2.0 x_5 - 4.0 x_6 - 4.0 x_7 - 8.0 x_8 - 8.0 x_9 - x_10 - 6.0 x_11 - 3.0 x_13 - 2.0 x_16 - 6.0 x_17 - 2.0 x_18 <= -18.0 5.0 x_4 + 4.0 x_5 + 2.0 x_8 + x_9 + 2.0 x_10 + x_11 + x_12 + 4.0 x_13 + 2.0 x_14 + 2.0 x_16 + x_18 <= 10.0 1.0 <= x_0 + x_1 + x_2 + x_3 + x_4 + x_5 <= 1.0 x_6 + x_7 <= 1.0 x_8 + x_9 <= 1.0 Variables: x_0 is a boolean variable (min=0.0, max=1.0) x_1 is a boolean variable (min=0.0, max=1.0) x_2 is a boolean variable (min=0.0, max=1.0) x_3 is a boolean variable (min=0.0, max=1.0) x_4 is a boolean variable (min=0.0, max=1.0) x_5 is a boolean variable (min=0.0, max=1.0) x_6 is a boolean variable (min=0.0, max=1.0) x_7 is a boolean variable (min=0.0, max=1.0) x_8 is a boolean variable (min=0.0, max=1.0) x_9 is a boolean variable (min=0.0, max=1.0) x_10 is a boolean variable (min=0.0, max=1.0) x_11 is a boolean variable (min=0.0, max=1.0) x_12 is a boolean variable (min=0.0, max=1.0) x_13 is a boolean variable (min=0.0, max=1.0) x_14 is a boolean variable (min=0.0, max=1.0) x_15 is a boolean variable (min=0.0, max=1.0) x_16 is a boolean variable (min=0.0, max=1.0) x_17 is a boolean variable (min=0.0, max=1.0) x_18 is a boolean variable (min=0.0, max=1.0) x_19 is a boolean variable (min=0.0, max=1.0)
{0: 1.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 1.0, 8: 1.0, 9: 0.0, 10: 0.0, 11: 1.0, 12: 0.0, 13: 0.0, 14: 0.0, 15: 0.0, 16: 1.0, 17: 0.0, 18: 0.0, 19: 1.0}
for i in range(20): if soln[i]==1: print(Mfood[i])
chicken Brown Rice Black Beans Queso Sour cream Lettuce
calories=0 for i in range(20): if soln[i]==1: calories=calories+M[i][2] calories
755
M=[["Taste Rank","Cost","Calories","Total Fat","Sodium", "Protein","Sugar"],[98,6.85,180,7,310,32,0],[90,7.85,150,6,330,21,0],[40,7.3,210,12,450,23,0],[40,7.85,170,7,530,24,0],[50,6.85,150,10,560,8,5],[60,4.8,40,0,300,2,4],[65,0,210,4,350,4,0],[55,0,210,6,190,4,0],[65,0,130,1.5,210,8,2],[50,0,130,1.5,210,8,1],[7,0,20,0,150,1,2],[80,1.25,120,8,200,6,1],[65,0,25,0,550,0,1],[50,0,80,1.5,330,3,4],[25,0,15,0,260,0,2],[65,0,30,0,500,0,0],[58,0,110,9,30,2,2],[79,0,110,8,190,6,0],[93,2.05,230,22,370,2,1],[50,0,5,0,0,0,0]] show(M) show(matrix(RDF,M))
[[TastexRank,Cost,Calories,TotalxFat,Sodium,Protein,Sugar],[98,6.85000000000000,180,7,310,32,0],[90,7.85000000000000,150,6,330,21,0],[40,7.30000000000000,210,12,450,23,0],[40,7.85000000000000,170,7,530,24,0],[50,6.85000000000000,150,10,560,8,5],[60,4.80000000000000,40,0,300,2,4],[65,0,210,4,350,4,0],[55,0,210,6,190,4,0],[65,0,130,1.50000000000000,210,8,2],[50,0,130,1.50000000000000,210,8,1],[7,0,20,0,150,1,2],[80,1.25000000000000,120,8,200,6,1],[65,0,25,0,550,0,1],[50,0,80,1.50000000000000,330,3,4],[25,0,15,0,260,0,2],[65,0,30,0,500,0,0],[58,0,110,9,30,2,2],[79,0,110,8,190,6,0],[93,2.05000000000000,230,22,370,2,1],[50,0,5,0,0,0,0]]\renewcommand{\Bold}[1]{\mathbf{#1}}\left[\left[\verb|Taste|\phantom{\verb!x!}\verb|Rank|, \verb|Cost|, \verb|Calories|, \verb|Total|\phantom{\verb!x!}\verb|Fat|, \verb|Sodium|, \verb|Protein|, \verb|Sugar|\right], \left[98, 6.85000000000000, 180, 7, 310, 32, 0\right], \left[90, 7.85000000000000, 150, 6, 330, 21, 0\right], \left[40, 7.30000000000000, 210, 12, 450, 23, 0\right], \left[40, 7.85000000000000, 170, 7, 530, 24, 0\right], \left[50, 6.85000000000000, 150, 10, 560, 8, 5\right], \left[60, 4.80000000000000, 40, 0, 300, 2, 4\right], \left[65, 0, 210, 4, 350, 4, 0\right], \left[55, 0, 210, 6, 190, 4, 0\right], \left[65, 0, 130, 1.50000000000000, 210, 8, 2\right], \left[50, 0, 130, 1.50000000000000, 210, 8, 1\right], \left[7, 0, 20, 0, 150, 1, 2\right], \left[80, 1.25000000000000, 120, 8, 200, 6, 1\right], \left[65, 0, 25, 0, 550, 0, 1\right], \left[50, 0, 80, 1.50000000000000, 330, 3, 4\right], \left[25, 0, 15, 0, 260, 0, 2\right], \left[65, 0, 30, 0, 500, 0, 0\right], \left[58, 0, 110, 9, 30, 2, 2\right], \left[79, 0, 110, 8, 190, 6, 0\right], \left[93, 2.05000000000000, 230, 22, 370, 2, 1\right], \left[50, 0, 5, 0, 0, 0, 0\right]\right]
WARNING: Some output was deleted.
p=MixedIntegerLinearProgram(maximization=True) x=p.new_variable(binary=True) #Calories constraint min p.add_constraint(add([x[i]*M[i][2] for i in range(20)]) >= 750) #Calories constraint max p.add_constraint(add([x[i]*M[i][2] for i in range(20)]) <= 1000) #Fat constraint min p.add_constraint(add([x[i]*M[i][3] for i in range(20)]) >= 15) #Fat constraint max p.add_constraint(add([x[i]*M[i][3] for i in range(20)]) <= 32) #Sodium p.add_constraint(add([x[i]*M[i][4] for i in range(20)]) <= 1300) ##OG sodium constraint was 500. Had to increase for a feasible sol'n #Protein constraint Min p.add_constraint(add([x[i]*M[i][5] for i in range(20)]) >= 18) #Sugar constraint p.add_constraint(add([x[i]*M[i][6] for i in range(20)]) <= 10) #Must have 1 meat in the bowl p.add_constraint(add([x[k] for k in range(6)]) == 1) p.add_constraint(x[6]+x[7]<=1) #rice constraint p.add_constraint(x[8]+x[9]<=1) #beans constraint, can only have 1 type max p.add_constraint(add([x[i] for i in range(12,15)])>=1) #when we order veggies, it comes with guac #p.add_constraint(x[5]+x[18]==0%2) p.set_objective(objtaste-objcost) p.show() p.solve() soln=p.get_values(x) soln
Maximization: 91.15 x_0 + 82.15 x_1 + 32.7 x_2 + 32.15 x_3 + 43.15 x_4 + 55.2 x_5 + 65.0 x_6 + 55.0 x_7 + 65.0 x_8 + 50.0 x_9 + 7.0 x_10 + 78.75 x_11 + 65.0 x_12 + 50.0 x_13 + 25.0 x_14 + 65.0 x_15 + 58.0 x_16 + 79.0 x_17 + 90.95 x_18 + 50.0 x_19 Constraints: -180.0 x_0 - 150.0 x_1 - 210.0 x_2 - 170.0 x_3 - 150.0 x_4 - 40.0 x_5 - 210.0 x_6 - 210.0 x_7 - 130.0 x_8 - 130.0 x_9 - 20.0 x_10 - 120.0 x_11 - 25.0 x_12 - 80.0 x_13 - 15.0 x_14 - 30.0 x_15 - 110.0 x_16 - 110.0 x_17 - 230.0 x_18 - 5.0 x_19 <= -750.0 180.0 x_0 + 150.0 x_1 + 210.0 x_2 + 170.0 x_3 + 150.0 x_4 + 40.0 x_5 + 210.0 x_6 + 210.0 x_7 + 130.0 x_8 + 130.0 x_9 + 20.0 x_10 + 120.0 x_11 + 25.0 x_12 + 80.0 x_13 + 15.0 x_14 + 30.0 x_15 + 110.0 x_16 + 110.0 x_17 + 230.0 x_18 + 5.0 x_19 <= 1000.0 -7.0 x_0 - 6.0 x_1 - 12.0 x_2 - 7.0 x_3 - 10.0 x_4 - 4.0 x_6 - 6.0 x_7 - 1.5 x_8 - 1.5 x_9 - 8.0 x_11 - 1.5 x_13 - 9.0 x_16 - 8.0 x_17 - 22.0 x_18 <= -15.0 7.0 x_0 + 6.0 x_1 + 12.0 x_2 + 7.0 x_3 + 10.0 x_4 + 4.0 x_6 + 6.0 x_7 + 1.5 x_8 + 1.5 x_9 + 8.0 x_11 + 1.5 x_13 + 9.0 x_16 + 8.0 x_17 + 22.0 x_18 <= 32.0 310.0 x_0 + 330.0 x_1 + 450.0 x_2 + 530.0 x_3 + 560.0 x_4 + 300.0 x_5 + 350.0 x_6 + 190.0 x_7 + 210.0 x_8 + 210.0 x_9 + 150.0 x_10 + 200.0 x_11 + 550.0 x_12 + 330.0 x_13 + 260.0 x_14 + 500.0 x_15 + 30.0 x_16 + 190.0 x_17 + 370.0 x_18 <= 1300.0 -32.0 x_0 - 21.0 x_1 - 23.0 x_2 - 24.0 x_3 - 8.0 x_4 - 2.0 x_5 - 4.0 x_6 - 4.0 x_7 - 8.0 x_8 - 8.0 x_9 - x_10 - 6.0 x_11 - 3.0 x_13 - 2.0 x_16 - 6.0 x_17 - 2.0 x_18 <= -18.0 5.0 x_4 + 4.0 x_5 + 2.0 x_8 + x_9 + 2.0 x_10 + x_11 + x_12 + 4.0 x_13 + 2.0 x_14 + 2.0 x_16 + x_18 <= 10.0 1.0 <= x_0 + x_1 + x_2 + x_3 + x_4 + x_5 <= 1.0 x_6 + x_7 <= 1.0 x_8 + x_9 <= 1.0 - x_12 - x_13 - x_14 <= -1.0 Variables: x_0 is a boolean variable (min=0.0, max=1.0) x_1 is a boolean variable (min=0.0, max=1.0) x_2 is a boolean variable (min=0.0, max=1.0) x_3 is a boolean variable (min=0.0, max=1.0) x_4 is a boolean variable (min=0.0, max=1.0) x_5 is a boolean variable (min=0.0, max=1.0) x_6 is a boolean variable (min=0.0, max=1.0) x_7 is a boolean variable (min=0.0, max=1.0) x_8 is a boolean variable (min=0.0, max=1.0) x_9 is a boolean variable (min=0.0, max=1.0) x_10 is a boolean variable (min=0.0, max=1.0) x_11 is a boolean variable (min=0.0, max=1.0) x_12 is a boolean variable (min=0.0, max=1.0) x_13 is a boolean variable (min=0.0, max=1.0) x_14 is a boolean variable (min=0.0, max=1.0) x_15 is a boolean variable (min=0.0, max=1.0) x_16 is a boolean variable (min=0.0, max=1.0) x_17 is a boolean variable (min=0.0, max=1.0) x_18 is a boolean variable (min=0.0, max=1.0) x_19 is a boolean variable (min=0.0, max=1.0)
{0: 0.0, 1: 1.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 1.0, 8: 1.0, 9: 0.0, 10: 0.0, 11: 0.0, 12: 0.0, 13: 1.0, 14: 0.0, 15: 0.0, 16: 1.0, 17: 1.0, 18: 0.0, 19: 1.0}
for i in range(20): if soln[i]==1: print(Mfood[i])
steak Brown Rice Black Beans Chilicorn salsa Sour cream Cheese Lettuce
calories=0 for i in range(20): if soln[i]==1: calories=calories+M[i][2] calories
795