Changeset 967 for trunk


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

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

Location:
trunk/Couenne/src
Files:
2 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
  • trunk/Couenne/src/problem/checkNLP.cpp

    r940 r967  
    419419
    420420      double
    421         v = (*(variables_ [i])) (),
    422         f = (*(variables_ [i] -> Image ())) ();
    423 
    424       printf ("[%g,%g]\n", v, f);
    425 
    426       printf ("checking aux -- %+.12e = %+.12e [%+.12e] ", v, f, v-f);
    427       variables_ [i] -> print ();             printf (" := ");
     421        vdb = (*(variables_ [i])) (),
     422        fdb = (*(variables_ [i] -> Image ())) ();
     423
     424      double
     425        del =
     426        ((v -> sign () == expression::AUX_GEQ) && (vdb >= fdb)) ? 0. :
     427        ((v -> sign () == expression::AUX_LEQ) && (vdb <= fdb)) ? 0. :
     428        fabs (vdb - fdb);
     429
     430      printf ("[%g,%g]\n", vdb, fdb);
     431
     432      printf ("checking aux -- %+.12e = %+.12e [%+.12e] ", vdb, fdb, del);
     433      variables_ [i] -> print ();
     434      if(v->sign()== expression::AUX_GEQ) printf(" >= ");
     435      if(v->sign()== expression::AUX_LEQ) printf(" <= ");
     436      if(v->sign()== expression::AUX_EQ) printf(" := ");
    428437      variables_ [i] -> Image () -> print (); printf ("\n");
    429438    }
     
    629638    for (int i=0; i<nOrigVars_ - ndefined_; i++)
    630639      printf ("%.12e ", solution [i]);
    631     printf ("\nCouenneProblem::checkNLP2(): Start checking computed_solution\n");
     640    printf ("\nCouenneProblem::checkNLP2(): Start checking recomputed_solution\n");
    632641  }
    633642
     
    642651
    643652  if (stopAtFirstViol && !isFeasRec && Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_PROBLEM))
    644     printf("CouenneProblem::checkNLP2(): modified_solution is infeasible (some orig vars not integer feasible; violation: %12.10g)\n", maxViolRecSol);
     653    printf("CouenneProblem::checkNLP2(): recomputed_solution is infeasible (some orig vars not integer feasible; violation: %12.10g)\n", maxViolRecSol);
    645654
    646655#ifdef CHECK
     
    659668  // install NL solution candidate and original bounds in evaluation structure
    660669  // bounds are important so that getAuxs below works properly
    661   domain_.push(nVars(), domain_.x(), getRecordBestSol()->getInitDomLb(),
     670  domain_.push(nVars(), solution, getRecordBestSol()->getInitDomLb(),
    662671               getRecordBestSol()->getInitDomUb(), false);
    663672
     
    678687    double maxDelta = 0;
    679688    for (int i=0; i<nVars (); i++) {
    680       printf ("%4d %+e %+e [%+e %+e] %+e\n", i, solution[i], domain_.x (i), domain_.lb (i), domain_.ub (i), solution[i] - domain_.x (i));
    681       if (maxDelta < fabs(solution[i] - domain_.x(i))) maxDelta = fabs (solution[i] - domain_.x(i));
    682     }
    683     printf ("maxDelta: %.12g\n", maxDelta);
     689      exprVar *v = variables_ [i];
     690      if (v -> Multiplicity () <= 0)
     691        continue;
     692      if(i < nOrigVars_ - ndefined_) {
     693        double soli = solution[i];
     694        double domi = domain_.x (i);
     695        double domlbi = domain_.lb (i);
     696        double domubi = domain_.ub (i);
     697        printf ("%4d %+e %+e [%+e %+e] %+e\n", i, solution[i], domain_.x (i), domain_.lb (i), domain_.ub (i), solution[i] - domain_.x (i));
     698        if (maxDelta < fabs(solution[i] - domain_.x(i))) maxDelta = fabs (solution[i] - domain_.x(i));
     699      }
     700      else {
     701        if(v -> Type() == AUX) {
     702          printf ("%4d  ------     %+e [%+e %+e]\n", i, domain_.x (i), domain_.lb (i), domain_.ub (i));
     703        }
     704      }
     705      printf ("maxDelta: %.12g\n", maxDelta);
     706    }
    684707  }
    685708
     
    912935      // printf ("]\n");
    913936
    914       printf ("checkNLP2(): RETURN: selected solution is feasible (maxViol: %g)\n", maxViol);
     937      printf ("checkNLP2(): RETURN: feasible (maxViol: %g)\n", maxViol);
    915938    }
    916939    else {
    917       printf ("checkNLP2(): RETURN: modified_solution and solution are infeasible\n");
     940      printf ("checkNLP2(): RETURN: recomputed_solution and solution are infeasible\n");
    918941      if(!stopAtFirstViol) {
    919942        printf("(maxViol: %g)\n", maxViol);
Note: See TracChangeset for help on using the changeset viewer.