Changeset 551


Ignore:
Timestamp:
May 24, 2007 4:07:04 PM (12 years ago)
Author:
pbelotti
Message:

fixed some excessive coefficient in expr{Inv,Pow}. avoid conv cuts on sin/cos when argument is unbounded.

Location:
branches/Couenne/Couenne
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/Couenne/Couenne/TODO

    r548 r551  
    1313- q.f. partitioning into PD + nonconvex
    1414- (reverse Polish notation)-based evaluation for efficiency
     15- create CouenneTMINLP interface for Ipopt
     16- separate function evaluation lib from convexification
     17- QQP convexification
  • branches/Couenne/Couenne/src/convex/createCuts.cpp

    r537 r551  
    1717
    1818
    19 #define MAX_COEFF 1e10
     19//#define MAX_COEFF 1e12
    2020
    2121/// general procedure for inserting a linear cut with up to three
     
    3030  bool numerics = false;
    3131
    32   // a maximum of three terms are allowed here. Index -1 means the
    33   // term is not considered
     32  // a maximum of three terms are allowed here. If index -1 (default)
     33  // the term is not considered
    3434
    3535  int nterms = 0;
    3636
    37   if (i1 >= 0) {if (fabs (c1) > MAX_COEFF) numerics = true; nterms++;} else c1 = 0;
    38   if (i2 >= 0) {if (fabs (c2) > MAX_COEFF) numerics = true; nterms++;} else c2 = 0;
    39   if (i3 >= 0) {if (fabs (c3) > MAX_COEFF) numerics = true; nterms++;} else c3 = 0;
     37  if (i1 >= 0) {if (fabs (c1) > COU_MAX_COEFF) numerics = true; nterms++;} else c1 = 0;
     38  if (i2 >= 0) {if (fabs (c2) > COU_MAX_COEFF) numerics = true; nterms++;} else c2 = 0;
     39  if (i3 >= 0) {if (fabs (c3) > COU_MAX_COEFF) numerics = true; nterms++;} else c3 = 0;
    4040
    4141  if (!nterms) // nonsense cut
     
    4343
    4444  // cut has large coefficients/rhs, bail out
    45   if (numerics || (fabs (rhs) > MAX_COEFF)) {
    46     printf ("Warning, too large coefficients/rhs: %g, %g, %g; %g\n", c1, c2, c3, rhs);
     45  if (numerics || (fabs (rhs) > COU_MAX_COEFF)) {
     46    printf ("Warning, too large coefficients/rhs: %g (%d), %g (%d), %g (%d); %g\n",
     47            c1, i1, c2, i2, c3, i3, rhs);
    4748    return 0;
    4849  }
     
    8990    if (c1 < 0) sign = -sign;
    9091
    91     if (sign <= 0) cut -> setUbs (1, &i1, &bound);
    92     if (sign >= 0) cut -> setLbs (1, &i1, &bound);
     92    if (sign <= 0) {cut -> setUbs (1, &i1, &bound); problem_ -> Ub (i1) = bound;}
     93    if (sign >= 0) {cut -> setLbs (1, &i1, &bound); problem_ -> Lb (i1) = bound;}
    9394
    9495    cut -> setGloballyValid (is_global); // global?
  • branches/Couenne/Couenne/src/convex/generateCuts.cpp

    r548 r551  
    213213
    214214        int nCurCuts = cs.sizeRowCuts ();
    215         //      genRowCuts (si, cs, nchanged, changed);
     215        genRowCuts (si, cs, nchanged, changed);
    216216        repeat = nCurCuts < cs.sizeRowCuts (); // reapply only if new cuts available
    217217      }
  • branches/Couenne/Couenne/src/convex/operators/conv-exprInv.cpp

    r534 r551  
    4646
    4747
    48 #define MIN_DENOMINATOR 1e-10
     48#define MIN_DENOMINATOR 1e-6
    4949
    5050// generate convexification cut for constraint w = 1/x
     
    113113    (cs, (l > 0) ? +1 : -1,
    114114     inv, oppInvSqr, w_ind, x_ind,
    115      (cg -> isFirst ()) ?
    116        // place it somewhere in the interval (we won't care)
     115     (cg -> isFirst ()) ? // is this first call?
     116       // place it somewhere in the interval (we don't care)
    117117       ((l > COUENNE_EPS) ? l : u) :
    118        // not first call, gotta replace it where it gives deepest cut
     118       // otherwise, replace it where it gives deepest cut
    119119       powNewton ((*argument_) (), (*aux) (), inv, oppInvSqr, inv_dblprime),
    120120     l, u);
  • branches/Couenne/Couenne/src/convex/operators/conv-exprPow.cpp

    r548 r551  
    224224      sign = -1;
    225225
    226     // upper envelope -- when k negative, add only if
    227 
    228     CouNumber powThres = pow (COU_MAX_COEFF, 1./k), // don't want big coefficients
     226    CouNumber powThres = mymin (COUENNE_INFINITY,
     227                                pow (COU_MAX_COEFF, 1./k)), // don't want big coefficients
    229228              powStep  = 1;
    230229
    231     if ((  (k > COUENNE_EPS)
    232         || (l > COUENNE_EPS)       // bounds do not contain 0
     230    // upper envelope
     231
     232    if ((  (k > COUENNE_EPS)        // when k negative, add only if
     233        || (l > COUENNE_EPS)        // bounds do not contain 0
    233234        || (u < - COUENNE_EPS)) &&
    234         (l > - powThres) &&    // and are finite
     235        (l > - powThres) &&         // and are finite
    235236        (u <   powThres) &&
    236         (fabs (l+u) > COUENNE_EPS)) // bounds are not opposite
     237        (fabs (l+u) > COUENNE_EPS)) // bounds are not opposite (otherwise it's a variable bound)
    237238
    238239      cg -> addSegment (cs, w_ind, x_ind, l, safe_pow (l, k), u, safe_pow (u, k), -sign);
  • branches/Couenne/Couenne/src/convex/operators/conv-exprSinCos.cpp

    r548 r551  
    2323
    2424
    25 // generate convexification cut for constraint w = sin (this)
     25///
     26void addHexagon (const CouenneCutGenerator *, // cut generator that has called us
     27                 OsiCuts &,      // cut set to be enriched
     28                 enum cou_trig,  // sine or cosine
     29                 exprAux *,      // auxiliary variable
     30                 expression *);  // argument of cos/sin (should be a variable)
     31
     32
     33/// generate convexification cut for constraint w = sin (this)
    2634
    2735void exprSin::generateCuts (exprAux *w, const OsiSolverInterface &si,
     
    3139  trigEnvelope (cg, cs, w, w -> Image () -> Argument (), COU_SINE);
    3240#else
    33   addHexagon (cg, cs, sin, w, w -> Image () -> Argument());
     41  addHexagon (cg, cs, COU_SINE, w, w -> Image () -> Argument());
    3442#endif
    3543}
    3644
    3745
    38 // generate convexification cut for constraint w = cos (this)
     46/// generate convexification cut for constraint w = cos (this)
    3947
    4048void exprCos::generateCuts (exprAux *w, const OsiSolverInterface &si,
     
    4452  trigEnvelope (cg, cs, w, w -> Image () -> Argument (), COU_COSINE);
    4553#else
    46   addHexagon (cg, cs, cos, w, w -> Image () -> Argument());
     54  addHexagon (cg, cs, COU_COSINE, w, w -> Image () -> Argument());
    4755#endif
    4856}
    4957
    5058
    51 // add lateral edges of the hexagon providing
     59/// add lateral edges of the hexagon providing
    5260
    5361void addHexagon (const CouenneCutGenerator *cg, // cut generator that has called us
    5462                 OsiCuts &cs,       // cut set to be enriched
    55                  unary_function f,  // sine or cosine
     63                 enum cou_trig tt,  // sine or cosine
    5664                 exprAux *aux,      // auxiliary variable
    5765                 expression *arg) { // argument of cos/sin (should be a variable)
    5866
     67  unary_function fn = (tt == COU_SINE) ? sin : cos;
     68
    5969  expression *lbe, *ube;
    6070  arg -> getBounds (lbe, ube);
     
    6575  int x_ind = arg -> Index ();
    6676  int w_ind = aux -> Index ();
    67   /*
     77
    6878  if (fabs (ub - lb) < COUENNE_EPS) {
    6979
    7080    CouNumber x0 = 0.5 * (ub+lb), f, fp;
    7181
    72     if (which_trig == COU_SINE) {f = sin (x0); fp =  cos (x0);}
    73     else                        {f = cos (x0); fp = -sin (x0);}
     82    if (tt == COU_SINE) {f = sin (x0); fp =  cos (x0);}
     83    else                {f = cos (x0); fp = -sin (x0);}
    7484
    7585    cg -> createCut (cs, f - fp*x0, 0, w_ind, 1., x_ind, -fp);
    7686    return;
    7787  }
    78   */
    79   // add the lower envelope
    80   cg -> createCut (cs, f (lb) - lb, -1, w_ind, 1., x_ind, -1.); // left:  w - x <= f lb - lb
    81   cg -> createCut (cs, f (ub) + ub, -1, w_ind, 1., x_ind,  1.); // right: w + x <= f ub + ub
    82 
    83   // add the upper envelope
    84   cg -> createCut (cs, f (ub) - ub, +1, w_ind, 1., x_ind, -1.); // right: w - x >= cos ub - ub
    85   cg -> createCut (cs, f (lb) + lb, +1, w_ind, 1., x_ind,  1.); // left:  w + x >= cos lb + lb
     88
     89  // add  /    \ envelope
     90  //      \    /
     91
     92  // left
     93  if (lb > -COUENNE_INFINITY) { // if not unbounded
     94    cg -> createCut (cs, fn (lb) - lb, -1, w_ind, 1., x_ind, -1.); // up:  w - x <= f lb - lb
     95    cg -> createCut (cs, fn (lb) + lb, +1, w_ind, 1., x_ind,  1.); // dn:  w + x >= f lb + lb
     96  }
     97
     98  // right
     99  if (ub <  COUENNE_INFINITY) { // if not unbounded
     100    cg -> createCut (cs, fn (ub) - ub, +1, w_ind, 1., x_ind, -1.); // dn: w - x >= f ub - ub
     101    cg -> createCut (cs, fn (ub) + ub, -1, w_ind, 1., x_ind,  1.); // up: w + x <= f ub + ub
     102  }
    86103
    87104  delete lbe;
     
    139156       skip_dn = false;
    140157
    141   bayEnvelope (cg, cs, wi, xi, lb, ub, displacement, skip_up, skip_dn); // lb
    142   bayEnvelope (cg, cs, wi, xi, ub, lb, displacement, skip_up, skip_dn); // ub
    143 }
    144 
    145 
    146 // study single bay ( \__/ or /~~\ ) of the trigonometric function
     158  if (lb > -COUENNE_INFINITY) bayEnvelope (cg, cs, wi, xi, lb, ub, displacement, skip_up, skip_dn);
     159  if (ub <  COUENNE_INFINITY) bayEnvelope (cg, cs, wi, xi, ub, lb, displacement, skip_up, skip_dn);
     160}
     161
     162
     163//                             __
     164// study single bay ( \__/ or /  \ ) of the trigonometric function
     165//
    147166
    148167int bayEnvelope (const CouenneCutGenerator *cg, // cut generator that has called us
  • branches/Couenne/Couenne/src/expression/CouennePrecisions.h

    r534 r551  
    1010#define COUENNE_PRECISIONS_H
    1111
    12 #include <CouenneTypes.h>
    1312#include <math.h>
    1413
    1514/* keep it at least 1e-7, or strange things happen */
    16 #define COUENNE_EPS       1e-7
     15#define COUENNE_EPS           1e-7
    1716#define COUENNE_EPS_CHK       1e-7
    1817#define COUENNE_EPS_SET       1e-15
    1918
    20 #define COUENNE_EPS_SIMPL 1e-20
     19#define COUENNE_EPS_SIMPL     1e-20
    2120
    22 #define COUENNE_INFINITY  1e+50
    23 #define COUENNE_INFINITY_CHK  1e+30
    24 #define COUENNE_INFINITY_SET  1e+60
     21#define COUENNE_INFINITY      1.0e+50
     22#define COUENNE_INFINITY_CHK  1.0e+40
     23#define COUENNE_INFINITY_SET  1.0e+60
    2524
    26 #define COU_MAX_COEFF     1e6
     25#define COU_MAX_COEFF     1e12
    2726
    2827#define COUENNE_round(x) ((int) (floor ((x) + 0.5)))
  • branches/Couenne/Couenne/src/expression/exprAux.cpp

    r543 r551  
    5050  CouNumber l, u;
    5151
     52  /*printf ("### Generating cut for ");
     53  print (std::cout);  printf (" := ");
     54  image_ -> print (std::cout); printf ("\n");*/
     55
    5256  if ((!(cg -> isFirst ())) &&
    5357      (fabs ((l = expression::Lbound (varIndex_)) -
     
    5862  // check if cuts have coefficients, rhs too large or too small
    5963
    60   for (int jj=j; jj < cs.sizeRowCuts ();jj++) {
     64  for (int jj=j; jj < cs.sizeRowCuts (); jj++) {
    6165
    6266    int           n   = cs.rowCutPtr (jj) -> row (). getNumElements();
     
    6670
    6771    while (n--)
    68       if      (fabs (el [n]) > 1e9)  printf ("coefficient too large: %.12e x%d\n", el [n], ind [n]);
     72      if      (fabs (el [n]) > COU_MAX_COEFF)  {
     73        printf ("coefficient too large: %.12e x%d\n", el [n], ind [n]);
     74      }
    6975    //   else if (fabs (el[n]) < 1e-10) printf ("coefficient too small: %g x%d\n", el [n], ind [n]);
    7076
    71     if      (fabs (rhs) > 1e9)  printf ("rhs too large: %.12e\n", rhs);
     77    if      (fabs (rhs) > COU_MAX_COEFF) {
     78      printf ("rhs too large: %.12e\n", rhs);
     79    }
    7280    //    else if (fabs (rhs) < 1e-10) printf ("rhs too small: %g\n", rhs);
    7381  }
  • branches/Couenne/Couenne/src/expression/operators/exprCos.cpp

    r548 r551  
    3838  //  return;
    3939
    40   // TODO
    4140  expression *xl, *xu;
    4241  argument_ -> getBounds (xl, xu);
  • branches/Couenne/Couenne/src/expression/operators/exprCos.h

    r543 r551  
    6767/// convex envelope for sine/cosine
    6868
    69 void addHexagon (const CouenneCutGenerator *, // pointer to the caller cut generator
    70                  OsiCuts &,      // cut set to be enriched
    71                  unary_function, // sine or cosine
    72                  exprAux *,      // auxiliary variable
    73                  expression *);  // argument of cos/sin (should be a variable)
     69//void addHexagon (const CouenneCutGenerator *, // pointer to the caller cut generator
     70//               OsiCuts &,      // cut set to be enriched
     71//               unary_function, // sine or cosine
     72//               exprAux *,      // auxiliary variable
     73//               expression *);  // argument of cos/sin (should be a variable)
    7474
    7575#endif
  • branches/Couenne/Couenne/src/expression/operators/exprSin.cpp

    r548 r551  
    4242  //  return;
    4343
    44   // TODO:
    4544  expression *xl, *xu;
    4645
Note: See TracChangeset for help on using the changeset viewer.