1 /* $Id$ */
2 /*
3  * Name:    constraint.cpp
4  * Author:  Pietro Belotti
5  * Purpose: methods of the classes CouenneConstraint and LinearConstraint
6  *
7  * (C) Carnegie-Mellon University, 2006.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include "CouenneTypes.hpp"
12 #include "CouenneProblemElem.hpp"
13 
14 #include <cstdio>
15 
16 using namespace Couenne;
17 
18 // output nonlinear constraint
print(std::ostream & out)19 void CouenneConstraint::print (std::ostream &out) {
20 
21   bool samebounds = ((lb_ -> Type () == CONST) &&
22 		     (ub_ -> Type () == CONST) &&
23 		     (fabs (lb_ -> Value () - ub_ -> Value ()) < COUENNE_EPS));
24 
25   // left hand side (a in a <= h(x) <= b)
26 
27   if (lb_ &&
28       !samebounds &&
29       ((lb_ -> Type  () != CONST) ||
30        (lb_ -> Value () > - COUENNE_INFINITY))) {
31 
32     lb_ -> print (out); fflush (stdout);
33     out  << " <= "; fflush (stdout);
34   }
35 
36   // body: h(x) in a <= h(x) <= b
37 
38   body_ -> print (out); fflush (stdout);
39 
40   // right hand side
41 
42   if (ub_ && ((ub_ -> Type  () != CONST) ||
43 	      (ub_ -> Value () <  COUENNE_INFINITY))) {
44 
45     out << ' ';
46     if (!samebounds) out << "<";
47     out << "= "; fflush (stdout);
48     ub_ -> print (out); fflush (stdout);
49   }
50 
51   out << std::endl;
52 }
53