From 870be1680e4020a5f89c06e8af28fd16545a1fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 22 Nov 2016 18:12:02 +0100 Subject: [PATCH] =?UTF-8?q?Made=20output=20of=20Boolean=20variables=20cons?= =?UTF-8?q?istent=20with=20clingo=E2=80=99s=20input=20language.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/anthem/HeadLiteralVisitor.h | 14 ++++----- include/anthem/LiteralVisitor.h | 21 +++++++------ include/anthem/StatementVisitor.h | 12 ++++---- include/anthem/TermVisitor.h | 47 ----------------------------- 4 files changed, 24 insertions(+), 70 deletions(-) diff --git a/include/anthem/HeadLiteralVisitor.h b/include/anthem/HeadLiteralVisitor.h index 285630e..f548451 100644 --- a/include/anthem/HeadLiteralVisitor.h +++ b/include/anthem/HeadLiteralVisitor.h @@ -58,30 +58,30 @@ struct HeadLiteralVisitor //////////////////////////////////////////////////////////////////////////////////////////////////// -struct HeadLiteralCollectVariablesVisitor +struct HeadLiteralCollectTermsVisitor { - void visit(const Clingo::AST::Literal &literal, const Clingo::AST::HeadLiteral &, std::vector &variables) + void visit(const Clingo::AST::Literal &literal, const Clingo::AST::HeadLiteral &, std::vector &terms) { - literal.data.accept(LiteralCollectVariablesVisitor(), literal, variables); + literal.data.accept(LiteralCollectTermsVisitor(), literal, terms); } - void visit(const Clingo::AST::Disjunction &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) + void visit(const Clingo::AST::Disjunction &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) { // TODO: implement throwErrorUnsupportedHeadLiteral("disjunction", headLiteral); } - void visit(const Clingo::AST::Aggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) + void visit(const Clingo::AST::Aggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) { throwErrorUnsupportedHeadLiteral("aggregate", headLiteral); } - void visit(const Clingo::AST::HeadAggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) + void visit(const Clingo::AST::HeadAggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) { throwErrorUnsupportedHeadLiteral("head aggregate", headLiteral); } - void visit(const Clingo::AST::TheoryAtom &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) + void visit(const Clingo::AST::TheoryAtom &, const Clingo::AST::HeadLiteral &headLiteral, std::vector &) { throwErrorUnsupportedHeadLiteral("theory", headLiteral); } diff --git a/include/anthem/LiteralVisitor.h b/include/anthem/LiteralVisitor.h index aed8b4a..ee0c79a 100644 --- a/include/anthem/LiteralVisitor.h +++ b/include/anthem/LiteralVisitor.h @@ -29,9 +29,9 @@ struct LiteralVisitor void visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &) { if (boolean.value == true) - std::cout << "true"; + std::cout << "#true"; else - std::cout << "false"; + std::cout << "#false"; } void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &) @@ -52,24 +52,25 @@ struct LiteralVisitor //////////////////////////////////////////////////////////////////////////////////////////////////// -struct LiteralCollectVariablesVisitor +struct LiteralCollectTermsVisitor { - void visit(const Clingo::AST::Boolean &, const Clingo::AST::Literal &, std::vector &) + void visit(const Clingo::AST::Boolean &, const Clingo::AST::Literal &, std::vector &) { } - void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, std::vector &variables) + void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, std::vector &terms) { - term.data.accept(TermCollectVariablesVisitor(), term, variables); + terms.push_back(term); } - void visit(const Clingo::AST::Comparison &comparison, const Clingo::AST::Literal &, std::vector &variables) + void visit(const Clingo::AST::Comparison &comparison, const Clingo::AST::Literal &, std::vector &terms) { - comparison.left.data.accept(TermCollectVariablesVisitor(), comparison.left, variables); - comparison.right.data.accept(TermCollectVariablesVisitor(), comparison.right, variables); + terms.reserve(terms.size() + 2); + terms.push_back(comparison.left); + terms.push_back(comparison.right); } - void visit(const Clingo::AST::CSPLiteral &, const Clingo::AST::Literal &literal, std::vector &) + void visit(const Clingo::AST::CSPLiteral &, const Clingo::AST::Literal &literal, std::vector &) { throwErrorUnsupportedLiteral("CSP literal", literal); } diff --git a/include/anthem/StatementVisitor.h b/include/anthem/StatementVisitor.h index ef0fc77..5f5f01b 100644 --- a/include/anthem/StatementVisitor.h +++ b/include/anthem/StatementVisitor.h @@ -37,19 +37,19 @@ struct StatementVisitor void visit(const Clingo::AST::Rule &rule, const Clingo::AST::Statement &) { - std::vector headVariables; - rule.head.data.accept(HeadLiteralCollectVariablesVisitor(), rule.head, headVariables); + std::vector headTerms; + rule.head.data.accept(HeadLiteralCollectTermsVisitor(), rule.head, headTerms); - if (!headVariables.empty()) + if (!headTerms.empty()) { std::cout << "exists "; - for (auto i = headVariables.cbegin(); i != headVariables.cend(); i++) + for (auto i = headTerms.cbegin(); i != headTerms.cend(); i++) { - if (i != headVariables.cbegin()) + if (i != headTerms.cbegin()) std::cout << ", "; - std::cout << *i; + std::cout << "AUX" << (i - headTerms.cbegin()); } std::cout << ": "; diff --git a/include/anthem/TermVisitor.h b/include/anthem/TermVisitor.h index 5ed7e18..b853a8d 100644 --- a/include/anthem/TermVisitor.h +++ b/include/anthem/TermVisitor.h @@ -63,53 +63,6 @@ struct TermVisitor } }; - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -struct TermCollectVariablesVisitor -{ - void visit(const Clingo::Symbol &, const Clingo::AST::Term &, std::vector &) - { - } - - void visit(const Clingo::AST::Variable &variable, const Clingo::AST::Term &, std::vector &variables) - { - variables.push_back(variable); - } - - void visit(const Clingo::AST::UnaryOperation &unaryOperation, const Clingo::AST::Term &, std::vector &variables) - { - unaryOperation.argument.data.accept(*this, unaryOperation.argument, variables); - } - - void visit(const Clingo::AST::BinaryOperation &binaryOperation, const Clingo::AST::Term &, std::vector &variables) - { - binaryOperation.left.data.accept(*this, binaryOperation.left, variables); - binaryOperation.right.data.accept(*this, binaryOperation.right, variables); - } - - void visit(const Clingo::AST::Interval &interval, const Clingo::AST::Term &, std::vector &variables) - { - interval.left.data.accept(*this, interval.left, variables); - interval.right.data.accept(*this, interval.right, variables); - } - - void visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, std::vector &variables) - { - if (function.external) - throwErrorAtLocation(term.location, "external functions currently not supported"); - - for (const auto &argument : function.arguments) - argument.data.accept(*this, argument, variables); - } - - void visit(const Clingo::AST::Pool &pool, const Clingo::AST::Term &, std::vector &variables) - { - for (const auto &argument : pool.arguments) - argument.data.accept(*this, argument, variables); - } -}; - //////////////////////////////////////////////////////////////////////////////////////////////////// }