forked from anubhav-gres/VAL-4.2.08
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOwnership.cpp
More file actions
546 lines (496 loc) · 13.6 KB
/
Copy pathOwnership.cpp
File metadata and controls
546 lines (496 loc) · 13.6 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
/************************************************************************
* 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:20 $
$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 "Ownership.h"
#include "Validator.h"
#include "Action.h"
#include "FuncExp.h"
#include "Environment.h"
#include "Proposition.h"
using std::make_pair;
using std::cerr;
namespace VAL {
bool
Ownership::ownsForAdd(const Action * a,const SimpleProposition * p)
{
map<const SimpleProposition *,pair<const Action *,ownership> >::iterator po = propOwner.find(p);
if(po != propOwner.end())
{
if(po->second.first != a && po->second.second != E_ADD)
{
// Different action wants to use the same proposition.
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{Mutex violation: \\action{" << *a << "} (adds \\exprn{" << *p << "})";
if(po->second.first) *report << " and \\exprn{" << po->second.first << "}\n";
*report << "}\\\\";
}
else
{
cout << "Mutex violation: " << *a << " (adds " << *p << ")";
if(po->second.first) cout << " and " << po->second.first << "\n";
};
*report << "\n";
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,po->second.first,&(vld->getState()));
return false;
};
switch(po->second.second)
{
case E_PPRE:
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} adds a precondition literal \\exprn{"
<< *p << "}}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " adds a precondition literal "
<< *p << "\n";
};
};
case E_PRE:
case E_NPRE:
po->second.second = E_ADD;
return true;
case E_DEL:
// Action deletes and adds the same literal.
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} adds and deletes the literal \\exprn{"
<< *p << "}}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " adds and deletes the literal "
<< *p << "\n";
};
};
return true;
case E_ADD:
// Action adds the same literal twice.
if(Verbose)
{
if(po->second.first == a)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} adds the literal \\exprn{"
<< *p << "} twice}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " adds the literal "
<< *p << " twice\n";
};
}
else
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} and \\action{" << *(po->second.first)
<< "} both add the literal \\exprn{"
<< *p << "}}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " and " << *(po->second.first)
<< " both add the literal "
<< *p << "\n";
};
};
};
return true;
default:
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,po->second.first,&(vld->getState()));
return false;
};
}
else
{
propOwner[p] = make_pair(a,E_ADD);
return true;
};
};
bool
Ownership::ownsForDel(const Action * a,const SimpleProposition * p)
{
map<const SimpleProposition *,pair<const Action *,ownership> >::iterator po = propOwner.find(p);
if(po != propOwner.end())
{
if(po->second.first != a && po->second.second != E_DEL)
{
// Different action wants to use the same proposition.
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{Mutex violation: \\action{" << a
<< "} (deletes \\exprn{" << *p << "})";
if(po->second.first) *report << " and \\exprn{" << po->second.first << "}}\\\\";
}
else
{
cout << "Mutex violation: " << a << " (deletes " << *p << ")";
if(po->second.first) cout << " and " << po->second.first;
};
*report << "\n";
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,po->second.first,&(vld->getState()));
return false;
};
switch(po->second.second)
{
case E_NPRE:
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} deletes a false precondition literal \\exprn{"
<< *p << "}}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " deletes a false precondition literal "
<< *p << "\n";
};
};
case E_PPRE:
case E_PRE:
po->second.second = E_DEL;
return true;
case E_DEL:
// Action deletes the same literal twice.
if(Verbose)
{
if(po->second.first == a)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} deletes the literal \\exprn{"
<< *p << "} twice}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " deletes the literal "
<< *p << " twice\n";
};
}
else
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} and \\action{" << *(po->second.first)
<< "} both delete the literal \\exprn{"
<< *p << "}}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " and " << *(po->second.first)
<< " both delete the literal "
<< *p << "\n";
};
};
};
return true;
case E_ADD:
// Action adds and deletes the same literal.
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} adds and deletes the literal \\exprn{"
<< *p << "}}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " adds and deletes the literal "
<< *p << "\n";
};
};
return true;
default:
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,po->second.first,&(vld->getState()));
return false;
};
}
else
{
propOwner[p] = make_pair(a,E_DEL);
return true;
};
};
bool Ownership::markOwnedPrecondition(const Action * a,const SimpleProposition * p,ownership o)
{
map<const SimpleProposition *,pair<const Action *,ownership> >::const_iterator po = propOwner.find(p);
if(po != propOwner.end())
{
if(po->second.second == E_PRE || po->second.second == E_NPRE
|| po->second.second == E_PPRE)
{
if(po->second.first != a) propOwner[p] = make_pair(static_cast<const Action *>(0),o);
return true;
}
else
{
if(Verbose && po->second.first != a)
{
if(LaTeX)
{
*report << " \\> \\listrow{Mutex violation: \\action{" << a
<< "} (requires \\exprn{" << p << "})}\\\\\n";
}
else
{
cout << "Mutex violation: " << a << " (requires " << p << ")\n";
};
};
if((po->second.first != a) && ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,po->second.first,&(vld->getState()));
return po->second.first == a;
};
}
else
{
propOwner[p] = make_pair(a,o);
return true;
};
};
bool Ownership::markOwnedPreconditionFEs(const Action * a,const expression * e,const Environment & bs)
{
if(dynamic_cast<const num_expression *>(e)) return true;
if(const func_term * fe = dynamic_cast<const func_term *>(e))
{
const FuncExp * fexp = vld->fef.buildFuncExp(fe,bs);
if(FEOwner.find(fexp) != FEOwner.end())
{
if(FEOwner[fexp].first == a)
return true;
if(FEOwner[fexp].second == E_PRE)
{
FEOwner[fexp] = make_pair(static_cast<const Action *>(0),E_PRE);
return true;
}
else
{
if(LaTeX)
{
*report << " \\> \\listrow{Mutex violation: \\action{" << a
<< "} (requires \\fexprn{" << *fexp << "})}\\\\\n";
}
else
{
if(Verbose) cout << "Mutex violation: " << a << " (requires " << *fexp << ")\n";
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,0,&(vld->getState()));
return false;
};
}
else
{
FEOwner[fexp] = make_pair(a,E_PRE);
return true;
};
};
if(const binary_expression * bexp = dynamic_cast<const binary_expression *>(e))
{
return markOwnedPreconditionFEs(a,bexp->getLHS(),bs) &&
markOwnedPreconditionFEs(a,bexp->getRHS(),bs);
};
if(const uminus_expression * uexp = dynamic_cast<const uminus_expression *>(e))
{
return markOwnedPreconditionFEs(a,uexp->getExpr(),bs);
};
if(dynamic_cast<const special_val_expr *>(e))
{
return true;
};
if(Verbose)
{
if(LaTeX) *report << " \\> ";
*report << "Unrecognised expression type\n";
if(LaTeX) *report << " \\\\";
};
UnrecognisedCondition uc;
throw uc;
};
bool Ownership::markOwnedEffectFE(const Action * a,const FuncExp * fe,assign_op aop,
const expression * e,const Environment & bs)
{
if(!markOwnedPreconditionFEs(a,e,bs))
{
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{Conflict over ownership of resource: \\fexprn{"
<< *fe << "} wanted by \\action{" << a << "}}\\\\\n";
}
else
{
cout << "Conflict over ownership of resource: " << *fe << " wanted by " << a << "\n";
};
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,0,&(vld->getState()));
return false;
};
if(FEOwner.find(fe) != FEOwner.end())
{
if(FEOwner[fe].first != a)
{
if(FEOwner[fe].second == E_ADD && (aop == E_INCREASE || aop == E_DECREASE))
{
// Commuting additive assignments are OK.
FEOwner[fe].first = static_cast<const Action *>(0);
return true;
};
// Different action wants to use the same FE for conflicting uses.
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{Mutex violation: \\action{" << a
<< "} (expression \\fexprn{" << *fe << "})";
if(FEOwner[fe].first) *report << " and \\fexprn{" << FEOwner[fe].first << "}";
*report << "}\\\\";
}
else
{
cout << "Mutex violation: " << a << " (expression " << *fe << ")";
if(FEOwner[fe].first) cout << " and " << FEOwner[fe].first;
};
*report << "\n";
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,0,&(vld->getState()));
return false;
};
switch(FEOwner[fe].second)
{
case E_PRE:
if(aop == E_INCREASE || aop == E_DECREASE)
{
FEOwner[fe].second = E_ADD;
}
else
{
FEOwner[fe].second = E_ASSIGNMENT;
};
return true;
case E_ADD:
// Action deletes the same literal twice.
if(aop != E_INCREASE && aop != E_DECREASE)
{
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{\\action{"<< *a
<< "} both assigns to and updates expression \\fexprn{" << *fe << "}}\\\\\n";
}
else
{
cout << *a << " both assigns to and updates expression " << *fe << "\n";
};
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,0,&(vld->getState()));
return false;
};
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{WARNING: \\action{" << *a
<< "} assigns to expression \\fexprn{"
<< *fe << "} twice}\\\\\n";
}
else
{
cout << "WARNING: " << *a << " assigns to expression "
<< *fe << "twice\n";
};
};
return true;
case E_ASSIGNMENT:
// Action assigns to expression twice.
if(Verbose)
{
if(LaTeX)
{
*report << " \\> \\listrow{\\action{"<< *a
<< "} assigns to expression \\fexprn{" << *fe << "} twice}\\\\\n";
}
else
{
cout << *a << " assigns to expression " << *fe << " twice\n";
};
};
if(ErrorReport) vld->getErrorLog().addMutexViolation(vld->getCurrentHappeningTime(),a,0,&(vld->getState()));
return false;
default:
if(Verbose)
{
if(LaTeX) *report << " \\> \\listrow{";
*report << "Unknown expression type in " << a << "\n";
if(LaTeX) *report << "}\\\\";
};
UnrecognisedCondition uc;
throw uc;
};
}
else
{
FEOwner[fe] = make_pair(a,(aop==E_INCREASE || aop==E_DECREASE)?E_ADD:E_ASSIGNMENT);
return true;
};
};
};