-
Notifications
You must be signed in to change notification settings - Fork 2
/
derived_actions.h
96 lines (76 loc) · 3.13 KB
/
derived_actions.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
#ifndef DERIVED_H
#define DERIVED_H
#include "actions.h"
class DerivedActions : public Actions{
public:
DerivedActions( parser::pddl::Domain *_od, parser::pddl::Domain *_cd ): Actions( _od, _cd ){}
void createEvalActions( const String &name ){
//String name = "DERIVED-EVALUATION";
parser::pddl::Action *act = createAction( name , StringVec( 1, "STACKROW" ) );
addPrecondition( name, "TODO-DERIVED" );
addPrecondition( name, "TOP-STACK", false, IntVec( 1, 0 ) );
addEffect( name, "DONE-DERIVED" );
addEffect( name, "TODO-DERIVED", true );
// Derived predicates as conditional effects of derived evaluation
for ( unsigned derived_id = 0; derived_id < od->derived.size(); derived_id++ ){
//if( d->derived[ derived_id ]->name != prefix_name ) continue;
String derived_name = od->derived[ derived_id ]->name;
unsigned dsize = od->derived[ derived_id ]->params.size();
if( dsize == 0 ){
( ( parser::pddl::And * )act->eff )->add( new parser::pddl::Not( cd->ground( derived_name, IntVec() ) ) );
}
else{
parser::pddl::Forall *f = new parser::pddl::Forall;
f->params = od->derived[ derived_id ]->params;
//f->addParams( 0, 1 );
f->cond = new parser::pddl::And;
( ( parser::pddl::And * )f->cond )->add( new parser::pddl::Not( cd->ground( derived_name, incvec( 1 , dsize + 1 ) ) ) );
( ( parser::pddl::And * ) act->eff)->add( f );
}
parser::pddl::Exists * exists = dynamic_cast< parser::pddl::Exists * >( od->derived[ derived_id ]->cond );
//Forall * forall = dynamic_cast< Forall * >( od->derived[ derived_id ]->cond );
if ( exists ) { // Originally is an Exists
parser::pddl::When *w = new parser::pddl::When;
w->pars = exists->cond->copy( *cd );
w->cond = new parser::pddl::And;
( ( parser::pddl::And *) w->cond)->add( cd->ground( derived_name, incvec( 0 , dsize ) ) );
//w->addParams( dsize, 1 );
w->addParams( 0, 1 );
parser::pddl::Forall * f = new parser::pddl::Forall;
//f->params = exists->params;
for( int i : od->derived[ derived_id ]->params )
f->params.push_back( i );
for( int i : exists->params )
f->params.push_back( i );
f->cond = w;
addStackRow( f, 0 );
( ( parser::pddl::And * )act->eff )->add( f );
}
/*else if( forall ){ // Originally is a Forall (Not tested)
When *w = new When;
//w->pars = forall->cond->copy( *cd );
w->pars = forall->cond;
w->cond = new And;
( ( And *) w->cond)->add( cd->ground( derived_name, incvec( 0 , dsize ) ) );
Forall * f = new Forall;
f->params = od->derived[ derived_id ]->params;
for( int i : forall->params )
f->params.push_back( i );
f->cond = w;
f->addParams( 0, 1 );
addStackRow( f, 0 );
( ( And * )act->eff )->add( f );
}*/
else { // Originally is a When
parser::pddl::When *w = new parser::pddl::When;
w->pars = od->derived[ derived_id ]->cond->copy( *cd );
w->cond = new parser::pddl::And;
( ( parser::pddl::And *) w->cond)->add( cd->ground( derived_name, incvec( 0 , dsize ) ) );
w->addParams( 0, 1 );
addStackRow( w, 0 );
( ( parser::pddl::And * )act->eff )->add( w );
}
}
}
};
#endif