forked from anubhav-gres/VAL-4.2.08
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidator.cpp
More file actions
3552 lines (2448 loc) · 92.9 KB
/
Validator.cpp
File metadata and controls
3552 lines (2448 loc) · 92.9 KB
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************
* Copyright 2008, Strathclyde Planning Group,
* Department of Computer and Information Sciences,
* University of Strathclyde, Glasgow, UK
* http://planning.cis.strath.ac.uk/
*
* Maria Fox, Richard Howey and Derek Long - VAL
* Stephen Cresswell - PDDL Parser
*
* This file is part of VAL, the PDDL validator.
*
* VAL is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* VAL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAL. If not, see <http://www.gnu.org/licenses/>.
*
************************************************************************/
/*-----------------------------------------------------------------------------
VAL - The Automatic Plan Validator for PDDL+
$Date: 2009-02-05 10:50:24 $
$Revision: 1.2 $
Maria Fox, Richard Howey and Derek Long - PDDL+ and VAL
Stephen Cresswell - PDDL Parser
maria.fox@cis.strath.ac.uk
derek.long@cis.strath.ac.uk
stephen.cresswell@cis.strath.ac.uk
richard.howey@cis.strath.ac.uk
By releasing this code we imply no warranty as to its reliability
and its use is entirely at your own risk.
Strathclyde Planning Group
http://planning.cis.strath.ac.uk
----------------------------------------------------------------------------*/
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include "Validator.h"
#include "Action.h"
#include "Utils.h"
#include "typecheck.h"
#include "Exceptions.h"
#include "RobustAnalyse.h"
#include "random.h"
#include <sstream>
using std::stringstream;
using std::make_pair;
//#define map std::map
//#define vector std::vector
namespace VAL {
string getName(plan_step* ps)
{
string actionName = ps->op_sym->getName();
for(typed_symbol_list<const_symbol>::const_iterator j = ps->params->begin();
j != ps->params->end(); ++j)
{
actionName += (*j)->getName();
};
return actionName;
};
struct compareActionEndPoints {
compareActionEndPoints() {};
bool operator()(pair<double,string> a1,pair<double,string> a2) const
{
if(a1.first < a2.first) return true;
return false;
};
};
void changeActionTime(const plan * aPlan, string actionName, double newTime)
{
for(pc_list<plan_step*>::const_iterator i = aPlan->begin(); i != aPlan->end(); ++i)
{
if(getName(*i) == actionName)
{
(*i)->start_time = newTime; (*i)->start_time_given = true;
};
};
};
DerivationRules::DerivationRules(const derivations_list * d,const operator_list * o) : ops(o),derivPreds()
{
drvs = new derivations_list();
for(pc_list<derivation_rule *>::const_iterator i = d->begin(); i != d->end();++i)
{
map<string,pair<const goal *,const var_symbol_table *> >::iterator dp = derivPreds.find((*i)->get_head()->head->getName());
if(dp != derivPreds.end())
{
if(dp->second.second->size() != (*i)->get_head()->args->size())
{
if(LaTeX) *report << "\\\\";
*report << "Derived predicates of the same name must have the same number of parameters!\n";
if(LaTeX) *report << "\\end{document}\n";
DerivedPredicateError dpe;
throw dpe;
};
//change variables of second dp to match that of the first
//parameter_symbol_list::const_iterator k = dp->second.second->begin();
map<string,var_symbol*>::const_iterator k = dp->second.second->begin();
map<parameter_symbol*,parameter_symbol*> newvars;
for(parameter_symbol_list::iterator j = (*i)->get_head()->args->begin(); j != (*i)->get_head()->args->end();++j)
{
if(dynamic_cast<const var_symbol *>(*j))
{
newvars[const_cast<parameter_symbol*>(*j)] = k->second;
};
k++;
};
goal * agoal = const_cast<goal*>(dp->second.first);
goal * bgoal = (*i)->get_body();
changeVars(bgoal,newvars);
goal_list * gl = new goal_list();
//gl->push_back((*i)->get_body());
gl->push_back(agoal);
gl->push_back(bgoal);
const disj_goal * dg = new disj_goal(gl); repeatedDPDisjs.push_back(dg);
for(pc_list<derivation_rule *>::iterator h = drvs->begin(); h != drvs->end();++h)
{
if((*h)->get_head()->head->getName() == dp->first) {(*h)->set_body(const_cast<disj_goal*>(dg)); break;};
};
derivPreds[dp->first] = make_pair(dg,dp->second.second);
}
else
{
//build para list for derived predicate painfully
var_symbol_table * vst = new var_symbol_table();
char count = 41; //to ensure ordering of bindings is correct when vst is looped thro which is a map which orders its loop with its key, (we dont want the name of parameter just var sym address and its order of appearance)
for(parameter_symbol_list::const_iterator j = (*i)->get_head()->args->begin(); j != (*i)->get_head()->args->end();++j)
{
if(dynamic_cast<const var_symbol *>(*j))
{
string s = toString(count++);
(*vst)[s] = const_cast<var_symbol*>(dynamic_cast<const var_symbol *>(*j));
};
};
drvs->push_back(*i);
derivPreds[(*i)->get_head()->head->getName()] = make_pair((*i)->get_body(),vst);
};
};
};
//this changes the bindings of a DP to match the bindings of its disjuctive counterpart as given by the map
void changeVars(goal * g,map<parameter_symbol*,parameter_symbol*> varMap)
{
if(dynamic_cast<const comparison*>(g))
{
const comparison * comp = dynamic_cast<const comparison*>(g);
changeVars(const_cast<expression*>(comp->getLHS()),varMap);
changeVars(const_cast<expression*>(comp->getRHS()),varMap);
};
if(dynamic_cast<const conj_goal *>(g))
{
const conj_goal * cg = dynamic_cast<const conj_goal *>(g);
for(pc_list<goal*>::const_iterator i = cg->getGoals()->begin(); i != cg->getGoals()->end(); ++i)
{
changeVars(*i,varMap);
};
};
if(dynamic_cast<const disj_goal*>(g))
{
const disj_goal * dg = dynamic_cast<const disj_goal *>(g);
for(pc_list<goal*>::const_iterator i = dg->getGoals()->begin(); i != dg->getGoals()->end(); ++i)
{
changeVars(*i,varMap);
};
};
if(dynamic_cast<const neg_goal *>(g))
{
changeVars(const_cast<goal*>(dynamic_cast<const neg_goal *>(g)->getGoal()),varMap);
};
if(dynamic_cast<const imply_goal*>(g))
{
const imply_goal * ig = dynamic_cast<const imply_goal*>(g);
changeVars(const_cast<goal*>(ig->getAntecedent()),varMap);
changeVars(const_cast<goal*>(ig->getConsequent()),varMap);
};
if(dynamic_cast<const simple_goal*>(g))
{
const simple_goal * sg = dynamic_cast<const simple_goal*>(g);
for(parameter_symbol_list::iterator i = sg->getProp()->args->begin(); i != sg->getProp()->args->end();++i)
{
if(dynamic_cast<const var_symbol *>(*i))
{
// *i = varMap[const_cast<var_symbol*>(dynamic_cast<const var_symbol *>(*i))];
map<parameter_symbol*,parameter_symbol*>::const_iterator nv = varMap.find(const_cast<parameter_symbol*>(*i));
if( nv != varMap.end()) *i = nv->second;
};
};
};
if(dynamic_cast<const qfied_goal*>(g))
{
changeVars(const_cast<goal*>(dynamic_cast<const qfied_goal*>(g)->getGoal()),varMap);
};
};
void changeVars(expression * e,map<parameter_symbol*,parameter_symbol*> varMap)
{
if(dynamic_cast<const binary_expression*>(e))
{
const binary_expression * be = dynamic_cast<const binary_expression*>(e);
changeVars(const_cast<expression*>(be->getLHS()),varMap);
changeVars(const_cast<expression*>(be->getRHS()),varMap);
};
if(dynamic_cast<const uminus_expression*>(e))
{
const uminus_expression * ue = dynamic_cast<const uminus_expression*>(e);
changeVars(const_cast<expression*>(ue->getExpr()),varMap);
};
if(dynamic_cast<const func_term*>(e))
{
const func_term * fe = dynamic_cast<const func_term*>(e);
parameter_symbol_list *param_list = const_cast<parameter_symbol_list*>(fe->getArgs());
for(parameter_symbol_list::iterator i = param_list->begin(); i != param_list->end();++i)
{
if(dynamic_cast<const var_symbol *>(*i))
{
//*i = varMap[const_cast<parameter_symbol*>(*i)];
map<parameter_symbol*,parameter_symbol*>::const_iterator nv = varMap.find(const_cast<parameter_symbol*>(*i));
if( nv != varMap.end()) *i = nv->second;
};
};
};
};
bool DerivationRules::stratification() const
{
map<pair<derivation_rule *,derivation_rule *>, unsigned int> analyseDPs;
//order DPs
for(pc_list<derivation_rule *>::const_iterator i = drvs->begin(); i != drvs->end();++i)
{
for(pc_list<derivation_rule *>::const_iterator j = drvs->begin(); j != drvs->end();++j)
{
analyseDPs[make_pair(*i,*j)] = 0;
};
};
for(pc_list<derivation_rule *>::const_iterator j = drvs->begin(); j != drvs->end();++j)
{
for(pc_list<derivation_rule *>::const_iterator i = drvs->begin(); i != drvs->end();++i)
{
unsigned int ijoccurNNF = occurNNF(*i,*j); //i appears in j?
if( ijoccurNNF == 2 )
analyseDPs[make_pair(*i,*j)] = 2;
else if( ijoccurNNF == 1 )
{
if(analyseDPs[make_pair(*i,*j)] < 1) analyseDPs[make_pair(*i,*j)] = 1;
};
};
};
for(pc_list<derivation_rule *>::const_iterator i = drvs->begin(); i != drvs->end();++i)
{
for(pc_list<derivation_rule *>::const_iterator j = drvs->begin(); j != drvs->end();++j)
{
for(pc_list<derivation_rule *>::const_iterator k = drvs->begin(); k != drvs->end();++k)
{
if( analyseDPs[make_pair(*i,*j)] > 0 && analyseDPs[make_pair(*j,*k)] > 0 )
{
unsigned int maxijjk;
if( analyseDPs[make_pair(*i,*j)] > analyseDPs[make_pair(*j,*k)] )
maxijjk = analyseDPs[make_pair(*i,*j)];
else
maxijjk = analyseDPs[make_pair(*j,*k)];
if(maxijjk > analyseDPs[make_pair(*i,*k)] ) analyseDPs[make_pair(*i,*k)] = maxijjk;
};
};
};
};
//check DPs can be stratified
for(pc_list<derivation_rule *>::const_iterator i = drvs->begin(); i != drvs->end();++i)
{
if(analyseDPs[make_pair(*i,*i)] == 2) return false;
};
if(!Verbose || drvs->size() == 0) return true;
//extract stratification
vector< pair<unsigned int,vector<string> > > stratification;
unsigned int level = 1;
map< derivation_rule *, unsigned int> remaining;
for(pc_list<derivation_rule *>::const_iterator i = drvs->begin(); i != drvs->end();++i)
{
remaining[*i] = 1;
};
while(true){
vector<string> stratum;
bool stratfin = true;
vector< derivation_rule *> toRemove;
for(map< derivation_rule *, unsigned int>::const_iterator i = remaining.begin(); i != remaining.end();++i)
{
if(remaining[i->first] == 1) {stratfin = false; break;};
};
if(stratfin) break;
for(map< derivation_rule *, unsigned int>::const_iterator j = remaining.begin(); j != remaining.end();++j)
{
if(remaining[j->first] == 1)
{
bool ijr2 = true;
for(map< derivation_rule *, unsigned int>::const_iterator i = remaining.begin(); i != remaining.end();++i)
{
if(remaining[i->first] == 1 && analyseDPs[make_pair(i->first,j->first)] == 2) ijr2 = false;
};
if(ijr2)
{
stratum.push_back(j->first->get_head()->head->getName());
toRemove.push_back(j->first);
};
};
};
for(vector<derivation_rule *>::const_iterator k = toRemove.begin(); k != toRemove.end(); ++k) remaining[*k] = 0;
stratification.push_back(make_pair(level,stratum));
++level;
};
if(LaTeX)
{
*report<< "\\subsection{Stratification}\n";
for(vector< pair<unsigned int,vector<string> > >::const_iterator i = stratification.begin(); i != stratification.end(); )
{
*report << "{\\bf Strata "<<i->first<<":}\\\\\n ";
for(vector<string>::const_iterator s = i->second.begin(); s != i->second.end(); ++s)
{
*report << *s;
if( s+1 != i->second.end() ) *report <<", ";
};
if( ++i != stratification.end()) *report << "\\\\";
*report << "\n";
};
}
else if(Verbose)
{
cout<< "Stratification\n";
for(vector< pair<unsigned int,vector<string> > >::const_iterator i = stratification.begin(); i != stratification.end(); ++i)
{
cout << "Strata "<<i->first<<": ";
for(vector<string>::const_iterator s = i->second.begin(); s != i->second.end(); ++s)
{
cout << *s;
if( s+1 != i->second.end() ) cout <<", ";
};
cout << "\n\n";
};
};
return true;
};
//first DP appears in DP, negatively, positively or neither?
//0 = does not appear, 2 = appears negatively, 1 = appears positively
unsigned int DerivationRules::occurNNF(derivation_rule * drv1,derivation_rule * drv2) const
{
const goal * g = NNF(new goal(*drv2->get_body()));
bool ans = occur(drv1->get_head()->head->getName(),g);
delete g;
return ans;
};
//0 = does not appear, 2 = appears negatively, 1 = appears positively (as an atom within formula)
unsigned int DerivationRules::occur(string s,const goal * g) const
{
if(dynamic_cast<const comparison*>(g))
{
return 0;
};
if(dynamic_cast<const conj_goal *>(g))
{
const conj_goal * cg = dynamic_cast<const conj_goal *>(g);
unsigned int ans = 0;
for(pc_list<goal*>::const_iterator i = cg->getGoals()->begin(); i != cg->getGoals()->end(); ++i)
{
unsigned int occ = occur(s,*i);
if(occ > ans) ans = occ;
if(ans == 2) break;
};
return ans;
};
if(dynamic_cast<const disj_goal*>(g))
{
const disj_goal * dg = dynamic_cast<const disj_goal*>(g);
unsigned int ans = 0;
for(pc_list<goal*>::const_iterator i = dg->getGoals()->begin(); i != dg->getGoals()->end(); ++i)
{
unsigned int occ = occur(s,*i);
if(occ > ans) ans = occ;
if(ans == 2) break;
};
return ans;
};
if(dynamic_cast<const neg_goal *>(g))
{
const neg_goal * ng = dynamic_cast<const neg_goal *>(g);
if(dynamic_cast<const simple_goal*>(ng->getGoal()) && occur(s,ng->getGoal()) == 1)
return 2;
return occur(s,ng->getGoal());
};
//shouldn't need this if g is in NNF
if(dynamic_cast<const imply_goal*>(g))
{
const imply_goal * ig = dynamic_cast<const imply_goal*>(g);
neg_goal * ng = new neg_goal(const_cast<goal *>(ig->getAntecedent()));
goal_list * gl = new goal_list();
goal * agoal = const_cast<goal *>(ig->getConsequent());
gl->push_back(ng);
gl->push_back(agoal);
const disj_goal * dg = new disj_goal(gl);
return occur(s,dg);
};
if(dynamic_cast<const simple_goal*>(g))
{
const simple_goal * sg = dynamic_cast<const simple_goal*>(g);
if(isDerivedPred(sg->getProp()->head->getName()))
{
if( s == sg->getProp()->head->getName())
{
if(sg->getPolarity()==E_POS)
{
return 1;
}
else
return 2;
};
};
return 0;
};
if(dynamic_cast<const qfied_goal*>(g))
{
const qfied_goal * qg = dynamic_cast<const qfied_goal*>(g);
return occur(s,qg->getGoal());
};
return 0;
};
const goal * DerivationRules::NNF(const goal * gl) const
{
const goal * g = gl;
if(dynamic_cast<const neg_goal *>(g))
{
const goal * ng = (dynamic_cast<const neg_goal *>(g))->getGoal();
if(dynamic_cast<const conj_goal *>(ng))
{
const conj_goal * cg = dynamic_cast<const conj_goal *>(ng);
goal_list * gl = new goal_list();
for(pc_list<goal*>::const_iterator i = cg->getGoals()->begin(); i != cg->getGoals()->end(); ++i)
{
goal * agoal = const_cast<goal *>(NNF(new neg_goal(new goal(*const_cast<goal*>(*i)))));
gl->push_back(agoal);
};
return new disj_goal(gl);
};
if(dynamic_cast<const disj_goal*>(ng))
{
const disj_goal * dg = dynamic_cast<const disj_goal*>(ng);
goal_list * gl = new goal_list();
for(pc_list<goal*>::const_iterator i = dg->getGoals()->begin(); i != dg->getGoals()->end(); ++i)
{
goal * agoal = const_cast<goal *>(NNF(new neg_goal(new goal(*const_cast<goal*>(*i)))));
gl->push_back(agoal);
};
return new conj_goal(gl);
};
if(dynamic_cast<const neg_goal *>(ng))
{
const neg_goal * nng = dynamic_cast<const neg_goal *>(ng);
return NNF(nng->getGoal());
};
if(dynamic_cast<const imply_goal*>(ng))
{
const imply_goal * ig = dynamic_cast<const imply_goal*>(ng);
neg_goal * nng = new neg_goal(const_cast<goal *>(ig->getConsequent()));
goal_list * gl = new goal_list();
goal * agoal = new goal(*const_cast<goal *>(ig->getAntecedent()));
gl->push_back(nng);
gl->push_back(agoal);
const conj_goal * cg = new conj_goal(gl);
return NNF(cg);
};
if(dynamic_cast<const simple_goal*>(ng))
{
return new goal(*g);
};
if(dynamic_cast<const qfied_goal*>(ng))
{
const qfied_goal * qg = dynamic_cast<const qfied_goal*>(ng);
const qfied_goal * ans;
if(qg->getQuantifier() == E_EXISTS)
ans = new qfied_goal(E_FORALL,new var_symbol_list(*const_cast<var_symbol_list*>(qg->getVars())),
const_cast<goal*>(NNF(new neg_goal(const_cast<goal*>(qg->getGoal())))),
new var_symbol_table(*const_cast<var_symbol_table*>(qg->getSymTab())));
else
ans = new qfied_goal(E_EXISTS,new var_symbol_list(*const_cast<var_symbol_list*>(qg->getVars())),
const_cast<goal*>(NNF(new neg_goal(const_cast<goal*>(qg->getGoal())))),
new var_symbol_table(*const_cast<var_symbol_table*>(qg->getSymTab())));
return ans;
};
};
if(dynamic_cast<const imply_goal*>(g))
{
const imply_goal * ig = dynamic_cast<const imply_goal*>(g);
neg_goal * ng = new neg_goal(const_cast<goal *>(ig->getAntecedent()));
goal_list * gl = new goal_list();;
goal * agoal = new goal(*const_cast<goal *>(ig->getConsequent()));
gl->push_back(ng);
gl->push_back(agoal);
const disj_goal * dg = new disj_goal(gl);
return NNF(dg);
};
if(dynamic_cast<const conj_goal *>(g))
{
const conj_goal * cg = dynamic_cast<const conj_goal *>(g);
goal_list * gl = new goal_list();
for(pc_list<goal*>::const_iterator i = cg->getGoals()->begin(); i != cg->getGoals()->end(); ++i)
{
gl->push_back(const_cast<goal*>(NNF(*i)));
};
return new conj_goal(gl);
};
if(dynamic_cast<const disj_goal*>(g))
{
const disj_goal * dg = dynamic_cast<const disj_goal*>(g);
goal_list * gl = new goal_list();
for(pc_list<goal*>::const_iterator i = dg->getGoals()->begin(); i != dg->getGoals()->end(); ++i)
{
gl->push_back(new goal(*const_cast<goal*>(NNF(*i))));
};
return new disj_goal(gl);
};
if(dynamic_cast<const qfied_goal*>(g))
{
const qfied_goal * qg = dynamic_cast<const qfied_goal*>(g);
const qfied_goal * ans;
if(qg->getQuantifier() == E_EXISTS)
ans = new qfied_goal(E_EXISTS,new var_symbol_list(*const_cast<var_symbol_list*>(qg->getVars())),
const_cast<goal*>(NNF(const_cast<goal*>(qg->getGoal()))),
new var_symbol_table(*const_cast<var_symbol_table*>(qg->getSymTab())));
else
ans = new qfied_goal(E_FORALL,new var_symbol_list(*const_cast<var_symbol_list*>(qg->getVars())),
const_cast<goal*>(NNF(const_cast<goal*>(qg->getGoal()))),
new var_symbol_table(*const_cast<var_symbol_table*>(qg->getSymTab())));
return ans;
};
if(dynamic_cast<const simple_goal*>(g))
{
return new goal (*g);
};
return g;
};
bool DerivationRules::isDerivedPred(string s) const
{
bool ans = false;
map<string,pair<const goal *,const var_symbol_table *> >::const_iterator i = derivPreds.find(s);
if(i != derivPreds.end()) ans = true;
return ans;
};
bool DerivationRules::effects(const effect_lists* efflist) const
{
for(pc_list<simple_effect*>::const_iterator e1 = efflist->add_effects.begin(); e1 != efflist->add_effects.end();++e1)
{
if(isDerivedPred((*e1)->prop->head->getName())) return false;
};
for(pc_list<simple_effect*>::const_iterator e2 = efflist->del_effects.begin(); e2 != efflist->del_effects.end();++e2)
{
if(isDerivedPred((*e2)->prop->head->getName())) return false;
};
for(pc_list<forall_effect*>::const_iterator e3 = efflist->forall_effects.begin(); e3 != efflist->forall_effects.end();++e3)
{
if(!effects((*e3)->getEffects())) return false;
};
for(pc_list<cond_effect*>::const_iterator e4 = efflist->cond_effects.begin(); e4 != efflist->cond_effects.end();++e4)
{
if(!effects((*e4)->getEffects())) return false;
};
for(pc_list<assignment*>::const_iterator e5 = efflist->assign_effects.begin(); e5 != efflist->assign_effects.end();++e5)
{
if(isDerivedPred((*e5)->getFTerm()->getFunction()->getName())) return false;
};
return true;
};
bool DerivationRules::effects() const
{
//check that derived predicates are not used in effects
for(pc_list<operator_*>::const_iterator i = ops->begin(); i != ops->end();++i)
{
for(pc_list<simple_effect*>::const_iterator e1 = (*i)->effects->add_effects.begin(); e1 != (*i)->effects->add_effects.end();++e1)
{
if(isDerivedPred((*e1)->prop->head->getName())) return false;
};
for(pc_list<simple_effect*>::const_iterator e2 = (*i)->effects->del_effects.begin(); e2 != (*i)->effects->del_effects.end();++e2)
{
if(isDerivedPred((*e2)->prop->head->getName())) return false;
};
for(pc_list<forall_effect*>::const_iterator e3 = (*i)->effects->forall_effects.begin(); e3 != (*i)->effects->forall_effects.end();++e3)
{
if(!effects((*e3)->getEffects())) return false;
};
for(pc_list<cond_effect*>::const_iterator e4 = (*i)->effects->cond_effects.begin(); e4 != (*i)->effects->cond_effects.end();++e4)
{
if(!effects((*e4)->getEffects())) return false;
};
for(pc_list<assignment*>::const_iterator e5 = (*i)->effects->assign_effects.begin(); e5 != (*i)->effects->assign_effects.end();++e5)
{
if(isDerivedPred((*e5)->getFTerm()->getFunction()->getName())) return false;
};
};
return true;
};
DerivationRules::~DerivationRules()
{
drvs->clear(); delete drvs;
for(map<string,pair<const goal *,const var_symbol_table *> >::iterator i = derivPreds.begin(); i != derivPreds.end(); ++i)
{
delete i->second.second;
};
for(vector<const disj_goal *>::iterator j = repeatedDPDisjs.begin(); j != repeatedDPDisjs.end(); ++j)
{
const_cast<goal_list*>((*j)->getGoals())->clear();
delete (*j);
};
};
Validator::~Validator()
{
for(vector<Action*>::iterator i = actionRegistry.begin();i != actionRegistry.end();++i)
{
delete (*i);
};
for(map<const FuncExp *,FEGraph *>::iterator j = graphs.begin(); j != graphs.end(); ++j)
{
delete j->second;
};
graphs.clear();
Environment::collect(this);
delete finalInterestingState;
};
bool DerivationRules::checkDerivedPredicates() const
{
if(!effects())
{
if(LaTeX) *report << "\\\\";
*report << "A derived predicate appears as an effect!\n";
return false;
};
if(!stratification())
{
if(LaTeX) *report << "\\\\";
*report << "The set of derived predicates do not form a stratified set!\n";
return false;
};
return true;
};
FEGraph::~FEGraph()
{
};
Gantt::~Gantt()
{
for(map<int, map<int, GanttElement *> >::iterator i = chartRows.begin(); i != chartRows.end(); ++i)
{
for(map<int, GanttElement *>::iterator j = i->second.begin(); j != i->second.end(); ++j)
{
delete j->second;
};
};
};
const double FEGraph::graphMaxH = 4;
const double FEGraph::graphMaxV = 2;
const int FEGraph::pointSize = 100;
const double Gantt::graphH = 4.5;
const double Gantt::graphV = 7.2;
const int Gantt::pointSize = 100;
bool Validator::execute()
{
bool isOK = true;
if(theplan.length() == 0) return isOK;
// cout << "STATE CURRENTLY: " << state << "\n";
if(LaTeX)
{
setMaxTime(); //needed for drawing graphs
*report << "\\begin{tabbing}\n";
*report << "\\headingtimedetails \n";
}
else if(Verbose) cout << "Plan Validation details\n-----------------------\n";
if(finalInterestingState) delete finalInterestingState;
finalInterestingState = 0;
followUp = theplan.end();
bool isReg;
isOK = events.triggerInitialEvents(this,thisStep.getTime());
//main loop of plan execution
while(thisStep != theplan.end())