equal
deleted
inserted
replaced
10 //int decimal,sign; |
10 //int decimal,sign; |
11 std::ostringstream buf; |
11 std::ostringstream buf; |
12 buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus()); |
12 buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus()); |
13 |
13 |
14 // itoa(stat,buf1, 10); |
14 // itoa(stat,buf1, 10); |
15 check(lp.primalStatus()==stat, buf.str()); |
15 check(lp.mipStatus()==stat, buf.str()); |
16 |
16 |
17 if (stat == LpSolverBase::OPTIMAL) { |
17 if (stat == LpSolverBase::OPTIMAL) { |
18 std::ostringstream buf; |
18 std::ostringstream buf; |
19 buf << "Wrong optimal value: the right optimum is " << exp_opt; |
19 buf << "Wrong optimal value: the right optimum is " << exp_opt; |
20 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str()); |
20 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str()); |
33 Col x1 = mip.addCol(); |
33 Col x1 = mip.addCol(); |
34 Col x2 = mip.addCol(); |
34 Col x2 = mip.addCol(); |
35 |
35 |
36 |
36 |
37 |
37 |
|
38 |
|
39 |
|
40 |
|
41 //Objective function |
|
42 mip.setObj(x1); |
|
43 |
|
44 mip.max(); |
|
45 |
|
46 |
|
47 //Unconstrained optimization |
|
48 mip.solve(); |
|
49 //Check it out! |
|
50 |
38 //Constraints |
51 //Constraints |
39 mip.addRow(2*x1+x2 <=2); |
52 mip.addRow(2*x1+x2 <=2); |
40 mip.addRow(x1-2*x2 <=0); |
53 mip.addRow(x1-2*x2 <=0); |
41 |
54 |
42 //Nonnegativity of the variable x1 |
55 //Nonnegativity of the variable x1 |
43 mip.colLowerBound(x1, 0); |
56 mip.colLowerBound(x1, 0); |
44 |
57 |
45 |
58 |
46 |
59 |
47 //Objective function |
|
48 mip.setObj(x1); |
|
49 |
|
50 mip.max(); |
|
51 |
|
52 |
|
53 //Maximization of x1 |
60 //Maximization of x1 |
54 //over the triangle with vertices |
61 //over the triangle with vertices |
55 double expected_opt=4.0/5.0; |
62 double expected_opt=4.0/5.0; |
56 solveAndCheck(mip, Mip::OPTIMAL, expected_opt); |
63 solveAndCheck(mip, Mip::OPTIMAL, expected_opt); |
57 |
64 |
58 //Restrict x2 to integer |
65 //Restrict x2 to integer |
59 mip.colType(x2,Mip::INTEGER); |
66 mip.colType(x2,Mip::INTEGER); |