computeMulBrDist.cpp
Go to the documentation of this file.
1 /* $Id: computeMulBrDist.cpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: computeMulBrDist.cpp
4  * Author: Pietro Belotti
5  * Purpose: compute distance to new convexifications generated by branching on product
6  *
7  * (C) Carnegie-Mellon University, 2008-10.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include "CouennePrecisions.hpp"
12 #include "CouenneTypes.hpp"
13 #include "CouenneObject.hpp"
14 
15 #include "CouenneExprMul.hpp"
16 #include "CouenneFunTriplets.hpp"
17 #include "CouenneProjections.hpp"
18 
19 namespace Couenne {
20 
21 // compute distance from future convexifications in set \f$\{(x,y,w):
22 // w = xy\}\f$ with x,y,w bounded
23 double *computeMulBrDist (const OsiBranchingInformation *info,
24  int xi, int yi, int wi,
25  int brind, double *brpt, int nPts) {
26 
27  // use rule of thumb to compute distance: fix two of the three
28  // variables and compute distance between current LP point and curve
29  // w=x/y (z is the branching variable, x or y)
30  //
31  // 1) fix x,y: distances are w - x/y and ||(w-x/y, z-zb)||_2
32  // 2) fix x,w: y - x/w and ||(y-x/w, z-zb)||_2
33  // 3) fix y,w: x - y*w and ||(x-y*w, z-zb)||_2
34 
35  CouNumber
36  x0 = info -> solution_ [xi], //xl = info -> lower_ [xi], xu = info -> upper_ [xi],
37  y0 = info -> solution_ [yi], //yl = info -> lower_ [yi], yu = info -> upper_ [yi],
38  w0 = info -> solution_ [wi]; //wl = info -> lower_ [wi], wu = info -> upper_ [wi];
39 
40  double *dist = (double *) malloc (2 * sizeof (double));
41 
42  // two main cases:
43  //
44  // 1) wi is the branching index: the bounding box is divided in two
45  // by the rule w <= wb and w >= wb. Finding the distances from the
46  // current point (x0,y0,w0) to the two semi-surfaces depends on
47  // which side w0 stands.
48  //
49  // 2) xi or yi are the branching index: reduce to the problem of
50  // finding the distance from a point (x0,y0,w0) to the same surface
51  // within the (two) element of a partition of the bounding box.
52 
53 
54  // case 1 ////////////////////////////////////////////////////////////////////
55  //
56  // Depending on whether
57  //
58  // a) w0 <=/>= wb
59  // b) w0 <=/>= x0*y0
60  // c) wb <=/>= 0
61  //
62  // there are eight (!) cases, each with a similar computation for
63  // the two distances. We unify it below.
64 
65  // [for now give a simplified version with rough distance computation]
66 
67  if (brind == wi) {
68 
69  // easy implementation: for own side, w0 - x0 y0; for other side,
70  // horiz/vert distance to curve x0 w0 = wb
71 
72  bool side = (((x0*y0 > *brpt) && (*brpt > 0)) ||
73  ((x0*y0 < *brpt) && (*brpt < 0)));
74 
75  dist [side ? 1 : 0] = CoinMax
76  (fabs (w0 - x0*y0), CoinMin
77  ((fabs (y0) > COUENNE_EPS) ? fabs (x0 - *brpt / y0) : 0.,
78  (fabs (x0) > COUENNE_EPS) ? fabs (y0 - *brpt / x0) : 0.));
79 
80  dist [side ? 0 : 1] = fabs (w0 - x0*y0);
81  }
82 
83  // case 2 ////////////////////////////////////////////////////////////////////
84 
85  else {
86 
87  CouNumber diff = info -> solution_ [brind] - *brpt;
88  bool side = (diff > 0.);
89 
90  dist [side ? 0 : 1] = CoinMax (fabs (w0 - x0 * y0), fabs (diff));
91  dist [side ? 1 : 0] = fabs (w0 - x0 *y0);
92  }
93 
94  //dist [0] = dist [1] = 1;
95  return dist;
96 }
97 
98 }
static Bigint * diff(Bigint *a, Bigint *b)
Definition: OSdtoa.cpp:1120
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
ULong * x0
Definition: OSdtoa.cpp:1776
double * computeMulBrDist(const OsiBranchingInformation *info, int xi, int yi, int wi, int brind, double *brpt, int nPts)
compute distance from future convexifications in set with x,y,w bounded.
#define COUENNE_EPS
double CouNumber
main number type in Couenne