Started implementing PDDL normalization.
This commit is contained in:
@@ -30,7 +30,7 @@ class Action
|
||||
const Expression *precondition() const;
|
||||
const Expression *effect() const;
|
||||
|
||||
void normalizeParameterNames();
|
||||
void normalize();
|
||||
|
||||
private:
|
||||
Action() = default;
|
||||
|
@@ -58,6 +58,11 @@ class Context
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr static const char *auxiliaryPrefix()
|
||||
{
|
||||
return "__plasp_";
|
||||
}
|
||||
|
||||
Parser parser;
|
||||
utils::Logger logger;
|
||||
};
|
||||
|
@@ -67,8 +67,6 @@ class Domain
|
||||
|
||||
void parseActionSection();
|
||||
|
||||
void normalizeParameterNames();
|
||||
|
||||
Context &m_context;
|
||||
|
||||
std::string m_name;
|
||||
|
@@ -96,6 +96,13 @@ class Expression
|
||||
virtual ~Expression() = default;
|
||||
|
||||
virtual Type expressionType() const = 0;
|
||||
|
||||
// Normalizes the expression dependent on its type, recursing through all child expressions
|
||||
//
|
||||
// Result:
|
||||
// * a new expression pointer to replace this one if required; this object is then empty
|
||||
// * nullptr otherwise; the object may or may not have changed
|
||||
virtual ExpressionPointer normalize() = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -34,12 +34,13 @@ class At: public ExpressionCRTP<At>
|
||||
|
||||
size_t timePoint() const;
|
||||
|
||||
const Expression *argument() const;
|
||||
|
||||
private:
|
||||
void setArgument(const Expression *argument);
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
const Expression *argument() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
protected:
|
||||
size_t m_timePoint;
|
||||
|
||||
const Expression *m_argument;
|
||||
|
@@ -28,14 +28,15 @@ class Binary: public ExpressionCRTP<Derived>
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const std::array<const Expression *, 2> &arguments() const;
|
||||
|
||||
private:
|
||||
template<size_t i>
|
||||
void setArgument(const Expression *argument);
|
||||
template<size_t i>
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
const std::array<const Expression *, 2> &arguments() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
protected:
|
||||
std::array<const Expression *, 2> m_arguments;
|
||||
std::array<ExpressionPointer, 2> m_argumentStorage;
|
||||
};
|
||||
@@ -104,6 +105,28 @@ const std::array<const Expression *, 2> &Binary<Derived>::arguments() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer Binary<Derived>::normalize()
|
||||
{
|
||||
for (size_t i = 0; i < m_argumentStorage.size(); i++)
|
||||
{
|
||||
BOOST_ASSERT(m_argumentStorage[i]);
|
||||
|
||||
auto normalizedArgument = m_argumentStorage[i]->normalize();
|
||||
|
||||
// Replace argument if changed by normalization
|
||||
if (!normalizedArgument)
|
||||
continue;
|
||||
|
||||
m_argumentStorage[i] = std::move(normalizedArgument);
|
||||
m_arguments[i] = m_argumentStorage[i].get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,8 @@ class Constant: public ExpressionCRTP<Constant>
|
||||
const std::string &name() const;
|
||||
const PrimitiveType *type() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
private:
|
||||
static ConstantPointer parseDeclaration(Context &context);
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
|
||||
|
@@ -22,6 +22,9 @@ class Either: public NAry<Either>
|
||||
static const Expression::Type ExpressionType = Expression::Type::Either;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer normalize() override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -22,6 +22,9 @@ class Imply: public Binary<Imply>
|
||||
static const Expression::Type ExpressionType = Expression::Type::Imply;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer normalize() override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -28,12 +28,13 @@ class NAry: public ExpressionCRTP<Derived>
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const std::vector<const Expression *> &arguments() const;
|
||||
|
||||
private:
|
||||
void addArgument(const Expression *argument);
|
||||
void addArgument(ExpressionPointer &&argument);
|
||||
const std::vector<const Expression *> &arguments() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
protected:
|
||||
std::vector<const Expression *> m_arguments;
|
||||
Expressions m_argumentStorage;
|
||||
};
|
||||
@@ -110,6 +111,28 @@ const std::vector<const Expression *> &NAry<Derived>::arguments() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer NAry<Derived>::normalize()
|
||||
{
|
||||
for (size_t i = 0; i < m_argumentStorage.size(); i++)
|
||||
{
|
||||
BOOST_ASSERT(m_argumentStorage[i]);
|
||||
|
||||
auto normalizedArgument = m_argumentStorage[i]->normalize();
|
||||
|
||||
// Replace argument if changed by normalization
|
||||
if (!normalizedArgument)
|
||||
continue;
|
||||
|
||||
m_argumentStorage[i] = std::move(normalizedArgument);
|
||||
m_arguments[i] = m_argumentStorage[i].get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,12 +29,13 @@ class Not: public ExpressionCRTP<Not>
|
||||
public:
|
||||
Not();
|
||||
|
||||
const Expression *argument() const;
|
||||
|
||||
private:
|
||||
void setArgument(const Expression *argument);
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
const Expression *argument() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
protected:
|
||||
const Expression *m_argument;
|
||||
ExpressionPointer m_argumentStorage;
|
||||
};
|
||||
|
@@ -30,6 +30,8 @@ class Predicate: public ExpressionCRTP<Predicate>
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
private:
|
||||
Predicate();
|
||||
|
||||
|
@@ -29,7 +29,7 @@ class PredicateDeclaration: public ExpressionCRTP<PredicateDeclaration>
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
void normalizeParameterNames();
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
private:
|
||||
PredicateDeclaration();
|
||||
|
@@ -35,6 +35,8 @@ class PrimitiveType: public ExpressionCRTP<PrimitiveType>
|
||||
const std::string &name() const;
|
||||
const std::vector<const PrimitiveType *> &parentTypes() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
private:
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
@@ -27,6 +27,8 @@ class Unsupported: public ExpressionCRTP<Unsupported>
|
||||
public:
|
||||
const std::string &type() const;
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
private:
|
||||
std::string m_type;
|
||||
};
|
||||
|
@@ -38,6 +38,8 @@ class Variable: public ExpressionCRTP<Variable>
|
||||
|
||||
void setType(const Expression *type);
|
||||
|
||||
ExpressionPointer normalize() override;
|
||||
|
||||
private:
|
||||
static void parseDeclaration(Context &context, Variables ¶meters);
|
||||
|
||||
|
Reference in New Issue
Block a user