Assignment Search Framework
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
transition_system.h
Go to the documentation of this file.
1 /*
2  * transition_system.h
3  *
4  * LICENSE HERE
5  *
6  * Created on: 2016-08-15
7  * Author: Rick Valenzano
8  */
9 
10 #ifndef TRANSITIONSYSTEM_H_
11 #define TRANSITIONSYSTEM_H_
12 
13 #include <vector>
14 
22 template<class state_t, class action_t>
24 {
25 public:
30 
34  virtual ~TransitionSystem();
35 
43  virtual bool isApplicable(const state_t &state, const action_t &action) const;
44 
52  virtual bool isChildState(const state_t &parent, const state_t &child) const;
53 
63  virtual double getActionCost(const state_t &state, const action_t &action) const = 0;
64 
73  virtual void applyAction(state_t &state, const action_t &action) const = 0;
74 
81  virtual void getActions(const state_t &state, std::vector<action_t> &actions) const = 0;
82 
91  virtual void getSuccessors(const state_t &state, std::vector<state_t> &children) const;
92 
102  virtual bool isInvertible(const state_t &state, const action_t &action) const;
103 
113  virtual action_t getInverse(const state_t &state, const action_t &action) const;
114 
122  virtual action_t getDummyAction() const = 0;
123 
130  virtual bool isDummyAction(const action_t &action) const = 0;
131 
141  bool applyActionSequence(state_t &state, const std::vector<action_t> &actions) const;
142 
150  bool isApplicableSequence(const state_t &state, const std::vector<action_t> &actions) const;
151 };
152 
153 template<class state_t, class action_t>
155 {
156 }
157 
158 template<class state_t, class action_t>
160 {
161 }
162 
163 template<class state_t, class action_t>
164 bool TransitionSystem<state_t, action_t>::isApplicable(const state_t &state, const action_t &action) const
165 {
166  if(action == getDummyAction())
167  return false;
168 
169  std::vector<action_t> actions;
170 
171  getActions(state, actions);
172 
173  for(unsigned i = 0; i < actions.size(); i++) {
174  if(action == actions[i])
175  return true;
176  }
177 
178  return false;
179 }
180 
181 template<class state_t, class action_t>
182 bool TransitionSystem<state_t, action_t>::isChildState(const state_t &parent, const state_t &child) const
183 {
184  std::vector<state_t> children;
185 
186  getSuccessors(parent, children);
187 
188  for(unsigned i = 0; i < children.size(); i++) {
189  if(child == children[i])
190  return true;
191  }
192 
193  return false;
194 }
195 
196 template<class state_t, class action_t>
197 void TransitionSystem<state_t, action_t>::getSuccessors(const state_t &state, std::vector<state_t> &children) const
198 {
199  std::vector<action_t> actions;
200 
201  getActions(state, actions);
202 
203  for(unsigned i = 0; i < actions.size(); i++) {
204  state_t state_copy(state);
205  applyAction(state_copy, actions[i]);
206 
207  children.push_back(state_copy);
208  }
209 }
210 
211 template<class state_t, class action_t>
212 bool TransitionSystem<state_t, action_t>::isInvertible(const state_t &state, const action_t &action) const {
213  return false;
214 }
215 
216 template<class state_t, class action_t>
217 action_t TransitionSystem<state_t, action_t>::getInverse(const state_t &state, const action_t &action) const {
218  return getDummyAction();
219 }
220 
221 
222 template<class state_t, class action_t>
224  const std::vector<action_t> &actions) const
225 {
226  for(unsigned i = 0; i < actions.size(); i++) {
227  if(!isApplicable(state, actions[i]))
228  return false;
229  applyGivenAction(state, actions[i]);
230  }
231 
232  return true;
233 }
234 
235 template<class state_t, class action_t>
237  const std::vector<action_t> &actions) const
238 {
239  state_t state_copy(state);
240 
241  if(!applyActionSequence(state, actions))
242  return false;
243 
244  return true;
245 }
246 #endif /* TRANSITIONSYSTEM_H_ */
virtual void getSuccessors(const state_t &state, std::vector< state_t > &children) const
Definition: transition_system.h:197
virtual bool isInvertible(const state_t &state, const action_t &action) const
Definition: transition_system.h:212
virtual void applyAction(state_t &state, const action_t &action) const =0
virtual bool isChildState(const state_t &parent, const state_t &child) const
Definition: transition_system.h:182
TransitionSystem()
Definition: transition_system.h:154
bool isApplicableSequence(const state_t &state, const std::vector< action_t > &actions) const
Definition: transition_system.h:236
virtual void getActions(const state_t &state, std::vector< action_t > &actions) const =0
virtual action_t getDummyAction() const =0
virtual double getActionCost(const state_t &state, const action_t &action) const =0
virtual bool isApplicable(const state_t &state, const action_t &action) const
Definition: transition_system.h:164
virtual bool isDummyAction(const action_t &action) const =0
virtual action_t getInverse(const state_t &state, const action_t &action) const
Definition: transition_system.h:217
Definition: transition_system.h:23
virtual ~TransitionSystem()
Definition: transition_system.h:159
bool applyActionSequence(state_t &state, const std::vector< action_t > &actions) const
Definition: transition_system.h:223