Skip to content

Commit 6b20bbe

Browse files
committed
various bug fixes
1 parent 03da6ee commit 6b20bbe

File tree

12 files changed

+78
-28
lines changed

12 files changed

+78
-28
lines changed

src/deadend.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ int FSAP::get_index() {
3636
return op->get_id();
3737
}
3838

39+
int FSAP::get_nondet_index() {
40+
return PR2.general.nondet_name_to_index[op->get_nondet_name()];
41+
}
42+
3943

4044
bool is_deadend(PR2State &state) {
4145
PR2.deadend.reachability_heuristic->reset();
@@ -154,8 +158,9 @@ void update_deadends(vector< DeadendTuple* > &failed_states) {
154158
}
155159

156160
// Add a pointer from the operator to the newly created fsaps
157-
for (auto fsap : fsaps)
158-
PR2.deadend.nondetop2fsaps[fsap->get_index()]->push_back(fsap);
161+
for (auto fsap : fsaps) {
162+
PR2.deadend.nondetop2fsaps[fsap->get_nondet_index()]->push_back(fsap);
163+
}
159164

160165
PR2.deadend.policy->update_policy(fsaps);
161166
PR2.deadend.states->update_policy(deadends);

src/fd_integration/fsap_penalized_ff_heuristic.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ int FSAPPenalizedFFHeuristic::compute_heuristic(const State &state) {
336336
PR2.deadend.policy->generate_entailed_items(*ps, reg_items);
337337
delete ps;
338338
for (auto item : reg_items)
339-
forbidden_ops.insert(item->get_index());
339+
forbidden_ops.insert(item->get_nondet_index());
340340

341341
// Collecting the relaxed plan also sets the preferred operators.
342342
for (size_t i = 0; i < goal_propositions.size(); ++i)

src/fd_integration/partial_state.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ bool PR2State::triggers(const EffectProxy &effect) {
6464
return true;
6565
}
6666

67+
bool PR2State::triggers(const FactProxy &fact) {
68+
if (vars[fact.get_variable().get_id()] != fact.get_value())
69+
return false;
70+
return true;
71+
}
72+
6773
PR2State * PR2State::progress(const PR2OperatorProxy &op) {
6874

6975
assert(!op.is_axiom());
@@ -93,18 +99,24 @@ PR2State * PR2State::regress(const PR2OperatorProxy &op, PR2State *context) {
9399

94100
PR2State * prev = new PR2State(*this);
95101

102+
std::set<int> seen;
103+
96104
// Remove all of the effect settings
97105
for (auto eff : op.get_all_effects()) {
98106
if (context->triggers(eff)) {
99107
int var = eff.get_fact().get_variable().get_id();
100108
int val = eff.get_fact().get_value();
101109

110+
seen.insert(var);
111+
102112
bool inconsistent = (vars[var] != -1) && (vars[var] != val);
103113

104114
if (inconsistent) {
105115
cout << "\n\n !! Error: Inconsistent regression !!\n" << endl;
106116
// Dump the effect
107117
cout << "Effect: " << endl;
118+
op.dump();
119+
108120
for (auto cond : eff.get_conditions())
109121
cout << " " << cond.get_variable().get_id() << " = " << cond.get_value() << endl;
110122
}
@@ -113,6 +125,15 @@ PR2State * PR2State::regress(const PR2OperatorProxy &op, PR2State *context) {
113125
(*prev)[eff.get_fact().get_variable().get_id()] = -1;
114126
}
115127
}
128+
129+
// Remove all of the prevail effects
130+
for (auto pre : op.get_preconditions()) {
131+
int var = pre.get_variable().get_id();
132+
int val = pre.get_value();
133+
if (0 == seen.count(var) && context->triggers(pre)) {
134+
(*prev)[var] = -1;
135+
}
136+
}
116137

117138
// Assign the values from the context that are mentioned in conditions
118139
for (auto var : *(PR2.general.conditional_mask[op.nondet_index]))

src/fd_integration/partial_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PR2State : public StateInterface {
5353
PR2State * progress(const PR2OperatorProxy &op);
5454
PR2State * regress(const PR2OperatorProxy &op, PR2State *context=NULL);
5555

56+
bool triggers(const FactProxy &fact);
5657
bool triggers(const EffectProxy &effect);
5758
bool consistent_with(const PR2State &other);
5859
bool entails(const PR2State &other);

src/fd_integration/pr2_proxies.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../../plan_manager.h"
66
#include "../../search_algorithm.h"
77
#include "../../plugins/options.h"
8+
#include <regex>
89

910
class TaskProxy;
1011
class OperatorProxy;
@@ -40,6 +41,7 @@ class PR2OperatorProxy : public OperatorProxy {
4041
int nondet_outcome;
4142

4243
// TODO: https://github.com/QuMuLab/rbp/blob/main/src/search/global_operator.cc#L142
44+
// Dead link
4345
PR2State *all_fire_context;
4446

4547
PR2OperatorProxy(const AbstractTask &task, int index, bool is_axiom)
@@ -55,11 +57,9 @@ class PR2OperatorProxy : public OperatorProxy {
5557
return "goal_action";
5658
}
5759
string name = get_name();
58-
// Split the get_name() string and return everything before _DETDUP_x and after
59-
//Only works up to 9 splits. Will have to be rewritten to accomdate more
60-
if (name.find("_detdup_") != std::string::npos)
61-
name = name.erase(name.find("_detdup_"), name.find("_detdup_") + 1);
62-
return name;
60+
std::regex target("_detdup_[0-9]*");
61+
string name2 = std::regex_replace(name, target, "");
62+
return name2;
6363
}
6464
void dump() const {
6565
cout << "Operator: " << get_name() << endl;

src/fd_integration/pr2_search_algorithm.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void DeadendAwareSuccessorGenerator::generate_applicable_ops(const PR2State &_cu
144144
set<int> forbidden;
145145
for (auto item : reg_items) {
146146

147-
int index = item->get_index();
147+
int index = item->get_nondet_index();
148148

149149
forbidden.insert(index);
150150

@@ -165,7 +165,7 @@ void DeadendAwareSuccessorGenerator::generate_applicable_ops(const PR2State &_cu
165165
if (!PR2.weaksearch.limit_states && PR2.deadend.record_online &&
166166
PR2.deadend.combine && (orig_ops.size() > 0) && ops.empty()) {
167167

168-
// Combind all of the FSAPs
168+
// Combined all of the FSAPs
169169
PR2State *newDE = new PR2State();
170170
for (unsigned i = 0; i < ruled_out.size(); i++) {
171171
newDE->combine_with(*((fsap_map[ruled_out[i]])->state));

src/policy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct FSAP : PolicyItem {
5353
string get_name();
5454
int get_index();
5555
void dump() const;
56+
57+
int get_nondet_index();
5658
};
5759

5860
template<typename T> class Policy {

src/pr2.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ bool PR2Wrapper::run_pr2() {
238238

239239
}
240240

241-
242241
cout << endl;
243242

244243
return PR2.solution.best->is_strong_cyclic();
@@ -267,17 +266,14 @@ void PR2Wrapper::generate_nondet_operator_mappings() {
267266
assert(PR2.general.nondet_outcome_mapping.empty());
268267

269268
// temporary mapping from non-det name to index
270-
map<string, int> nondet_name_to_index;
271269

272270
int current_nondet_index = 0;
273271

274272
for (auto op : PR2.proxy->get_operators()) {
275273
//If not in the mapping yet
276-
PR2.general.conditional_mask.push_back(new vector<int>());
277-
PR2.deadend.nondetop2fsaps.push_back(new vector< FSAP* >());
278274

279-
if (nondet_name_to_index.find(op.get_nondet_name()) == nondet_name_to_index.end()) {
280-
nondet_name_to_index[op.get_nondet_name()] = current_nondet_index;
275+
if (PR2.general.nondet_name_to_index.find(op.get_nondet_name()) == PR2.general.nondet_name_to_index.end()) {
276+
PR2.general.nondet_name_to_index[op.get_nondet_name()] = current_nondet_index;
281277
PR2.general.nondet_mapping.push_back(vector<int>());
282278
current_nondet_index++;
283279

@@ -286,10 +282,10 @@ void PR2Wrapper::generate_nondet_operator_mappings() {
286282
PR2.general.conditional_mask.push_back(new vector<int>());
287283
PR2.deadend.nondetop2fsaps.push_back(new vector< FSAP* >());
288284
}
289-
PR2.general.nondet_mapping[nondet_name_to_index[op.get_nondet_name()]].push_back(op.get_id());
285+
PR2.general.nondet_mapping[PR2.general.nondet_name_to_index[op.get_nondet_name()]].push_back(op.get_id());
290286
PR2.general.nondet_outcome_mapping[op.get_id()] =
291-
PR2.general.nondet_mapping[nondet_name_to_index[op.get_nondet_name()]].size() - 1;
292-
op.nondet_index = nondet_name_to_index[op.get_nondet_name()];
287+
PR2.general.nondet_mapping[PR2.general.nondet_name_to_index[op.get_nondet_name()]].size() - 1;
288+
op.nondet_index = PR2.general.nondet_name_to_index[op.get_nondet_name()];
293289
op.nondet_outcome = PR2.general.nondet_outcome_mapping[op.get_id()];
294290
nondet_index_map[op.get_id()] = op.nondet_index;
295291

src/pr2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ struct PR2Wrapper {
311311
// General data structures
312312
vector< vector<int> > nondet_mapping; // Maps a non-deterministic action id to a list of ground operator ids
313313
map<int, int> nondet_outcome_mapping; // Maps an action id to the outcome of the non-deterministic action
314+
map<string, int> nondet_name_to_index; // Maps an action name to a non-deterministic index
314315

315316
vector<vector<int> *> conditional_mask; // Maps a non-deterministic action id to the variables that must be defined when doing context-sensitive regression
316317
Policy<PolicyItem> *regressable_ops; // The policy to check what operators are regressable

src/regression.cc

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
#include "pr2.h"
55

66
bool RegressableOperator::check_relevance(const PR2State &ps) {
7-
for (auto eff : op.get_effects())
8-
if (!ps.is_undefined(eff.get_fact().get_variable().get_id()))
7+
8+
std::set<int> seen;
9+
10+
for (auto eff : op.get_all_effects()) {
11+
int var = eff.get_fact().get_variable().get_id();
12+
seen.insert(var);
13+
if (!ps.is_undefined(var))
14+
return true;
15+
}
16+
for (auto pre : op.get_preconditions()) {
17+
int var = pre.get_variable().get_id();
18+
if (0 == seen.count(var) && !ps.is_undefined(var))
919
return true;
20+
}
1021
return false;
1122
}
1223

@@ -33,9 +44,21 @@ void generate_regressable_ops() {
3344
if (0 == PR2.general.conditional_mask[op.nondet_index]->size()) {
3445
s = new PR2State();
3546

47+
std::set<int> seen;
48+
3649
// Only applicable if the effects currently hold.
37-
for (auto eff : op.get_effects()) {
38-
(*s)[eff.get_fact().get_variable().get_id()] = eff.get_fact().get_value();
50+
for (auto eff : op.get_all_effects()) {
51+
int var = eff.get_fact().get_variable().get_id();
52+
(*s)[var] = eff.get_fact().get_value();
53+
seen.insert(var);
54+
}
55+
56+
// Prevail Conditions
57+
for (auto pre : op.get_preconditions()) {
58+
int var = pre.get_variable().get_id();
59+
if (0 == seen.count(var)) {
60+
(*s)[var] = pre.get_value();
61+
}
3962
}
4063

4164
reg_steps.push_back(new RegressableOperator(op, s));
@@ -62,7 +85,7 @@ void generate_regressable_ops() {
6285

6386
// Only makes sense to continue if it is consistent so far
6487
if (consistent) {
65-
for (auto eff : op.get_effects()) {
88+
for (auto eff : op.get_all_effects()) {
6689
for (auto cond : eff.get_conditions()) {
6790

6891

@@ -91,7 +114,7 @@ void generate_regressable_ops() {
91114
// Only makes sense to continue if it is consistent so far
92115
if (consistent) {
93116
// Only applicable if the post conditions currently hold.
94-
for (auto eff : op.get_effects()) {
117+
for (auto eff : op.get_all_effects()) {
95118
int eff_var = eff.get_fact().get_variable().get_id();
96119
bool var_is_defined = !(s->is_undefined(eff_var));
97120
bool var_is_consistent = (eff.get_fact().get_value() == (*s)[eff_var]);

0 commit comments

Comments
 (0)