Implemented parsing the operator predicates.
This commit is contained in:
parent
0e4233cc65
commit
6e36fc128e
@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/sas/Effect.h>
|
||||
#include <plasp/sas/Predicate.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
@ -24,7 +25,7 @@ struct Operator
|
||||
using Conditions = std::vector<Condition>;
|
||||
using Effects = std::vector<Effect>;
|
||||
|
||||
std::string name;
|
||||
Predicate predicate;
|
||||
Conditions preconditions;
|
||||
Effects effects;
|
||||
size_t costs;
|
||||
|
34
include/plasp/sas/Predicate.h
Normal file
34
include/plasp/sas/Predicate.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef __SAS__PREDICATE_H
|
||||
#define __SAS__PREDICATE_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Predicate
|
||||
{
|
||||
std::string name;
|
||||
std::vector<std::string> arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::ostream &operator <<(std::ostream &ostream, const Predicate &predicate);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
@ -29,7 +30,7 @@ Description Description::fromStream(std::istream &istream)
|
||||
{
|
||||
Description description;
|
||||
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
std::setlocale(LC_NUMERIC, "C");
|
||||
|
||||
istream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
|
||||
@ -170,7 +171,7 @@ void Description::print(std::ostream &ostream) const
|
||||
std::for_each(m_operators.cbegin(), m_operators.cend(),
|
||||
[&](const auto &operator_)
|
||||
{
|
||||
ostream << "\t" << operator_.name << ":" << std::endl;
|
||||
ostream << "\t" << operator_.predicate << ":" << std::endl;
|
||||
ostream << "\t\tpreconditions: " << operator_.preconditions.size() << std::endl;
|
||||
|
||||
std::for_each(operator_.preconditions.cbegin(), operator_.preconditions.cend(),
|
||||
@ -445,10 +446,30 @@ void Description::parseOperatorSection(std::istream &istream)
|
||||
{
|
||||
parseSectionIdentifier(istream, "begin_operator");
|
||||
|
||||
istream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
|
||||
auto &operator_ = m_operators[i];
|
||||
std::getline(istream, operator_.name);
|
||||
|
||||
try
|
||||
{
|
||||
istream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
|
||||
// TODO: Inefficient, reimplement in one pass
|
||||
std::string line;
|
||||
std::getline(istream, line);
|
||||
|
||||
std::stringstream lineStream(line);
|
||||
|
||||
operator_.predicate.name = parse<std::string>(lineStream);
|
||||
|
||||
while (lineStream.peek() == ' ')
|
||||
lineStream.ignore(1);
|
||||
|
||||
for (std::string argument; std::getline(lineStream, argument, ' ');)
|
||||
operator_.predicate.arguments.push_back(std::move(argument));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
throw ParserException("Could not parse operator predicate");
|
||||
}
|
||||
|
||||
const auto numberOfPrevailConditions = parse<size_t>(istream);
|
||||
operator_.preconditions.reserve(numberOfPrevailConditions);
|
||||
|
34
src/plasp/sas/Predicate.cpp
Normal file
34
src/plasp/sas/Predicate.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <plasp/sas/Predicate.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::ostream &operator <<(std::ostream &ostream, const Predicate &predicate)
|
||||
{
|
||||
ostream << predicate.name << "(";
|
||||
|
||||
for (size_t i = 0; i < predicate.arguments.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
ostream << ", ";
|
||||
|
||||
ostream << predicate.arguments[i];
|
||||
}
|
||||
|
||||
return (ostream << ")");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user