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