domain_transition_graph.h
Go to the documentation of this file.
00001 #ifndef DOMAIN_TRANSITION_GRAPH_H
00002 #define DOMAIN_TRANSITION_GRAPH_H
00003 
00004 #include <iostream>
00005 #include <map>
00006 #include <vector>
00007 #include <tr1/unordered_map>
00008 //#include "globals.h"
00009 #include "operator.h"
00010 using namespace std;
00011 
00012 class CGHeuristic;
00013 class TimeStampedState;
00014 class Operator;
00015 
00016 class ValueNode;
00017 class ValueTransition;
00018 class ValueTransitionLabel;
00019 class DomainTransitionGraph;
00020 
00021 // Note: We do not use references but pointers to refer to the "parents" of
00022 // transitions and nodes. This is because these structures could not be
00023 // put into vectors otherwise.
00024 
00025 typedef multimap<int, ValueNode *> Heap;
00026 typedef std::tr1::unordered_map<int, int> hashmap;
00027 typedef hashmap::value_type ValuePair;
00028 
00029 struct LocalAssignment
00030 {
00031     DomainTransitionGraph *prev_dtg;
00032     int local_var;
00033     double value;
00034     int var;
00035     assignment_op fop;
00036     condition_type cond_type;
00037     LocalAssignment(DomainTransitionGraph *_prev_dtg, int _local_var, double _value, condition_type _cond_type) :
00038         prev_dtg(_prev_dtg), local_var(_local_var), value(_value), cond_type(_cond_type)
00039     {
00040         var = -1;
00041     }
00042     LocalAssignment(DomainTransitionGraph *_prev_dtg, int _local_var, int _var, assignment_op _fop, condition_type _cond_type) :
00043         prev_dtg(_prev_dtg), local_var(_local_var), var(_var), fop(_fop), cond_type(_cond_type)
00044     {
00045         value = -1.0;
00046     }
00047     LocalAssignment(istream &in);
00048     void dump() const;
00049 };
00050 
00051 class ValueTransitionLabel
00052 {
00053     public:
00054         int duration_variable;
00055         vector<LocalAssignment> precond;
00056         trans_type type;
00057         vector<LocalAssignment> effect;
00058         Operator *op;
00059         ValueTransitionLabel(int the_duration_variable, const vector<LocalAssignment> &the_precond,
00060             trans_type the_type, const vector<LocalAssignment> &the_effect = vector<LocalAssignment> (), Operator* theOp = NULL) :
00061             duration_variable(the_duration_variable), precond(the_precond), type(the_type), effect(the_effect), op(theOp)
00062         {
00063         }
00064         virtual ~ValueTransitionLabel() {}
00065 };
00066 
00067 class ValueTransition
00068 {
00069     public:
00070         ValueNode *target;
00071         vector<ValueTransitionLabel*> ccg_labels; // labels for cyclic CG heuristic
00072 
00073         ValueTransition(ValueNode *targ) : target(targ) {}
00074         void dump() const;
00075 };
00076 
00077 struct ValueNode
00078 {
00079     DomainTransitionGraph *parent_graph;
00080     int value;
00081     vector<ValueTransition> transitions;
00082     vector<ValueTransition> additional_transitions;
00083 
00084     ValueNode(DomainTransitionGraph *parent, int val) :
00085         parent_graph(parent), value(val)
00086     {
00087     }
00088     void dump() const;
00089 };
00090 
00091 struct CompTransition
00092 {
00093     int left_var;
00094     int right_var;
00095     binary_op op;
00096 
00097     void dump() const;
00098 };
00099 
00100 class FuncTransitionLabel : public ValueTransitionLabel
00101 {
00102     public:
00103         int starting_variable;
00104         assignment_op a_op;
00105         int influencing_variable;
00106         FuncTransitionLabel(int the_starting_variable, vector<LocalAssignment> the_precond,
00107                 vector<LocalAssignment> the_effect, assignment_op the_a_op,
00108                 int the_influencing_variable, int the_duration_variable, trans_type type,
00109                 Operator *the_op) :
00110             ValueTransitionLabel(the_duration_variable, the_precond, type, the_effect, the_op),
00111             starting_variable(the_starting_variable), a_op(the_a_op), influencing_variable(the_influencing_variable)
00112         {
00113         }
00114 };
00115 
00116 class DomainTransitionGraph
00117 {
00118     public:
00119         int var;
00120         bool is_axiom;
00121 
00122         vector<int> ccg_parents;
00123         // used for mapping variables in conditions to their global index
00124         // (only needed for initializing child_state for the start node?)
00125         hashmap global_to_local_ccg_parents;
00126 
00127         virtual ~DomainTransitionGraph() {}
00128         static void read_all(istream &in);
00129         virtual void read_data(istream &in) = 0;
00130         static void compute_causal_graph_parents_comp(int var, map<int, int> &global_to_ccg_parent);
00131         static void collect_func_transitions(int var, map<int, int> &global_to_ccg_parent);
00132         virtual void dump() const = 0;
00133     protected:
00134         int translate_global_to_local(map<int, int> &global_to_ccg_parent, int global_var);
00135 };
00136 
00137 class DomainTransitionGraphModule : public DomainTransitionGraph
00138 {
00139     public:
00140         DomainTransitionGraphModule(int var_index)
00141         {
00142             var = var_index;
00143         }
00144         void read_data(istream & in)
00145         {
00146             check_magic(in, "begin_DTG");
00147             check_magic(in, "0");
00148             check_magic(in, "end_DTG");
00149         }
00150         void dump() const
00151         {
00152         }
00153 };
00154 
00155 class DomainTransitionGraphSymb : public DomainTransitionGraph
00156 {
00157     public:
00158         vector<ValueNode> nodes;
00159 
00160         DomainTransitionGraphSymb(int var_index, int node_count);
00161         virtual void read_data(istream &in);
00162         virtual void dump() const;
00163         virtual void get_successors(int value, vector<int> &result) const;
00164         // Build vector of values v' such that there is a transition from value to v'.
00165 
00166     private:
00167         void compress_effects(const Operator* op, vector<PrePost>& pre_post);
00168         bool add_relevant_functional_vars_to_context(int var_no, map<int, int> &global_to_ccg_parent);
00169         void extend_cyclic_effect(const PrePost& pre_post, vector<LocalAssignment>& cyclic_effect,
00170             map<int, int> &global_to_ccg_parent, const vector<pair<int, int> >& precond_pairs);
00171         DomainTransitionGraphSymb(const DomainTransitionGraphSymb &other); // copying forbidden
00172 };
00173 
00174 class DomainTransitionGraphSubterm : public DomainTransitionGraph
00175 {
00176     public:
00177         int left_var;
00178         int right_var;
00179         binary_op op;
00180 
00181         DomainTransitionGraphSubterm(int var_index);
00182         virtual void read_data(istream &in);
00183         virtual void dump() const;
00184 
00185     private:
00186         DomainTransitionGraphSubterm(const DomainTransitionGraphSubterm &other); // copying forbidden
00187 };
00188 
00189 class DomainTransitionGraphFunc : public DomainTransitionGraph
00190 {
00191     public:
00192         vector<FuncTransitionLabel> transitions;
00193         DomainTransitionGraphFunc(int var_index);
00194         virtual void read_data(istream &in);
00195         virtual void dump() const;
00196 
00197     private:
00198         DomainTransitionGraphFunc(const DomainTransitionGraphFunc &other); // copying forbidden
00199 };
00200 
00201 class DomainTransitionGraphComp : public DomainTransitionGraph
00202 {
00203     public:
00204         //all transitions which modify a primitve functional variable which is a child
00205         //in the causal graph of this variable
00206         // in contrast to DomainTransitionGraphFunc, here the variables are local
00207         vector<FuncTransitionLabel> transitions;
00208 
00209         std::pair<CompTransition, CompTransition> nodes; //first has start value false; second has start value true
00210         DomainTransitionGraphComp(int var_index);
00211         virtual void read_data(istream &in);
00212         void compute_recursively_parents(int var, map<int, int> &global_to_ccg_parent);
00213         void collect_recursively_func_transitions(int var, map<int, int> &global_to_ccg_parent);
00214         virtual void dump() const;
00215     private:
00216         DomainTransitionGraphComp(const DomainTransitionGraphComp &other); // copying forbidden
00217 };
00218 
00219 #endif


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Mon Oct 6 2014 07:52:06