Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneDomain.hpp
Go to the documentation of this file.
1 /* $Id: CouenneDomain.hpp 927 2012-11-28 15:25:47Z stefan $
2  *
3  * Name: domain.hpp
4  * Author: Pietro Belotti
5  * Purpose: class for point and bounding box
6  *
7  * (C) Carnegie-Mellon University, 2008-09.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_DOMAIN_HPP
12 #define COUENNE_DOMAIN_HPP
13 
14 #include <stdlib.h>
15 #include <stack>
16 
17 #include "CouenneTypes.hpp"
18 
19 namespace Osi {
20 
21  class OsiSolverInterface;
22  class OsiCuts;
23 }
24 
25 
26 namespace Couenne {
27 
29 
30 class DomainPoint {
31 
32  friend class Domain;
33 
34 protected:
35 
36  int dimension_;
37 
41 
42  bool copied_;
43 
45  bool isNlp_;
46 public:
48 
50  DomainPoint (int dim,
51  CouNumber *x,
52  CouNumber *lb,
53  CouNumber *ub,
54  bool copy = true);
55 
57  DomainPoint (int dim = 0,
58  const CouNumber *x = NULL,
59  const CouNumber *lb = NULL,
60  const CouNumber *ub = NULL,
61  bool copy = true);
62 
65  if (copied_) {
66  if (x_) free (x_);
67  if (lb_) free (lb_);
68  if (ub_) free (ub_);
69  }
70  }
71 
73  DomainPoint (const DomainPoint &src);
74 
76  void resize (int newdim);
77 
79  int size () const {return dimension_;}
80 
82  inline int Dimension () {return dimension_;}
83 
84  inline CouNumber &x (register int index) {return x_ [index];}
85  inline CouNumber &lb (register int index) {return lb_ [index];}
86  inline CouNumber &ub (register int index) {return ub_ [index];}
87 
88  inline CouNumber *x () {return x_ ;}
89  inline CouNumber *lb () {return lb_;}
90  inline CouNumber *ub () {return ub_;}
91 
93  DomainPoint &operator= (const DomainPoint &src);
94 
96  bool &isNlp ()
97  {return isNlp_;}
98 };
99 
100 
103 
104 class Domain {
105 
106 protected:
107 
109  std::stack <DomainPoint *> domStack_;
110 
111 public:
112 
114  Domain (): point_ (NULL) {}
115 
117  Domain (const Domain &src) {
118  point_ = new DomainPoint (*(src.point_));
119  // TODO -- not important, discard previous points when copying problem
120  /*for (std::stack <DomainPoint *>::iterator i = src.domStack_.begin ();
121  i != src.domStack_.end (); ++i)
122  domStack_.push (new DomainPoint (**i));*/
123  }
124 
126  ~Domain ();
127 
129  void push (int dim,
130  CouNumber *x,
131  CouNumber *lb,
132  CouNumber *ub,
133  bool copy = true);
134 
136  void push (int dim,
137  const CouNumber *x,
138  const CouNumber *lb,
139  const CouNumber *ub,
140  bool copy = true);
141 
144  void push (const OsiSolverInterface *si,
145  OsiCuts *cs = NULL,
146  bool copy = true);
147 
149  void push (const DomainPoint &dp, bool copy = true);
150 
152  void pop ();
153 
154  inline DomainPoint *current () {return point_;}
155 
156  inline CouNumber &x (register int index) {return point_ -> x (index);}
157  inline CouNumber &lb (register int index) {return point_ -> lb (index);}
158  inline CouNumber &ub (register int index) {return point_ -> ub (index);}
159 
160  inline CouNumber *x () {return point_ -> x ();}
161  inline CouNumber *lb () {return point_ -> lb ();}
162  inline CouNumber *ub () {return point_ -> ub ();}
163 };
164 
165 }
166 
167 #endif
CouNumber & lb(register int index)
return current lower bound
std::stack< DomainPoint * > domStack_
stack of saved points
CouNumber & x(register int index)
return current variable
void push(int dim, CouNumber *x, CouNumber *lb, CouNumber *ub, bool copy=true)
save current point and start using another
Domain(const Domain &src)
copy constructor
int size() const
return current size
CouNumber * x()
return current variable vector
CouNumber & ub(register int index)
current upper bound
CouNumber * lb_
lower bound
Domain()
basic constructor
CouNumber * lb()
return current lower bound vector
CouNumber & lb(register int index)
current lower bound
DomainPoint(int dim, CouNumber *x, CouNumber *lb, CouNumber *ub, bool copy=true)
constructor
CouNumber * x()
return current variable vector
int Dimension()
return dimension_
Define a point in the solution space and the bounds around it.
void pop()
restore previous point
bool copied_
true if data has been copied (so we own it, and have to delete it upon destruction) ...
void resize(int newdim)
resize domain point (for extending into higher space)
CouNumber & ub(register int index)
return current upper bound
int dimension_
dimension of point
bool isNlp_
true if this point comes from an NLP solver (and is thus nlp feasible)
bool & isNlp()
true if this point is the nlp solution
double CouNumber
main number type in Couenne
~Domain()
destructor
CouNumber & x(register int index)
current variable
DomainPoint * point_
current point
DomainPoint & operator=(const DomainPoint &src)
assignment operator
CouNumber * ub_
upper bound
DomainPoint * current()
return current point
CouNumber * ub()
return current upper bound vector
CouNumber * x_
current value of variables
CouNumber * lb()
return current lower bound vector
~DomainPoint()
destructor
CouNumber * ub()
return current upper bound vector
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...