Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,8 +62,11 @@ 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 |
-
#
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
# Constraint: Total cost must not exceed the daily budget
|
| 69 |
A_ub = [costs] # Sum of costs * portions <= 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
|