diff options
Diffstat (limited to 'impl/EquationSystem.h')
-rw-r--r-- | impl/EquationSystem.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/impl/EquationSystem.h b/impl/EquationSystem.h new file mode 100644 index 0000000..9a393c8 --- /dev/null +++ b/impl/EquationSystem.h @@ -0,0 +1,40 @@ +#ifndef EQUATIONSYSTEM_H +#define EQUATIONSYSTEM_H + +#include "Equation.h" +#include <list> + +template<class T> +struct EquationSystem { + bool add(Equation<T> e) { + for (iterator it = equations.begin(); + it != equations.end(); + ++it) { + if ((*it).var().name() == e.var().name()) { + return false; + } + } + this->equations.push_back(e); + return true; + } + + std::map<std::string, T> solve(std::map<std::string, T> start) { + std::map<std::string, T> result = start; + std::map<std::string, T> comparison; + do { + comparison = result; + for (iterator it = equations.begin(); + it != equations.end(); + ++it) { + result = it->solve(result); + } + } while (comparison != result); + return result; + } + + private: + typedef typename std::list< Equation<T> >::iterator iterator; + std::list< Equation<T> > equations; +}; + +#endif |