• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 25th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. id      name               energy   sugar   Food_Groups
2. 1       4-Grain Flakes      140     58.8    Breakfast
3. 2       Beef Mince, Fried   1443    8.0     Meat
4. 3       Pork                1000    3.0     Meat
5. 4       cake                1200    150     Sweet
6. 5       cheese              1100    140     Sweet
7. 6       Juice               700     85      Drink
8. 7       cabbage             60      13      vegetarian
9. 8       cucumber            10      10      vegetarian
10. 9       eggs                45      30      Breakfast
11.
12. # Create the 'prob' variable to contain the problem data
13. prob = LpProblem("Simple Diet Problem",LpMinimize)
14. #create data variables and dictionary
15. food_items = list(df['name'])
16. calories = dict(zip(food_items,df['energy']))
17. sugars = dict(zip(food_items,df['sugar']))
18.
19. food_vars =LpVariable.dicts("Food",food_items,lowBound=0,cat='Integer')
20.
21. #Building the LP problem by adding the main objective function.
22. prob += lpSum([sugars[i]*food_vars[i] for i in food_items])
23.
25. prob += lpSum([calories[f] * food_vars[f] for f in food_items]) >=
26. 1800.0, "CalorieMinimum"
27. prob += lpSum([calories[f] * food_vars[f] for f in food_items]) <=
28. 2200.0, "CalorieMaximum"
29.
30. prob.writeLP("SimpleDietProblem.lp")
31.
32. prob.solve()
33.
34. print("Status:", LpStatus[prob.status])
35.
36. # Creates a list of the Food_groups
37. food_choices = list(df['Food_Groups'])
38.
39. food_chosen = LpVariable.dicts("Chosen",food_choices,0,1,cat='Integer')
40.
41.
42. # Creates a list of the Days
43. Days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
44.