COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/mip_demo.cc

Last change on this file was 2553:bfced05fa852, checked in by Alpar Juttner, 16 years ago

Happy New Year to LEMON (+ better update-copyright-header script)

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