test/lp_test.cc
changeset 1209 4a170261cc54
parent 1131 4add05447ca0
equal deleted inserted replaced
19:ae155e35588d 20:18f90208ae53
   337 
   337 
   338   //Testing the problem retrieving routines
   338   //Testing the problem retrieving routines
   339   check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
   339   check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
   340   check(lp.sense() == lp.MAX,"This is a maximization!");
   340   check(lp.sense() == lp.MAX,"This is a maximization!");
   341   check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
   341   check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
       
   342   check(lp.coeff(upright,x2)==2,"The coefficient in question is 1!");
   342   check(lp.colLowerBound(x1)==0,
   343   check(lp.colLowerBound(x1)==0,
   343         "The lower bound for variable x1 should be 0.");
   344         "The lower bound for variable x1 should be 0.");
   344   check(lp.colUpperBound(x1)==LpSolver::INF,
   345   check(lp.colUpperBound(x1)==LpSolver::INF,
   345         "The upper bound for variable x1 should be infty.");
   346         "The upper bound for variable x1 should be infty.");
   346   check(lp.rowLowerBound(upright) == -LpSolver::INF,
   347   check(lp.rowLowerBound(upright) == -LpSolver::INF,
   422   delete lp;
   423   delete lp;
   423   delete lpnew;
   424   delete lpnew;
   424   delete lpclone;
   425   delete lpclone;
   425 }
   426 }
   426 
   427 
       
   428 template<class LP>
       
   429 void rangeConstraintTest()
       
   430 {
       
   431   LP lp;
       
   432   // Add two columns (variables) to the problem
       
   433   typename LP::Col x1 = lp.addCol();
       
   434   typename LP::Col x2 = lp.addCol();
       
   435   // Add rows (constraints) to the problem
       
   436   lp.addRow(x1 - 5 <= x2);
       
   437     lp.addRow(0 <= 2 * x1 + x2 <= 25);
       
   438   
       
   439   // Set lower and upper bounds for the columns (variables)
       
   440   lp.colLowerBound(x1, 0);
       
   441   lp.colUpperBound(x2, 10);
       
   442   
       
   443   // Specify the objective function
       
   444   lp.max();
       
   445   lp.obj(5 * x1 + 3 * x2);
       
   446   
       
   447   // Solve the problem using the underlying LP solver
       
   448   lp.solve();
       
   449   // Print the results
       
   450   check(lp.primalType() == LP::OPTIMAL, "Optimal solution is not found");
       
   451   check(lp.primal() <= 67.501 && lp.primal() >= 67.499, "Wrong objective value");
       
   452   check(lp.primal(x1) <= 7.501 && lp.primal(x1) >= 7.499, "Wrong value for x1");
       
   453   check(lp.primal(x2) <= 10.001 && lp.primal(x2) >= 9.999, "Wrong value for x2");
       
   454 }
       
   455 
   427 int main()
   456 int main()
   428 {
   457 {
   429   LpSkeleton lp_skel;
   458   LpSkeleton lp_skel;
   430   lpTest(lp_skel);
   459   lpTest(lp_skel);
   431 
   460 
   442   {
   471   {
   443     GlpkLp lp_glpk1,lp_glpk2;
   472     GlpkLp lp_glpk1,lp_glpk2;
   444     lpTest(lp_glpk1);
   473     lpTest(lp_glpk1);
   445     aTest(lp_glpk2);
   474     aTest(lp_glpk2);
   446     cloneTest<GlpkLp>();
   475     cloneTest<GlpkLp>();
       
   476     rangeConstraintTest<GlpkLp>();
   447   }
   477   }
   448 #endif
   478 #endif
   449 
   479 
   450 #ifdef LEMON_HAVE_CPLEX
   480 #ifdef LEMON_HAVE_CPLEX
   451   try {
   481   try {
   452     CplexLp lp_cplex1,lp_cplex2;
   482     CplexLp lp_cplex1,lp_cplex2;
   453     lpTest(lp_cplex1);
   483     lpTest(lp_cplex1);
   454     aTest(lp_cplex2);
   484     aTest(lp_cplex2);
   455     cloneTest<CplexLp>();
   485     cloneTest<CplexLp>();
       
   486     rangeConstraintTest<CplexLp>();
   456   } catch (CplexEnv::LicenseError& error) {
   487   } catch (CplexEnv::LicenseError& error) {
   457     check(false, error.what());
   488     check(false, error.what());
   458   }
   489   }
   459 #endif
   490 #endif
   460 
   491 
   462   {
   493   {
   463     SoplexLp lp_soplex1,lp_soplex2;
   494     SoplexLp lp_soplex1,lp_soplex2;
   464     lpTest(lp_soplex1);
   495     lpTest(lp_soplex1);
   465     aTest(lp_soplex2);
   496     aTest(lp_soplex2);
   466     cloneTest<SoplexLp>();
   497     cloneTest<SoplexLp>();
       
   498     rangeConstraintTest<Soplex>();
   467   }
   499   }
   468 #endif
   500 #endif
   469 
   501 
   470 #ifdef LEMON_HAVE_CLP
   502 #ifdef LEMON_HAVE_CLP
   471   {
   503   {
   472     ClpLp lp_clp1,lp_clp2;
   504     ClpLp lp_clp1,lp_clp2;
   473     lpTest(lp_clp1);
   505     lpTest(lp_clp1);
   474     aTest(lp_clp2);
   506     aTest(lp_clp2);
   475     cloneTest<ClpLp>();
   507     cloneTest<ClpLp>();
       
   508     rangeConstraintTest<ClpLp>();
   476   }
   509   }
   477 #endif
   510 #endif
   478 
   511 
   479   return 0;
   512   return 0;
   480 }
   513 }