Handling <none of those> values in ASP translator.
This commit is contained in:
parent
d118788142
commit
3ff20da97e
@ -27,6 +27,9 @@ MutexGroup MutexGroup::fromSAS(std::istream &istream, const Variables &variables
|
|||||||
for (size_t j = 0; j < numberOfFacts; j++)
|
for (size_t j = 0; j < numberOfFacts; j++)
|
||||||
{
|
{
|
||||||
mutexGroup.m_facts.emplace_back(Fact::fromSAS(istream, variables));
|
mutexGroup.m_facts.emplace_back(Fact::fromSAS(istream, variables));
|
||||||
|
|
||||||
|
if (mutexGroup.m_facts[j].value() == Value::None)
|
||||||
|
throw utils::ParserException("Mutex groups must not contain <none of those> values");
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::parseExpected<std::string>(istream, "end_mutex_group");
|
utils::parseExpected<std::string>(istream, "end_mutex_group");
|
||||||
|
@ -76,6 +76,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(values.cbegin(), values.cend(),
|
std::for_each(values.cbegin(), values.cend(),
|
||||||
[&](const auto &value)
|
[&](const auto &value)
|
||||||
{
|
{
|
||||||
|
if (value == Value::None)
|
||||||
|
return;
|
||||||
|
|
||||||
const auto match = std::find_if(fluents.cbegin(), fluents.cend(),
|
const auto match = std::find_if(fluents.cbegin(), fluents.cend(),
|
||||||
[&](const auto &fluent)
|
[&](const auto &fluent)
|
||||||
{
|
{
|
||||||
@ -97,7 +100,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
if (fact.value().sign() == Value::Sign::Negative)
|
if (fact.value() == Value::None || fact.value().sign() == Value::Sign::Negative)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ostream << "initialState(";
|
ostream << "initialState(";
|
||||||
@ -113,6 +116,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
|
if (fact.value() == Value::None)
|
||||||
|
return;
|
||||||
|
|
||||||
ostream << "goal(";
|
ostream << "goal(";
|
||||||
fact.value().printAsASPPredicateBody(ostream);
|
fact.value().printAsASPPredicateBody(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
@ -144,6 +150,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||||
[&](const auto &precondition)
|
[&](const auto &precondition)
|
||||||
{
|
{
|
||||||
|
if (precondition.value() == Value::None)
|
||||||
|
return;
|
||||||
|
|
||||||
ostream << "precondition(";
|
ostream << "precondition(";
|
||||||
operator_.predicate().printAsASP(ostream);
|
operator_.predicate().printAsASP(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
@ -156,6 +165,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(effects.cbegin(), effects.cend(),
|
std::for_each(effects.cbegin(), effects.cend(),
|
||||||
[&](const auto &effect)
|
[&](const auto &effect)
|
||||||
{
|
{
|
||||||
|
if (effect.postcondition().value() == Value::None)
|
||||||
|
return;
|
||||||
|
|
||||||
ostream << "postcondition(";
|
ostream << "postcondition(";
|
||||||
operator_.predicate().printAsASP(ostream);
|
operator_.predicate().printAsASP(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
@ -175,22 +187,37 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
{
|
{
|
||||||
const auto &values = variable.values();
|
const auto &values = variable.values();
|
||||||
|
|
||||||
|
BOOST_ASSERT(!values.empty());
|
||||||
|
|
||||||
// Skip trivial constraints of the form :- x, not x.
|
// Skip trivial constraints of the form :- x, not x.
|
||||||
if (values.size() == 2 && values[0].name() == values[1].name())
|
if (values.size() == 2 && values[0].name() == values[1].name())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto i = values.cbegin(); i != values.cend(); i++)
|
for (auto i = values.cbegin(); i != values.cend(); i++)
|
||||||
|
{
|
||||||
|
const auto &value1 = *i;
|
||||||
|
|
||||||
|
if (value1 == Value::None)
|
||||||
|
continue;
|
||||||
|
|
||||||
for (auto j = i + 1; j != values.cend(); j++)
|
for (auto j = i + 1; j != values.cend(); j++)
|
||||||
{
|
{
|
||||||
const auto &value1 = *i;
|
|
||||||
const auto &value2 = *j;
|
const auto &value2 = *j;
|
||||||
|
|
||||||
|
if (value2 == Value::None)
|
||||||
|
continue;
|
||||||
|
|
||||||
ostream << "mutex(";
|
ostream << "mutex(";
|
||||||
value1.printAsASPPredicateBody(ostream);
|
value1.printAsASPPredicateBody(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
value2.printAsASPPredicateBody(ostream);
|
value2.printAsASPPredicateBody(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No further constraint with <none of those> values (the variable need not be assigned at all)
|
||||||
|
if (values.back() == Value::None)
|
||||||
|
return;
|
||||||
|
|
||||||
ostream << ":- ";
|
ostream << ":- ";
|
||||||
|
|
||||||
|
@ -35,8 +35,14 @@ Variable Variable::fromSAS(std::istream &istream)
|
|||||||
variable.m_values.reserve(numberOfValues);
|
variable.m_values.reserve(numberOfValues);
|
||||||
|
|
||||||
for (size_t j = 0; j < numberOfValues; j++)
|
for (size_t j = 0; j < numberOfValues; j++)
|
||||||
|
{
|
||||||
variable.m_values.emplace_back(Value::fromSAS(istream));
|
variable.m_values.emplace_back(Value::fromSAS(istream));
|
||||||
|
|
||||||
|
// <none of those> values are only allowed at the end
|
||||||
|
if (j < numberOfValues - 1 && variable.m_values[j] == Value::None)
|
||||||
|
throw utils::ParserException("<none of those> value must be the last value of a variable");
|
||||||
|
}
|
||||||
|
|
||||||
utils::parseExpected<std::string>(istream, "end_variable");
|
utils::parseExpected<std::string>(istream, "end_variable");
|
||||||
|
|
||||||
return variable;
|
return variable;
|
||||||
|
Reference in New Issue
Block a user