Changeset 3030


Ignore:
Timestamp:
May 2, 2020 12:47:31 PM (2 months ago)
Author:
unxusr
Message:

C interface: fix objective value for maximization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Cbc_C_Interface.cpp

    r3029 r3030  
    239239#endif
    240240
     241  double obj_value;
    241242
    242243  int nSos;
     
    10361037  model->solver_ = new OsiClpSolverInterface();
    10371038  model->relax_ = 0;
     1039  model->obj_value = COIN_DBL_MAX;
    10381040
    10391041  model->cbcModel_ = NULL;
     
    17771779  solver->initialSolve();
    17781780
    1779   if (solver->isProvenOptimal())
     1781  if (solver->isProvenOptimal()) {
     1782    model->obj_value = solver->getObjValue();
    17801783    return 0;
    1781   if (solver->isIterationLimitReached())
     1784  }
     1785  if (solver->isIterationLimitReached()) {
     1786    model->obj_value = solver->getObjValue();
    17821787    return 1;
     1788  }
    17831789  if (solver->isProvenDualInfeasible())
    17841790    return 3;
     
    17931799{
    17941800  CoinMessages generalMessages = model->solver_->getModelPtr()->messages();
     1801
     1802  model->obj_value = COIN_DBL_MAX;
    17951803
    17961804  int res = Cbc_solveLinearProgram(model);
     
    18051813      solver->isAbandoned() || solver->isIterationLimitReached() || model->relax_ == 1
    18061814      || solver->getNumIntegers() == 0) {
     1815    if (solver->isProvenOptimal() || solver->isIterationLimitReached()) {
     1816      model->obj_value = solver->getObjValue();
     1817    }
    18071818    return 0;
    18081819  }
     
    19771988      memcpy(model->lastOptMIPSol, cbcModel->bestSolution(), sizeof(double)*Cbc_getNumCols(model) );
    19781989      model->lastOptNCols = Cbc_getNumCols(model);
     1990
     1991      model->obj_value = cbcModel->getObjValue();
     1992
     1993      if (cbcModel->getObjSense()==-1) {
     1994        model->obj_value = 0.0;
     1995
     1996        for (int j=0 ; j<solver->getNumCols() ; ++j )
     1997          model->obj_value += cbcModel->bestSolution()[j] * solver->getObjCoefficients()[j];
     1998      } // circunvent CBC bug
    19791999    }
    19802000
     
    22402260Cbc_getObjValue(Cbc_Model *model)
    22412261{
    2242   switch (model->lastOptimization) {
    2243     case ModelNotOptimized:
    2244       fprintf( stderr, "Information not available, model was not optimized yet.\n");
    2245       abort();
    2246       break;
    2247     case ContinuousOptimization:
    2248       return model->solver_->getObjValue();
    2249     case IntegerOptimization:
    2250       return model->cbcModel_->getObjValue();
    2251   }
    2252 
    2253   return COIN_DBL_MAX;
     2262  return model->obj_value;
    22542263}
    22552264
     
    28792888  result->cutCBhowOften = model->cutCBhowOften;
    28802889  result->cutCBAtSol = model->cutCBAtSol;
     2890
     2891  result->obj_value = model->obj_value;
    28812892
    28822893
Note: See TracChangeset for help on using the changeset viewer.