COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/mip_demo.cc @ 2524:44675961f645

Last change on this file since 2524:44675961f645 was 2492:387f6ff851ef, checked in by Balazs Dezso, 17 years ago

Adding doc

File size: 1.7 KB
Line 
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
19
20///\ingroup demos
21///\file
22///\brief Mixed integer program solver demo
23///
24/// This example shows how can we solve an integer program with lemon
25/// \c Mip interface and with default solver.
26///
27/// \include mip_demo.cc
28
29#include <lemon/lp.h>
30
31using namespace lemon;
32
33int main(){
34
35   Mip ilp;
36
37
38  typedef Mip::Row Row;
39  typedef Mip::Col Col;
40 
41  ilp.max();
42 
43  Col x1 = ilp.addCol();
44  Col x2 = ilp.addCol();
45  Col x3 = ilp.addCol();
46 
47  ilp.integer(x1,true);
48  ilp.integer(x2,true);
49  ilp.integer(x3,true);
50 
51  ilp.addRow(x1+x2+x3 <=100); 
52  ilp.addRow(10*x1+4*x2+5*x3<=600); 
53  ilp.addRow(2*x1+2*x2+6*x3<=300);
54 
55  ilp.colLowerBound(x1, 0);
56  ilp.colLowerBound(x2, 0);
57  ilp.colLowerBound(x3, 0);
58  //Objective function
59  ilp.obj(10*x1+6*x2+4*x3);
60 
61  //Call the routine of the underlying LP solver
62  ilp.solve();
63 
64  //Print results
65  if (ilp.primalStatus()==LpSolverBase::OPTIMAL){
66    std::cout<<"Optimal solution found!"<<std::endl;
67    printf("optimum value = %g; x1 = %g; x2 = %g; x3 = %g\n",
68           ilp.primalValue(),
69           ilp.primal(x1), ilp.primal(x2), ilp.primal(x3));
70  }
71  else{
72    std::cout<<"Optimal solution not found!"<<std::endl;
73  }
74
75}
Note: See TracBrowser for help on using the repository browser.