-
Notifications
You must be signed in to change notification settings - Fork 2
/
effects.h
326 lines (273 loc) · 11.5 KB
/
effects.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#ifndef EFFECTS_H
#define EFFECTS_H
#include "global.h"
#include "terms.h"
#include <assert.h>
#include <iostream>
#include <vector>
class Rational;
class PredicateTable;
class FunctionTable;
class ValueMap;
class Expression;
class Application;
class StateFormula;
class Atom;
class AtomSet;
class AtomList;
class stripsEffect_t;
class conditionalEffectList_t;
class probabilisticEffectList_t;
class state_t;
class stateProbList_t;
class problem_t;
class Assignment
{
public:
enum { ASSIGN_OP, SCALE_UP_OP, SCALE_DOWN_OP, INCREASE_OP, DECREASE_OP };
Assignment( unsigned oper, const Application& application, const Expression& expr );
~Assignment();
const Application& application( void ) const { return( *application_ ); }
void affect( ValueMap& values ) const;
void affect( state_t& state ) const;
const Assignment& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
bool operator==( const Assignment &assig ) const;
void print( std::ostream& os, const FunctionTable& functions,
const TermTable& terms ) const;
private:
unsigned operator_;
const Application* application_;
const Expression* expr_;
};
class AssignmentList : public std::vector<const Assignment*> { };
class Effect
{
mutable size_t ref_count_;
protected:
Effect() : ref_count_(0) { }
public:
virtual ~Effect()
{
assert( ref_count_ == 0 );
}
static void register_use( const Effect* e )
{
#ifdef MEM_DEBUG
if(e) std::cerr << "<eff>: inc-ref-count " << e << " = " << e->ref_count_+1 << std::endl;
#endif
if( e ) e->ref_count_++;
}
static void unregister_use( const Effect* e )
{
#ifdef MEM_DEBUG
if(e) std::cerr << "<eff>: dec-ref-count " << e << " = " << e->ref_count_-1 << std::endl;
#endif
if( e && (--e->ref_count_ == 0) ) delete e;
}
virtual const Effect& flatten( void ) const = 0;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const = 0;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const = 0;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const = 0;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const = 0;
virtual bool operator==( const Effect& eff ) const = 0;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const = 0;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const = 0;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const = 0;
};
class EffectList : public std::vector<const Effect*> { };
class AddEffect : public Effect
{
const Atom* atom_;
public:
AddEffect( const Atom& atom );
virtual ~AddEffect();
const Atom& atom( void ) const { return( *atom_ ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
class DeleteEffect : public Effect
{
const Atom* atom_;
public:
DeleteEffect( const Atom& atom );
virtual ~DeleteEffect();
const Atom& atom( void ) const { return( *atom_ ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
class AssignmentEffect : public Effect
{
const Assignment* assignment_;
public:
AssignmentEffect( const Assignment& assignment );
virtual ~AssignmentEffect();
const Assignment& assignment( void ) const { return( *assignment_ ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
class ConjunctiveEffect : public Effect
{
EffectList conjuncts_;
public:
ConjunctiveEffect();
virtual ~ConjunctiveEffect();
void add_conjunct( const Effect& conjunct );
size_t size( void ) const { return( conjuncts_.size() ); }
const Effect& conjunct( size_t i ) const { return( *conjuncts_[i] ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
class ConditionalEffect : public Effect
{
const StateFormula* condition_;
const Effect* effect_;
ConditionalEffect( const StateFormula& condition, const Effect& effect );
static bool working_;
public:
virtual ~ConditionalEffect();
static const Effect& make( const StateFormula& condition,
const Effect& effect );
const StateFormula& condition( void ) const { return( *condition_ ); }
const Effect& effect( void ) const { return( *effect_ ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
class ProbabilisticEffect : public Effect
{
std::vector<int> weights_;
int weight_sum_;
EffectList effects_;
static bool working_;
public:
ProbabilisticEffect();
virtual ~ProbabilisticEffect();
const ProbabilisticEffect& cross_product( const ProbabilisticEffect &effect ) const;
bool add_outcome( const Rational& p, const Effect& effect );
size_t size( void ) const { return( weights_.size() ); }
Rational probability( size_t i ) const;
const Effect& effect( size_t i ) const { return( *effects_[i] ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
void translate( probabilisticEffectList_t &plist ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
class QuantifiedEffect : public Effect
{
VariableList parameters_;
const Effect* effect_;
public:
QuantifiedEffect( const Effect& effect );
virtual ~QuantifiedEffect();
void add_parameter( Variable parameter ) { parameters_.push_back( parameter ); }
size_t arity( void ) const { return( parameters_.size() ); }
Variable parameter( size_t i ) const { return( parameters_[i] ); }
const Effect& effect( void ) const { return( *effect_ ); }
virtual const Effect& flatten( void ) const;
virtual void state_change( AtomList& adds, AtomList& deletes,
AssignmentList& assignments,
const state_t& state ) const;
virtual const stateProbList_t& expand( const stateProbList_t &state_list ) const;
virtual void translate( stripsEffect_t &s_effect,
conditionalEffectList_t &c_effect ) const;
virtual const Effect& instantiation( const SubstitutionMap& subst,
const problem_t& problem ) const;
virtual bool operator==( const Effect& eff ) const;
virtual void print( std::ostream& os, const PredicateTable& predicates,
const FunctionTable& functions,
const TermTable& terms ) const;
virtual void analyze( PredicateTable &predicates, TermTable &terms,
std::map<const StateFormula*,const Atom*> &hash ) const;
virtual const Effect& rewrite( std::map<const StateFormula*,const Atom*> &hash ) const;
};
#endif /* EFFECTS_H */