/home/coin/SVN-release/OS-2.4.1/Couenne/src/expression/operators/exprTrilinear.cpp

Go to the documentation of this file.
00001 /* $Id: exprTrilinear.cpp 490 2011-01-14 16:07:12Z pbelotti $
00002  *
00003  * Name:    exprTrilinear.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: definition of trilinear terms
00006  *
00007  * This file is licensed under the Eclipse Public License (EPL)
00008  */
00009 
00010 #include <stdlib.h>
00011 #include <assert.h>
00012 
00013 #include "CoinHelperFunctions.hpp"
00014 #include "CouenneExprMul.hpp"
00015 #include "CouenneExprTrilinear.hpp"
00016 #include "CouenneExprSum.hpp"
00017 #include "CouenneExprConst.hpp"
00018 #include "CouenneExprClone.hpp"
00019 #include "CouennePrecisions.hpp"
00020 
00021 using namespace Couenne;
00022 
00024 exprTrilinear::exprTrilinear  (expression **al, int n): 
00025   exprMul (al, n) {}
00026 
00027 
00029 exprTrilinear::exprTrilinear (expression *arg0, expression *arg1, expression *arg2):
00030 
00031   exprMul (NULL, 0) {
00032 
00033   nargs_ = 3;
00034   arglist_ = new expression * [nargs_];
00035 
00036   arglist_ [0] = arg0;
00037   arglist_ [1] = arg1;
00038   arglist_ [2] = arg2;
00039 
00040   qsort (arglist_, nargs_, sizeof (expression*), compareExpr);
00041 }
00042 
00043 
00045 void exprTrilinear::closestFeasible (expression *varind,
00046                                      expression *vardep,
00047                                      CouNumber &left,
00048                                      CouNumber &right) const {
00049 
00050   printf ("using VT and trilinear terms: not implemented yet\n");
00051   exit (-1);
00052 
00053   // TODO: if use quadrilinear and VT, fill this
00054 
00055   // expression *varoth = arglist_ [0]; // suppose $w = cy$;
00056 
00057   // if (varoth -> Index () == varind -> Index ())
00058   //   varoth = arglist_ [1]; // actually no, it's $w = x*c$
00059 
00060   // assert (varoth -> Index () >= 0);
00061 
00062   // CouNumber
00063   //   x = (*varind) (),
00064   //   y = (*vardep) (),
00065   //   c = (*varoth) ();
00066 
00067   // if (c < 0.)
00068   //   if (y < c*x) {assert (y/c >= right); right = y/c;}
00069   //   else         {assert (y/c <= left);  left  = y/c;}
00070   // else if (c > 0.)
00071   //   if (y < c*x) {assert (y/c <= left);  left  = y/c;}
00072   //   else         {assert (y/c >= right); right = y/c;}
00073   // else left = - (right = COIN_DBL_MAX);
00074 
00075 }
00076 
00077 
00079 CouNumber exprTrilinear::gradientNorm (const double *x) {
00080 
00081   int 
00082     ind0 = arglist_ [0] -> Index (),
00083     ind1 = arglist_ [1] -> Index (),
00084     ind2 = arglist_ [2] -> Index ();
00085 
00086   CouNumber 
00087     x0 = (ind0 < 0) ? arglist_ [0] -> Value () : x [ind0],
00088     x1 = (ind1 < 0) ? arglist_ [1] -> Value () : x [ind1],
00089     x2 = (ind1 < 0) ? arglist_ [2] -> Value () : x [ind2];
00090 
00091   if (ind0 < 0)
00092     if (ind1 < 0)
00093       if (ind2 < 0) return 0.;                            // c*d*e
00094       else          return fabs (x0*x1);                  // c*d*y
00095     else
00096       if (ind2 < 0) return fabs (x0*x2);                  // c*y*e
00097       else          return fabs (x0*sqrt(x1*x1 + x2*x2)); // c*y*z
00098   else 
00099     if (ind1 < 0)
00100       if (ind2 < 0) return fabs (x1*x2);                  // x*d*e
00101       else          return fabs (x1*sqrt(x0*x0 + x2*x2)); // x*d*z
00102     else
00103       if (ind2 < 0) return fabs (x2*sqrt(x0*x0 + x1*x1)); // x*y*e
00104       else          return sqrt (x0*x0 + x1*x1 + x2*x2);  // x*y*z
00105 }

Generated on Thu Nov 10 03:05:44 2011 by  doxygen 1.4.7