dindizz commited on
Commit
4714c60
·
verified ·
1 Parent(s): 21cbae6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -62,18 +62,15 @@ def optimize_dishes_for_budget(city, daily_budget):
62
  calories = [nutritional_data[dish]["Energy (kcal)"] for dish in nutritional_data]
63
  proteins = [nutritional_data[dish]["Protein (g)"] for dish in nutritional_data]
64
 
65
- # Introduce a small penalty for selecting large quantities of any single dish
66
- diversity_penalty = np.ones(len(costs)) * 0.01
67
-
68
- # Objective function: Maximize nutritional value (calories + protein) while encouraging diversity
69
- c = [-1 * (cal + prot) + penalty for cal, prot, penalty in zip(calories, proteins, diversity_penalty)]
70
 
71
  # Constraint: Total cost must not exceed the daily budget
72
  A_ub = [costs] # Sum of costs * portions <= daily_budget
73
  b_ub = [daily_budget]
74
 
75
  # Bounds for each dish (x >= 0)
76
- bounds = [(0, None) for _ in costs]
77
 
78
  # Solve the optimization problem
79
  result = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')
 
62
  calories = [nutritional_data[dish]["Energy (kcal)"] for dish in nutritional_data]
63
  proteins = [nutritional_data[dish]["Protein (g)"] for dish in nutritional_data]
64
 
65
+ # Objective function: Maximize nutritional value (calories + protein)
66
+ c = [-1 * (cal + prot) for cal, prot in zip(calories, proteins)] # Minimize negative of nutrition for maximization
 
 
 
67
 
68
  # Constraint: Total cost must not exceed the daily budget
69
  A_ub = [costs] # Sum of costs * portions <= daily_budget
70
  b_ub = [daily_budget]
71
 
72
  # Bounds for each dish (x >= 0)
73
+ bounds = [(0.1, None) for _ in costs] # Minimum 0.1 portion to encourage diversity
74
 
75
  # Solve the optimization problem
76
  result = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')