FLOPC++
MP_expression.hpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_expression.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_expression_hpp_
10 #define _MP_expression_hpp_
11 
12 #include <vector>
13 #include <set>
14 using std::vector;
15 using std::set;
16 
17 #include "MP_domain.hpp"
18 #include "MP_constant.hpp"
19 #include "MP_utilities.hpp"
20 
21 namespace flopc {
22 
23  class MP_constraint;
24  class TerminalExpression;
25  class MP_variable;
26  class VariableRef;
27 
28  class MP {
29  friend class MP_expression;
30  friend class MP_constraint;
31  friend class MP_model;
32  friend class Messenger;
33  friend class VerboseMessenger;
34  friend class CoefLess;
35  friend class MP_expression_base;
36  friend class VariableRef;
37 
38  struct Coef {
39  Coef(int c, int r, double v, int s = 0) :
40  col(c), row(r), stage(s), val(v) {}
41  int col, row, stage;
42  double val;
43  };
44 
45  struct CoefLess {
46  bool operator() (const MP::Coef& a, const MP::Coef& b) const;
47  };
48 
49  protected:
50  class GenerateFunctor : public Functor {
51  public:
52  GenerateFunctor(MP_constraint* r, vector<Coef>& cfs): R(r), Coefs(cfs) {}
53 
54  void setMultiplicator(vector<Constant>& mults, double m) {
55  multiplicators = mults;
56  M = m;
57  }
59  C = c;
60  }
61 
62  void operator()() const;
63  private:
64  vector<Constant> multiplicators;
66  double M; // sign (1=lhs, -1=rhs)
68  vector<MP::Coef>& Coefs;
69  };
70  };
71 
72 
79  friend class MP_expression;
80  friend class Handle<MP_expression_base*>;
81  private:
82  int count;
83  public:
84  MP_expression_base() : count(0) {}
85 
86  virtual double level() const = 0;
87  virtual void generate(const MP_domain& domain,
88  vector<Constant> multiplicators,
90  double m) const = 0;
91 
92  virtual void insertVariables(set<MP_variable*>& v) const = 0;
93 
94  virtual ~MP_expression_base() {}
95  };
96 
97 
110  class MP_expression : public Handle<MP_expression_base*> {
111  public:
114  MP_expression(const Constant& c);
116  MP_expression(const VariableRef& v);
118  };
119 
120 
128  public:
129  virtual double getValue() const = 0;
130  virtual int getColumn() const = 0;
131  virtual int getStage() const = 0;
132  };
133 
139  friend class MP_variable;
140  public:
141  int getColumn() const;
142  private:
144  const MP_index_exp& i1,
145  const MP_index_exp& i2,
146  const MP_index_exp& i3,
147  const MP_index_exp& i4,
148  const MP_index_exp& i5);
149 
150  double level() const;
151 
152  void insertVariables(set<MP_variable*>& v) const {
153  v.insert(V);
154  }
155  double getValue() const {
156  return 1.0;
157  }
158  int getStage() const {
159  return 0;
160  }
161  void generate(const MP_domain& domain,
162  vector<Constant> multiplicators,
164  double m) const;
166  int offset;
167  const MP_index_exp I1,I2,I3,I4,I5;
168  };
169 
171  MP_expression operator+(const MP_expression& e1, const MP_expression& e2);
173  MP_expression operator+(const MP_expression& e1, const Constant& e2);
175  MP_expression operator+(const Constant& e1, const MP_expression& e2);
177  MP_expression operator-(const MP_expression& e1, const MP_expression& e2);
179  MP_expression operator-(const MP_expression& e1, const Constant& e2);
181  MP_expression operator-(const Constant& e1, const MP_expression& e2);
183  MP_expression operator*(const Constant& e1, const MP_expression& e2);
185  MP_expression operator*(const MP_expression& e1, const Constant& e2);
187  MP_expression operator/(const MP_expression& e1, const Constant& e2);
189  MP_expression sum(const MP_domain& d, const MP_expression& e);
190 
191 } // End of namespace flopc
192 #endif
Coef(int c, int r, double v, int s=0)
void setMultiplicator(vector< Constant > &mults, double m)
vector< MP::Coef > & Coefs
Symbolic representation of a linear expression.This is one of the main public interface classes...
Constant operator/(const Constant &a, const Constant &b)
Returns the quotient of two constants.This is used in the formation of an expression.
void setTerminalExpression(const TerminalExpression *c)
Inteface for hooking up to internal flopc++ message handling.In more advanced use of FlopC++...
Definition: MP_model.hpp:36
friend class MP_expression
Utility for doing reference counted pointers.
Constant operator+(const Constant &a, const Constant &b)
Returns the sum of two constants.This is used in the formation of an expression.
MP_expression(MP_expression_base *r)
Representation of an expression involving an index.This is one of the main public interface classes...
Definition: MP_index.hpp:141
The base class for all expressions.
vector< Constant > multiplicators
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
Definition: MP_model.hpp:90
double getValue() const
Constant operator-(const Constant &a, const Constant &b)
Returns the difference of two constants.This is used in the formation of an expression.
friend class VariableRef
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
Range over which some other constuct is defined.This is one of the main public interface classes...
Definition: MP_domain.hpp:61
GenerateFunctor(MP_constraint *r, vector< Coef > &cfs)
const TerminalExpression * C
Symantic representation of a variable.This is one of the main public interface classes. It should be directly declared by clients of the FlopC++. The parametersof construction are MP_set s which specify the indexes over which the variable is defined.
Definition: MP_variable.hpp:35
Function object. Often used.
const MP_index_exp I5
Reference counted class for all "constant" types of data.
Definition: MP_constant.hpp:49
Constant operator*(const Constant &a, const Constant &b)
Returns the product of two constants.This is used in the formation of an expression.
Constant sum(const MP_domain &i, const Constant &e)
Returns the sum of two constants.
The base class for all expressions.
void insertVariables(set< MP_variable *> &v) const
Semantic representation of a linear constraint.This is one of the main public interface classes...