summaryrefslogtreecommitdiff
path: root/impl/EquationSystem.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'impl/EquationSystem.hpp')
-rw-r--r--impl/EquationSystem.hpp77
1 files changed, 0 insertions, 77 deletions
diff --git a/impl/EquationSystem.hpp b/impl/EquationSystem.hpp
deleted file mode 100644
index 3232620..0000000
--- a/impl/EquationSystem.hpp
+++ /dev/null
@@ -1,77 +0,0 @@
-#ifndef EQUATION_SYSTEM_H
-#define EQUATION_SYSTEM_H
-
-#include <map>
-#include <string>
-#include "Expression.hpp"
-
-template<typename T>
-struct EquationSystem {
- void add(std::string k, Expression<T> v) {
- equations.insert(std::pair<std::string, Expression<T> >(k, v));
- }
- unsigned int count() const {
- return equations.size();
- }
- /**
- init is the value where it STARTS, it's working the other way
- if there's no stability then it ends with -init
- */
- std::map<std::string, T> solveBF(const T& init) const {
- std::map<std::string, T> solutions;
- for (typename std::map<std::string, Expression<T> >::const_iterator it = equations.begin();
- it != equations.end();
- ++it){
- solutions[it->first] = init;
- }
- int num = equations.size();
- for (int i = 0; i < num; ++i) {
- solutions = eval(solutions, false, -init);
- }
- solutions = eval(solutions, true, -init);
- for (int i = 0; i < num-1; ++i) {
- solutions = eval(solutions, false, -init);
- }
- return solutions;
- }
-
- EquationSystem maxStrategy(const std::map<std::string, T>& assignment) {
- EquationSystem result;
- for (typename std::map<std::string, Expression<T> >::const_iterator it = equations.begin();
- it != equations.end();
- ++it) {
- result.add(it->first, it->second.maxStrategyEager(assignment));
- }
- return result;
- }
-
- std::string output() const {
- std::string output = "";
- for (typename std::map<std::string, Expression<T> >::const_iterator it = equations.begin();
- it != equations.end();
- ++it) {
- output += it->first + " = " + it->second.output() + "\n";
- }
- return output;
- }
-
- private:
- std::map<std::string, T> eval(const std::map<std::string, T>& assignment, bool infinity, const T& infValue) const {
- std::map<std::string, T> result;
- for (typename std::map<std::string, Expression<T> >::const_iterator it = equations.begin();
- it != equations.end();
- ++it) {
- T val = it->second.eval(assignment);
- if (infinity) {
- typename std::map<std::string, T>::const_iterator oldEntry = assignment.find(it->first);
- result[it->first] = (oldEntry->second == val ? val : infValue);
- } else {
- result[it->first] = val;
- }
- }
- return result;
- }
- std::map<std::string, Expression<T> > equations;
-};
-
-#endif