I have written the following code for meal generation for different days, but I get the same meal everyday. I want to have "meat" and "Vegetarian" food_groups on alternate days.
my dataframe is as follows:
id name energy sugar Food_Groups
1 4-Grain Flakes 140 58.8 Breakfast
2 Beef Mince, Fried 1443 8.0 Meat
3 Pork 1000 3.0 Meat
4 cake 1200 150 Sweet
5 cheese 1100 140 Sweet
6 Juice 700 85 Drink
7 cabbage 60 13 vegetarian
8 cucumber 10 10 vegetarian
9 eggs 45 30 Breakfast
I am using PuLP to minimize sugar with a constraint on calories intake.
# Create the 'prob' variable to contain the problem data
prob = LpProblem("Simple Diet Problem",LpMinimize)
#create data variables and dictionary
food_items = list(df['name'])
calories = dict(zip(food_items,df['energy']))
sugars = dict(zip(food_items,df['sugar']))
food_vars =LpVariable.dicts("Food",food_items,lowBound=0,cat='Integer')
#Building the LP problem by adding the main objective function.
prob += lpSum([sugars[i]*food_vars[i] for i in food_items])
#adding calorie constraint
prob += lpSum([calories[f] * food_vars[f] for f in food_items]) >=
1800.0, "CalorieMinimum"
prob += lpSum([calories[f] * food_vars[f] for f in food_items]) <=
2200.0, "CalorieMaximum"
I loop over prob.solve() to generate menu for different days
prob.writeLP("SimpleDietProblem.lp")
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
for i in days:
print(i)
prob.solve(PULP_CBC_CMD())
# print("Status:", LpStatus[prob.status])
print("Therefore, the optimal balanced diet consists of\n"+"-")
for v in prob.variables():
if v.varValue:
print(v.name , "=", v.varValue)
print("The total sugar of this balanced diet is: {}\n\n".format(round(value(prob.objective),2)))
My problem is that the output is repeated for all the days. How do I get "meat" and "vegetarian" on alternate days??