demo/mip_demo.cc
author alpar
Tue, 17 Oct 2006 11:02:30 +0000
changeset 2252 133028e83940
parent 2146 5fcb6598276d
child 2369 6ae1a97055a2
permissions -rw-r--r--
A trial to make the last test platform independent.
athos@2146
     1
#include <lemon/lp.h>
athos@2146
     2
//#include <lemon/ilp_glpk.h>
athos@2146
     3
athos@2146
     4
using namespace lemon;
athos@2146
     5
athos@2146
     6
int main(){
athos@2146
     7
athos@2146
     8
  //MipGlpk ilp;
athos@2146
     9
athos@2146
    10
   Mip ilp;
athos@2146
    11
athos@2148
    12
athos@2146
    13
  typedef Mip::Row Row;
athos@2146
    14
  typedef Mip::Col Col;
athos@2146
    15
  
athos@2146
    16
  ilp.max();
athos@2146
    17
  
athos@2146
    18
  Col x1 = ilp.addCol();
athos@2146
    19
  Col x2 = ilp.addCol();
athos@2146
    20
  Col x3 = ilp.addCol();
athos@2146
    21
  
athos@2146
    22
  ilp.integer(x1,true);
athos@2146
    23
  ilp.integer(x2,true);
athos@2146
    24
  ilp.integer(x3,true);
athos@2146
    25
  
athos@2146
    26
  ilp.addRow(x1+x2+x3 <=100);  
athos@2146
    27
  ilp.addRow(10*x1+4*x2+5*x3<=600);  
athos@2146
    28
  ilp.addRow(2*x1+2*x2+6*x3<=300); 
athos@2146
    29
  
athos@2146
    30
  ilp.colLowerBound(x1, 0);
athos@2146
    31
  ilp.colLowerBound(x2, 0);
athos@2146
    32
  ilp.colLowerBound(x3, 0);
athos@2146
    33
  //Objective function
athos@2146
    34
  ilp.setObj(10*x1+6*x2+4*x3);
athos@2146
    35
  
athos@2146
    36
  //Call the routine of the underlying LP solver
athos@2146
    37
  ilp.solve();
athos@2146
    38
  
athos@2146
    39
  //Print results
athos@2146
    40
  if (ilp.primalStatus()==LpSolverBase::OPTIMAL){
athos@2146
    41
    std::cout<<"Optimal solution found!"<<std::endl;
athos@2146
    42
    printf("optimum value = %g; x1 = %g; x2 = %g; x3 = %g\n", 
athos@2146
    43
           ilp.primalValue(), 
athos@2146
    44
           ilp.primal(x1), ilp.primal(x2), ilp.primal(x3));
athos@2146
    45
  }
athos@2146
    46
  else{
athos@2146
    47
    std::cout<<"Optimal solution not found!"<<std::endl;
athos@2146
    48
  }
athos@2146
    49
athos@2146
    50
}