source: branches/Couenne/Couenne/src/include/CouenneProblemElem.h @ 344

Last change on this file since 344 was 344, checked in by pbelotti, 13 years ago

modified branching point selection. Minor fixes in printing constraints

File size: 3.3 KB
Line 
1/*
2 * Name:    CouenneProblemElem.h
3 * Author:  Pietro Belotti
4 * Purpose: define the classes used by class CouenneProblem
5 *
6 * This file is licensed under the Common Public License (CPL)
7 */
8
9#ifndef COUENNE_PROBLEM_ELEM_H
10#define COUENNE_PROBLEM_ELEM_H
11
12#include <iostream>
13
14#include <CouenneTypes.h>
15#include <expression.h>
16
17
18// CouenneConstraint class, with any expression as the body and two range
19// expressions
20
21class CouenneConstraint {
22
23 protected:
24
25  // a general constraint is defined as lb_ <= body_ <= ub_, where all
26  // three components are expressions, depending on variables,
27  // auxiliaries and bounds. If the constraint is 2 <= exp (x1+x2) <=
28  // 4, then:
29
30  // body_ = exp (x1+x2), that is,
31  // new exprExp (new exprSum (new exprVar (1), new exprVar (2)),
32  expression *body_;
33
34  // while lb_ = new exprConst (2) and ub_ = new exprConst (4).
35  expression *lb_;
36  expression *ub_;
37
38 public:
39
40  // constructor
41  CouenneConstraint  (expression *body = NULL, 
42                      expression *lb   = NULL, 
43                      expression *ub   = NULL):
44    body_ (body), 
45    lb_   (lb), 
46    ub_   (ub) {
47
48    if (!lb_) 
49      if (!ub_) {
50        lb_ = new exprConst (0);
51        ub_ = new exprConst (0);
52      } 
53      else         lb_ = new exprConst (- COUENNE_INFINITY);
54    else if (!ub_) ub_ = new exprConst   (COUENNE_INFINITY);
55  }
56
57  // destructor
58  ~CouenneConstraint () {
59    delete body_; 
60    delete lb_; 
61    delete ub_;
62  }
63
64  // copy constructor
65  CouenneConstraint  (const CouenneConstraint &c):
66    body_  (c.Body () -> clone ()), 
67    lb_    (c.Lb   () -> clone ()),
68    ub_    (c.Ub   () -> clone ()) {}
69
70  // cloning method
71  inline CouenneConstraint *clone () const
72    {return new CouenneConstraint (*this);}
73
74  // get constraint's elements
75  inline expression *Lb   () const {return lb_;}
76  inline expression *Ub   () const {return ub_;}
77  inline expression *Body () const {return body_;}
78
79  // set body of constraint
80  inline expression *Body (expression *newBody) 
81    {body_ = newBody; return body_;}
82
83  // decompose body of constraint through auxiliary variables
84  inline exprAux *standardize (CouenneProblem *p) 
85    {return body_ -> standardize (p);}
86
87  // print constraint
88  void print (std::ostream &);
89};
90
91
92// Objective function class, with an expression and an optimization
93// direction
94
95class Objective {
96
97 protected:
98
99  // expression to optimize
100  expression *body_;
101
102  // can be COUENNE_MAXIMIZE or COUENNE_MINIMIZE
103  enum opt_sense sense_;
104
105 public:
106
107  // constructor
108  Objective  (expression *body, enum opt_sense sense):
109    body_ (body), sense_ (sense) {}
110
111  // destructor
112  ~Objective () 
113    {delete body_;}
114
115  // copy constructor
116  Objective  (const Objective &o):
117    body_  (o.Body  () -> clone ()), 
118    sense_ (o.Sense ()) {}
119
120  // cloning method
121  inline Objective *clone () const
122    {return new Objective (*this);}
123
124  // optimization sense
125  inline enum opt_sense Sense () const
126    {return sense_;}
127
128  // get body
129  inline expression *Body () const
130    {return body_;}
131
132  // set body
133  expression *Body (expression *newBody) 
134    {body_ = newBody; return body_;}
135
136  // get standard form of this objective function
137  inline exprAux *standardize (CouenneProblem *p) 
138    {return body_ -> standardize (p);}
139
140  // I/O
141  void print (std::ostream &out = std::cout) {
142    out << (sense_ == MAXIMIZE ? "max " : "min ");
143    body_ -> print (out);
144    out << std::endl;
145  }
146};
147
148#endif
Note: See TracBrowser for help on using the repository browser.