Otawa  0.10
AbstractSystem.h
Go to the documentation of this file.
1 /*
2  * ilp::AbstractSystem class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2015, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef OTAWA_ILP_ABSTRACTSYSTEM_H_
22 #define OTAWA_ILP_ABSTRACTSYSTEM_H_
23 
24 #include <elm/genstruct/FragTable.h>
25 #include <otawa/ilp/Expression.h>
26 #include <otawa/ilp/System.h>
27 
28 namespace otawa { namespace ilp {
29 
30 using namespace elm;
31 
32 class AbstractSystem;
33 
35 public:
36  AbstractConstraint(string label, comparator_t comp, double cst);
37  virtual ~AbstractConstraint(void);
38 
39  virtual double coefficient(Var *var = 0) const;
40  virtual double constant(void) const;
41  virtual comparator_t comparator(void) const;
42  virtual const string& label(void) const;
43  virtual void add(double coef, Var *var = 0);
44  virtual void sub(double coef, Var *var = 0);
45  virtual elm::datastruct::IteratorInst<Term> *terms(void);
46  virtual void setComparator(comparator_t comp);
47  virtual void setLabel(const string& label);
48 
50  public:
51  inline TermIter(AbstractConstraint *cons): Expression::Iterator(&cons->_expr) { }
52  };
53 
54 private:
55  friend class AbstractSystem;
56  string _label;
59  double _cst;
60  int _idx;
62 };
63 
64 class AbstractSystem: public System {
65  class AbstractVar: public Var {
66  public:
67  AbstractVar(const string& name, type_t type);
68  virtual ~AbstractVar(void);
69  inline int index(void) const { return _idx; }
70  private:
71  friend class AbstractSystem;
73  int _idx;
74  };
75 
76 public:
77  AbstractSystem(void);
78  virtual ~AbstractSystem(void);
79  virtual Constraint *newConstraint(Constraint::comparator_t comp, double constant);
80  virtual Constraint *newConstraint(const string& label, Constraint::comparator_t comp, double constant);
81  virtual void addObjectFunction(double coef, Var *var);
82  virtual Var *newVar(const string& name);
83  virtual int countVars(void);
84  virtual int countConstraints(void);
85  virtual elm::datastruct::IteratorInst<ilp::Constraint*> *constraints(void);
87  virtual void exportLP(io::Output& out);
88  virtual void dumpSolution(io::Output& out);
89  virtual Var *newVar(Var::type_t type, const string& name);
90 
91 protected:
92  int index(ilp::Var *var);
93 
94  class ConstIter: public genstruct::FragTable<AbstractConstraint *>::Iterator {
95  public:
97  : genstruct::FragTable<AbstractConstraint *>::Iterator(sys->conss) { }
98  inline void next(void) {
99  do {
101  } while(!ended() && !item());
102  }
103  };
104 
105  class VarIter: public genstruct::FragTable<AbstractVar *>::Iterator {
106  public:
107  inline VarIter(AbstractSystem *sys)
108  : genstruct::FragTable<AbstractVar *>::Iterator(sys->vars) { }
109  inline void next(void) {
110  do {
112  } while(!ended() && !item());
113  }
114  };
115 
116 private:
117 
118  friend class AbstractConstraint;
119  void remove(AbstractConstraint *cons);
120  friend class AbstractVar;
121  void remove(AbstractVar *var);
122 
126  bool cleaning;
127 };
128 
129 } } // otawa::ilp
130 
131 #endif /* OTAWA_ILP_ABSTRACTSYSTEM_H_ */
genstruct::FragTable< AbstractVar * > vars
Definition: AbstractSystem.h:123
ConstIter(AbstractSystem *sys)
Definition: AbstractSystem.h:96
An expression allows to represent a sum of terms and may be used to represent the value of an aliased...
Definition: Expression.h:43
comparator_t
Definition: Constraint.h:36
AbstractSystem * _sys
Definition: AbstractSystem.h:72
Constraint generated by AbstractSystem.
Definition: AbstractSystem.h:34
Definition: AbstractSystem.h:65
bool cleaning
Definition: AbstractSystem.h:126
Expression obj
Definition: AbstractSystem.h:125
Definition: AbstractSystem.h:105
Definition: Expression.h:61
int index(void) const
Definition: AbstractSystem.h:69
Definition: AbstractSystem.h:49
This class provides a convenient way to handle ILP systems in OTAWA.
Definition: AbstractSystem.h:64
Expression _expr
Definition: AbstractSystem.h:57
double _cst
Definition: AbstractSystem.h:59
string _label
Definition: AbstractSystem.h:56
TermIter(AbstractConstraint *cons)
Definition: AbstractSystem.h:51
sys::SystemOutStream & out
This class is used to represent constraints in an ILP system with the following form: ...
Definition: Constraint.h:33
comparator_t _comp
Definition: AbstractSystem.h:58
int _idx
Definition: AbstractSystem.h:73
inst add(int d, int a, int b)
Definition: inst.h:163
inst sub(int d, int a, int b)
Definition: inst.h:164
AbstractSystem * _sys
Definition: AbstractSystem.h:61
Definition: AbstractSystem.h:94
VarIter(AbstractSystem *sys)
Definition: AbstractSystem.h:107
cstring name
Definition: odisasm.cpp:107
void next(void)
Definition: AbstractSystem.h:98
int _idx
Definition: AbstractSystem.h:60
Encapsulation for ilp::Constraint pointers for {ilp} expr user-fiendly interface. ...
Definition: expr.h:46
genstruct::FragTable< AbstractConstraint * > conss
Definition: AbstractSystem.h:124
A variable is an identifier used for performing ILP computation.
Definition: Var.h:36
An ILP system is a colletion of ILP constraint that may maximize or minimize some object function...
Definition: System.h:42
const Type & type(void)
Definition: type.h:163
Encapsulation for ilp::Var pointers for {ilp} expr user-fiendly interface.
Definition: expr.h:29
type_t
Type of an ILP variable.
Definition: Var.h:38
void next(void)
Definition: AbstractSystem.h:109