X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=blobdiff_plain;f=node.h;h=4b8708db18c1da03d3fde8e18b314de5ea49876c;hp=cfa02223854a9d66dfad039fc2fcd0deb57e2a76;hb=HEAD;hpb=3dadaa088d9fff7ca05cbb297f3d7e88179faccb diff --git a/node.h b/node.h index cfa0222..4b8708d 100644 --- a/node.h +++ b/node.h @@ -5,35 +5,106 @@ #include #include "action.h" +/** + * A node in the plan graph, corresponds to a single action. + */ class Node { public: - Node(const Action& action); + /** + * Creates a node for the given action. + */ + Node(const Action* action); + + /** + * Creates an empty, non-functional, node. + */ Node(); + + /** + * Creates a copy of the given node. + */ Node(const Node& node); virtual ~Node(){} + + /** + * Add a child node, which will be executed after this node. + */ void addChild(Node* node); - const Action& action() const; - void execute(const literals& effects); + + /** + * Returns the action this node corresponds to. + */ + const Action* action() const; + + /** + * Execute this node, and hence the corresponding action. + * Sets the effects achieved. + * + * If _executed is true or _preconditions.size() > 0 this method will + * just return. + */ + void execute(); + + /** + * Checks if this node has been executed or not. + */ bool executed() const; - const literals& effects() const; + + /** + * Returns the effects that was achieved from execution. + */ + const Literals& effects() const; + + /** + * Satisfy a single condition. + */ + bool satisfyCondition(std::string effect); + + /** + * Satisfies a list of conditions. + */ + bool satisfyConditions(const Literals& effects); + + /** + * Returns all the children to this node. + */ + const std::vector& children() const; + + /** + * Returns the unsatisfied preconditions. + */ + const Preconditions& preconditions() const; protected: - Action _action; + //! The action this node corresponds to. + const Action* _action; + //! The list of children to this node. std::vector _children; - literals _preconditions; + //! The, so far, unsatisfied preconditions. + Preconditions _preconditions; + //! Will be true if this node has been executed. bool _executed; - literals _effects; + //! The effects which were achieved by the execution. + Literals _effects; }; -class StartNode : Node { +/** + * Class which is used as the start node in the plan graph. + */ +class StartNode :public Node { public: - StartNode(const literals& init); + StartNode(const Literals& init); + ~StartNode(){delete _action;} }; -class EndNode : Node { +/** + * Class which is used as the end node in the plan graph. + */ +class EndNode :public Node { public: - EndNode(const literals& goal); + EndNode(const Literals& goal); + ~EndNode(){delete _action;} }; #endif