Made output of Boolean variables consistent with clingo’s input language.
This commit is contained in:
parent
920f3ab210
commit
870be1680e
@ -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
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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<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);
|
||||
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<Clingo::AST::Variable> &)
|
||||
void visit(const Clingo::AST::CSPLiteral &, const Clingo::AST::Literal &literal, std::vector<Clingo::AST::Term> &)
|
||||
{
|
||||
throwErrorUnsupportedLiteral("CSP literal", literal);
|
||||
}
|
||||
|
@ -37,19 +37,19 @@ struct StatementVisitor
|
||||
|
||||
void visit(const Clingo::AST::Rule &rule, const Clingo::AST::Statement &)
|
||||
{
|
||||
std::vector<Clingo::AST::Variable> headVariables;
|
||||
rule.head.data.accept(HeadLiteralCollectVariablesVisitor(), rule.head, headVariables);
|
||||
std::vector<Clingo::AST::Term> 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 << ": ";
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user