patrick
/
plasp
Archived
1
0
Fork 0

Handling <none of those> values in ASP translator.

This commit is contained in:
Patrick Lühne 2016-05-23 01:53:42 +02:00
parent d118788142
commit 3ff20da97e
3 changed files with 38 additions and 2 deletions

View File

@ -27,6 +27,9 @@ MutexGroup MutexGroup::fromSAS(std::istream &istream, const Variables &variables
for (size_t j = 0; j < numberOfFacts; j++)
{
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");

View File

@ -76,6 +76,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(values.cbegin(), values.cend(),
[&](const auto &value)
{
if (value == Value::None)
return;
const auto match = std::find_if(fluents.cbegin(), fluents.cend(),
[&](const auto &fluent)
{
@ -97,7 +100,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
[&](const auto &fact)
{
if (fact.value().sign() == Value::Sign::Negative)
if (fact.value() == Value::None || fact.value().sign() == Value::Sign::Negative)
return;
ostream << "initialState(";
@ -113,6 +116,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
[&](const auto &fact)
{
if (fact.value() == Value::None)
return;
ostream << "goal(";
fact.value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl;
@ -144,6 +150,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(preconditions.cbegin(), preconditions.cend(),
[&](const auto &precondition)
{
if (precondition.value() == Value::None)
return;
ostream << "precondition(";
operator_.predicate().printAsASP(ostream);
ostream << ", ";
@ -156,6 +165,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(effects.cbegin(), effects.cend(),
[&](const auto &effect)
{
if (effect.postcondition().value() == Value::None)
return;
ostream << "postcondition(";
operator_.predicate().printAsASP(ostream);
ostream << ", ";
@ -175,22 +187,37 @@ void TranslatorASP::translate(std::ostream &ostream) const
{
const auto &values = variable.values();
BOOST_ASSERT(!values.empty());
// Skip trivial constraints of the form :- x, not x.
if (values.size() == 2 && values[0].name() == values[1].name())
return;
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++)
{
const auto &value1 = *i;
const auto &value2 = *j;
if (value2 == Value::None)
continue;
ostream << "mutex(";
value1.printAsASPPredicateBody(ostream);
ostream << ", ";
value2.printAsASPPredicateBody(ostream);
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 << ":- ";

View File

@ -35,8 +35,14 @@ Variable Variable::fromSAS(std::istream &istream)
variable.m_values.reserve(numberOfValues);
for (size_t j = 0; j < numberOfValues; j++)
{
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");
return variable;