patrick
/
plasp
Archived
1
0
Fork 0
This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/src/plasp/sas/Operator.cpp

89 lines
2.3 KiB
C++
Raw Normal View History

2016-05-22 14:35:53 +02:00
#include <plasp/sas/Operator.h>
#include <iostream>
#include <limits>
#include <colorlog/Formatting.h>
2016-05-22 14:35:53 +02:00
#include <plasp/sas/VariableTransition.h>
namespace plasp
{
namespace sas
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Operator
//
////////////////////////////////////////////////////////////////////////////////////////////////////
2017-05-12 14:17:57 +02:00
Operator Operator::fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables)
2016-05-22 14:35:53 +02:00
{
Operator operator_;
2017-05-12 14:17:57 +02:00
tokenizer.expect<std::string>("begin_operator");
2016-05-22 14:35:53 +02:00
2017-05-12 14:17:57 +02:00
operator_.m_predicate = Predicate::fromSAS(tokenizer);
2016-05-22 14:35:53 +02:00
2017-05-12 14:17:57 +02:00
const auto numberOfPrevailConditions = tokenizer.get<size_t>();
2016-05-22 14:35:53 +02:00
operator_.m_preconditions.reserve(numberOfPrevailConditions);
for (size_t j = 0; j < numberOfPrevailConditions; j++)
2017-05-12 14:17:57 +02:00
operator_.m_preconditions.emplace_back(Condition::fromSAS(tokenizer, variables));
2016-05-22 14:35:53 +02:00
2017-05-12 14:17:57 +02:00
const auto numberOfEffects = tokenizer.get<size_t>();
2016-05-22 14:35:53 +02:00
operator_.m_effects.reserve(numberOfEffects);
for (size_t j = 0; j < numberOfEffects; j++)
2017-05-12 14:17:57 +02:00
operator_.m_effects.emplace_back(Effect::fromSAS(tokenizer, variables, operator_.m_preconditions));
2016-05-22 14:35:53 +02:00
2017-05-12 14:17:57 +02:00
operator_.m_costs = tokenizer.get<size_t>();
2016-05-22 14:35:53 +02:00
2017-05-12 14:17:57 +02:00
tokenizer.expect<std::string>("end_operator");
2016-05-22 14:35:53 +02:00
return operator_;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Operator::printPredicateAsASP(colorlog::ColorStream &stream) const
{
stream << colorlog::Keyword("action") << "(";
m_predicate.printAsASP(stream);
stream << ")";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-05-22 14:35:53 +02:00
const Predicate &Operator::predicate() const
{
return m_predicate;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const Operator::Conditions &Operator::preconditions() const
{
return m_preconditions;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const Effects &Operator::effects() const
{
return m_effects;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
size_t Operator::costs() const
{
return m_costs;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}