COIN-OR::LEMON - Graph Library

Changeset 1427:57abff252556 in lemon for test/lp_test.cc


Ignore:
Timestamp:
01/20/21 16:17:21 (3 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Bugfixes in CplexBase? and ClpLp? (#639)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/lp_test.cc

    r1337 r1427  
    340340  check(lp.sense() == lp.MAX,"This is a maximization!");
    341341  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!");
    342343  check(lp.colLowerBound(x1)==0,
    343344        "The lower bound for variable x1 should be 0.");
     
    425426}
    426427
     428template<class LP>
     429void 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
    427456int main()
    428457{
     
    445474    aTest(lp_glpk2);
    446475    cloneTest<GlpkLp>();
     476    rangeConstraintTest<GlpkLp>();
    447477  }
    448478#endif
     
    454484    aTest(lp_cplex2);
    455485    cloneTest<CplexLp>();
     486    rangeConstraintTest<CplexLp>();
    456487  } catch (CplexEnv::LicenseError& error) {
    457488    check(false, error.what());
     
    465496    aTest(lp_soplex2);
    466497    cloneTest<SoplexLp>();
     498    rangeConstraintTest<Soplex>();
    467499  }
    468500#endif
     
    474506    aTest(lp_clp2);
    475507    cloneTest<ClpLp>();
     508    rangeConstraintTest<ClpLp>();
    476509  }
    477510#endif
Note: See TracChangeset for help on using the changeset viewer.