COIN-OR::LEMON - Graph Library

Ticket #639: 639-57abff252556.patch

File 639-57abff252556.patch, 4.9 KB (added by Alpar Juttner, 3 months ago)
  • cmake/FindILOG.cmake

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1611155841 -3600
    #      Wed Jan 20 16:17:21 2021 +0100
    # Node ID 57abff252556e0ffd928de63314904bd531974c1
    # Parent  8c567e298d7f3fad82cc66754f2fb6c4a420366b
    Bugfixes in CplexBase and ClpLp (#639)
    
    diff --git a/cmake/FindILOG.cmake b/cmake/FindILOG.cmake
    a b  
    9696  SET(ILOG_LIBRARIES ${ILOG_CPLEX_LIBRARY} ${ILOG_CONCERT_LIBRARY})
    9797  IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    9898    # SET(CPLEX_LIBRARIES "${CPLEX_LIBRARIES};m;pthread")
    99     SET(ILOG_LIBRARIES ${ILOG_LIBRARIES} "m" "pthread")
     99    SET(ILOG_LIBRARIES ${ILOG_LIBRARIES} "m" "pthread" "dl")
    100100  ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    101101ENDIF(ILOG_FOUND)
    102102
  • lemon/clp.cc

    diff --git a/lemon/clp.cc b/lemon/clp.cc
    a b  
    227227  }
    228228
    229229  ClpLp::Value ClpLp::_getCoeff(int ix, int jx) const {
    230     CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
    231     CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
     230    CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[jx];
     231    CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[jx];
    232232
    233233    const int* indices = _prob->clpMatrix()->getIndices();
    234234    const double* elements = _prob->clpMatrix()->getElements();
    235235
    236     const int* it = std::lower_bound(indices + begin, indices + end, jx);
    237     if (it != indices + end && *it == jx) {
     236    const int* it = std::lower_bound(indices + begin, indices + end, ix);
     237    if (it != indices + end && *it == ix) {
    238238      return elements[it - indices];
    239239    } else {
    240240      return 0.0;
  • lemon/cplex.cc

    diff --git a/lemon/cplex.cc b/lemon/cplex.cc
    a b  
    158158    } else {
    159159      const char s = 'R';
    160160      double len = ub - lb;
    161       CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s,
     161      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s,
    162162                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    163163      CPXchgrngval(cplexEnv(), _prob, 1, &i, &len);
    164164    }
  • test/lp_test.cc

    diff --git a/test/lp_test.cc b/test/lp_test.cc
    a b  
    339339  check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
    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.");
    344345  check(lp.colUpperBound(x1)==LpSolver::INF,
     
    424425  delete lpclone;
    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{
    429458  LpSkeleton lp_skel;
     
    444473    lpTest(lp_glpk1);
    445474    aTest(lp_glpk2);
    446475    cloneTest<GlpkLp>();
     476    rangeConstraintTest<GlpkLp>();
    447477  }
    448478#endif
    449479
     
    453483    lpTest(lp_cplex1);
    454484    aTest(lp_cplex2);
    455485    cloneTest<CplexLp>();
     486    rangeConstraintTest<CplexLp>();
    456487  } catch (CplexEnv::LicenseError& error) {
    457488    check(false, error.what());
    458489  }
     
    464495    lpTest(lp_soplex1);
    465496    aTest(lp_soplex2);
    466497    cloneTest<SoplexLp>();
     498    rangeConstraintTest<Soplex>();
    467499  }
    468500#endif
    469501
     
    473505    lpTest(lp_clp1);
    474506    aTest(lp_clp2);
    475507    cloneTest<ClpLp>();
     508    rangeConstraintTest<ClpLp>();
    476509  }
    477510#endif
    478511
  • test/mip_test.cc

    diff --git a/test/mip_test.cc b/test/mip_test.cc
    a b  
    6161  }
    6262}
    6363
    64 void aTest(MipSolver& mip)
     64void aTest(MipSolver& mip, bool solve_empty=true)
    6565{
    6666  //The following example is very simple
    6767
     
    8080  mip.max();
    8181
    8282  //Unconstrained optimization
    83   mip.solve();
     83  if(solve_empty)
     84    mip.solve();
    8485  //Check it out!
    8586
    8687  //Constraints
     
    135136#ifdef LEMON_HAVE_MIP
    136137  {
    137138    Mip mip1;
     139#if LEMON_DEFAULT_MIP==LEMON_CBC_
     140    aTest(mip1, false);
     141#else
    138142    aTest(mip1);
     143#endif
    139144    cloneTest<Mip>();
    140145  }
    141146#endif
     
    161166#ifdef LEMON_HAVE_CBC
    162167  {
    163168    CbcMip mip1;
    164     aTest(mip1);
     169    aTest(mip1, false);
    165170    cloneTest<CbcMip>();
    166171  }
    167172#endif