Otawa  0.10
Constraint.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * ilp::Constraint class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2005-07, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef OTAWA_ILP_CONSTRAINT_H
23 #define OTAWA_ILP_CONSTRAINT_H
24 
25 #include <otawa/ilp/Var.h>
26 #include <elm/datastruct/Iterator.h>
27 #include <elm/utility.h>
28 #include "Expression.h"
29 
30 namespace otawa { namespace ilp {
31 
32 // Constraint class
33 class Constraint {
34 public:
36  typedef enum comparator_t {
37  UNDEF = -3, // interface 1.2.0
38  LT = -2,
39  LE = -1,
40  EQ = 0,
41  GE = 1,
42  GT = 2
43  } comparator_t;
44 
45  virtual ~Constraint(void) { };
46 
47  virtual double coefficient(Var *var = 0) const = 0;
48  virtual double constant(void) const = 0;
49  virtual comparator_t comparator(void) const = 0;
50  virtual const string& label(void) const = 0;
51 
52  virtual void add(double coef, Var *var = 0) = 0;
53  virtual void sub(double coef, Var *var = 0) = 0;
54 
55  virtual elm::datastruct::IteratorInst<Term> *terms(void) = 0;
56  inline void addLeft(double coef, Var *var = 0) { add(coef, var); }
57  inline void addRight(double coef, Var *var = 0) { add(-coef, var); }
58 
59  // interface 1.2.0
60  virtual void setComparator(comparator_t comp) = 0;
61  virtual void setLabel(const string& label) = 0;
62  inline void add(const Term& t) { add(t.snd, t.fst); }
63  inline void sub(const Term& t) { sub(t.snd, t.fst); }
64  void add(const Expression& e);
65  void sub(const Expression& e);
66 
68  public:
69  inline TermIterator(elm::datastruct::IteratorInst<Term> *_inst) : elm::datastruct::Iterator<Term>(_inst) { }
70  inline TermIterator(Constraint *_cons) : elm::datastruct::Iterator<Term>(_cons->terms()) {
71  }
72 
73  };
74 
75 };
76 
78 io::Output& operator<<(io::Output& out, const Term& t);
79 
80 } } // otawa::ilp
81 
82 #endif // OTAWA_ILP_CONSTRAINT_H
virtual elm::datastruct::IteratorInst< Term > * terms(void)=0
An expression allows to represent a sum of terms and may be used to represent the value of an aliased...
Definition: Expression.h:43
virtual comparator_t comparator(void) const =0
Get the constraint comparator.
coef_t snd
Definition: Expression.h:40
Iterator(IteratorInst< T > *_iter)
comparator_t
Definition: Constraint.h:36
virtual ~Constraint(void)
Definition: Constraint.h:45
Definition: Constraint.h:67
Definition: Constraint.h:38
virtual void setComparator(comparator_t comp)=0
Definition: Constraint.h:42
virtual void add(double coef, Var *var=0)=0
Add a term to the constraint to the left part of constraint.
Definition: Constraint.h:37
virtual const string & label(void) const =0
Definition: Constraint.h:40
void addRight(double coef, Var *var=0)
Add a factor on the right side.
Definition: Constraint.h:57
void sub(const Term &t)
Definition: Constraint.h:63
virtual double coefficient(Var *var=0) const =0
Get the coefficient for the given variable.
io::Output & operator<<(io::Output &out, Constraint::comparator_t comp)
Definition: ilp_Constraint.cpp:128
virtual void setLabel(const string &label)=0
TermIterator(Constraint *_cons)
Definition: Constraint.h:70
sys::SystemOutStream & out
This class is used to represent constraints in an ILP system with the following form: ...
Definition: Constraint.h:33
otawa::ilp::Term Term
Definition: Constraint.h:35
Definition: Expression.h:35
TermIterator(elm::datastruct::IteratorInst< Term > *_inst)
Definition: Constraint.h:69
Var * fst
Definition: Expression.h:39
virtual void sub(double coef, Var *var=0)=0
Substact a factor from the constraint.
virtual double constant(void) const =0
void add(const Term &t)
Definition: Constraint.h:62
Definition: Constraint.h:41
A variable is an identifier used for performing ILP computation.
Definition: Var.h:36
void addLeft(double coef, Var *var=0)
Add a factor on the left side.
Definition: Constraint.h:56
Encapsulation for ilp::Var pointers for {ilp} expr user-fiendly interface.
Definition: expr.h:29
Definition: Constraint.h:39