Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- # 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"
- prob.writeLP("SimpleDietProblem.lp")
- prob.solve()
- print("Status:", LpStatus[prob.status])
- # Creates a list of the Food_groups
- food_choices = list(df['Food_Groups'])
- food_chosen = LpVariable.dicts("Chosen",food_choices,0,1,cat='Integer')
- # Creates a list of the Days
- Days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
- days_menu = LpVariable.dicts("days_menu",Days,0,1,cat='Integer')
- #updating my objective function
- prob += lpSum([sugars[i]*food_vars[i]*days_menu[i]*food_chosen[i] for i in
- food_items])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement