forked from anubhav-gres/VAL-4.2.08
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaluator.cpp
217 lines (188 loc) · 5.28 KB
/
Evaluator.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
/************************************************************************
* 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 "Evaluator.h"
#include "TypedAnalyser.h"
#include "State.h"
#include "ptree.h"
#include "instantiation.h"
#include "InstPropLinker.h"
#include "Validator.h"
using namespace VAL;
namespace Inst {
Evaluator::Evaluator(Validator * v,const VAL::State * s,Inst::instantiatedOp * op,bool im) :
vld(v), value(true), env(toEnv(op)), f(op->getEnv()), state(s),
equality(VAL::current_analysis->pred_tab.symbol_probe("=")),
ignoreMetrics(im), context(true)
{};
void Evaluator::visit_preference(preference * p)
{};
void Evaluator::visit_simple_goal(simple_goal * s)
{
// cout << "Evaluating " << *s << " in state " << *state << "\n";
if(EPS(s->getProp()->head)->getParent() == this->equality)
{
// cout << "Got equality\n";
value = ((*f)[s->getProp()->args->front()] ==
(*f)[s->getProp()->args->back()]);
if(s->getPolarity() == E_NEG)
{
value = !value;
};
return;
};
// Evaluate the goal in the state
const SimpleProposition * sp = vld->pf.buildLiteral(s->getProp(),env);
value = state->evaluate(sp);
if(s->getPolarity() == E_NEG)
{
value = !value;
};
// cout << "Value determined as: " << value << "\n";
};
void Evaluator::visit_qfied_goal(qfied_goal * q)
{
cout << "Evaluator (line 70): Not handling quantified goals yet!\n";
for(var_symbol_list::const_iterator i = q->getVars()->begin();
i != q->getVars()->end();++i)
{
cout << "Got: " << static_cast<const IDsymbol<var_symbol> *>(*i)->getId() << "\n";
};
};
void Evaluator::visit_conj_goal(conj_goal * c)
{
value = true;
for(goal_list::const_iterator i = c->getGoals()->begin();
i != c->getGoals()->end();++i)
{
(*i)->visit(this);
if(!value) return;
};
};
void Evaluator::visit_disj_goal(disj_goal * d)
{
value = false;
for(goal_list::const_iterator i = d->getGoals()->begin();
i != d->getGoals()->end();++i)
{
(*i)->visit(this);
if(value) return;
};
};
void Evaluator::visit_timed_goal(timed_goal * t)
{
t->getGoal()->visit(this);
};
void Evaluator::visit_imply_goal(imply_goal * ig)
{
context = !context;
ig->getAntecedent()->visit(this);
context = !context;
if(value)
{
ig->getConsequent()->visit(this);
}
else value = true;
};
void Evaluator::visit_neg_goal(neg_goal * ng)
{
context = !context;
ng->getGoal()->visit(this);
context = !context;
value = !value;
};
void Evaluator::visit_event(event * op)
{
value = true;
op->precondition->visit(this);
};
void Evaluator::visit_process(process * op)
{
value = true;
op->precondition->visit(this);
};
void Evaluator::visit_comparison(comparison * comp)
{
// Note: Could avoid dual visits by doing parallel evaluation with and without metrics
if(ignoreMetrics)
{
value = context;
};
// Problem: Really this works for continuous change - should do proper evaluations
// for discretely changing values.
double eval = state->evaluate(comp->getLHS(),env) - state->evaluate(comp->getRHS(),env);
double tooSmall = 0.00001;
switch(comp->getOp())
{
case E_GREATER:
value = (eval > -tooSmall);
if(value && eval <= 0)
{
cout << "Sloppy evaluation disagrees: " << eval << " > 0\n";
};
return;
case E_GREATEQ:
value = (eval >= -tooSmall);
if(value && eval < 0)
{
cout << "Sloppy evaluation disagrees: " << eval << " >= 0\n";
};
return;
case E_LESS:
value = (eval < tooSmall);
if(value && eval >= 0)
{
cout << "Sloppy evaluation disagrees: " << eval << " < 0\n";
};
return;
case E_LESSEQ:
value = (eval <= tooSmall);
if(value && eval > 0)
{
cout << "Sloppy evaluation disagrees: " << eval << " <= 0\n";
};
return;
case E_EQUALS:
value = (eval < tooSmall && eval > -tooSmall);
if(value && eval != 0)
{
cout << "Sloppy evaluation disagrees: " << eval << " = 0\n";
};
return;
default:
return;
};
};
void Evaluator::visit_action(action * op)
{
value = true;
op->precondition->visit(this);
};
void Evaluator::visit_durative_action(durative_action * da)
{
value = true;
da->precondition->visit(this);
};
};