summaryrefslogtreecommitdiff
path: root/impl/main.cpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-30 21:30:53 +1100
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-30 21:30:53 +1100
commit3d372ecf513c951675602286b296f7af520bb3cf (patch)
tree87b3a75507c64e202ffc6d83028e9da1821412c9 /impl/main.cpp
parent093a35f07986ecfac8c43d053445e8417c7c2139 (diff)
parent6a4786bde976e9a023c7f65a395384d214c5102c (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'impl/main.cpp')
-rw-r--r--impl/main.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/impl/main.cpp b/impl/main.cpp
index 94351ec..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"
@@ -9,6 +10,8 @@
#include "MaxStrategy.hpp"
#include "VariableAssignment.hpp"
+#include <ctime>
+
extern "C" {
#include "parser/EquationSystemParser.h"
#include "parser/EquationSystemLexer.h"
@@ -134,44 +137,58 @@ 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)
+ 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())
- cout << var.name() << " = " << solver.solve(var) << endl;
+ 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);
- cout << var.name() << " = " << solver.solve(var) << endl;
+ solver.solve(var);
}
}
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &finish);
- /*
- DynamicMaxStrategy<ZBar> strategy(system);
- DynamicVariableAssignment<ZBar> rho(system, strategy);
- strategy.setRho(rho);
+ 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] << endl;
+ 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] << endl;
+ cout << var.name() << " = " << solver.solve(var) << endl;
}
}
- */
+
+ timespec temp;
+ if ((finish.tv_nsec-start.tv_nsec)<0) {
+ temp.tv_sec = finish.tv_sec-start.tv_sec-1;
+ temp.tv_nsec = 1000000000+finish.tv_nsec-start.tv_nsec;
+ } else {
+ temp.tv_sec = finish.tv_sec-start.tv_sec;
+ temp.tv_nsec = finish.tv_nsec-start.tv_nsec;
+ }
+ cerr << "Time taken: " << temp.tv_sec << "." << setfill('0') << setw(9) << temp.tv_nsec << " seconds." << endl;
parser -> free(parser);
tokens -> free(tokens);