Changeset 1004 for trunk


Ignore:
Timestamp:
Oct 13, 2013 12:04:19 PM (6 years ago)
Author:
pbelotti
Message:

correct handling of new bounds in BTPerfIndicator. Fixed passed new/old bounds from FixPt?

Location:
trunk/Couenne/src/bound_tightening
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/bound_tightening/BTPerfIndicator.cpp

    r953 r1004  
    1818
    1919///
    20 void CouenneBTPerfIndicator::update (CouNumber *lb, CouNumber *ub, int depth) const {
     20void CouenneBTPerfIndicator::update (const CouNumber *lb, const CouNumber *ub, int depth) const {
    2121
    2222  assert (oldLB_ != NULL &&
     
    2424
    2525  double
    26     curWei = 1./ CoinMax (1., (double) depth),
     26    curWei = 1. / CoinMax (1., (double) depth),
    2727    newWS  = weightSum_ + curWei;
    2828
     
    3939  CouNumber *optimum = problem_ -> bestSol ();
    4040
    41   for (int i=problem_ -> nVars (); i--;) {
     41  for (int i=0; i<problem_ -> nVars (); ++i) {
    4242
    4343    CouNumber
     
    4545      nlb = lb     [i], nub = ub     [i];
    4646
     47    if (nlb < olb) nlb = olb;
     48    if (nub > oub) nub = oub;
     49
    4750    // Check if optimal solution violated
    4851
    4952    if (optimum &&
    50         ((optimum [i] < nlb && optimum [i] > olb) ||
    51          (optimum [i] > nub && optimum [i] < oub)))
    52        
     53        ((optimum [i] < nlb - COUENNE_EPS && optimum [i] >= olb) ||
     54         (optimum [i] > nub + COUENNE_EPS && optimum [i] <= oub)))
     55
    5356      printf (" %30s cuts optimum at x_%d=%e: [%e,%e] --> [%e,%e], diff:%e\n",
    5457              name_.c_str (),
     
    7578    if (fabs (nlb - nub) <  COUENNE_EPS) {
    7679
    77       if (fabs (olb - oub) >= COUENNE_EPS)     /// case 1: variable got fixed
     80      if (fabs (olb - oub) > COUENNE_EPS)     /// case 1: variable got fixed
    7881        ++nFixed;
    7982
    80     } else if (nlb >= nub + COUENNE_EPS)
     83    } else if (nlb >= nub + 1e2 * COUENNE_EPS) { // infeasible
    8184
    8285      ++ nPrInf;
     86      nFixed  = nShr = nShrDbl = 0;
     87      ratio = 0.;
     88      break;
    8389
    84     else if (fabs (nlb - nub) <  COUENNE_INFINITY) { // finite bounds
     90    } else if ((nlb > -COUENNE_INFINITY) &&
     91               (nub <  COUENNE_INFINITY)) { // finite bounds
    8592
    86       if (fabs (olb - oub) >= COUENNE_INFINITY) { /// case 2: interval got finite from [-inf,u] or [l,+inf]
     93      if (olb <= -COUENNE_INFINITY ||
     94          oub >=  COUENNE_INFINITY) { /// case 2: interval got finite from [-inf,u] or [l,+inf]
    8795
    88         if ((olb < -COUENNE_INFINITY) &&
    89             (oub >  COUENNE_INFINITY))
     96        if ((olb <= -COUENNE_INFINITY) &&
     97            (oub >=  COUENNE_INFINITY)) // case 2a: actually it was [-inf,+inf]
    9098
    9199          nShr += 2;
     
    97105        // printf ("{%g}\t", ratio);
    98106
    99         ratio += (log (oub - olb) -
    100                   log (nub - nlb));
     107        ratio += (log (CoinMax (1e-6, oub - olb)) -
     108                  log (CoinMax (1e-6, nub - nlb)));
    101109
    102110        // printf ("%g\tlog (%g-%g) - log (%g-%g) = log %g - log %g = %g - %g = %g ===> %g, %g [%g,%g,%g]\n",
     
    105113        //      log (oub - olb),  log (nub - nlb),
    106114        //      log (oub - olb) - log (nub - nlb),
    107 
    108115        //      ratio, boundRatio_, weightSum_, curWei, newWS);
    109116
    110117      }
    111     } else if ((fabs (olb) > COUENNE_INFINITY) &&
    112                (fabs (oub) > COUENNE_INFINITY))  /// case 4: interval became [-inf,u] or [l,+inf] from [-inf,+inf]
     118    } else if ((olb <= -COUENNE_INFINITY) &&
     119               (oub >= COUENNE_INFINITY))  /// case 4: interval became [-inf,u] or [l,+inf] from [-inf,+inf]
    113120      ++nShrDbl;
    114121  }
    115    
     122
    116123  // Update
    117124
     
    123130  shrunkInf_       = (shrunkInf_       * weightSum_ + curWei * nShr)    / newWS;
    124131  shrunkDoubleInf_ = (shrunkDoubleInf_ * weightSum_ + curWei * nShrDbl) / newWS;
     132  nFixed_          = (nFixed_          * weightSum_ + curWei * nFixed)  / newWS;
    125133
    126134  nProvedInfeas_   += nPrInf;
    127   nFixed_          += nFixed;
    128 
    129   //nProvedInfeas_   = (nProvedInfeas_   * weightSum_ + curWei * nPrInf)  / newWS;
    130   //nFixed_          = (nFixed_          * weightSum_ + curWei * nFixed)  / newWS;
    131135
    132136  weightSum_ = newWS;
  • trunk/Couenne/src/bound_tightening/BTPerfIndicatorConstr.cpp

    r822 r1004  
    3333  stats_           ((p             != NULL) &&
    3434                    (GetRawPtr (p -> Jnlst ()) != NULL) &&
    35                     (p -> Jnlst () -> ProduceOutput (Ipopt::J_ERROR, J_BOUNDTIGHTENING))) {}
     35                    (p -> Jnlst () -> ProduceOutput (Ipopt::J_ERROR, J_COUENNE))) {}
    3636
    3737
     
    4444
    4545    if (stats_)
    46       printf ("Performance of %30s:\t %10gs, %8d runs fix:%10g shrink:%10g ubd:%10g 2ubd:%10g infeas:%10g\n",
     46      printf ("Performance of %30s:\t %10gs, %8d runs. fix: %10g shrnk: %10g ubd: %10g 2ubd: %10g infeas: %10g\n",
    4747              name_.c_str (),
    4848              totalTime_,
  • trunk/Couenne/src/bound_tightening/CouenneBTPerfIndicator.hpp

    r791 r1004  
    6868
    6969    ///
    70     void update (CouNumber *lb, CouNumber *ub, int depth) const;
     70    void update (const CouNumber *lb, const CouNumber *ub, int depth) const;
    7171  };
    7272}
  • trunk/Couenne/src/bound_tightening/CouenneFixPoint.hpp

    r945 r1004  
    7272    mutable double CPUtime_;
    7373
    74     /// Number of actual runs
    75     mutable int nRuns_;
    76 
    7774    /// Number of bounds tightened
    7875    mutable int nTightened_;
  • trunk/Couenne/src/bound_tightening/FixPointConstructors.cpp

    r786 r1004  
    2020  firstCall_  (true),
    2121  CPUtime_    (0.),
    22   nRuns_      (0),
    2322  nTightened_ (0),
    2423  perfIndicator_ (p, "Fixed Point LP") {
     
    3635  firstCall_     (rhs.firstCall_),
    3736  CPUtime_       (rhs.CPUtime_),
    38   nRuns_         (rhs.nRuns_),
    3937  nTightened_    (rhs.nTightened_),
    4038  perfIndicator_ (rhs.perfIndicator_) {}
     
    4240
    4341/// destructor
    44 CouenneFixPoint::~CouenneFixPoint () {
    45 
    46   if (0 && !firstCall_)
    47     printf ("Fixed point BT: CPU time %g, %d runs, %d tightened\n",
    48             CPUtime_, nRuns_, nTightened_);
    49 }
     42CouenneFixPoint::~CouenneFixPoint () {}
    5043
    5144
  • trunk/Couenne/src/bound_tightening/FixPointGenCuts.cpp

    r945 r1004  
    3535
    3636  /// Only run this if the latest FBBT terminated on the iteration
    37   /// limit, as this suggest that the FPLP might be of some help.
     37  /// limit, as this suggests that the FPLP might be of some help.
    3838  /// Termination before iteration limit reached implies that a
    3939  /// relaxation (on which the FPLP is based) won't generate better
     
    5959  double startTime = CoinCpuTime ();
    6060
    61   perfIndicator_. setOldBounds (si. getColLower (), si. getColUpper ());
    62 
    6361  int nInitTightened = nTightened_;
    6462
     
    7068  }
    7169
    72   ++nRuns_;
     70  //++nRuns_;
    7371
    7472  double now = CoinCpuTime ();
    7573
    7674  problem_ -> domain () -> push (&si, &cs);
     75
     76  double
     77    *oldLB = CoinCopyOfArray (problem_ -> Lb (), problem_ -> nVars ()),
     78    *oldUB = CoinCopyOfArray (problem_ -> Ub (), problem_ -> nVars ());
     79
     80  perfIndicator_. setOldBounds (problem_ -> Lb (), problem_ -> Ub ());
    7781
    7882  /// An LP relaxation of a MINLP problem is available in the first
     
    125129
    126130  const int
    127        n     = si.  getNumCols (),
    128        m     = si.  getNumRows (),
    129        nCuts = cs.sizeRowCuts   (),
    130     *ind     = A -> getIndices ();
     131    n     = si.  getNumCols (),
     132    m     = si.  getNumRows (),
     133    nCuts = cs.sizeRowCuts  (),
     134    *ind  = A -> getIndices ();
    131135
    132136  const double
    133     *lb  = si.  getColLower (),
    134     *ub  = si.  getColUpper (),
     137    *lb  = problem_ -> Lb (), //si.  getColLower (),
     138    *ub  = problem_ -> Ub (), //si.  getColUpper (),
    135139    *rlb = si.  getRowLower (),
    136140    *rub = si.  getRowUpper (),
     
    266270  fplp -> initialSolve ();
    267271
     272  const double
     273    *newLB = fplp -> getColSolution (),
     274    *newUB = newLB + n;
     275
     276  double infeasBounds [] = {1,-1};
     277
    268278  if (fplp -> isProvenOptimal ()) {
    269279
    270280    // if problem not solved to optimality, bounds are useless
    271 
    272     const double
    273       *newLB = fplp -> getColSolution (),
    274       *newUB = newLB + n,
    275       *oldLB = si. getColLower (),
    276       *oldUB = si. getColUpper ();
    277281
    278282    // check old and new bounds
     
    336340    }
    337341
    338     perfIndicator_. update (problem_ -> Lb (), problem_ -> Ub (), treeInfo.level);
    339     perfIndicator_. addToTimer (CoinCpuTime () - startTime);
    340 
    341342  } else {
     343
    342344    if (treeInfo.inTree &&
    343345        treeInfo.level <= 0)
     
    345347
    346348    WipeMakeInfeas (cs);
     349
     350    newLB = infeasBounds;
     351    newUB = infeasBounds + 1;
    347352  }
    348353
    349354  delete fplp;
    350355
     356  perfIndicator_. update (newLB, newUB, treeInfo.level);
     357  perfIndicator_. addToTimer (CoinCpuTime () - startTime);
     358
    351359  problem_ -> domain () -> pop ();
     360
     361  delete [] oldLB;
     362  delete [] oldUB;
    352363}
    353364
  • trunk/Couenne/src/bound_tightening/boundTightening.cpp

    r786 r1004  
    2525
    2626bool CouenneProblem::btCore (t_chg_bounds *chg_bds) const {
     27
     28  fbbtReachedIterLimit_ = false;
    2729
    2830  if (!chg_bds) {
Note: See TracChangeset for help on using the changeset viewer.