blob: 9a393c8bed81f8efff42947a2a40f413a58c45ec (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
|