forked from ricbit/easyscip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diet.cc
45 lines (36 loc) · 1.34 KB
/
diet.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Solves the diet problem using EasySCIP.
// by Ricardo Bittencourt 2013
#include <iostream>
#include "easyscip.h"
using namespace std;
using namespace easyscip;
int main() {
// Create a MIPSolver using EasySCIP.
MIPSolver solver;
// Create one variable for each food type.
// Each variable range from 0 to 1000, and the last coefficient is the price.
Variable corn = solver.integer_variable(0, 1000, 0.08);
Variable milk = solver.integer_variable(0, 1000, 0.23);
Variable bread = solver.integer_variable(0, 1000, 0.05);
// Add a constraint for the calories.
Constraint calories = solver.constraint();
calories.add_variable(corn, 72);
calories.add_variable(milk, 121);
calories.add_variable(bread, 65);
calories.commit(2000, 200000);
// Add a constraint for the vitamin A.
Constraint vitamin_a = solver.constraint();
vitamin_a.add_variable(corn, 107);
vitamin_a.add_variable(milk, 500);
vitamin_a.add_variable(bread, 0);
vitamin_a.commit(5000, 500000);
// Solve the MIP model.
Solution sol = solver.solve();
// Print solution.
cout << "Corn: " << sol.value(corn) << "\n";
cout << "Milk: " << sol.value(milk) << "\n";
cout << "Bread: " << sol.value(bread) << "\n";
// No need to worry about memory management, everything is released
// when the objects are deleted after falling out of scope.
return 0;
}