test/lp_test.cc
changeset 1205 57abff252556
parent 1131 4add05447ca0
     1.1 --- a/test/lp_test.cc	Sat Oct 27 13:00:48 2018 +0200
     1.2 +++ b/test/lp_test.cc	Wed Jan 20 16:17:21 2021 +0100
     1.3 @@ -339,6 +339,7 @@
     1.4    check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
     1.5    check(lp.sense() == lp.MAX,"This is a maximization!");
     1.6    check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
     1.7 +  check(lp.coeff(upright,x2)==2,"The coefficient in question is 1!");
     1.8    check(lp.colLowerBound(x1)==0,
     1.9          "The lower bound for variable x1 should be 0.");
    1.10    check(lp.colUpperBound(x1)==LpSolver::INF,
    1.11 @@ -424,6 +425,34 @@
    1.12    delete lpclone;
    1.13  }
    1.14  
    1.15 +template<class LP>
    1.16 +void rangeConstraintTest()
    1.17 +{
    1.18 +  LP lp;
    1.19 +  // Add two columns (variables) to the problem
    1.20 +  typename LP::Col x1 = lp.addCol();
    1.21 +  typename LP::Col x2 = lp.addCol();
    1.22 +  // Add rows (constraints) to the problem
    1.23 +  lp.addRow(x1 - 5 <= x2);
    1.24 +    lp.addRow(0 <= 2 * x1 + x2 <= 25);
    1.25 +  
    1.26 +  // Set lower and upper bounds for the columns (variables)
    1.27 +  lp.colLowerBound(x1, 0);
    1.28 +  lp.colUpperBound(x2, 10);
    1.29 +  
    1.30 +  // Specify the objective function
    1.31 +  lp.max();
    1.32 +  lp.obj(5 * x1 + 3 * x2);
    1.33 +  
    1.34 +  // Solve the problem using the underlying LP solver
    1.35 +  lp.solve();
    1.36 +  // Print the results
    1.37 +  check(lp.primalType() == LP::OPTIMAL, "Optimal solution is not found");
    1.38 +  check(lp.primal() <= 67.501 && lp.primal() >= 67.499, "Wrong objective value");
    1.39 +  check(lp.primal(x1) <= 7.501 && lp.primal(x1) >= 7.499, "Wrong value for x1");
    1.40 +  check(lp.primal(x2) <= 10.001 && lp.primal(x2) >= 9.999, "Wrong value for x2");
    1.41 +}
    1.42 +
    1.43  int main()
    1.44  {
    1.45    LpSkeleton lp_skel;
    1.46 @@ -444,6 +473,7 @@
    1.47      lpTest(lp_glpk1);
    1.48      aTest(lp_glpk2);
    1.49      cloneTest<GlpkLp>();
    1.50 +    rangeConstraintTest<GlpkLp>();
    1.51    }
    1.52  #endif
    1.53  
    1.54 @@ -453,6 +483,7 @@
    1.55      lpTest(lp_cplex1);
    1.56      aTest(lp_cplex2);
    1.57      cloneTest<CplexLp>();
    1.58 +    rangeConstraintTest<CplexLp>();
    1.59    } catch (CplexEnv::LicenseError& error) {
    1.60      check(false, error.what());
    1.61    }
    1.62 @@ -464,6 +495,7 @@
    1.63      lpTest(lp_soplex1);
    1.64      aTest(lp_soplex2);
    1.65      cloneTest<SoplexLp>();
    1.66 +    rangeConstraintTest<Soplex>();
    1.67    }
    1.68  #endif
    1.69  
    1.70 @@ -473,6 +505,7 @@
    1.71      lpTest(lp_clp1);
    1.72      aTest(lp_clp2);
    1.73      cloneTest<ClpLp>();
    1.74 +    rangeConstraintTest<ClpLp>();
    1.75    }
    1.76  #endif
    1.77