-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTypedAnalyser.cpp
282 lines (257 loc) · 7.43 KB
/
TypedAnalyser.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
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
/************************************************************************
* 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/>.
*
************************************************************************/
#include "TypedAnalyser.h"
namespace VAL {
ostream & operator<<(ostream & o,const SimplePropStore * sp)
{
sp->write(o);
return o;
};
ostream & operator<<(ostream & o,const SimplePropStore & sp)
{
sp.write(o);
return o;
};
void cwrite(const pddl_type * p,ostream & o)
{
o << p->getName();
};
CompoundPropStore::CompoundPropStore(int c,vector<pair<pddl_type *,vector<const pddl_type *> > > & tps,TMap & t,extended_pred_symbol * e,Associater * a) :
PropStore(), stores(c)
{
int arity = tps.size();
vector<pddl_type *> tps1;
for(int i = 0;i < c;++i)
{
tps1.clear();
TypeExtractor tex(tps,i);
while(!(tex == TypeExtractor(arity)))
{
pddl_type * tt = *tex;
// cout << "Got " << tt->getName() << "\n";
tps1.push_back(tt);
++tex;
};
// if(e->getName()=="can-carry")
// {
// t.write(cout);
// };
SimplePropStore * s = t.get(tps1.begin(),tps1.end());
if(!s)
{
// cout << "About to find\n";
extended_pred_symbol * f = a->find(e,tps1.begin(),tps1.end());
if(!f->getParent())
{
e->getParent()->add(f);
};
// cout << "Ready to record ";
// f->writeName(cout);
// cout << "\n";
s = new SimplePropStore(f);
// TypeExtractor te(tps,i);
// cout << "building for ";
// while(!(te == TypeExtractor(arity)))
// {
// cout << (*te)->getName() << " ";
// ++te;
// };
// cout << "\n";
t.insert(tps1.begin(),tps1.end(),s);
};
stores[i] = s;
records.insert(tps1.begin(),tps1.end(),s);
};
};
PropStore * extended_pred_symbol::records() const
{
if(!props)
{
const_cast<extended_pred_symbol*>(this)->props =
parent->buildPropStore(const_cast<extended_pred_symbol*>(this),types.begin(),types.end());//types);
};
return props;
};
PropStore * extended_pred_symbol::getAt(double t) const
{
if(timedInitials.find(t) == timedInitials.end())
{
extended_pred_symbol * tmp = const_cast<extended_pred_symbol *>(this);
PropStore * nps = parent->buildPropStore(tmp,types,t);
tmp->timedInitials[t] = nps;
return nps;
}
else
{
return timedInitials.find(t)->second;
};
};
vector<double> extended_pred_symbol::getTimedAchievers(Environment * f,const proposition * prop) const
{
vector<double> tms;
if(records()->get(f,prop))
{
tms.push_back(0);
};
for(map<double,PropStore *>::const_iterator i = timedInitials.begin();i != timedInitials.end();++i)
{
if(i->second->get(f,prop))
{
tms.push_back(i->first);
};
};
return tms;
};
PropInfoFactory * PropInfoFactory::pf = 0;
auto_ptr<EPSBuilder> Associater::buildEPS(new EPSBuilder());
// Associater associates predicates with their various type-specific versions.
// So, if a predicate is overloaded to work with multiple types this will store
// a tree structured association, indexed by types, down to an extended_pred_symbol
// that is the substitute predicate symbol for the specific type sequence.
Associater * Associater::handle(proposition * p)
{
// cout << "A-handle " << p->head->getName() << "\n";
Associater * a = this;
if(p->args->empty())
{
LeafAssociater * lf = dynamic_cast<LeafAssociater*>(this);
if(lf)
{
p->head = lf->get();
return this;
};
a =0;
};
parameter_symbol_list::iterator i = p->args->begin();
while(i != p->args->end())
{
pddl_type * t = (*i)->type;
// cout << "T " << t->getName() << "\n";
++i;
Associater * aa = a->lookup(t);
if(!aa)
{
if(i == p->args->end())
{
aa = new LeafAssociater(p->head,p);
}
else
{
aa = new NodeAssociater();
};
a->set(t,aa);
};
a = aa;
};
if(a)
{
if (!a->get()) {
std::cerr << "A problem has been encountered with your domain/problem file.\n";
std::cerr << "-------------------------------------------------------------\n";
std::cerr << "Unfortunately, a bug has been encountered in your domain and problem file,\n";
std::cerr << "and the planner has to terminate. The proposition:\n\n\t";
{
std::cerr << "(" << p->head->getName();
if (p->args) {
parameter_symbol_list::iterator pItr = p->args->begin();
const parameter_symbol_list::iterator pEnd = p->args->end();
for (; pItr != pEnd; ++pItr) {
std::cerr << " " << (*pItr)->getName();
}
}
std::cerr << ")\n\n";
}
std::cerr << "... cannot be mapped to any of the predicate declarations in the domain,\n";
std::cerr << "due to having the wrong number of arguments and/or wrong argument types.\n";
exit(0);
} else {
HPS(p->head)->add(a->get());
p->head = a->get();
return this;
}
}
else
{
a = new LeafAssociater(p->head,p);
if (!a->get()) {
std::cerr << "A problem has been encountered with your domain/problem file.\n";
std::cerr << "-------------------------------------------------------------\n";
std::cerr << "Unfortunately, a bug has been encountered in your domain and problem file,\n";
std::cerr << "and the planner has to terminate. The proposition:\n\n\t";
{
std::cerr << "(" << p->head->getName();
if (p->args) {
parameter_symbol_list::iterator pItr = p->args->begin();
const parameter_symbol_list::iterator pEnd = p->args->end();
for (; pItr != pEnd; ++pItr) {
std::cerr << " " << (*pItr)->getName();
}
}
std::cerr << ")\n\n";
}
std::cerr << "... cannot be mapped to any of the predicate declarations in the domain,\n";
std::cerr << "due to having the wrong number of arguments and/or wrong argument types.\n";
exit(0);
}
if(p->args->empty()) HPS(p->head)->add(a->get());
p->head = a->get();
return a;
};
};
void CompoundPropStore::notify(void(extended_pred_symbol::*f)(operator_ *,const proposition *),
operator_ * o,const proposition * p)
{
// cout << "Notifying compound about " << *p << "\n";
for(vector<SimplePropStore *>::iterator i = stores.begin();i != stores.end();++i)
{
// cout << "?";
extended_pred_symbol * ep = (*i)->getEP();
if(ep)
{
// cout << "Notification\n";
(ep->*f)(o,p);
};
};
};
void cwrite(const parameter_symbol * p,ostream & o)
{
o << p->getName();
};
PropInfo * SimplePropStore::partialGet(FastEnvironment * f,const proposition * prop) const
{
return records.partialGet(makeIterator(f,prop->args->begin()),
makeIterator(f,prop->args->end()));
};
PropInfo * CompoundPropStore::partialGet(FastEnvironment * f,const proposition * prop) const
{
for(vector<SimplePropStore *>::const_iterator s = stores.begin();s != stores.end();++s)
{
PropInfo * u = (*s)->partialGet(f,prop);
if(u) return u;
};
return 0;
};
};