1
1
2
2
#pragma once
3
3
4
+ #include < stdio.h>
5
+ #include < stdlib.h>
6
+
4
7
#include < iomanip>
5
8
#include < unordered_set>
6
9
@@ -192,9 +195,10 @@ public:
192
195
// !
193
196
unsigned _max_width;
194
197
195
- Config (int bound, bool complete, bool mark_negative) :
196
- _bound (bound), _complete(complete), _mark_negative(mark_negative), _max_width(1 ) {}
198
+ bool _use_goal_directed_info;
197
199
200
+ Config (int bound, bool complete, bool mark_negative, unsigned max_width, bool goal_directed_info) :
201
+ _bound (bound), _complete(complete), _mark_negative(mark_negative), _max_width(max_width), _use_goal_directed_info(goal_directed_info) {}
198
202
199
203
};
200
204
@@ -203,7 +207,9 @@ protected:
203
207
Config _config;
204
208
205
209
// ! _all_paths[i] contains all paths in the simulation that reach a node that satisfies goal atom 'i'.
206
- // std::vector<std::vector<NodePT>> _all_paths;
210
+ // std::vector<std::vector<NodePT>> _all_paths;
211
+
212
+ std::vector<NodePT> _optimal_paths;
207
213
208
214
// ! '_unreached' contains the indexes of all those goal atoms that have yet not been reached.
209
215
// TODO REMOVE
@@ -239,6 +245,7 @@ public:
239
245
Base (model, OpenListT(), ClosedListT()),
240
246
_config (config),
241
247
// _all_paths(model.num_subgoals()),
248
+ _optimal_paths (model.num_subgoals()),
242
249
_unreached (),
243
250
_in_seed (model.num_subgoals(), false ),
244
251
// _visited(),
@@ -267,14 +274,13 @@ public:
267
274
268
275
269
276
// ! Mark all atoms in the path to some goal. 'seed_nodes' contains all nodes satisfying some subgoal.
270
- std::vector<bool > compute_relevant_w1_atoms ( const std::vector<NodePT >& seed_nodes ) const {
277
+ void mark_atoms_in_path_to_subgoal ( const std::vector<NodePT>& seed_nodes, std::vector<bool >& atoms ) const {
271
278
const AtomIndex& index = Problem::getInstance ().get_tuple_index ();
272
279
std::unordered_set<NodePT> all_visited;
273
- std::vector< bool > seen_atoms ( index .size ());
280
+ assert (atoms. size () == index .size ());
274
281
275
282
for (NodePT node:seed_nodes) {
276
283
277
-
278
284
NodePT root = node;
279
285
// We ignore s0
280
286
while (node->has_parent ()) {
@@ -287,44 +293,87 @@ public:
287
293
for (unsigned var = 0 ; var < state.numAtoms (); ++var) {
288
294
if (state.getValue (var) == 0 ) continue ; // TODO THIS WON'T GENERALIZE WELL TO FSTRIPS DOMAINS
289
295
AtomIdx atom = index .to_index (var, state.getValue (var));
290
- seen_atoms [atom] = true ;
296
+ atoms [atom] = true ;
291
297
}
292
298
293
299
node = node->parent ;
294
300
}
295
301
}
296
- return seen_atoms;
302
+ }
303
+
304
+
305
+ std::vector<bool > compute_R (const StateT& seed) {
306
+ if (_config._use_goal_directed_info ) {
307
+ return compute_goal_directed_R (seed);
308
+ } else {
309
+ return compute_R_IW1 (seed);
310
+ }
297
311
}
298
312
299
313
std::vector<bool > compute_R_IW1 (const StateT& seed) {
314
+ LPT_INFO (" cout" , " IW Simulation - Computing blind R" );
300
315
_config._max_width = 1 ;
301
316
_config._bound = -1 ; // No bound
302
- std::vector<NodePT> w1_seed_nodes ;
303
- compute_R (seed, w1_seed_nodes );
304
-
305
- // auto rset = compute_relevant_w1_atoms(w1_seed_nodes );
306
- auto rset = _evaluator.reached_atoms ();
307
- LPT_INFO (" cout" , " IW Simulation - |R_{IW(1)}| = " << std::count (rset .begin (), rset .end (), true )); // TODO REMOVE THIS, IT'S EXPENSIVE
308
- return rset ;
317
+ std::vector<NodePT> seed_nodes ;
318
+ _compute_R (seed, seed_nodes );
319
+
320
+ LPT_INFO ( " cout " , " IW Simulation - Number of seed nodes: " << seed_nodes. size () );
321
+ std::vector< bool > rel_blind = _evaluator.reached_atoms ();
322
+ LPT_INFO (" cout" , " IW Simulation - Blind |R| = " << std::count (rel_blind .begin (), rel_blind .end (), true ));
323
+ return rel_blind ;
309
324
}
325
+
326
+ std::vector<bool > compute_goal_directed_R (const StateT& seed) {
327
+ LPT_INFO (" cout" , " IW Simulation - Computing goal-directed R" );
328
+ const AtomIndex& index = Problem::getInstance ().get_tuple_index ();
329
+ _config._max_width = 2 ;
330
+ _config._bound = -1 ; // No bound
331
+ std::vector<NodePT> seed_nodes;
332
+ _compute_R (seed, seed_nodes);
333
+
310
334
335
+ LPT_INFO (" cout" , " IW Simulation - Number of seed nodes: " << seed_nodes.size ());
336
+
337
+ std::vector<bool > rel_goal_directed (index .size (), false );
338
+ mark_atoms_in_path_to_subgoal (seed_nodes, rel_goal_directed);
339
+ LPT_INFO (" cout" , " IW Simulation - Goal-directed |R| = " << std::count (rel_goal_directed.begin (), rel_goal_directed.end (), true ));
340
+ return rel_goal_directed;
341
+ }
311
342
312
- std::vector<AtomIdx> compute_R (const StateT& seed, std::vector<NodePT>& w1_seed_nodes) {
343
+
344
+ std::vector<AtomIdx> _compute_R (const StateT& seed, std::vector<NodePT>& seed_nodes) {
313
345
314
346
_config._complete = false ;
315
347
316
- bool all_reached_before_bound = _run (seed);
348
+ _run (seed);
317
349
318
- if (all_reached_before_bound) {
319
- for (const auto & n:_w1_nodes) {
320
- if (n->satisfies_subgoal ) w1_seed_nodes.push_back (n);
321
- }
322
- } else {
323
- w1_seed_nodes = _w1_nodes;
350
+ LPT_INFO (" cout" , " IW Simulation - Num unreached subgoals: " << _unreached.size () << " / " << this ->_model .num_subgoals ());
351
+ if (!_unreached.empty ()) {
352
+ LPT_INFO (" cout" , " Some subgoals not reached during the simulation. ABORTING" );
353
+ exit (1 );
324
354
}
325
355
356
+ // std::vector<NodePT> w1_goal_reaching_nodes;
357
+ // std::vector<NodePT> w2_goal_reaching_nodes;
358
+ // std::vector<NodePT> wgt2_goal_reaching_nodes;
359
+
360
+
361
+ /*
362
+ for (unsigned subgoal_idx = 0; subgoal_idx < _all_paths.size(); ++subgoal_idx) {
363
+ const std::vector<NodePT>& paths = _all_paths[subgoal_idx];
364
+ assert(_in_seed[subgoal_idx] || !paths.empty());
365
+ seed_nodes.insert(seed_nodes.end(), paths.begin(), paths.end());
366
+ }
367
+ */
368
+
369
+ for (unsigned subgoal_idx = 0 ; subgoal_idx < _optimal_paths.size (); ++subgoal_idx) {
370
+ if (!_in_seed[subgoal_idx]) {
371
+ assert (_optimal_paths[subgoal_idx] != nullptr );
372
+ seed_nodes.push_back (_optimal_paths[subgoal_idx]);
373
+ }
374
+ }
375
+
326
376
327
- LPT_INFO (" cout" , " IW Simulation - Num unreached subgoals: " << _unreached.size () << " / " << this ->_model .num_subgoals ());
328
377
/*
329
378
LPT_INFO("cout", "IW Simulation - Number of novelty-1 nodes: " << _w1_nodes.size());
330
379
LPT_INFO("cout", "IW Simulation - Number of novelty=1 nodes expanded in the simulation: " << _w1_nodes_expanded);
@@ -356,18 +405,14 @@ public:
356
405
}
357
406
358
407
bool _run (const StateT& seed) {
359
- mark_seed_subgoals (seed);
360
-
361
408
NodePT n = std::make_shared<NodeT>(seed, _generated++);
409
+ mark_seed_subgoals (n);
362
410
363
411
auto nov =_evaluator.evaluate (*n);
364
412
_unused (nov);
365
413
assert (nov==1 );
366
414
// LPT_INFO("cout", "IW Simulation - Seed node: " << *n);
367
415
368
-
369
- // if (process_node(n)) return;
370
-
371
416
this ->_open .insert (n);
372
417
373
418
unsigned accepted = 1 ; // (the root node counts as accepted)
@@ -440,6 +485,7 @@ protected:
440
485
if (this ->_model .goal (state, subgoal_idx)) {
441
486
node->satisfies_subgoal = true ;
442
487
// _all_paths[subgoal_idx].push_back(node);
488
+ if (!_optimal_paths[subgoal_idx]) _optimal_paths[subgoal_idx] = node;
443
489
it = _unreached.erase (it);
444
490
} else {
445
491
++it;
@@ -456,15 +502,17 @@ protected:
456
502
for (unsigned i = 0 ; i < this ->_model .num_subgoals (); ++i) {
457
503
if (!_in_seed[i] && this ->_model .goal (state, i)) {
458
504
node->satisfies_subgoal = true ;
459
- // _all_paths[i].push_back(node);
505
+ if (!_optimal_paths[i]) _optimal_paths[i] = node;
506
+ _unreached.erase (i);
460
507
}
461
508
}
462
- return false ;
509
+ return _unreached.empty ();
510
+ // return false; // return false so we don't interrupt the processing
463
511
}
464
512
465
- void mark_seed_subgoals (const StateT& seed ) {
513
+ void mark_seed_subgoals (const NodePT& node ) {
466
514
for (unsigned i = 0 ; i < this ->_model .num_subgoals (); ++i) {
467
- if (this ->_model .goal (seed , i)) {
515
+ if (this ->_model .goal (node-> state , i)) {
468
516
_in_seed[i] = true ;
469
517
} else {
470
518
_unreached.insert (i);
0 commit comments