domain_transition_graph_func.cpp
Go to the documentation of this file.
00001 #include "domain_transition_graph_func.h"
00002 #include "operator.h"
00003 #include "axiom.h"
00004 #include "variable.h"
00005 #include "scc.h"
00006 
00007 #include <algorithm>
00008 #include <cassert>
00009 #include <iostream>
00010 using namespace std;
00011 
00012 DomainTransitionGraphFunc::DomainTransitionGraphFunc(const Variable &var) {
00013     //cout << "creating functional DTG for " << var.get_name() << endl;
00014     transitions.clear();
00015     level = var.get_level();
00016     assert(level != -1);
00017 }
00018 void DomainTransitionGraphFunc::addTransition(int fop, int right_var,
00019         const Operator &op, int op_index, trans_type type,
00020         vector<Variable *> variables) {
00021 
00022     class self_fulfilled_ {
00023         public:
00024             bool operator()(const vector<Operator::PrePost> &pre_post_start, const Variable *var,
00025                     const int &val) {
00026                 for(unsigned int j = 0; j < pre_post_start.size(); j++)
00027                     if(pre_post_start[j].var == var && pre_post_start[j].post == val)
00028                         return true;
00029                 return false;
00030             }
00031     } self_fulfilled;
00032 
00033     Transition trans(type, op_index);
00034     SetEdgeCondition &cond = trans.set_condition;
00035     const vector<Operator::Prevail> &prevail_start = op.get_prevail_start();
00036     const vector<Operator::Prevail> &prevail_overall = op.get_prevail_overall();
00037     const vector<Operator::Prevail> &prevail_end = op.get_prevail_end();
00038     const vector<Operator::PrePost> &pre_post_start = op.get_pre_post_start();
00039     const vector<Operator::PrePost> &pre_post_end = op.get_pre_post_end();
00040     for(int i = 0; i < prevail_start.size(); i++)
00041         if(true) { // [cycles]
00042             // if(prevail_start[i].var->get_level() < level) // [no cycles]
00043             cond.insert(std::tr1::make_tuple(prevail_start[i].var, prevail_start[i].prev, start_cond));
00044         }
00045     for(int i = 0; i < prevail_overall.size(); i++)
00046         if(true) // [cycles]
00047             // if(prevail_overall[i].var->get_level() < level) // [no cycles]
00048             if(!self_fulfilled(pre_post_start, prevail_overall[i].var,
00049                         prevail_overall[i].prev))
00050                 cond.insert(std::tr1::make_tuple(prevail_overall[i].var, prevail_overall[i].prev, overall_cond));
00051     for(int i = 0; i < prevail_end.size(); i++)
00052         if(true) // [cycles]
00053             // if(prevail_end[i].var->get_level() < level) // [no cycles]
00054             if(!self_fulfilled(pre_post_start, prevail_end[i].var,
00055                         prevail_end[i].prev))
00056                 cond.insert(std::tr1::make_tuple(prevail_end[i].var, prevail_end[i].prev, end_cond));
00057     for(int i = 0; i < pre_post_start.size(); i++) {
00058         if(pre_post_start[i].var->get_level() != level && pre_post_start[i].pre
00059                 != -1) // [cycles]
00060             // if(pre_post_start[i].var->get_level() < level && pre_post_start[i].pre != -1) //[no cycles]
00061             cond.insert(std::tr1::make_tuple(pre_post_start[i].var, pre_post_start[i].pre, start_cond));
00062         else if(pre_post_start[i].var->get_level() == level
00063                 && pre_post_start[i].is_conditional_effect) {
00064             for(int j = 0; j < pre_post_start[i].effect_conds_start.size(); j++)
00065                 cond.insert(std::tr1::make_tuple(pre_post_start[i].effect_conds_start[j].var,
00066                             pre_post_start[i].effect_conds_start[j].cond, start_cond));
00067             //      for(int j = 0; j < pre_post_start[i].effect_conds_overall.size(); j++)
00068             //  cond.insert(make_pair(pre_post_start[i].effect_conds_overall[j].var,
00069             //      pre_post_start[i].effect_conds_overall[j].cond));
00070             //      for(int j = 0; j < pre_post_start[i].effect_conds_end.size(); j++)
00071             //  cond.insert(make_pair(pre_post_start[i].effect_conds_end[j].var,
00072             //      pre_post_start[i].effect_conds_end[j].cond));
00073         }
00074     }
00075     for(int i = 0; i < pre_post_end.size(); i++) {
00076         if(pre_post_end[i].var->get_level() != level && pre_post_end[i].pre != -1) { // [cycles]
00077             // if(pre_post_end[i].var->get_level() < level && pre_post_end[i].pre != -1) //[no cycles]
00078             if(!self_fulfilled(pre_post_start, pre_post_end[i].var,
00079                         pre_post_end[i].pre))
00080                 cond.insert(std::tr1::make_tuple(pre_post_end[i].var, pre_post_end[i].pre, end_cond));
00081         } else if(pre_post_end[i].var->get_level() == level
00082                 && pre_post_end[i].is_conditional_effect) {
00083             //      for(int j = 0; j < pre_post_end[i].effect_conds_start.size(); j++)
00084             //  cond.insert(make_pair(pre_post_end[i].effect_conds_start[j].var,
00085             //      pre_post_end[i].effect_conds_start[j].cond));
00086             //      for(int j = 0; j < pre_post_end[i].effect_conds_overall.size(); j++)
00087             //  cond.insert(make_pair(pre_post_end[i].effect_conds_overall[j].var,
00088             //      pre_post_end[i].effect_conds_overall[j].cond));
00089             for(int j = 0; j < pre_post_end[i].effect_conds_end.size(); j++)
00090                 if(!self_fulfilled(pre_post_start,
00091                             pre_post_end[i].effect_conds_end[j].var,
00092                             pre_post_end[i].effect_conds_end[j].cond))
00093                     cond.insert(std::tr1::make_tuple(pre_post_end[i].effect_conds_end[j].var,
00094                                 pre_post_end[i].effect_conds_end[j].cond, end_cond));
00095         }
00096     }
00097     //write from set to vector
00098     EdgeCondition &cond_vec = trans.condition;
00099     for(SetEdgeCondition::iterator it = cond.begin(); it != cond.end(); ++it) {
00100         //    cout << "writing [" << (*it).first->get_level() << "," << (*it).second << "]" << endl;
00101         cond_vec.push_back(*it);
00102     }
00103 
00104     trans.duration = op.get_duration_cond();
00105     trans.fop = static_cast<foperator>(fop);
00106     trans.right_var = variables[right_var];
00107     transitions.push_back(trans);
00108 }
00109 
00110 void DomainTransitionGraphFunc::addAxRelTransition(int from, int to,
00111         const Axiom_relational &ax, int ax_index) {
00112 }
00113 
00114 void DomainTransitionGraphFunc::finalize() {
00115 }
00116 
00117 bool DomainTransitionGraphFunc::is_strongly_connected() const {
00118     return false;
00119 }
00120 
00121 void DomainTransitionGraphFunc::dump() const {
00122     cout << "Functional DTG!" << endl;
00123     for(int i = 0; i < transitions.size(); i++) {
00124         cout << " Transition:" << endl;
00125         const Transition &trans = transitions[i];
00126         cout << "  durations " << trans.duration.op << " "
00127             << trans.duration.var->get_name() << endl;
00128         for(int k = 0; k < trans.condition.size(); k++)
00129             cout << "  if " << std::tr1::get<0>(trans.condition[k])->get_name()
00130                 << " = " << std::tr1::get<1>(trans.condition[k]) << " (" << std::tr1::get<2>(trans.condition[k]) << ")" << endl;
00131         if(trans.type == start)
00132             cout << "  start effect" << endl;
00133         else if(trans.type == end)
00134             cout << "  end effect" << endl;
00135         else
00136             cout << "   " << "axiom" << endl;
00137         cout << "  " << trans.fop << " " << trans.right_var->get_name() << endl;
00138 
00139     }
00140 }
00141 
00142 void DomainTransitionGraphFunc::generate_cpp_input(ostream &outfile) const {
00143     outfile << transitions.size() << endl;
00144     for(int i = 0; i < transitions.size(); i++) {
00145         const Transition &trans = transitions[i];
00146         outfile << trans.op << endl; // operator doing the transition
00147         outfile << trans.type << endl; //type of transition
00148         outfile << trans.fop << " " << trans.right_var->get_level() << endl;
00149         //duration
00150         outfile << trans.duration.op << " " << trans.duration.var->get_level()
00151             << endl;
00152         //conditions
00153         outfile << trans.condition.size() << endl;
00154         for(int k = 0; k < trans.condition.size(); k++)
00155             outfile << std::tr1::get<0>(trans.condition[k])->get_level() << " "
00156                 << std::tr1::get<1>(trans.condition[k]) << " " << std::tr1::get<2>(trans.condition[k]) << endl;
00157     }
00158 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Tue Jan 22 2013 12:25:03