summaryrefslogtreecommitdiff
path: root/impl/main.cpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@carlo-laptop>2012-05-29 23:34:24 +1000
committerCarlo Zancanaro <carlo@carlo-laptop>2012-05-29 23:34:24 +1000
commitfd6bc1887fecca5338e7d5660d56a4038c805d96 (patch)
treeecc0f2188724834565b1f24705f3e90470ac37a7 /impl/main.cpp
parente043ee06a51a8d8c68f8cb0984d4f7bd8915bea8 (diff)
Range stuff better, RecursiveFixpoint broken.
Diffstat (limited to 'impl/main.cpp')
-rw-r--r--impl/main.cpp47
1 files changed, 36 insertions, 11 deletions
diff --git a/impl/main.cpp b/impl/main.cpp
index 21be64b..2006565 100644
--- a/impl/main.cpp
+++ b/impl/main.cpp
@@ -26,9 +26,21 @@ std::pair<Expression<T>*, Expression<T>*> treeToExpression(pANTLR3_BASE_TREE nod
// leaf node - variable
if (num == 0) {
- return std::pair<Expression<T>*, Expression<T>*>(
- system.newExpression(system.newVariable(name + "_l")),
- system.newExpression(system.newVariable(name + "_u")));
+ if (negative) {
+ vector<Expression<T>*> firstArgs;
+ firstArgs.push_back(system.newExpression(system.newVariable(name + "_u")));
+ vector<Expression<T>*> secondArgs;
+ secondArgs.push_back(system.newExpression(system.newVariable(name + "_l")));
+ return std::pair<Expression<T>*, Expression<T>*>(
+ system.newExpression(new Negate<T>(),
+ firstArgs),
+ system.newExpression(new Negate<T>(),
+ secondArgs));
+ } else {
+ return std::pair<Expression<T>*, Expression<T>*>(
+ system.newExpression(system.newVariable(name + "_l")),
+ system.newExpression(system.newVariable(name + "_u")));
+ }
}
// a range itself
@@ -43,7 +55,7 @@ std::pair<Expression<T>*, Expression<T>*> treeToExpression(pANTLR3_BASE_TREE nod
if (!(firstStream >> firstValue)) {
throw "Invalid number.";
}
- if (negative) firstValue = -firstValue;
+ string firstChildName = childName;
childNode = (pANTLR3_BASE_TREE) node->getChild(node, 1);
childName = (char*) childNode->getText(childNode)->chars;
@@ -51,11 +63,22 @@ std::pair<Expression<T>*, Expression<T>*> treeToExpression(pANTLR3_BASE_TREE nod
if (!(secondStream >> secondValue)) {
throw "Invalid number.";
}
- if (negative) secondValue = -secondValue;
+ string secondChildName = childName;
+
+ if (negative) {
+ T temp = firstValue;
+ string tempname = firstChildName;
+
+ firstValue = -secondValue;
+ firstChildName = "-" + secondChildName;
+
+ secondValue = -temp;
+ secondChildName = "-" + tempname;
+ }
return std::pair<Expression<T>*, Expression<T>*>(
- system.newExpression(new Constant<T>(firstValue)),
- system.newExpression(new Constant<T>(secondValue)));
+ system.newExpression(new Constant<T>(firstChildName, firstValue)),
+ system.newExpression(new Constant<T>(secondChildName, secondValue)));
}
if (name == "-") {
@@ -77,8 +100,8 @@ std::pair<Expression<T>*, Expression<T>*> treeToExpression(pANTLR3_BASE_TREE nod
if (name == "-") {
//if (firstArgs.size() == 1) { // secondArgs.size() == firstArgs.size()
return std::pair<Expression<T>*, Expression<T>*>(
- secondArgs[0],
- firstArgs[0]);
+ firstArgs[0],
+ secondArgs[0]);
}
if (name == "max") {
@@ -132,15 +155,17 @@ void treeToSystem(pANTLR3_BASE_TREE node, EquationSystem<T>& system) {
std::pair<Expression<T>*, Expression<T>*> exprs = treeToExpression(exprNode, system);
var = system.newVariable(varName + "_l");
- args.push_back(system.newExpression(new Constant<T>(-infinity<T>())));
+ args.push_back(system.newExpression(new Constant<T>("-inf", -infinity<T>())));
args.push_back(exprs.first);
system[*var] = system.newMaxExpression(args);
+ std::cout << var->op_name << " = " << *system[*var] << std::endl;
args.clear();
var = system.newVariable(varName + "_u");
- args.push_back(system.newExpression(new Constant<T>(-infinity<T>())));
+ args.push_back(system.newExpression(new Constant<T>("-inf", -infinity<T>())));
args.push_back(exprs.second);
system[*var] = system.newMaxExpression(args);
+ std::cout << var->op_name << " = " << *system[*var] << std::endl;
}
}