00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "CouenneCutGenerator.hpp"
00013 #include "CouenneProblem.hpp"
00014 #include "exprAux.hpp"
00015
00016
00017
00018
00019
00020 void draw_cuts (OsiCuts &cs, const CouenneCutGenerator *cg, int j, expression *w, expression *img) {
00021
00022 static bool first_draw = true;
00023 static CouNumber maxY = -COUENNE_INFINITY,
00024 minY = COUENNE_INFINITY;
00025
00026 if ((img -> code () == COU_EXPRSIN) ||
00027 (img -> code () == COU_EXPRPOW) ||
00028 (img -> code () == COU_EXPREXP) ||
00029 (img -> code () == COU_EXPRLOG) ||
00030 (img -> code () == COU_EXPRCOS)) {
00031
00032
00033
00034 expression *lbe, *ube;
00035
00036 expression *indep = img -> Argument ();
00037
00038 if (!indep)
00039 indep = img -> ArgList () [0];
00040
00041 int xi = indep -> Index ();
00042
00043
00044
00045
00046 indep -> getBounds (lbe, ube);
00047
00048 CouNumber lb = (*lbe) (),
00049 ub = (*ube) ();
00050
00051 delete lbe;
00052 delete ube;
00053
00054 if (xi >= 0) {
00055
00056 CouNumber curx = cg -> Problem () -> X (xi);
00057
00058 #define N_STEPS 100
00059
00060
00061
00062 if (first_draw) {
00063
00064 first_draw = false;
00065
00066 for (CouNumber x = lb;
00067 x <= ub + COUENNE_EPS;
00068 x += ((ub - lb) / N_STEPS)) {
00069
00070 cg -> Problem () -> X () [xi] = x;
00071
00072 CouNumber y = (*img) ();
00073
00074 if (y > maxY) maxY = y;
00075 if (y < minY) minY = y;
00076
00077 fprintf (stderr, "%.12e %.12e\n", x, y);
00078 }
00079
00080 maxY += (maxY-minY) / 20;
00081 minY -= (maxY-minY) / 20;
00082 }
00083
00084 lb -= (ub-lb) / 20;
00085 ub += (ub-lb) / 20;
00086
00087
00088
00089 for (int jj=j; jj < cs.sizeRowCuts (); jj++) {
00090
00091 CouNumber lb0 = lb,
00092 ub0 = ub;
00093
00094 const double *el = cs.rowCutPtr (jj) -> row (). getElements ();
00095 double rhs = cs.rowCutPtr (jj) -> rhs ();
00096
00097 if (fabs (el [1]) > COUENNE_EPS) {
00098 lb0 = CoinMax (lb, CoinMin ((rhs - el[0] * minY) / el [1], (rhs - el[0] * maxY) / el [1]));
00099 ub0 = CoinMin (ub, CoinMax ((rhs - el[0] * minY) / el [1], (rhs - el[0] * maxY) / el [1]));
00100 }
00101
00102 fprintf (stderr, "#m=2,S=%d\n", (cs.rowCutPtr (jj) -> sense () == 'L') ? 10:11);
00103
00104 fprintf (stderr, "%.12e %.12e\n", lb0, (rhs - el [1] * lb0) / el [0]);
00105 fprintf (stderr, "%.12e %.12e\n", ub0, (rhs - el [1] * ub0) / el [0]);
00106 }
00107
00108 cg -> Problem () -> X () [xi] = curx;
00109 exit(0);
00110 }
00111 }
00112 }