FLOPC++
MP_constraint.hpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_constraint.hpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 // ****************************************************************************
8 
9 #ifndef _MP_constraint_hpp_
10 #define _MP_constraint_hpp_
11 
12 #include <set>
13 using std::set;
14 
15 #include <map>
16 using std::map;
17 
18 #include "MP_set.hpp"
19 #include "MP_domain.hpp"
20 #include "MP_utilities.hpp"
21 #include "MP_expression.hpp"
22 #include "MP_boolean.hpp"
23 #include "MP_data.hpp"
24 
25 namespace flopc {
26 
27  class MP_constraint;
28  class Constant;
29  class MP_model;
30  class MP_variable;
31 
35  enum Sense_enum {LE,GE,EQ};
36 
43  public:
45  left(l), right(r), sense(s), count(0) {}
46 
49 // protected:
50  int count;
51  };
52 
53  class Constraint : public Handle<Constraint_base*> {
54  friend class MP_constraint;
55  friend class MP_model;
56  friend class Constraint_base;
57  friend Constraint operator<=(const MP_expression& l, const MP_expression& r);
58  friend Constraint operator<=(const Constant& l, const MP_expression& r);
59  friend Constraint operator<=(const MP_expression& l, const Constant& r);
60  friend Constraint operator<=(const VariableRef& l, const VariableRef& r);
61 
62  friend Constraint operator>=(const MP_expression& l, const MP_expression& r);
63  friend Constraint operator>=(const Constant& l, const MP_expression& r);
64  friend Constraint operator>=(const MP_expression& l, const Constant& r);
65  friend Constraint operator>=(const VariableRef& l, const VariableRef& r);
66 
67  friend Constraint operator==(const MP_expression& l, const MP_expression& r);
68  friend Constraint operator==(const Constant& l, const MP_expression& r);
69  friend Constraint operator==(const MP_expression& l, const Constant& r);
70  friend Constraint operator==(const VariableRef& l, const VariableRef& r);
71  public:
74  // MP_expression getLeft() {return root->left;}
75  };
76 
82  inline Constraint operator<=(const MP_expression& l, const MP_expression& r) {
83  return new Constraint_base(l, r, LE);
84  }
90  inline Constraint operator<=(const Constant& l, const MP_expression& r) {
91  return operator<=(MP_expression(l), r);
92  }
98  inline Constraint operator<=(const MP_expression& l, const Constant& r){
99  return operator<=(l, MP_expression(r));
100  }
106  inline Constraint operator<=(const VariableRef& l, const VariableRef& r) {
107  return new Constraint_base(l, r, LE);
108  }
109 
115  inline Constraint operator>=(const MP_expression& l, const MP_expression& r) {
116  return new Constraint_base(l, r, GE);
117  }
123  inline Constraint operator>=(const Constant& l, const MP_expression& r){
124  return operator>=(MP_expression(l), r);
125  }
131  inline Constraint operator>=(const MP_expression& l, const Constant& r){
132  return operator>=(l, MP_expression(r));
133  }
139  inline Constraint operator>=(const VariableRef& l, const VariableRef& r) {
140  return new Constraint_base(l, r, GE);
141  }
142 
148  inline Constraint operator==(const MP_expression& l, const MP_expression& r) {
149  return new Constraint_base(l, r, EQ);
150  }
156  inline Constraint operator==(const Constant& l, const MP_expression& r){
157  return operator==(MP_expression(l), r);
158  }
164  inline Constraint operator==(const MP_expression& l, const Constant& r) {
165  return operator==(l, MP_expression(r));
166  }
172  inline Constraint operator==(const VariableRef& l, const VariableRef& r) {
173  return new Constraint_base(l, r, EQ);
174  }
175 
176 
177  class GenerateFunctor;
178 
207  class MP_constraint : public RowMajor, public Named {
208  public:
211  const MP_set_base &s1 = MP_set::getEmpty(),
212  const MP_set_base &s2 = MP_set::getEmpty(),
213  const MP_set_base &s3 = MP_set::getEmpty(),
214  const MP_set_base &s4 = MP_set::getEmpty(),
215  const MP_set_base &s5 = MP_set::getEmpty()
216  );
217 
219  const MP_index_exp& i1 = MP_index_exp::getEmpty(),
220  const MP_index_exp& i2 = MP_index_exp::getEmpty(),
221  const MP_index_exp& i3 = MP_index_exp::getEmpty(),
222  const MP_index_exp& i4 = MP_index_exp::getEmpty(),
224  ) {
225  I1 = i1; I2 = i2; I3 = i3; I4 = i4; I5 = i5;
226  return *this;
227  }
228 
229  operator int() {
230  return offset + f(I1->evaluate(),I2->evaluate(),I3->evaluate(),
231  I4->evaluate(),I5->evaluate());
232  }
233 
234  virtual ~MP_constraint() {}
235 
236  double price(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const;
237 
238  void coefficients(vector<MP::Coef>& cfs);
239 
240  int row_number() const;
241 
243  B = b;
244  return *this;
245  }
246 
247  void insertVariables(set<MP_variable*>& v);
248 
249  void operator=(const Constraint& v);
250 
251  void display(string s="") const;
252 
254  int offset;
257  private:
259  const MP_set_base &S1, &S2, &S3, &S4, &S5;
261  };
262 
263 } // End of namespace flopc
264 #endif
MP_constraint & such_that(const MP_boolean &b)
static MP_set & getEmpty()
gets the distinct 'empty' MP_set.
Definition: MP_set.cpp:17
friend Constraint operator<=(const MP_expression &l, const MP_expression &r)
Uses operator overloading to construct an ConstraintConstucts a Constraint using operator overloading...
Constraint(Constraint_base *r)
MP_boolean operator>=(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:187
Symbolic representation of a linear expression.This is one of the main public interface classes...
double price(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
friend Constraint operator>=(const MP_expression &l, const MP_expression &r)
Uses operator overloading to construct an ConstraintConstucts a Constraint using operator overloading...
MP_constraint & operator()(const MP_index_exp &i1=MP_index_exp::getEmpty(), const MP_index_exp &i2=MP_index_exp::getEmpty(), const MP_index_exp &i3=MP_index_exp::getEmpty(), const MP_index_exp &i4=MP_index_exp::getEmpty(), const MP_index_exp &i5=MP_index_exp::getEmpty())
void operator=(const Constraint &v)
MP_boolean operator<=(const MP_index_exp &e1, const MP_index_exp &e2)
boolean which returns true if all in domain evaluate to true.This is used in the normal formation of ...
Definition: MP_boolean.cpp:175
const MP_set_base & S2
const MP_set_base & S1
Utility for doing reference counted pointers.
const MP_set_base & S3
Utility interface class for adding a string name onto a structure.
Representation of an expression involving an index.This is one of the main public interface classes...
Definition: MP_index.hpp:141
int f(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
void insertVariables(set< MP_variable * > &v)
static const MP_index_exp & getEmpty()
Return the unique empty expression.
Definition: MP_index.cpp:26
friend Constraint operator==(const MP_expression &l, const MP_expression &r)
Uses operator overloading to construct an ConstraintConstucts a Constraint using operator overloading...
MP_constraint(const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
construct the MP_constraint with appropriate sets for indexing.
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
Definition: MP_model.hpp:90
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
Reference counted class for all "boolean" types of data.This contains counters to ConstantBase pointe...
Definition: MP_boolean.hpp:40
Sense_enum
Enumeration for indicating direction of a constraint.
int row_number() const
Constraint_base(const MP_expression &l, const MP_expression &r, Sense_enum s)
void display(string s="") const
Reference counted class for all "constant" types of data.
Definition: MP_constant.hpp:49
MP_boolean operator==(const MP_index_exp &e1, const MP_index_exp &e2)
constructs a boolean evaluator using operator overloadingThis is used in the normal formation of an e...
Definition: MP_boolean.cpp:199
void coefficients(vector< MP::Coef > &cfs)
Internal representation of a "set".
Definition: MP_set.hpp:30
const MP_set_base & S5
const MP_set_base & S4
Semantic representation of a linear constraint.This is one of the main public interface classes...