diff -r 736a341e604b -r eba5aa390aca test/lp_test.cc --- a/test/lp_test.cc Thu Jan 21 08:36:53 2021 +0100 +++ b/test/lp_test.cc Thu Jan 21 18:58:37 2021 +0100 @@ -339,6 +339,7 @@ check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!"); check(lp.sense() == lp.MAX,"This is a maximization!"); check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!"); + check(lp.coeff(upright,x2)==2,"The coefficient in question is 1!"); check(lp.colLowerBound(x1)==0, "The lower bound for variable x1 should be 0."); check(lp.colUpperBound(x1)==LpSolver::INF, @@ -424,6 +425,34 @@ delete lpclone; } +template +void rangeConstraintTest() +{ + LP lp; + // Add two columns (variables) to the problem + typename LP::Col x1 = lp.addCol(); + typename LP::Col x2 = lp.addCol(); + // Add rows (constraints) to the problem + lp.addRow(x1 - 5 <= x2); + lp.addRow(0 <= 2 * x1 + x2 <= 25); + + // Set lower and upper bounds for the columns (variables) + lp.colLowerBound(x1, 0); + lp.colUpperBound(x2, 10); + + // Specify the objective function + lp.max(); + lp.obj(5 * x1 + 3 * x2); + + // Solve the problem using the underlying LP solver + lp.solve(); + // Print the results + check(lp.primalType() == LP::OPTIMAL, "Optimal solution is not found"); + check(lp.primal() <= 67.501 && lp.primal() >= 67.499, "Wrong objective value"); + check(lp.primal(x1) <= 7.501 && lp.primal(x1) >= 7.499, "Wrong value for x1"); + check(lp.primal(x2) <= 10.001 && lp.primal(x2) >= 9.999, "Wrong value for x2"); +} + int main() { LpSkeleton lp_skel; @@ -444,6 +473,7 @@ lpTest(lp_glpk1); aTest(lp_glpk2); cloneTest(); + rangeConstraintTest(); } #endif @@ -453,6 +483,7 @@ lpTest(lp_cplex1); aTest(lp_cplex2); cloneTest(); + rangeConstraintTest(); } catch (CplexEnv::LicenseError& error) { check(false, error.what()); } @@ -464,6 +495,7 @@ lpTest(lp_soplex1); aTest(lp_soplex2); cloneTest(); + rangeConstraintTest(); } #endif @@ -473,6 +505,7 @@ lpTest(lp_clp1); aTest(lp_clp2); cloneTest(); + rangeConstraintTest(); } #endif