conv-exprTrilinear.cpp
Go to the documentation of this file.
1 /* $Id: conv-exprTrilinear.cpp 1069 2014-02-05 01:45:36Z pbelotti $
2  *
3  * Name: conv-exprTrilinear.cpp
4  * Author: Pietro Belotti
5  * Purpose: convexify trilinear terms
6  *
7  * This file is licensed under the Eclipse Public License (EPL)
8  */
9 
10 #include "CouenneTypes.hpp"
11 #include "CouenneExprTrilinear.hpp"
12 #include "CouenneExprMin.hpp"
13 #include "CouenneExprMax.hpp"
14 #include "CouenneExprClone.hpp"
15 #include "CouenneProblem.hpp"
16 
17 using namespace Couenne;
18 
21 
23  **arglistMax = new expression* [16],
24  **arglistMin = new expression* [16],
25  **lbA = new expression* [3],
26  **ubA = new expression* [3];
27 
28  for (int i=0; i<3; i++)
29  arglist_ [i] -> getBounds (lbA [i], ubA [i]);
30 
31  for (int i0 = 0; i0 < 2; i0++)
32  for (int i1 = 0; i1 < 2; i1++)
33  for (int i2 = 0; i2 < 2; i2++) {
34 
35  int indexTerm = i0*8 + i1*4 + i2*2;
36 
37  expression *product = new exprTrilinear (new exprClone (i0 ? ubA [0] : lbA [0]),
38  new exprClone (i1 ? ubA [1] : lbA [1]),
39  new exprClone (i2 ? ubA [2] : lbA [2]));
40 
41  arglistMax [indexTerm] = new exprCopy (product); // saves value to be retrieved later for computation
42 
43  arglistMin [indexTerm] = new exprCopy (new exprClone (product));
44 
45  arglistMax [indexTerm + 1] = new exprStore (arglistMax [indexTerm]); // evaluated at the end, safe to just copy
46  arglistMin [indexTerm + 1] = new exprStore (arglistMin [indexTerm]); // evaluated at the end, safe to just copy
47  }
48 
49  lb = new exprMin (arglistMin, 16);
50  ub = new exprMax (arglistMax, 16);
51 }
52 
53 
55 
57 
58  CouNumber
59  lbA [3],
60  ubA [3];
61 
62  for (int i=0; i<3; i++)
63  arglist_ [i] -> getBounds (lbA [i], ubA [i]);
64 
65  lb = COUENNE_INFINITY;
66  ub = -COUENNE_INFINITY;
67 
68  for (int i0 = 0; i0 < 2; i0++)
69  for (int i1 = 0; i1 < 2; i1++)
70  for (int i2 = 0; i2 < 2; i2++) {
71 
72  register double curbound =
73  (i0 ? ubA [0] : lbA [0]) *
74  (i1 ? ubA [1] : lbA [1]) *
75  (i2 ? ubA [2] : lbA [2]);
76 
77  if (curbound < lb) lb = curbound;
78  if (curbound > ub) ub = curbound;
79  }
80 
81  bool isInt = true;
82 
83  for (int i=0; i<3; i++)
84  if (!(arglist_ [i] -> isInteger ())) {
85  isInt = false;
86  break;
87  }
88 
89  if (isInt) {
90  lb = ceil (lb - COUENNE_EPS);
91  ub = floor (ub + COUENNE_EPS);
92  }
93 }
virtual bool isInteger()
is this expression integer?
Definition: exprOp.cpp:188
virtual void getBounds(expression *&, expression *&)
Get lower and upper bound of an expression (if any)
exprTrilinear(expression **, int)
Constructor.
expression clone (points to another expression)
#define COUENNE_EPS
expression ** arglist_
argument list is an array of pointers to other expressions
double CouNumber
main number type in Couenne
#define COUENNE_INFINITY
storage class for previously evaluated expressions
Expression base class.