Made InitialState a proper class.
This commit is contained in:
parent
c7c7a93eba
commit
beef3aca60
@ -3,6 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
|
@ -2,14 +2,16 @@
|
||||
#define __SAS__DESCRIPTION_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <plasp/sas/AxiomRule.h>
|
||||
#include <plasp/sas/InitialState.h>
|
||||
#include <plasp/sas/MutexGroup.h>
|
||||
#include <plasp/sas/Operator.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/sas/AxiomRule.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -32,7 +34,7 @@ class Description
|
||||
bool usesActionCosts() const;
|
||||
const std::vector<Variable> &variables() const;
|
||||
const std::vector<MutexGroup> &mutexGroups() const;
|
||||
const std::vector<AssignedVariable> &initialStateFacts() const;
|
||||
const InitialState &initialState() const;
|
||||
const std::vector<AssignedVariable> &goalFacts() const;
|
||||
const std::vector<Operator> &operators() const;
|
||||
const std::vector<AxiomRule> &axiomRules() const;
|
||||
@ -55,7 +57,7 @@ class Description
|
||||
|
||||
std::vector<Variable> m_variables;
|
||||
std::vector<MutexGroup> m_mutexGroups;
|
||||
std::vector<AssignedVariable> m_initialStateFacts;
|
||||
std::unique_ptr<InitialState> m_initialState;
|
||||
std::vector<AssignedVariable> m_goalFacts;
|
||||
std::vector<Operator> m_operators;
|
||||
std::vector<AxiomRule> m_axiomRules;
|
||||
|
39
include/plasp/sas/InitialState.h
Normal file
39
include/plasp/sas/InitialState.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __SAS__INITIAL_STATE_H
|
||||
#define __SAS__INITIAL_STATE_H
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// InitialState
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class InitialState
|
||||
{
|
||||
public:
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = std::vector<Fact>;
|
||||
|
||||
static InitialState fromSAS(std::istream &istream, const std::vector<Variable> &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
||||
private:
|
||||
InitialState() = default;
|
||||
|
||||
Facts m_facts;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -83,9 +83,9 @@ const std::vector<MutexGroup> &Description::mutexGroups() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::vector<AssignedVariable> &Description::initialStateFacts() const
|
||||
const InitialState &Description::initialState() const
|
||||
{
|
||||
return m_initialStateFacts;
|
||||
return *m_initialState;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -158,7 +158,7 @@ void Description::print(std::ostream &ostream) const
|
||||
// Initial state section
|
||||
ostream << "initial state:" << std::endl;
|
||||
|
||||
std::for_each(m_initialStateFacts.cbegin(), m_initialStateFacts.cend(),
|
||||
std::for_each(m_initialState->facts().cbegin(), m_initialState->facts().cend(),
|
||||
[&](const auto &initialStateFact)
|
||||
{
|
||||
ostream << "\t" << initialStateFact.variable().name() << " = ";
|
||||
@ -295,14 +295,7 @@ void Description::parseMutexSection(std::istream &istream)
|
||||
|
||||
void Description::parseInitialStateSection(std::istream &istream)
|
||||
{
|
||||
utils::parseExpected<std::string>(istream, "begin_state");
|
||||
|
||||
m_initialStateFacts.reserve(m_variables.size());
|
||||
|
||||
for (size_t i = 0; i < m_variables.size(); i++)
|
||||
m_initialStateFacts.emplace_back(AssignedVariable::fromSAS(istream, m_variables[i]));
|
||||
|
||||
utils::parseExpected<std::string>(istream, "end_state");
|
||||
m_initialState = std::make_unique<InitialState>(InitialState::fromSAS(istream, m_variables));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
44
src/plasp/sas/InitialState.cpp
Normal file
44
src/plasp/sas/InitialState.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <plasp/sas/InitialState.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/utils/Parsing.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// InitialState
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
InitialState InitialState::fromSAS(std::istream &istream, const std::vector<Variable> &variables)
|
||||
{
|
||||
InitialState initialState;
|
||||
|
||||
utils::parseExpected<std::string>(istream, "begin_state");
|
||||
|
||||
initialState.m_facts.reserve(variables.size());
|
||||
|
||||
for (size_t i = 0; i < variables.size(); i++)
|
||||
initialState.m_facts.emplace_back(AssignedVariable::fromSAS(istream, variables[i]));
|
||||
|
||||
utils::parseExpected<std::string>(istream, "end_state");
|
||||
|
||||
return initialState;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const InitialState::Facts &InitialState::facts() const
|
||||
{
|
||||
return m_facts;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
@ -92,7 +92,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
ostream << std::endl;
|
||||
ostream << "% initial state" << std::endl;
|
||||
|
||||
const auto &initialStateFacts = m_description.initialStateFacts();
|
||||
const auto &initialStateFacts = m_description.initialState().facts();
|
||||
|
||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||
[&](const auto &initialStateFact)
|
||||
|
@ -58,9 +58,9 @@ TEST_F(SASParserTests, ParseValidSASFile)
|
||||
ASSERT_EQ(description.mutexGroups()[7].facts().size(), 2);
|
||||
ASSERT_EQ(&description.mutexGroups()[7].facts()[1].value(), &description.variables()[34].values()[1]);
|
||||
|
||||
ASSERT_EQ(description.initialStateFacts().size(), 37);
|
||||
ASSERT_EQ(&description.initialStateFacts()[0].value(), &description.variables()[0].values()[8]);
|
||||
ASSERT_EQ(&description.initialStateFacts()[36].value(), &description.variables()[36].values()[1]);
|
||||
ASSERT_EQ(description.initialState().facts().size(), 37);
|
||||
ASSERT_EQ(&description.initialState().facts()[0].value(), &description.variables()[0].values()[8]);
|
||||
ASSERT_EQ(&description.initialState().facts()[36].value(), &description.variables()[36].values()[1]);
|
||||
|
||||
ASSERT_EQ(description.goalFacts().size(), 2);
|
||||
ASSERT_EQ(&description.goalFacts()[0].value(), &description.variables()[6].values()[0]);
|
||||
|
Reference in New Issue
Block a user