summaryrefslogtreecommitdiff
path: root/impl/main.cpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@carlo-laptop>2012-10-30 20:56:38 +1100
committerCarlo Zancanaro <carlo@carlo-laptop>2012-10-30 20:56:38 +1100
commit6a4786bde976e9a023c7f65a395384d214c5102c (patch)
treef3dd303f21dfa0be269a932dd05438041a290f27 /impl/main.cpp
parentff2030f3a19926334fbe3a043c5f88622c17c2f8 (diff)
parent95b82ea3830c3a34455323167894647e3aa773a6 (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Conflicts: impl/test/run
Diffstat (limited to 'impl/main.cpp')
-rw-r--r--impl/main.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/impl/main.cpp b/impl/main.cpp
index b83894d..1fed389 100644
--- a/impl/main.cpp
+++ b/impl/main.cpp
@@ -1,5 +1,6 @@
#include "Log.hpp"
#include <iostream>
+#include <iomanip>
#include <vector>
#include <sstream>
#include "Complete.hpp"
@@ -136,44 +137,46 @@ int main (int argc, char* argv[]) {
EquationSystemParser_equation_system_return ret = parser -> equation_system(parser);
+ std::cerr << "Parse complete." << std::endl;
+
EquationSystem<ZBar> system;
treeToSystem<ZBar>(ret.tree, system);
log::debug << system << endl;
system.indexMaxExpressions(); // make reverse-lookup O(1) instead of O(n)
- DynamicMaxStrategy<ZBar> strategy(system);
- DynamicVariableAssignment<ZBar> rho(system, strategy);
- strategy.setRho(rho);
+ std::cerr << "System created and indexed." << std::endl;
+
+ Solver<ZBar> solver(system); // local *and* lazy. I love it!
timespec start, finish;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
if (variables.size() > 0) {
- for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) {
- Variable<ZBar>& var = system.variable(i);
- if (variables.find(var.name()) != variables.end()) {
- rho[var];
- }
+ for (set<string>::iterator it = variables.begin(), ei = variables.end();
+ it != ei;
+ ++it) {
+ solver.solve(system.variable(*it));
}
} else {
for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) {
Variable<ZBar>& var = system.variable(i);
- rho[var];
+ solver.solve(var);
}
}
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &finish);
+ std::cerr << "System solved." << std::endl;
+
if (variables.size() > 0) {
for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) {
Variable<ZBar>& var = system.variable(i);
- if (variables.find(var.name()) != variables.end()) {
- cout << var.name() << " = " << rho[var].asKnown() << endl;
- }
+ if (variables.find(var.name()) != variables.end())
+ cout << var.name() << " = " << solver.solve(var) << endl;
}
} else {
for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) {
Variable<ZBar>& var = system.variable(i);
- cout << var.name() << " = " << rho[var].asKnown() << endl;
+ cout << var.name() << " = " << solver.solve(var) << endl;
}
}
@@ -185,8 +188,7 @@ int main (int argc, char* argv[]) {
temp.tv_sec = finish.tv_sec-start.tv_sec;
temp.tv_nsec = finish.tv_nsec-start.tv_nsec;
}
- cerr << "Time taken: " << temp.tv_sec << " seconds and " << temp.tv_nsec << " nanoseconds." << endl;
-
+ cerr << "Time taken: " << temp.tv_sec << "." << setfill('0') << setw(9) << temp.tv_nsec << " seconds." << endl;
parser -> free(parser);
tokens -> free(tokens);