Ignore:
Timestamp:
Jun 24, 2013 6:13:05 AM (7 years ago)
Author:
fmargot
Message:

fix bug in checkNLP2 and handling of non-var objects in strong branching

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/branch/CouenneChooseStrong.cpp

    r930 r967  
    9999
    100100/***********************************************************************/
     101// returns
     102// 4 if not a variable object (deemed good)
     103// 3 if variable object and is good
     104// 2 if variable object and is not good (i.e. fixed variable)
     105// 1 if OsiSimpleBranchingObject and not good (deprecated)
    101106int CouenneChooseStrong::goodCandidate(OsiSolverInterface *solver,
    102107                                       OsiBranchingInformation *info,
     
    106111  int vInd = object [iObject] -> columnNumber ();
    107112
    108   if (vInd < 0) return 3;  // not a variable object, so deem it good
     113  if (vInd < 0) return 4;  // not a variable object, so deem it good
    109114
    110115  bool varIsInt = solver -> isInteger (vInd);
     
    211216     We can pick up a forced branch (can change bound) from whichForcedObject() and whichForcedWay()
    212217     If we have a solution then we can pick up from goodObjectiveValue() and goodSolution()
     218
     219Note: Must not return 4 for a non variable object
    213220  */
    214221  int CouenneChooseStrong::chooseVariable (OsiSolverInterface * solver,
     
    255262
    256263    if (isRoot) {
    257       numberStrong = CoinMax(numberStrong_, numberStrongRoot_);
     264      numberStrong = numberStrongRoot_;
    258265    }
    259266
     
    272279
    273280      results_.clear();
    274       int returnCode = 0;
     281
     282      // All look satisfied;
     283      //useful if all objects considered for strong branching use pseudo costs
     284      int returnCode = 1;
     285
    275286      int returnCodeSB = 0;
    276287      bestObjectIndex_ = -1;
     
    466477            }
    467478
    468             if((needBranch == 3) &&
     479            if((needBranch >= 3) &&
    469480               saveBestCand(object, iObject, value, upEstimate, downEstimate,
    470481                            bestTrustedVal1,
     
    546557         
    547558          // store bad candidates in secondary best
    548           if(needBranch != 3) {
     559          if(needBranch < 3) {
    549560            if(saveBestCand(object, iObject, value,
    550561                            upEstimate, downEstimate,
     
    566577                            bestTrustedVal1,
    567578                            bestTrustedVal2, bestObjectIndex_, bestWhichWay_)) {
     579              if(returnCode == 1) { // first saved object
     580                                    // is using pseudo-cost
     581                returnCode = 0;
     582              }
     583
    568584              returnCode = (returnCode ? 3 : 0); // if returnCode was 2 or 3
    569585                                                 // it becomes 3
     
    582598          bestWhichWay_ = bestWhichWay2;
    583599          bestTrustedVal1 = bestTrusted2Val1;
    584           returnCode = 4;
     600          if(goodCandidate(solver, info, object, 
     601                           bestObjectIndex_, prec) != 4) {
     602            returnCode = 4;
     603          }
     604          else {
     605            returnCode = 3;
     606          }
    585607        }
    586608      }
     
    604626          if(objectVarInd >= 0) {
    605627            double vUb = solver->getColUpper()[objectVarInd];
    606             double vLb = solver->getColLower()[objectVarInd];
     628            char strUb[400], strLb[400];
     629            if(vUb > 1e50) {
     630              sprintf(strUb, "+inf");
     631            }
     632            else {
     633              sprintf(strUb, "%f", vUb);
     634            }
     635            double vLb = solver->getColLower()[objectVarInd];
     636            if(vLb < -1e50) {
     637              sprintf(strLb, "-inf");
     638            }
     639            else {
     640              sprintf(strLb, "%f", vLb);
     641            }
    607642            double vSolI = info->solution_[objectVarInd];
    608643            double vSolS = solver->getColSolution()[objectVarInd];
    609             printf("Branch on object %d (var: %d): solInfo: %10.4f  SolSolver: %10.4f low: %10.4f  up: %10.4f\n",
    610                    bestObjectIndex_, objectVarInd, vSolI, vSolS, vLb, vUb);
     644            printf("Branch on object %d (var: %d): solInfo: %10.4f  SolSolver: %10.4f low: %s  up: %s\n",
     645                   bestObjectIndex_, objectVarInd, vSolI, vSolS, strLb, strU
     646
     647b);
    611648          }
    612649          else {
     
    618655      message(CHOSEN_VAR)<<bestObjectIndex_<<CoinMessageEol;
    619656   
    620       if (numberFixed==numberUnsatisfied_&&numberFixed)
    621         returnCode=4;
     657      if((numberFixed==numberUnsatisfied_&&numberFixed) &&
     658         (goodCandidate(solver, info, object, bestObjectIndex_, prec) != 4)) {
     659        returnCode = 4;
     660      }
    622661
    623662      if((returnCode == 2) || (returnCode == 3)) {
    624663        if((objectVarInd > -1) &&
    625            (goodCandidate(solver, info, object, bestObjectIndex_, prec) != 2)) {
     664           (goodCandidate(solver, info, object, bestObjectIndex_, prec) != 4)) {
    626665          // Can occur: two objects for same var, first scanned object
    627666          // has both branches feasible and is saved as bestObjectIndex_,
     
    703742
    704743#ifdef TRACE_STRONG
     744    printf("Start CouenneChooseStrong::setupList()\n");
    705745    OsiObject ** object = info->solver_->objects();
    706746    if(problem_->doPrint_) {
     
    759799#ifdef TRACE_STRONG
    760800    if(problem_->doPrint_) {
    761       printf("Strong list: (obj_ind var_ind priority useful)\n");
     801      printf("Strong list: (obj_ind var_ind priority useful viol)\n");
    762802      printf("numberStrong: %d  numberStrongRoot: %d  retval: %d\n",
    763803             numberStrong_, numberStrongRoot_, retval);
     
    769809        // }
    770810        // else {
    771           objectInd = object[list_[i]]->columnNumber();
     811        objectInd = object[list_[i]]->columnNumber();
    772812        // }
    773         printf(" (%d %d %d %6.4f)", list_[i], objectInd,
    774                object[list_[i]]->priority(), useful_[i]);
    775       }
    776       printf("\n");
    777     }
     813
     814        int wayprint;
     815        double violprint = object[list_[i]]->infeasibility(info, wayprint);
     816        if(violprint < COIN_DBL_MAX / 100) {
     817          printf(" (%d %d %d %6.4f %6.4f)", list_[i], objectInd,
     818                 object[list_[i]]->priority(), useful_[i],
     819                 violprint);
     820        }
     821        else {
     822          printf(" (%d %d %d %6.4f +inf)", list_[i], objectInd,
     823                 object[list_[i]]->priority(), useful_[i]);
     824        }
     825        printf("\n");
     826      }
    778827#endif
    779828
     
    785834    jnlst_ -> Printf (J_ITERSUMMARY, J_BRANCHING,
    786835                      "----------------- (strong) setup list done - %d infeasibilities\n", retval);
     836
     837#if (defined TRACE_STRONG)
     838    printf("Done CouenneChooseStrong::setupList()\n");
     839#endif
    787840
    788841    problem_ -> domain () -> pop ();
     
    876929    }
    877930    printf("\nmaxViol: %g  minPosViol: %g\n", maxViol, minPosViol);
    878 
    879931  } /* printObjViol */
    880932
Note: See TracChangeset for help on using the changeset viewer.