demo/lp_demo.cc
changeset 1536 308150155bb5
parent 1513 b2a79aaa6867
child 1577 15098fb5275c
equal deleted inserted replaced
1:780f36c792b3 2:bd54eafb223a
    21 
    21 
    22 int main()
    22 int main()
    23 {     
    23 {     
    24  //The following example is taken from the documentation of the GLPK library.
    24  //The following example is taken from the documentation of the GLPK library.
    25  //See it in the GLPK reference manual and among the GLPK sample files (sample.c)
    25  //See it in the GLPK reference manual and among the GLPK sample files (sample.c)
       
    26 
       
    27   //A default solver is taken
    26   LpDefault lp;
    28   LpDefault lp;
    27   typedef LpDefault::Row Row;
    29   typedef LpDefault::Row Row;
    28   typedef LpDefault::Col Col;
    30   typedef LpDefault::Col Col;
    29   
    31   
    30 
    32 
    34   //We add coloumns (variables) to our problem
    36   //We add coloumns (variables) to our problem
    35   Col x1 = lp.addCol();
    37   Col x1 = lp.addCol();
    36   Col x2 = lp.addCol();
    38   Col x2 = lp.addCol();
    37   Col x3 = lp.addCol();
    39   Col x3 = lp.addCol();
    38 
    40 
    39   //One solution
       
    40   //   Row p = lp.addRow();
       
    41   //   Row q = lp.addRow();
       
    42   //   Row r = lp.addRow();
       
    43   //   lp.setRow(p,x1+x2+x3 <=100);  
       
    44   //   lp.setRow(q,10*x1+4*x2+5*x3<=600);  
       
    45   //   lp.setRow(r,2*x1+2*x2+6*x3<=300);  
       
    46 
       
    47   //A more elegant one
       
    48   //Constraints
    41   //Constraints
    49   lp.addRow(x1+x2+x3 <=100);  
    42   lp.addRow(x1+x2+x3 <=100);  
    50   lp.addRow(10*x1+4*x2+5*x3<=600);  
    43   lp.addRow(10*x1+4*x2+5*x3<=600);  
    51   lp.addRow(2*x1+2*x2+6*x3<=300);  
    44   lp.addRow(2*x1+2*x2+6*x3<=300);  
    52   //Nonnegativity of the variables
    45   //Nonnegativity of the variables
    67   }
    60   }
    68   else{
    61   else{
    69     std::cout<<"Optimal solution not found!"<<std::endl;
    62     std::cout<<"Optimal solution not found!"<<std::endl;
    70   }
    63   }
    71 
    64 
       
    65   //End of LEMON style code
    72 
    66 
    73   //Here comes the same problem written in C using GLPK API routines
    67   //Here comes the same problem written in C using GLPK API routines
    74 
    68 
    75 //   LPX *lp;
    69 //   LPX *lp;
    76 //       int ia[1+1000], ja[1+1000];
    70 //       int ia[1+1000], ja[1+1000];