Skip to content

Commit

Permalink
Address code review, change option for overapproximating default valu…
Browse files Browse the repository at this point in the history
…e axioms.
  • Loading branch information
salome-eriksson committed Jul 16, 2024
1 parent 262e2b2 commit 90b8f2c
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 89 deletions.
3 changes: 2 additions & 1 deletion src/search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ create_fast_downward_library(

create_fast_downward_library(
NAME default_value_axioms_task
HELP "Task transformation adding axioms for the default value of derived variables"
HELP "Task transformation adding axioms describing under which "
"circumstances a derived variable is set to its default value."
SOURCES
tasks/default_value_axioms_task
DEPENDS
Expand Down
3 changes: 2 additions & 1 deletion src/search/cartesian_abstractions/split_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ SplitSelector::SplitSelector(
if (pick == PickSplit::MIN_HADD || pick == PickSplit::MAX_HADD) {
additive_heuristic =
utils::make_unique_ptr<additive_heuristic::AdditiveHeuristic>(
true, task, false, "h^add within CEGAR abstractions",
tasks::AxiomHandlingType::APPROXIMATE_NEGATIVE, task,
false, "h^add within CEGAR abstractions",
utils::Verbosity::SILENT);
additive_heuristic->compute_heuristic_for_cegar(
task_proxy.get_initial_state());
Expand Down
3 changes: 2 additions & 1 deletion src/search/cartesian_abstractions/subtask_generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SortFactsByIncreasingHaddValues {
explicit SortFactsByIncreasingHaddValues(
const shared_ptr<AbstractTask> &task)
: hadd(utils::make_unique_ptr<additive_heuristic::AdditiveHeuristic>(
true, task, false, "h^add within CEGAR abstractions",
tasks::AxiomHandlingType::APPROXIMATE_NEGATIVE, task,
false, "h^add within CEGAR abstractions",
utils::Verbosity::SILENT)) {
TaskProxy task_proxy(*task);
hadd->compute_heuristic_for_cegar(task_proxy.get_initial_state());
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/additive_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace additive_heuristic {
const int AdditiveHeuristic::MAX_COST_VALUE;

AdditiveHeuristic::AdditiveHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity)
: RelaxationHeuristic(
simple_default_value_axioms, transform, cache_estimates, description,
axiom_handling, transform, cache_estimates, description,
verbosity),
did_write_overflow_warning(false) {
if (log.is_at_least_normal()) {
Expand Down
2 changes: 1 addition & 1 deletion src/search/heuristics/additive_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AdditiveHeuristic : public relaxation_heuristic::RelaxationHeuristic {
int compute_add_and_ff(const State &state);
public:
AdditiveHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity);
Expand Down
18 changes: 6 additions & 12 deletions src/search/heuristics/cea_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "../plugins/plugin.h"

#include "../task_utils/task_properties.h"
#include "../tasks/default_value_axioms_task.h"
#include "../utils/logging.h"

#include <cassert>
Expand Down Expand Up @@ -410,11 +409,11 @@ int ContextEnhancedAdditiveHeuristic::compute_heuristic(
}

ContextEnhancedAdditiveHeuristic::ContextEnhancedAdditiveHeuristic(
bool simple_default_value_axioms, const shared_ptr<AbstractTask> &transform,
bool cache_estimates, const string &description,
utils::Verbosity verbosity)
tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity)
: Heuristic(tasks::get_default_value_axioms_task_if_needed(
transform, simple_default_value_axioms),
transform, axiom_handling),
cache_estimates, description, verbosity),
min_action_cost(task_properties::get_min_operator_cost(task_proxy)) {
if (log.is_at_least_normal()) {
Expand Down Expand Up @@ -454,12 +453,7 @@ class ContextEnhancedAdditiveHeuristicFeature
ContextEnhancedAdditiveHeuristicFeature() : TypedFeature("cea") {
document_title("Context-enhanced additive heuristic");

add_option<bool>(
"simple_default_value_axioms",
"For derived variables that need negated axioms, introduce the trivial"
"rule with an empty body. This makes the heuristic weaker but avoids"
"a potentially expensive precomputation.",
"false");
tasks::add_axioms_option_to_feature(*this);
add_heuristic_options_to_feature(*this, "cea");

document_language_support("action costs", "supported");
Expand All @@ -480,7 +474,7 @@ class ContextEnhancedAdditiveHeuristicFeature
create_component(const plugins::Options &opts,
const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<ContextEnhancedAdditiveHeuristic>(
opts.get<bool>("simple_default_value_axioms"),
tasks::get_axioms_arguments_from_options(opts),
get_heuristic_arguments_from_options(opts)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/search/heuristics/cea_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../heuristic.h"

#include "../algorithms/priority_queues.h"
#include "../tasks/default_value_axioms_task.h"

#include <vector>

Expand Down Expand Up @@ -51,7 +52,7 @@ class ContextEnhancedAdditiveHeuristic : public Heuristic {
virtual int compute_heuristic(const State &ancestor_state) override;
public:
ContextEnhancedAdditiveHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity);
Expand Down
14 changes: 4 additions & 10 deletions src/search/heuristics/cg_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "../plugins/plugin.h"
#include "../task_utils/task_properties.h"
#include "../tasks/default_value_axioms_task.h"
#include "../utils/logging.h"

#include <algorithm>
Expand All @@ -18,12 +17,12 @@ using namespace domain_transition_graph;

namespace cg_heuristic {
CGHeuristic::CGHeuristic(
int max_cache_size, bool simple_default_value_axioms,
int max_cache_size, tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates, const string &description,
utils::Verbosity verbosity)
: Heuristic(tasks::get_default_value_axioms_task_if_needed(
transform, simple_default_value_axioms),
transform, axiom_handling),
cache_estimates, description, verbosity),
cache_hits(0),
cache_misses(0),
Expand Down Expand Up @@ -299,12 +298,7 @@ class CGHeuristicFeature
"maximum number of cached entries per variable (set to 0 to disable cache)",
"1000000",
plugins::Bounds("0", "infinity"));
add_option<bool>(
"simple_default_value_axioms",
"For derived variables that need negated axioms, introduce the trivial"
"rule with an empty body. This makes the heuristic weaker but avoids"
"a potentially expensive precomputation.",
"false");
tasks::add_axioms_option_to_feature(*this);
add_heuristic_options_to_feature(*this, "cg");

document_language_support("action costs", "supported");
Expand All @@ -326,7 +320,7 @@ class CGHeuristicFeature
const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<CGHeuristic>(
opts.get<int>("max_cache_size"),
opts.get<bool>("simple_default_value_axioms"),
tasks::get_axioms_arguments_from_options(opts),
get_heuristic_arguments_from_options(opts)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/search/heuristics/cg_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../heuristic.h"

#include "../algorithms/priority_queues.h"
#include "../tasks/default_value_axioms_task.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -45,7 +46,7 @@ class CGHeuristic : public Heuristic {
public:
explicit CGHeuristic(
int max_cache_size,
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_hanlding,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity);
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/ff_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ using namespace std;
namespace ff_heuristic {
// construction and destruction
FFHeuristic::FFHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity)
: AdditiveHeuristic(
simple_default_value_axioms, transform, cache_estimates, description,
axiom_handling, transform, cache_estimates, description,
verbosity),
relaxed_plan(task_proxy.get_operators().size(), false) {
if (log.is_at_least_normal()) {
Expand Down
2 changes: 1 addition & 1 deletion src/search/heuristics/ff_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FFHeuristic : public additive_heuristic::AdditiveHeuristic {
virtual int compute_heuristic(const State &ancestor_state) override;
public:
FFHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity);
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/max_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace max_heuristic {

// construction and destruction
HSPMaxHeuristic::HSPMaxHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity)
: RelaxationHeuristic(
simple_default_value_axioms, transform, cache_estimates, description,
axiom_handling, transform, cache_estimates, description,
verbosity) {
if (log.is_at_least_normal()) {
log << "Initializing HSP max heuristic..." << endl;
Expand Down
2 changes: 1 addition & 1 deletion src/search/heuristics/max_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HSPMaxHeuristic : public relaxation_heuristic::RelaxationHeuristic {
virtual int compute_heuristic(const State &ancestor_state) override;
public:
HSPMaxHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity);
Expand Down
17 changes: 6 additions & 11 deletions src/search/heuristics/relaxation_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "../plugins/plugin.h"
#include "../task_utils/task_properties.h"
#include "../tasks/default_value_axioms_task.h"
#include "../utils/collections.h"
#include "../utils/logging.h"
#include "../utils/timer.h"
Expand Down Expand Up @@ -37,30 +36,26 @@ UnaryOperator::UnaryOperator(

void add_relaxation_heuristic_options_to_feature(
plugins::Feature &feature, const string &description) {
feature.add_option<bool>(
"simple_default_value_axioms",
"For derived variables that need negated axioms, introduce the trivial"
"rule with an empty body. This makes the heuristic weaker but avoids"
"a potentially expensive precomputation.",
"false");
tasks::add_axioms_option_to_feature(feature);
add_heuristic_options_to_feature(feature, description);
}

tuple<bool, shared_ptr<AbstractTask>, bool, string, utils::Verbosity>
tuple<tasks::AxiomHandlingType, shared_ptr<AbstractTask>, bool, string,
utils::Verbosity>
get_relaxation_heuristic_arguments_from_options(const plugins::Options &opts) {
return tuple_cat(
make_tuple(opts.get<bool>("simple_default_value_axioms")),
tasks::get_axioms_arguments_from_options(opts),
get_heuristic_arguments_from_options(opts));
}


// construction and destruction
RelaxationHeuristic::RelaxationHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity)
: Heuristic(tasks::get_default_value_axioms_task_if_needed(
transform, simple_default_value_axioms),
transform, axiom_handling),
cache_estimates, description, verbosity) {
// Build propositions.
propositions.resize(task_properties::get_num_facts(task_proxy));
Expand Down
7 changes: 4 additions & 3 deletions src/search/heuristics/relaxation_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "../heuristic.h"

#include "../tasks/default_value_axioms_task.h"
#include "../utils/collections.h"

#include <cassert>
Expand Down Expand Up @@ -111,7 +112,7 @@ class RelaxationHeuristic : public Heuristic {
Proposition *get_proposition(const FactProxy &fact);
public:
RelaxationHeuristic(
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity);
Expand All @@ -121,8 +122,8 @@ class RelaxationHeuristic : public Heuristic {

extern void add_relaxation_heuristic_options_to_feature(
plugins::Feature &feature, const std::string &description);
extern std::tuple<
bool, std::shared_ptr<AbstractTask>, bool, std::string, utils::Verbosity>
extern std::tuple<tasks::AxiomHandlingType, std::shared_ptr<AbstractTask>,
bool, std::string, utils::Verbosity>
get_relaxation_heuristic_arguments_from_options(const plugins::Options &opts);
}
#endif
4 changes: 2 additions & 2 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ namespace landmarks {
LandmarkCostPartitioningHeuristic::LandmarkCostPartitioningHeuristic(
const shared_ptr<LandmarkFactory> &lm_factory, bool pref,
bool prog_goal, bool prog_gn, bool prog_r,
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity,
CostPartitioningMethod cost_partitioning, bool alm,
lp::LPSolverType lpsolver)
: LandmarkHeuristic(
simple_default_value_axioms, pref, transform, cache_estimates, description, verbosity) {
axiom_handling, pref, transform, cache_estimates, description, verbosity) {
if (log.is_at_least_normal()) {
log << "Initializing landmark cost partitioning heuristic..." << endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LandmarkCostPartitioningHeuristic : public LandmarkHeuristic {
LandmarkCostPartitioningHeuristic(
const std::shared_ptr<LandmarkFactory> &lm_factory, bool pref,
bool prog_goal, bool prog_gn, bool prog_r,
bool simple_default_value_axioms,
tasks::AxiomHandlingType axiom_handling,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates, const std::string &description,
utils::Verbosity verbosity,
Expand Down
25 changes: 9 additions & 16 deletions src/search/landmarks/landmark_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
#include "../plugins/plugin.h"
#include "../task_utils/successor_generator.h"
#include "../tasks/cost_adapted_task.h"
#include "../tasks/default_value_axioms_task.h"
#include "../tasks/root_task.h"
#include "../utils/markup.h"

using namespace std;

namespace landmarks {
LandmarkHeuristic::LandmarkHeuristic(
bool simple_default_value_axioms,
bool use_preferred_operators,
tasks::AxiomHandlingType axiom_handling, bool use_preferred_operators,
const shared_ptr<AbstractTask> &transform, bool cache_estimates,
const string &description, utils::Verbosity verbosity)
: Heuristic(tasks::get_default_value_axioms_task_if_needed(
transform, simple_default_value_axioms),
transform, axiom_handling),
cache_estimates, description, verbosity),
use_preferred_operators(use_preferred_operators),
successor_generator(nullptr) {
Expand All @@ -40,7 +38,7 @@ void LandmarkHeuristic::initialize(
&& dynamic_cast<tasks::DefaultValueAxiomsTask *>(task.get()) == nullptr) {
cerr << "The landmark heuristics currently only support "
<< "task transformations that modify the operator costs "
<< "or add negated axioms. See issues 845 and 686 "
<< "or add negated axioms. See issues 845, 686 and 454 "
<< "for details." << endl;
utils::exit_with(utils::ExitCode::SEARCH_UNSUPPORTED);
}
Expand Down Expand Up @@ -230,20 +228,16 @@ void add_landmark_heuristic_options_to_feature(
"prog_gn", "Use greedy-necessary ordering progression.", "true");
feature.add_option<bool>(
"prog_r", "Use reasonable ordering progression.", "true");
feature.add_option<bool>(
"simple_default_value_axioms",
"For derived variables that need negated axioms, introduce the trivial"
"rule with an empty body. This makes the heuristic weaker but avoids"
"a potentially expensive precomputation.",
"false");
tasks::add_axioms_option_to_feature(feature);
add_heuristic_options_to_feature(feature, description);

feature.document_property("preferred operators",
"yes (if enabled; see ``pref`` option)");
}

tuple<shared_ptr<LandmarkFactory>, bool, bool, bool, bool, bool,
shared_ptr<AbstractTask>, bool, string, utils::Verbosity>
tuple<shared_ptr<LandmarkFactory>, bool, bool, bool, bool,
tasks::AxiomHandlingType, shared_ptr<AbstractTask>, bool, string,
utils::Verbosity>
get_landmark_heuristic_arguments_from_options(
const plugins::Options &opts) {
return tuple_cat(
Expand All @@ -252,9 +246,8 @@ get_landmark_heuristic_arguments_from_options(
opts.get<bool>("pref"),
opts.get<bool>("prog_goal"),
opts.get<bool>("prog_gn"),
opts.get<bool>("prog_r"),
opts.get<bool>("simple_default_value_axioms")
),
opts.get<bool>("prog_r")),
tasks::get_axioms_arguments_from_options(opts),
get_heuristic_arguments_from_options(opts));
}
}
Loading

0 comments on commit 90b8f2c

Please sign in to comment.