22 #include "stn_action.h"
31 size_t StnAction::count = 0;
44 StnAction::StnAction(
const std::string & name,
45 const std::vector<Predicate> & preconds,
46 const std::vector<Predicate> & effects,
47 const std::string & opts,
49 const std::vector<std::string> &cond_breakups,
50 const std::vector<std::string> &temp_breakups)
56 cond_breakups_(cond_breakups),
57 temp_breakups_(temp_breakups)
67 operator<<(std::ostream &strm,
const StnAction &a)
69 strm <<
"id: " << a.id_ << std::endl <<
"action: " << a.name_ <<
"\npreconditions:" << std::endl;
73 strm <<
"effects:" << std::endl;
74 for (Predicate e : a.effects_) {
77 strm <<
"required actions: ";
78 for (
auto const &kv : a.cond_actions_) {
79 strm << kv.first <<
":" << kv.second.first;
80 for (
auto const &p : kv.second.second) {
84 strm <<
"duration: " << std::to_string(a.duration_) << std::endl;
85 if (!a.cond_breakups_.empty()) {
86 strm <<
"conditional breakup conditions: ";
88 for (
auto const &p : a.cond_breakups_) {
91 if (!a.temp_breakups_.empty()) {
92 strm <<
"temporal breakup conditions: ";
94 for (
auto const &p : a.temp_breakups_) {
97 strm << std::endl << std::endl;
137 std::vector<size_t> ids;
138 for (
auto const &kv : cond_actions_) {
139 ids.push_back(kv.first);
152 const std::vector<std::string> *breakups;
153 if (t == EdgeType::CONDITIONAL) {
154 breakups = &cond_breakups_;
155 }
else if (t == EdgeType::TEMPORAL) {
156 breakups = &temp_breakups_;
158 throw "Wrong Edge type";
161 if (std::find(breakups->begin(), breakups->end(), p.
name()) != breakups->end()) {
162 std::cout <<
"Break because of: " << p <<
" ";
164 case EdgeType::CONDITIONAL: std::cout <<
"Conditional" << std::endl;
break;
165 case EdgeType::TEMPORAL: std::cout <<
"Temporal" << std::endl;
break;
178 return "Action ID: " + std::to_string(id_) +
"\n" +
"Name: " + name_ +
"\n" +
"Params: " + opts_;
188 std::string edge_label;
189 std::map<size_t, std::pair<std::string, std::vector<Predicate>>>::const_iterator it =
190 cond_actions_.find(cond_action);
191 if (it == cond_actions_.end())
195 edge_label +=
"<FONT COLOR=\"darkgreen\">";
197 edge_label +=
"<FONT COLOR=\"red\">";
199 edge_label += p.
name() +
": ";
200 for (
const std::string s : p.
attrs()) {
201 edge_label += s +
" ";
203 edge_label +=
"</FONT>";
214 std::string edge_label =
"<FONT COLOR=\"blue\">";
215 edge_label += std::to_string(duration_);
216 edge_label +=
"</FONT>";
226 std::vector<Predicate> check_preds = preconds_;
228 for (
int i = candidate_actions.size() - 1; i >= 0; i--) {
230 for (
Predicate candidate_pred : candidate_actions.at(i).effects_) {
231 for (
auto pred_it = check_preds.begin(); pred_it != check_preds.end();) {
232 if (!
checkForBreakup(EdgeType::CONDITIONAL, (*pred_it)) && (*pred_it) == candidate_pred) {
233 std::map<size_t, std::pair<std::string, std::vector<Predicate>>>::iterator it =
234 cond_actions_.find(candidate_actions.at(i).id_);
235 if (it == cond_actions_.end()) {
236 cond_actions_.insert(
237 std::map<
size_t, std::pair<std::string, std::vector<Predicate>>>::value_type(
238 candidate_actions.at(i).id_,
239 std::make_pair(candidate_actions.at(i).name_,
240 std::vector<Predicate>{(*pred_it)})));
242 it->second.second.push_back((*pred_it));
246 pred_it = check_preds.erase(pred_it);
252 }
catch (std::exception &e) {
253 std::cout <<
"ERROR in stn_action: " << e.what() << std::endl;
267 const std::vector<Predicate> &