Made output of Boolean variables consistent with clingo’s input language.

This commit is contained in:
Patrick Lühne 2016-11-22 18:12:02 +01:00
parent 920f3ab210
commit 870be1680e
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
4 changed files with 24 additions and 70 deletions

View File

@ -58,30 +58,30 @@ struct HeadLiteralVisitor
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
struct HeadLiteralCollectVariablesVisitor struct HeadLiteralCollectTermsVisitor
{ {
void visit(const Clingo::AST::Literal &literal, const Clingo::AST::HeadLiteral &, std::vector<Clingo::AST::Variable> &variables) void visit(const Clingo::AST::Literal &literal, const Clingo::AST::HeadLiteral &, std::vector<Clingo::AST::Term> &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<Clingo::AST::Variable> &) void visit(const Clingo::AST::Disjunction &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Term> &)
{ {
// TODO: implement // TODO: implement
throwErrorUnsupportedHeadLiteral("disjunction", headLiteral); throwErrorUnsupportedHeadLiteral("disjunction", headLiteral);
} }
void visit(const Clingo::AST::Aggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Variable> &) void visit(const Clingo::AST::Aggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Term> &)
{ {
throwErrorUnsupportedHeadLiteral("aggregate", headLiteral); throwErrorUnsupportedHeadLiteral("aggregate", headLiteral);
} }
void visit(const Clingo::AST::HeadAggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Variable> &) void visit(const Clingo::AST::HeadAggregate &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Term> &)
{ {
throwErrorUnsupportedHeadLiteral("head aggregate", headLiteral); throwErrorUnsupportedHeadLiteral("head aggregate", headLiteral);
} }
void visit(const Clingo::AST::TheoryAtom &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Variable> &) void visit(const Clingo::AST::TheoryAtom &, const Clingo::AST::HeadLiteral &headLiteral, std::vector<Clingo::AST::Term> &)
{ {
throwErrorUnsupportedHeadLiteral("theory", headLiteral); throwErrorUnsupportedHeadLiteral("theory", headLiteral);
} }

View File

@ -29,9 +29,9 @@ struct LiteralVisitor
void visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &) void visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &)
{ {
if (boolean.value == true) if (boolean.value == true)
std::cout << "true"; std::cout << "#true";
else else
std::cout << "false"; std::cout << "#false";
} }
void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &) 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<Clingo::AST::Variable> &) void visit(const Clingo::AST::Boolean &, const Clingo::AST::Literal &, std::vector<Clingo::AST::Term> &)
{ {
} }
void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, std::vector<Clingo::AST::Variable> &variables) void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, std::vector<Clingo::AST::Term> &terms)
{ {
term.data.accept(TermCollectVariablesVisitor(), term, variables); terms.push_back(term);
} }
void visit(const Clingo::AST::Comparison &comparison, const Clingo::AST::Literal &, std::vector<Clingo::AST::Variable> &variables) void visit(const Clingo::AST::Comparison &comparison, const Clingo::AST::Literal &, std::vector<Clingo::AST::Term> &terms)
{ {
comparison.left.data.accept(TermCollectVariablesVisitor(), comparison.left, variables); terms.reserve(terms.size() + 2);
comparison.right.data.accept(TermCollectVariablesVisitor(), comparison.right, variables); terms.push_back(comparison.left);
terms.push_back(comparison.right);
} }
void visit(const Clingo::AST::CSPLiteral &, const Clingo::AST::Literal &literal, std::vector<Clingo::AST::Variable> &) void visit(const Clingo::AST::CSPLiteral &, const Clingo::AST::Literal &literal, std::vector<Clingo::AST::Term> &)
{ {
throwErrorUnsupportedLiteral("CSP literal", literal); throwErrorUnsupportedLiteral("CSP literal", literal);
} }

View File

@ -37,19 +37,19 @@ struct StatementVisitor
void visit(const Clingo::AST::Rule &rule, const Clingo::AST::Statement &) void visit(const Clingo::AST::Rule &rule, const Clingo::AST::Statement &)
{ {
std::vector<Clingo::AST::Variable> headVariables; std::vector<Clingo::AST::Term> headTerms;
rule.head.data.accept(HeadLiteralCollectVariablesVisitor(), rule.head, headVariables); rule.head.data.accept(HeadLiteralCollectTermsVisitor(), rule.head, headTerms);
if (!headVariables.empty()) if (!headTerms.empty())
{ {
std::cout << "exists "; 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 << ", ";
std::cout << *i; std::cout << "AUX" << (i - headTerms.cbegin());
} }
std::cout << ": "; std::cout << ": ";

View File

@ -63,53 +63,6 @@ struct TermVisitor
} }
}; };
////////////////////////////////////////////////////////////////////////////////////////////////////
struct TermCollectVariablesVisitor
{
void visit(const Clingo::Symbol &, const Clingo::AST::Term &, std::vector<Clingo::AST::Variable> &)
{
}
void visit(const Clingo::AST::Variable &variable, const Clingo::AST::Term &, std::vector<Clingo::AST::Variable> &variables)
{
variables.push_back(variable);
}
void visit(const Clingo::AST::UnaryOperation &unaryOperation, const Clingo::AST::Term &, std::vector<Clingo::AST::Variable> &variables)
{
unaryOperation.argument.data.accept(*this, unaryOperation.argument, variables);
}
void visit(const Clingo::AST::BinaryOperation &binaryOperation, const Clingo::AST::Term &, std::vector<Clingo::AST::Variable> &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<Clingo::AST::Variable> &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<Clingo::AST::Variable> &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<Clingo::AST::Variable> &variables)
{
for (const auto &argument : pool.arguments)
argument.data.accept(*this, argument, variables);
}
};
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
} }