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