00001
00002
00003
00004
00005
00006
00007
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
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
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.;
00094 else return fabs (x0*x1);
00095 else
00096 if (ind2 < 0) return fabs (x0*x2);
00097 else return fabs (x0*sqrt(x1*x1 + x2*x2));
00098 else
00099 if (ind1 < 0)
00100 if (ind2 < 0) return fabs (x1*x2);
00101 else return fabs (x1*sqrt(x0*x0 + x2*x2));
00102 else
00103 if (ind2 < 0) return fabs (x2*sqrt(x0*x0 + x1*x1));
00104 else return sqrt (x0*x0 + x1*x1 + x2*x2);
00105 }