-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathHTNMethod.cpp
71 lines (57 loc) · 1.51 KB
/
HTNMethod.cpp
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
#include "Domain.h"
void HTNMethod::SHOPPrint( std::ostream & s, unsigned indent, const TokenStruct< std::string > & ts, Domain & d ) {
s << "( :METHOD (" << name << " ";
//params
TokenStruct< std::string > astruct;
std::stringstream ss;
printParams( 0, s, astruct, d );
s<<")\n";
//preconds
if ( pre ) pre->PDDLPrint( s, 1, astruct, d );
else s << "\t()";
s << "\n";
//tasks
if ( tasks.size() > 0 ){
s << "\t( ";
for(unsigned i=0;i<tasks.size();++i)
tasks[i]->SHOPPrint( s, 1, astruct, d );
s << " )";
}
else s << "\t()";
s << "\n";
s << ")\n";
}
void HTNMethod::SHOPparse( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) {
TokenStruct< std::string > astruct = f.parseTypedList( false );
params = d.convertTypes( astruct.types );
parseSHOPConditions( f, astruct, d );
parseTaskList( f, astruct, d );
}
void HTNMethod::parseSHOPConditions( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) {
f.next();
f.assert( "(" );
if ( f.getChar() != ')' ) {
if(f.getChar() == '('){
pre = new And;
}
else
pre = createSHOPCondition( f, d );
pre->SHOPparse( f, ts, d );
}
else ++f.c;
}
void HTNMethod::parseTaskList( Filereader & f, TokenStruct< std::string > & ts, Domain & d ) {
f.next();
f.assert( "(" );
for ( f.next(); f.getChar() != ')'; f.next() ) {
f.assert( "(" );
std::string s = f.getToken();
Task * task = new Task(s);
task->SHOPparse( f, ts, d );
tasks.push_back( task );
d.tasks.insert( task );
}
++f.c;
f.next();
f.assert( ")" );
}