[2391] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2007 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[2146] | 19 | #include <lemon/lp.h> |
---|
| 20 | //#include <lemon/ilp_glpk.h> |
---|
| 21 | |
---|
| 22 | using namespace lemon; |
---|
| 23 | |
---|
| 24 | int main(){ |
---|
| 25 | |
---|
| 26 | //MipGlpk ilp; |
---|
| 27 | |
---|
| 28 | Mip ilp; |
---|
| 29 | |
---|
[2148] | 30 | |
---|
[2146] | 31 | typedef Mip::Row Row; |
---|
| 32 | typedef Mip::Col Col; |
---|
| 33 | |
---|
| 34 | ilp.max(); |
---|
| 35 | |
---|
| 36 | Col x1 = ilp.addCol(); |
---|
| 37 | Col x2 = ilp.addCol(); |
---|
| 38 | Col x3 = ilp.addCol(); |
---|
| 39 | |
---|
| 40 | ilp.integer(x1,true); |
---|
| 41 | ilp.integer(x2,true); |
---|
| 42 | ilp.integer(x3,true); |
---|
| 43 | |
---|
| 44 | ilp.addRow(x1+x2+x3 <=100); |
---|
| 45 | ilp.addRow(10*x1+4*x2+5*x3<=600); |
---|
| 46 | ilp.addRow(2*x1+2*x2+6*x3<=300); |
---|
| 47 | |
---|
| 48 | ilp.colLowerBound(x1, 0); |
---|
| 49 | ilp.colLowerBound(x2, 0); |
---|
| 50 | ilp.colLowerBound(x3, 0); |
---|
| 51 | //Objective function |
---|
[2369] | 52 | ilp.obj(10*x1+6*x2+4*x3); |
---|
[2146] | 53 | |
---|
| 54 | //Call the routine of the underlying LP solver |
---|
| 55 | ilp.solve(); |
---|
| 56 | |
---|
| 57 | //Print results |
---|
| 58 | if (ilp.primalStatus()==LpSolverBase::OPTIMAL){ |
---|
| 59 | std::cout<<"Optimal solution found!"<<std::endl; |
---|
| 60 | printf("optimum value = %g; x1 = %g; x2 = %g; x3 = %g\n", |
---|
| 61 | ilp.primalValue(), |
---|
| 62 | ilp.primal(x1), ilp.primal(x2), ilp.primal(x3)); |
---|
| 63 | } |
---|
| 64 | else{ |
---|
| 65 | std::cout<<"Optimal solution not found!"<<std::endl; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | } |
---|