-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathterm_manager.h
609 lines (531 loc) · 31.1 KB
/
term_manager.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
#ifndef MYPOP_TERM_MANAGER_H
#define MYPOP_TERM_MANAGER_H
#include <string>
#include <ostream>
#include <assert.h>
#include "VALfiles/ptree.h"
#include "manager.h"
#include "plan_types.h"
namespace MyPOP {
class Bindings;
class Type;
class TypeManager;
class Object;
class Variable;
typedef std::vector<const Object*> TermDomain;
/**
* A term is an abstract class which can either be an object or a variable, all
* the behavioural code is in these classes. Other classes only need to consider
* terms without worrying if the actual object is a variable or an object.
*/
class Term : public ManageableObject {
public:
Term() {}
virtual ~Term() {};
/**
* Get the type of this term.
*/
const Type* getType() const { return type_; }
/**
* Get the name of this term.
*/
const std::string& getName() const { return name_; }
/**
* Create a copy of this term. Note that we NEVER copy objects.
*/
virtual const Term& clone() const = 0;
/**
* Check if this term is unifiable with the given term. This means that if we take the intersection
* of both term's domains it yields a non-empty set.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param lhs_bindings The class which contains the bindings for the lhs term.
* @param rhs_bindings The class which contains the bindings for the rhs term. If this value is assigned NULL it will
* be treated as equal to @param lhs_bindings
* @return True if the terms can be unified, false otherwise.
*/
bool canUnify(StepID lhs_id, const Term& rhs, StepID rhs_id, const Bindings& lhs_bindings, const Bindings* rhs_bindings = NULL) const;
/**
* Unify the two terms, there are three different possible scenarios.
* - Both terms are variable: in this case we merge both variables, a change to one of the variables will
* affect the other variables. They are the same after unifying.
* - One is an object and the other a variable: in this case the variable's domain will be reduced to the
* given object. There is no other relation between both terms.
* - Both are objects: Nothing will happen, the result will be identical to a call to canUnify.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
*/
virtual bool unify(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings) const = 0;
/**
* Make two term disjunct, the following cases can occur:
* - Both terms are variable: in this case we add each variable to each other's unequal table.
* - The LHS is a variable and the RHS is an object: in this case the object will be removed from the variable's domain.
* - The LHS is an object: Nothing will happen, but the program will fail if asked to make the domain of the object empty.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain of the lhs has been changed.
*/
virtual bool makeDisjunct(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings) const = 0;
/**
* Modify the domain of this term such that it contains the same objects of the given term. Note that if
* the other term contains objects not contained in this term, these will not be added. So we take the
* conjunction of both domains and assign it to this domain.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
virtual bool makeDomainEqualTo(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& lhs_bindings, Bindings* rhs_bindings = NULL) const = 0;
/**
* Modify the domain of this term such that it only contains the objects present in @param objects. We
* take the conjunction of this domain and the list of objects.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param objects The list of objects which this domain can take.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
virtual bool makeDomainEqualTo(StepID lhs_id, const std::vector<const Object*>& objects, Bindings& bindings) const = 0;
/**
* Modify the domain of this term such that all objects present in the rhs term are removed from this term.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
virtual bool makeDomainUnequalTo(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings, Bindings* rhs_bindings = NULL) const = 0;
/**
* Modify the domain of this term such that all the objects present in @param objects are removed from it.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param objects The list of objects which this domain can take.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
virtual bool makeDomainUnequalTo(StepID lhs_id, const std::vector<const Object*>& objects, Bindings& bindings) const = 0;
/**
* Get the domain of this term, in the case of an object this will be a single object and in the
* case of the variable it will be a list of objects (possibly empty).
* @param id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings In the case of variables we need the bindings to discover its domain since it
* is stored in the Bindings class.
* @return The domain of this term.
*/
virtual const std::vector<const Object*>& getDomain(StepID id, const Bindings& bindings) const = 0;
/**
* Check if two terms are the same, note that this is not an equivalent check, what is checked here is if
* both term's domains point to the same memory space.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if both term's domains point to the same memory space, false otherwise.
*/
bool isTheSameAs(StepID lhs_id, const Term& rhs, StepID rhs_id, const Bindings& bindings) const;
/**
* Check if two terms are equivalent, that is the domains contain exactly the same objects.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param lhs_bindings The class which contains the bindings for the lhs term.
* @param rhs_bindings The class which contains the bindings for the rhs term, if it is equal to NULL it is equal to lhs_bindings.
* @return True if both term's domains are equivalent, false otherwise.
*/
bool isEquivalentTo(StepID lhs_id, const Term& rhs, StepID rhs_id, const Bindings& lhs_bindings, const Bindings* rhs_bindings = NULL) const;
/**
* Check if the given object is a member of this term's domain.
* @param object The object we are looking for.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if object is part of this term's domain.
*/
bool contains(const Object& object, StepID lhs_id, const Bindings& bindings) const;
/**
* Check if at least one of the given objects is a member of this term's domain.
* @param objects The objects we are looking for.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if one of the objects is part of this term's domain.
*/
bool containsAtLeastOneOf(const std::vector<const Object*>& objects, StepID lhs_id, const Bindings& bindings) const;
/**
* Check if this term is a proper super set of the given set.
* @param lhs_id The id this term is bounded by.
* @param other The term to compare it with.
* @param rhs_id The id the other term is bounded by.
* @return True if this term is a proper super set, false otherwise.
*/
bool isProperSuperSetOf(StepID lhs_id, const Term& other, StepID rhs_id, const Bindings& bindings) const;
/**
* Check if this term is a proper sub set of the given set.
* @param lhs_id The id this term is bounded by.
* @param other The term to compare it with.
* @param rhs_id The id the other term is bounded by.
* @return True if this term is a proper sub set, false otherwise.
*/
bool isProperSubSetOf(StepID lhs_id, const Term& other, StepID rhs_id, const Bindings& bindings) const;
/**
* Method that should be called by @param bindings to bind this term to the given bindings object.
* @param Bindings the bindings object to bind this term to.
* @param new_step_id the id which should be given to the binding.
*/
virtual void bind(Bindings& bindings, StepID new_step_id) const = 0;
/**
* Print the term in a userfriendly way.
*/
virtual void print(std::ostream& os, const Bindings& bindings, StepID id) const = 0;
/**
* Unify this term with an object.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param object The object the compare the domain against.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
virtual bool unifyWith(StepID lhs_id, const Object& object, Bindings& bindings) const = 0;
/**
* Unify this term with a variable.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param variable The variable to compare the domain against.
* @param rhs_id The step id for the variable, used to find its variable domain in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
virtual bool unifyWith(StepID lhs_id, const Variable& variable, StepID rhs_id, Bindings& bindings) const = 0;
/**
* Make the given variable disjunct from this term.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param variable The variable to compare the domain against.
* @param rhs_id The step id for the variable, used to find its variable domain in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain of this term has been modified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
virtual bool makeDisjunctWith(StepID lhs_id, const Variable& variable, StepID rhs_id, Bindings& bindings) const = 0;
protected:
Term(const Type& type, const std::string& name);
private:
const Type* type_;
const std::string name_;
};
std::ostream& operator<<(std::ostream& os, const Term& term);
/**
* Object...
*/
class Object : public Term {
public:
Object (const Type& type, const std::string& name);
virtual ~Object();
/**
* We NEVER clone objects, rather we return an instance of the same instance.
*/
virtual const Term& clone() const { return *this; }
/**
* Unify the two terms, there are three different possible scenarios.
* - Both terms are variable: in this case we merge both variables, a change to one of the variables will
* affect the other variables. They are the same after unifying.
* - One is an object and the other a variable: in this case the variable's domain will be reduced to the
* given object. There is no other relation between both terms.
* - Both are objects: Nothing will happen, the result will be identical to a call to canUnify.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
*/
bool unify(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings) const;
/**
* Make two term disjunct, the following cases can occur:
* - Both terms are variable: in this case we add each variable to each other's unequal table.
* - The LHS is a variable and the RHS is an object: in this case the object will be removed from the variable's domain.
* - The LHS is an object: Nothing will happen, but the program will fail if asked to make the domain of the object empty.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain of the lhs has been changed.
*/
bool makeDisjunct(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings) const;
/**
* Modify the domain of this term such that it contains the same objects of the given term. Note that if
* the other term contains objects not contained in this term, these will not be added. So we take the
* conjunction of both domains and assign it to this domain.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainEqualTo(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& lhs_bindings, Bindings* rhs_bindings = NULL) const;
/**
* Modify the domain of this term such that it only contains the objects present in @param objects. We
* take the conjunction of this domain and the list of objects.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param objects The list of objects which this domain can take.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainEqualTo(StepID lhs_id, const std::vector<const Object*>& objects, Bindings& bindings) const;
/**
* Modify the domain of this term such that all objects present in the rhs term are removed from this term.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainUnequalTo(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& lhs_bindings, Bindings* rhs_bindings = NULL) const;
/**
* Modify the domain of this term such that all the objects present in @param objects are removed from it.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param objects The list of objects which this domain can take.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainUnequalTo(StepID lhs_id, const std::vector<const Object*>& objects, Bindings& bindings) const;
/**
* Get the domain of this term, in the case of an object this will be a single object and in the
* case of the variable it will be a list of objects (possibly empty).
* @param id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings In the case of variables we need the bindings to discover its domain since it
* is stored in the Bindings class.
* @return The domain of this term.
*/
const std::vector<const Object*>& getDomain(StepID id, const Bindings& bindings) const;
/**
* Check if the given object is a member of this term's domain.
* @param object The object we are looking for.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if object is part of this term's domain.
*/
//bool contains(const Object& object, StepID lhs_id, const Bindings& bindings) const;
/**
* In the case of objects nothing needs to be done, it cannot be bound.
* @param Bindings the bindings object to bind this term to.
* @param new_step_id the id which should be given to the binding.
* @note Bad design to have a NOP method...
*/
void bind(Bindings& bindings, StepID new_step_id) const;
/**
* Print the term in a userfriendly way.
*/
void print(std::ostream& os, const Bindings& bindings, StepID id) const;
protected:
/**
* Unify this term with an object.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param object The object the compare the domain against.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
bool unifyWith(StepID lhs_id, const Object& object, Bindings& bindings) const;
/**
* Unify this term with a variable.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param variable The variable to compare the domain against.
* @param rhs_id The step id for the variable, used to find its variable domain in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
bool unifyWith(StepID lhs_id, const Variable& variable, StepID rhs_id, Bindings& bindings) const;
/**
* Make the given variable disjunct from this term.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param variable The variable to compare the domain against.
* @param rhs_id The step id for the variable, used to find its variable domain in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain of this term has been modified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
bool makeDisjunctWith(StepID lhs_id, const Variable& variable, StepID rhs_id, Bindings& bindings) const;
private:
// For efficiency reasons and making the implemenation easier, we force every object to
// have a domain with only itself as member.
std::vector<const Object*> domain_;
};
class Variable : public Term {
public:
Variable (const Type& type, const std::string& name);
virtual ~Variable();
/**
* Create a clone of the variable with the same type and name.
*/
virtual Term& clone() const { return *(new Variable(*getType(), getName())); }
/**
* Unify the two terms, there are three different possible scenarios.
* - Both terms are variable: in this case we merge both variables, a change to one of the variables will
* affect the other variables. They are the same after unifying.
* - One is an object and the other a variable: in this case the variable's domain will be reduced to the
* given object. There is no other relation between both terms.
* - Both are objects: Nothing will happen, the result will be identical to a call to canUnify.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
*/
bool unify(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings) const;
/**
* Make two term disjunct, the following cases can occur:
* - Both terms are variable: in this case we add each variable to each other's unequal table.
* - The LHS is a variable and the RHS is an object: in this case the object will be removed from the variable's domain.
* - The LHS is an object: Nothing will happen, but the program will fail if asked to make the domain of the object empty.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain of the lhs has been changed.
*/
bool makeDisjunct(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& bindings) const;
/**
* Modify the domain of this term such that it contains the same objects of the given term. Note that if
* the other term contains objects not contained in this term, these will not be added. So we take the
* conjunction of both domains and assign it to this domain.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainEqualTo(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& lhs_bindings, Bindings* rhs_bindings = NULL) const;
/**
* Modify the domain of this term such that it only contains the objects present in @param objects. We
* take the conjunction of this domain and the list of objects.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param objects The list of objects which this domain can take.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainEqualTo(StepID lhs_id, const std::vector<const Object*>& objects, Bindings& bindings) const;
/**
* Modify the domain of this term such that all objects present in the rhs term are removed from this term.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param rhs The term the compare the domain against.
* @param rhs_id The step id for the rhs term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainUnequalTo(StepID lhs_id, const Term& rhs, StepID rhs_id, Bindings& lhs_bindings, Bindings* rhs_bindings = NULL) const;
/**
* Modify the domain of this term such that all the objects present in @param objects are removed from it.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param objects The list of objects which this domain can take.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain has been modified, false otherwise.
*/
bool makeDomainUnequalTo(StepID lhs_id, const std::vector<const Object*>& objects, Bindings& bindings) const;
/**
* Get the domain of this term, in the case of an object this will be a single object and in the
* case of the variable it will be a list of objects (possibly empty).
* @param id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings In the case of variables we need the bindings to discover its domain since it
* is stored in the Bindings class.
* @return The domain of this term.
*/
const std::vector<const Object*>& getDomain(StepID id, const Bindings& bindings) const;
/**
* Check if the given object is a member of this term's domain.
* @param object The object we are looking for.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if object is part of this term's domain.
*/
//bool contains(const Object& object, StepID lhs_id, const Bindings& bindings) const;
/**
* We make a callback to the bindings method and tell it to bind the variable to the given ID.
* It's inconvenient to do it this way, but this is the only way to shield the actual implemenation
* of all derived classes of Term.
* @param Bindings the bindings object to bind this term to.
* @param new_step_id the id which should be given to the binding.
*/
void bind(Bindings& bindings, StepID new_step_id) const;
/**
* Print the term in a userfriendly way.
*/
void print(std::ostream& os, const Bindings& bindings, StepID id) const;
//protected:
/**
* Unify this term with an object.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param object The object the compare the domain against.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
bool unifyWith(StepID lhs_id, const Object& object, Bindings& bindings) const;
/**
* Unify this term with a variable.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param variable The variable to compare the domain against.
* @param rhs_id The step id for the variable, used to find its variable domain in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the terms can be unified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
bool unifyWith(StepID lhs_id, const Variable& variable, StepID rhs_id, Bindings& bindings) const;
/**
* Make the given variable disjunct from this term.
* @param lhs_id The step id for this term, used to find its variable domain (if applicable) in @param bindings.
* @param variable The variable to compare the domain against.
* @param rhs_id The step id for the variable, used to find its variable domain in @param bindings.
* @param bindings The class which contains the bindings for both terms.
* @return True if the domain of this term has been modified, false otherwise.
* NOTE: this isn't very nice since it violates the OO paradigm (base class shouldn't be dependend on its
* derived classes).
*/
bool makeDisjunctWith(StepID lhs_id, const Variable& variable, StepID rhs_id, Bindings& bindings) const;
};
/**
* All terms, that is objects and variables are stored by this manager.
*/
class TermManager : public Manager<Term> {
public:
TermManager(const TypeManager& type_manager);
TermManager(const TermManager& term_manager);
virtual ~TermManager();
// Process the variables linked to the actions.
void processActionVariables(const VAL::operator_list& operators);
// Add a variable (of an action) to the list of types.
void addTerm(const VAL::symbol& symbol, Term& term);
void addTerm(const VAL::symbol& symbol, Object& term);
// Get the term object linked to the VAL::symbol as processed by the parser. Note
// that this function can only be called during the parsing phase, afterwards all references
// to VAL::symbol are deleted.
const Term* getTerm(const VAL::symbol&) const;
const Term* getTerm(const std::string& name) const;
// Get all the objects in the domain.
const std::vector<const Object*>& getAllObjects() const { return domain_objects_; }
// Get the object with the given name.
const Object& getObject(const std::string& name) const;
// Return the type manager.
const TypeManager& getTypeManager() const { return *type_manager_; }
private:
const TypeManager* type_manager_;
// During construction of the types keep track of the indexing from the
// symbol type to TermID.
std::map<const VAL::symbol*, const Term*>* term_indexing_;
std::map<std::string, const Term*>* term_string_indexing_;
// Store the objects from the domain separately.
std::vector<const Object*> domain_objects_;
};
std::ostream& operator<<(std::ostream& os, const TermManager& term_manager);
};
#endif