drawCuts.cpp
Go to the documentation of this file.
1 /* $Id: drawCuts.cpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: drawCuts.cpp
4  * Author: Pietro Belotti
5  * Purpose: print function and cut information to be later displayed
6  * through PlotUtils' graph
7  *
8  * (C) Carnegie-Mellon University, 2006.
9  * This file is licensed under the Eclipse Public License (EPL)
10  */
11 
12 #include "CouenneCutGenerator.hpp"
13 #include "CouenneProblem.hpp"
14 #include "CouenneExprAux.hpp"
15 
16 using namespace Couenne;
17 
18 // [cool!] print graph-readable output for displaying inequalities
19 // on a Cartesian plane
20 
21 void draw_cuts (OsiCuts &cs, const CouenneCutGenerator *cg, int j, expression *w, expression *img) {
22 
23  static bool first_draw = true;
24  static CouNumber maxY = -COUENNE_INFINITY,
25  minY = COUENNE_INFINITY;
26 
27  if ((img -> code () == COU_EXPRSIN) ||
28  (img -> code () == COU_EXPRPOW) ||
29  (img -> code () == COU_EXPREXP) ||
30  (img -> code () == COU_EXPRLOG) ||
31  (img -> code () == COU_EXPRCOS)) {
32 
33  // fprintf (stderr, " ==> "); w -> print (std::cerr); fprintf (stderr, "\n");
34 
35  expression *lbe, *ube;
36 
37  expression *indep = img -> Argument ();
38 
39  if (!indep)
40  indep = img -> ArgList () [0];//getFixVar ();
41 
42  int xi = indep -> Index ();
43 
44  // fprintf (stderr, "looking into w_%d = f (x_%d)\n",
45  // w -> Index (), xi);
46 
47  indep -> getBounds (lbe, ube);
48 
49  CouNumber lb = (*lbe) (),
50  ub = (*ube) ();
51 
52  delete lbe;
53  delete ube;
54 
55  if (xi >= 0) {
56 
57  CouNumber curx = cg -> Problem () -> X (xi);
58 
59 #define N_STEPS 100
60 
61  // plot function
62 
63  if (first_draw) {
64 
65  first_draw = false;
66 
67  for (CouNumber x = lb;
68  x <= ub + COUENNE_EPS;
69  x += ((ub - lb) / N_STEPS)) {
70 
71  cg -> Problem () -> X () [xi] = x;
72 
73  CouNumber y = (*img) ();
74 
75  if (y > maxY) maxY = y;
76  if (y < minY) minY = y;
77 
78  fprintf (stderr, "%.12e %.12e\n", x, y);
79  }
80 
81  maxY += (maxY-minY) / 20;
82  minY -= (maxY-minY) / 20;
83  }
84 
85  lb -= (ub-lb) / 20;
86  ub += (ub-lb) / 20;
87 
88  // plot lines defining constraint (only for cuts involving at
89  // most two variables (that is, w is a unary function)
90  for (int jj=j; jj < cs.sizeRowCuts (); jj++) {
91 
92  CouNumber lb0 = lb,
93  ub0 = ub;
94 
95  const double *el = cs.rowCutPtr (jj) -> row (). getElements ();
96  double rhs = cs.rowCutPtr (jj) -> rhs ();
97 
98  if (fabs (el [1]) > COUENNE_EPS) {
99  lb0 = CoinMax (lb, CoinMin ((rhs - el[0] * minY) / el [1], (rhs - el[0] * maxY) / el [1]));
100  ub0 = CoinMin (ub, CoinMax ((rhs - el[0] * minY) / el [1], (rhs - el[0] * maxY) / el [1]));
101  }
102 
103  fprintf (stderr, "#m=2,S=%d\n", (cs.rowCutPtr (jj) -> sense () == 'L') ? 10:11);
104 
105  fprintf (stderr, "%.12e %.12e\n", lb0, (rhs - el [1] * lb0) / el [0]);
106  fprintf (stderr, "%.12e %.12e\n", ub0, (rhs - el [1] * ub0) / el [0]);
107  }
108 
109  cg -> Problem () -> X () [xi] = curx;
110  exit(0);
111  }
112  }
113 }
Cut Generator for linear convexifications.
void draw_cuts(OsiCuts &, const CouenneCutGenerator *, int, expression *, expression *)
allow to draw function within intervals and cuts introduced
Definition: drawCuts.cpp:21
static char * j
Definition: OSdtoa.cpp:3622
#define COUENNE_EPS
double CouNumber
main number type in Couenne
#define COUENNE_INFINITY
#define N_STEPS
Expression base class.
void fint fint fint real fint real real real real real real real real * w
void fint fint fint real fint real * x