Otawa  0.10
System.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * ilp::System 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_SYSTEM_H
23 #define OTAWA_ILP_SYSTEM_H
24 
25 #include <elm/io/OutStream.h>
26 #include <elm/string.h>
27 #include <otawa/ilp/Constraint.h>
28 #include <elm/datastruct/Iterator.h>
29 #include <otawa/proc/Monitor.h>
30 
31 #include "features.h"
32 
33 namespace otawa {
34 
35 class WorkSpace;
36 
37 namespace ilp {
38 
39 class ILPPlugin;
40 
41 // System class
42 class System {
43 public:
44  virtual ~System(void) { }
45 
46  // 1.0.0 & 1.1.0 interfaces
48  double constant = 0) = 0;
49  virtual Constraint *newConstraint(const string& label,
50  Constraint::comparator_t comp, double constant = 0) = 0;
51  virtual bool solve(WorkSpace *ws = 0) = 0;
52  virtual void addObjectFunction(double coef, Var *var = 0) = 0;
53  virtual double valueOf(Var *var) = 0;
54  virtual double value(void) = 0;
55  virtual Var *newVar(const string& name = "") = 0;
56  virtual int countVars(void) = 0;
57  virtual int countConstraints(void) = 0;
60  virtual void exportLP(io::Output& out = elm::cout) = 0;
61  virtual void dumpSystem(io::Output& out = elm::cout);
62  virtual void dumpSolution(io::Output& out = elm::cout) = 0;
63  virtual void dump(elm::io::OutStream& out = elm::io::out);
64 
65  // 1.2.0 interface
66  virtual bool solve(WorkSpace *ws, otawa::Monitor& mon);
67  virtual string lastErrorMessage(void);
68  virtual ILPPlugin *plugin(void);
69  virtual Var *newVar(Var::type_t type, const string& name = "") = 0;
70 
71  // output methods
72  bool hasDump(format_t fmt);
77 
78  class ConstIterator: public elm::datastruct::Iterator<Constraint*> {
79  public:
80 
82  elm::datastruct::Iterator<Constraint*>(_inst) { }
83  inline ConstIterator(System *_sys) : elm::datastruct::Iterator<Constraint*>(_sys->constraints()) {
84 
85  }
86 
87  };
88 
89  class ObjTermIterator: public elm::datastruct::Iterator<Constraint::Term> {
90  public:
91 
93  elm::datastruct::Iterator<Constraint::Term>(_inst) { }
94  inline ObjTermIterator(System *_sys):
95  elm::datastruct::Iterator<Constraint::Term>(_sys->objTerms()) { }
96  };
97 };
98 
99 } } // otawa::ilp
100 
101 #endif // OTAWA_ILP_SYSTEM_H
Iterator(IteratorInst< T > *_iter)
comparator_t
Definition: Constraint.h:36
bool hasDump(format_t fmt)
Tests if it is possible to dump in the given format.
Definition: ilp_System.cpp:599
virtual double valueOf(Var *var)=0
This method can only be called after the resolution of the system and returns the value of a variable...
virtual string lastErrorMessage(void)
Get the message of the last error.
Definition: ilp_System.cpp:125
virtual void dump(elm::io::OutStream &out=elm::io::out)
Dump the system to the given output.
Definition: ilp_System.cpp:101
format_t
Definition: features.h:30
virtual void dumpSolution(io::Output &out=elm::cout)=0
Dump the solution textually to the given output.
void dumpLPSolve(elm::io::OutStream &out=elm::io::out)
Dump in LPSolve format.
Definition: ilp_System.cpp:227
io::Output cout(io::out)
virtual void addObjectFunction(double coef, Var *var=0)=0
Add a factor to the object function.
virtual bool solve(WorkSpace *ws=0)=0
Solve the ILP system.
virtual elm::datastruct::IteratorInst< ilp::Constraint * > * constraints(void)=0
virtual Constraint * newConstraint(Constraint::comparator_t comp, double constant=0)=0
Build a new constraint that may be initialized by the user.
Definition: System.h:78
virtual double value(void)=0
Return the value of the optimized object function.
virtual ~System(void)
Definition: System.h:44
ConstIterator(elm::datastruct::IteratorInst< Constraint * > *_inst)
Definition: System.h:81
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
void dumpCPlex(elm::io::OutStream &out=elm::io::out)
Dump system in CPlex format.
Definition: ilp_System.cpp:439
ConstIterator(System *_sys)
Definition: System.h:83
ObjTermIterator(System *_sys)
Definition: System.h:94
void dumpMOSEK(elm::io::OutStream &out=elm::io::out)
Dump in MOSEK format.
Definition: ilp_System.cpp:315
sys::SystemOutStream & out
This class is used to represent constraints in an ILP system with the following form: ...
Definition: Constraint.h:33
Definition: Expression.h:35
virtual Var * newVar(const string &name="")=0
virtual void dumpSystem(io::Output &out=elm::cout)
Dump the system in text format (as a default, call exportLP).
Definition: ilp_System.cpp:638
cstring name
Definition: odisasm.cpp:107
virtual int countConstraints(void)=0
Count the number of constraints in the system.
virtual elm::datastruct::IteratorInst< ilp::Constraint::Term > * objTerms(void)=0
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
virtual ILPPlugin * plugin(void)
Return the owner plugin.
Definition: ilp_System.cpp:144
This interface must be implemented by plugins providing ILP processors.
Definition: ILPPlugin.h:24
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
ObjTermIterator(elm::datastruct::IteratorInst< Constraint::Term > *_inst)
Definition: System.h:92
virtual void exportLP(io::Output &out=elm::cout)=0
Export the system to the given output using the LP format (lp_solve).
virtual int countVars(void)=0
Count the number of variables in the system.