22#include "domain_action.h"
41 const std::vector<std::string> ¶ms,
42 const std::vector<Predicate> & preconds,
43 const std::vector<Predicate> & effects,
45 const std::vector<std::string> &cond_breakups,
46 const std::vector<std::string> &temp_breakups)
52 cond_breakups_(cond_breakups),
53 temp_breakups_(temp_breakups)
66 strm <<
"DomainAction: " << a.name_ << std::endl;
68 for (
auto ¶m : a.params_) {
71 strm << std::endl <<
"\tPreconditions:" << std::endl;
72 for (
auto &pred : a.preconds_) {
73 strm <<
"\t\t" << pred;
75 strm << std::endl <<
"\tEffects:" << std::endl;
76 for (
auto &eff : a.effects_) {
77 strm <<
"\t\t" << eff;
79 strm << std::endl <<
"\tDuration: " << std::to_string(a.duration_) << std::endl;
80 strm <<
"\tConditional Breakups:";
81 for (
auto &breakup : a.cond_breakups_) {
82 strm <<
" " << breakup;
84 strm << std::endl <<
"\tTemporal Breakups:";
85 for (
auto &breakup : a.temp_breakups_) {
86 strm <<
" " << breakup;
103const std::vector<std::string>
117 std::cout <<
"Generating StnAction " << name <<
" with params " <<
params << std::endl;
119 std::vector<Predicate> preconds;
120 std::vector<Predicate> effects;
122 std::istringstream iss(
params);
123 std::vector<std::string> params_vec{std::istream_iterator<std::string>{iss},
124 std::istream_iterator<std::string>{}};
125 std::map<std::string, std::string> params_map;
126 if (params_vec.size() != params_.size()) {
127 std::cout <<
"Param counts differ for DomainAction (" << std::to_string(params_.size()) <<
") "
128 << name_ <<
" and StnAction (" <<
params <<
") " << name << std::endl;
130 for (
size_t i = 0; i < params_vec.size(); i++) {
132 params_map.insert(std::pair<std::string, std::string>(
"?" + params_.at(i), params_vec.at(i)));
133 std::cout <<
"Inserting "
134 <<
"?" + params_.at(i) <<
" with " << params_vec.at(i) << std::endl;
136 std::cout <<
"Applying precods" << std::endl;
138 std::vector<std::string> precond_attr;
139 for (std::string attr : pred.attrs()) {
142 if (attr[0] ==
'?') {
143 if (params_map.find(attr) == params_map.end()) {
144 std::cout <<
"err, could not find attribute for precondition: " << attr << std::endl;
146 opt = params_map.find(attr)->second;
150 precond_attr.push_back(opt);
152 preconds.push_back(
Predicate(pred.name(), pred.condition(), precond_attr));
154 std::cout <<
"Applying effects" << std::endl;
156 std::vector<std::string> effect_attr;
157 for (
auto attr : pred.attrs()) {
160 if (attr.find(
"?") == 0) {
161 if (params_map.find(attr) == params_map.end()) {
162 std::cout <<
"err, could not find attribute for effect: " << attr << std::endl;
164 opt = params_map.find(attr)->second;
168 effect_attr.push_back(opt);
170 effects.push_back(
Predicate(pred.name(), pred.condition(), effect_attr));
172 std::cout <<
"StnAction built" << std::endl;
174 return StnAction(name_, preconds, effects,
params, duration_, cond_breakups_, temp_breakups_);
A representation of an action used by the STN generator.
const std::vector< std::string > params()
Get the list of parameters of the action.
StnAction generateStnAction(const std::string &name, const std::string ¶ms)
Generate an StnAction from the DomainAction.
DomainAction(const std::string &name, const std::vector< std::string > ¶ms, const std::vector< Predicate > &preconds, const std::vector< Predicate > &effects, int duration=0, const std::vector< std::string > &cond_breakups={}, const std::vector< std::string > &temp_breakups={})
Constructor.
const std::string getName()
Get the name of the action.
A representation of a Predicate in the STN.
An action representation within an STN.
Fawkes library namespace.