Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue1075 #180

Merged
merged 8 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 7 additions & 59 deletions src/search/landmarks/landmark_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@
using namespace std;

namespace landmarks {
static bool landmark_is_interesting(
const State &state, ConstBitsetView &past,
const landmarks::LandmarkNode &lm_node, bool all_lms_reached) {
/*
We consider a landmark interesting in two (exclusive) cases:
(1) If all landmarks are reached and the landmark must hold in the goal
but does not hold in the current state.
(2) If it has not been reached before and all its parents are reached.
*/

if (all_lms_reached) {
const Landmark &landmark = lm_node.get_landmark();
return landmark.is_true_in_goal && !landmark.is_true_in_state(state);
} else {
return !past.test(lm_node.get_id()) &&
all_of(lm_node.parents.begin(), lm_node.parents.end(),
[&](const pair<LandmarkNode *, EdgeType> parent) {
return past.test(parent.first->get_id());
});
}
}

LandmarkHeuristic::LandmarkHeuristic(
const plugins::Options &opts)
: Heuristic(opts),
Expand Down Expand Up @@ -137,30 +115,16 @@ void LandmarkHeuristic::compute_landmark_graph(const plugins::Options &opts) {
}

void LandmarkHeuristic::generate_preferred_operators(
const State &state, ConstBitsetView &past) {
const State &state, ConstBitsetView &future) {
/*
Find operators that achieve landmark leaves. If a simple landmark can be
achieved, prefer only operators that achieve simple landmarks. Otherwise,
prefer operators that achieve disjunctive landmarks, or don't prefer any
operators if no such landmarks exist at all.

Find operators that achieve future landmarks.
ClemensBuechner marked this conversation as resolved.
Show resolved Hide resolved
TODO: Conjunctive landmarks are ignored in *lm_graph->get_node(...)*, so
they are ignored when computing preferred operators. We consider this
a bug and want to fix it in issue1072.
*/
assert(successor_generator);
vector<OperatorID> applicable_operators;
successor_generator->generate_applicable_ops(state, applicable_operators);
vector<OperatorID> preferred_operators_simple;
vector<OperatorID> preferred_operators_disjunctive;

bool all_landmarks_past = true;
for (int i = 0; i < past.size(); ++i) {
if (!past.test(i)) {
all_landmarks_past = false;
break;
}
}

for (OperatorID op_id : applicable_operators) {
OperatorProxy op = task_proxy.get_operators()[op_id];
ClemensBuechner marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -170,27 +134,11 @@ void LandmarkHeuristic::generate_preferred_operators(
continue;
FactProxy fact_proxy = effect.get_fact();
LandmarkNode *lm_node = lm_graph->get_node(fact_proxy.get_pair());
if (lm_node && landmark_is_interesting(
state, past, *lm_node, all_landmarks_past)) {
if (lm_node->get_landmark().disjunctive) {
preferred_operators_disjunctive.push_back(op_id);
} else {
preferred_operators_simple.push_back(op_id);
}
if (lm_node && future.test(lm_node->get_id())) {
set_preferred(op);
}
}
}

OperatorsProxy operators = task_proxy.get_operators();
if (preferred_operators_simple.empty()) {
for (OperatorID op_id : preferred_operators_disjunctive) {
set_preferred(operators[op_id]);
}
} else {
for (OperatorID op_id : preferred_operators_simple) {
set_preferred(operators[op_id]);
}
}
}

int LandmarkHeuristic::compute_heuristic(const State &ancestor_state) {
Expand Down Expand Up @@ -220,10 +168,10 @@ int LandmarkHeuristic::compute_heuristic(const State &ancestor_state) {
}
int h = get_heuristic_value(ancestor_state);
if (use_preferred_operators) {
ConstBitsetView past =
lm_status_manager->get_past_landmarks(ancestor_state);
ConstBitsetView future =
lm_status_manager->get_future_landmarks(ancestor_state);
State state = convert_ancestor_state(ancestor_state);
generate_preferred_operators(state, past);
generate_preferred_operators(state, future);
}
return h;
}
Expand Down
2 changes: 1 addition & 1 deletion src/search/landmarks/landmark_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LandmarkHeuristic : public Heuristic {
virtual int get_heuristic_value(const State &ancestor_state) = 0;

void generate_preferred_operators(
const State &state, ConstBitsetView &past);
const State &state, ConstBitsetView &future);
virtual int compute_heuristic(const State &ancestor_state) override;
public:
explicit LandmarkHeuristic(const plugins::Options &opts);
Expand Down