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

Issue559 prototype #3

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
eabc16d
[issue559-prototype] add search engine builders
Jun 11, 2019
a72414b
[issue559-prototype] finish implementation
Jun 12, 2019
c2525c9
[issue559-prototype] let build return a shared ptr
Jun 12, 2019
218a05d
[issue559-prototype] add missing plugin
Jun 12, 2019
45559f4
[issue559-prototype] add builders for some evaluators and blind heuri…
Jun 12, 2019
c8f4d81
[issue559-prototype] Build evaluators. Blind search works now.
jendrikseipp Jun 13, 2019
63ee251
[issue559-prototype] Add CostAdaptedEvaluatorBuilder and pass Task to…
jendrikseipp Jun 13, 2019
8d08314
[issue559-prototype] Pass task to open lists.
jendrikseipp Jun 13, 2019
08fb21b
[issue559-prototype] Fix builder creation.
jendrikseipp Jun 13, 2019
cb181d1
[issue559-prototype] Unpack options for blind search heuristic earlier.
jendrikseipp Jun 13, 2019
bee9502
[issue559-prototype] Don't store options in EvaluatorBuilder.
jendrikseipp Jun 13, 2019
843c26e
[issue559-prototype] Restore evaluator argument for cost adaptation.
jendrikseipp Jun 13, 2019
09d5782
[issue559-prototype] Remove cruft.
jendrikseipp Jun 13, 2019
b6180c2
[issue559-prototype] Cache blind search heuristic.
jendrikseipp Jun 13, 2019
254b86a
[issue559-prototype] Rename plugin.
jendrikseipp Jun 13, 2019
ebad248
[issue559-prototype] Merge branch main.
Jul 10, 2020
0943ed0
[issue559-prototype] Merge with main.
FlorianPommerening Feb 10, 2021
a3da07b
[issue559-prototype] Use PerTaskInformation to cache elements for all…
FlorianPommerening Feb 10, 2021
1182f8e
[issue559-prototype] Cache search engines as well.
FlorianPommerening Feb 10, 2021
d3f06d8
[issue559-prototype] Add variable context (passed through but not yet…
FlorianPommerening Feb 10, 2021
3fa57a1
[issue559-prototype] First hacky version that has let and var express…
FlorianPommerening Feb 12, 2021
dc6a205
Add builder for lmcut.
salome-eriksson Feb 17, 2021
aef886b
Handle predefinitions by changing them into let expressions.
salome-eriksson Feb 19, 2021
bbc27dd
Add caches to builders in order to avoid rebuilding the same object.
salome-eriksson Feb 19, 2021
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
3 changes: 2 additions & 1 deletion build_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# USE_GLIBCXX_DEBUG is not compatible with USE_LP (see issue983).
glibcxx_debug = ["-DCMAKE_BUILD_TYPE=Debug", "-DUSE_LP=NO", "-DUSE_GLIBCXX_DEBUG=YES"]
minimal = ["-DCMAKE_BUILD_TYPE=Release", "-DDISABLE_PLUGINS_BY_DEFAULT=YES"]
prototype = ["-DCMAKE_BUILD_TYPE=Release", "-DDISABLE_PLUGINS_BY_DEFAULT=YES", "-DPLUGIN_BLIND_SEARCH_HEURISTIC_ENABLED=YES", "-DPLUGIN_PLUGIN_ASTAR_ENABLED=YES", "-DPLUGIN_LANDMARK_CUT_HEURISTIC_ENABLED=YES"]

DEFAULT = "release"
DEFAULT = "prototype" # "release"
DEBUG = "debug"
27 changes: 26 additions & 1 deletion src/search/DownwardFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ fast_downward_plugin(
evaluation_context
evaluation_result
evaluator
evaluator_builder
evaluator_cache
heuristic
heuristic_builder
open_list
open_list_factory
operator_cost
Expand All @@ -68,8 +70,14 @@ fast_downward_plugin(
per_task_information
plan_manager
plugin
plugin_builder
plugin_let_builder
plugin_variable_builder
plugin_variable_assignment
pruning_method
pruning_method_builder
search_engine
search_engine_builder
search_node_info
search_progress
search_space
Expand Down Expand Up @@ -263,11 +271,21 @@ fast_downward_plugin(
DEPENDS EVALUATORS_PLUGIN_GROUP
)

fast_downward_plugin(
NAME COST_ADAPTED_EVALUATOR
HELP "Cost-adapted evaluator"
SOURCES
evaluators/cost_adapted_evaluator_builder
DEPENDS EVALUATORS_PLUGIN_GROUP
CORE_PLUGIN
)

fast_downward_plugin(
NAME G_EVALUATOR
HELP "The g-evaluator"
SOURCES
evaluators/g_evaluator
evaluators/g_evaluator_builder
DEPENDS EVALUATORS_PLUGIN_GROUP
)

Expand All @@ -276,6 +294,7 @@ fast_downward_plugin(
HELP "The combining evaluator"
SOURCES
evaluators/combining_evaluator
evaluators/combining_evaluator_builder
DEPENDENCY_ONLY
)

Expand All @@ -300,6 +319,7 @@ fast_downward_plugin(
HELP "The weighted evaluator"
SOURCES
evaluators/weighted_evaluator
evaluators/weighted_evaluator_builder
DEPENDS EVALUATORS_PLUGIN_GROUP
)

Expand All @@ -308,6 +328,7 @@ fast_downward_plugin(
HELP "The sum evaluator"
SOURCES
evaluators/sum_evaluator
evaluators/sum_evaluator_builder
DEPENDS COMBINING_EVALUATOR EVALUATORS_PLUGIN_GROUP
)

Expand All @@ -316,6 +337,7 @@ fast_downward_plugin(
HELP "Pruning method that does nothing"
SOURCES
pruning/null_pruning_method
pruning/null_pruning_method_builder
DEPENDENCY_ONLY
)

Expand Down Expand Up @@ -357,7 +379,7 @@ fast_downward_plugin(
HELP "Basic classes used for all search engines"
SOURCES
search_engines/search_common
DEPENDS ALTERNATION_OPEN_LIST G_EVALUATOR BEST_FIRST_OPEN_LIST SUM_EVALUATOR TIEBREAKING_OPEN_LIST WEIGHTED_EVALUATOR
DEPENDS G_EVALUATOR BEST_FIRST_OPEN_LIST SUM_EVALUATOR TIEBREAKING_OPEN_LIST #ALTERNATION_OPEN_LIST WEIGHTED_EVALUATOR
DEPENDENCY_ONLY
)

Expand All @@ -366,6 +388,7 @@ fast_downward_plugin(
HELP "Eager search algorithm"
SOURCES
search_engines/eager_search
search_engines/eager_search_builder
DEPENDS NULL_PRUNING_METHOD ORDERED_SET SUCCESSOR_GENERATOR
DEPENDENCY_ONLY
)
Expand Down Expand Up @@ -481,6 +504,7 @@ fast_downward_plugin(
HELP "The 'blind search' heuristic"
SOURCES
heuristics/blind_search_heuristic
heuristics/blind_search_heuristic_builder
DEPENDS TASK_PROPERTIES
)

Expand Down Expand Up @@ -536,6 +560,7 @@ fast_downward_plugin(
HELP "The LM-cut heuristic"
SOURCES
heuristics/lm_cut_heuristic
heuristics/lm_cut_heuristic_builder
heuristics/lm_cut_landmarks
DEPENDS PRIORITY_QUEUES TASK_PROPERTIES
)
Expand Down
68 changes: 49 additions & 19 deletions src/search/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "option_parser.h"
#include "plan_manager.h"
#include "search_engine.h"
#include "search_engine_builder.h"

#include "options/doc_printer.h"
#include "options/predefinitions.h"
Expand Down Expand Up @@ -41,14 +41,17 @@ static int parse_int_arg(const string &name, const string &value) {
}
}

static shared_ptr<SearchEngine> parse_cmd_line_aux(
static shared_ptr<PluginBuilder<SearchEngine>> parse_cmd_line_aux(
const vector<string> &args, options::Registry &registry, bool dry_run) {
string plan_filename = "sas_plan";
int num_previously_generated_plans = 0;
bool is_part_of_anytime_portfolio = false;
options::Predefinitions predefinitions;
// bool is_part_of_anytime_portfolio = false;
// options::Predefinitions predefinitions;
unordered_map<string,string> predefinitions;
unordered_set<string> variable_names;
string search_string;
shared_ptr<PluginBuilder<SearchEngine>> engine;

shared_ptr<SearchEngine> engine;
/*
Note that we don’t sanitize all arguments beforehand because filenames should remain as-is
(no conversion to lower-case, no conversion of newlines to spaces).
Expand All @@ -61,9 +64,10 @@ static shared_ptr<SearchEngine> parse_cmd_line_aux(
if (is_last)
throw ArgError("missing argument after --search");
++i;
OptionParser parser(sanitize_arg_string(args[i]), registry,
predefinitions, dry_run);
engine = parser.start_parsing<shared_ptr<SearchEngine>>();
search_string = sanitize_arg_string(args[i]);
// OptionParser parser(sanitize_arg_string(args[i]), registry,
// predefinitions, dry_run);
// engine = parser.start_parsing<shared_ptr<PluginBuilder<SearchEngine>>>();
} else if (arg == "--help" && dry_run) {
cout << "Help:" << endl;
bool txt2tags = false;
Expand Down Expand Up @@ -101,7 +105,7 @@ static shared_ptr<SearchEngine> parse_cmd_line_aux(
if (is_last)
throw ArgError("missing argument after --internal-previous-portfolio-plans");
++i;
is_part_of_anytime_portfolio = true;
// is_part_of_anytime_portfolio = true;
num_previously_generated_plans = parse_int_arg(arg, args[i]);
if (num_previously_generated_plans < 0)
throw ArgError("argument for --internal-previous-portfolio-plans must be positive");
Expand All @@ -110,25 +114,51 @@ static shared_ptr<SearchEngine> parse_cmd_line_aux(
if (is_last)
throw ArgError("missing argument after " + arg);
++i;
registry.handle_predefinition(arg.substr(2),
sanitize_arg_string(args[i]),
predefinitions, dry_run);
std::pair<std::string, std::string> predefinition;
try {
predefinition = utils::split(args[i], "=");
} catch (utils::StringOperationError &) {
throw OptionParserError("Predefinition error: Predefinition has to be "
"of the form [name]=[definition].");
}

std::string key = predefinition.first;
std::string value = predefinition.second;
utils::strip(key);
utils::strip(value);
variable_names.insert(key);
predefinitions.insert(make_pair(key,value));
} else {
throw ArgError("unknown option " + arg);
}
}

if (engine) {
PlanManager &plan_manager = engine->get_plan_manager();
plan_manager.set_plan_filename(plan_filename);
plan_manager.set_num_previously_generated_plans(num_previously_generated_plans);
plan_manager.set_is_part_of_anytime_portfolio(is_part_of_anytime_portfolio);
for (auto predefinition : predefinitions) {
search_string = "let(" + predefinition.first +
", " + predefinition.second + ", " + search_string + ")";
}


/*
HACK: we currently do not test whether predefinition types match,
that is we could call "--landmarks h=lmcut() --search "astar(h)"
and it would work.
*/
OptionParser parser(search_string, registry,
variable_names, dry_run);
engine = parser.start_parsing<shared_ptr<PluginBuilder<SearchEngine>>>();

// if (engine) {
// PlanManager &plan_manager = engine->get_plan_manager();
// plan_manager.set_plan_filename(plan_filename);
// plan_manager.set_num_previously_generated_plans(num_previously_generated_plans);
// plan_manager.set_is_part_of_anytime_portfolio(is_part_of_anytime_portfolio);
// }
return engine;
}


shared_ptr<SearchEngine> parse_cmd_line(
shared_ptr<PluginBuilder<SearchEngine>> parse_cmd_line(
int argc, const char **argv, options::Registry &registry, bool dry_run, bool is_unit_cost) {
vector<string> args;
bool active = true;
Expand All @@ -153,7 +183,7 @@ shared_ptr<SearchEngine> parse_cmd_line(
string usage(const string &progname) {
return "usage: \n" +
progname + " [OPTIONS] --search SEARCH < OUTPUT\n\n"
"* SEARCH (SearchEngine): configuration of the search algorithm\n"
"* SEARCH (SearchEngineBuilder): configuration of the search algorithm\n"
"* OUTPUT (filename): translator output\n\n"
"Options:\n"
"--help [NAME]\n"
Expand Down
3 changes: 2 additions & 1 deletion src/search/command_line.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef COMMAND_LINE_H
#define COMMAND_LINE_H

#include "plugin_builder.h"
#include "utils/exceptions.h"

#include <memory>
Expand All @@ -20,7 +21,7 @@ class ArgError : public utils::Exception {
virtual void print() const override;
};

extern std::shared_ptr<SearchEngine> parse_cmd_line(
extern std::shared_ptr<PluginBuilder<SearchEngine>> parse_cmd_line(
int argc, const char **argv, options::Registry &registry, bool dry_run,
bool is_unit_cost);

Expand Down
27 changes: 5 additions & 22 deletions src/search/evaluator.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "evaluator.h"

#include "option_parser.h"
#include "plugin.h"

#include "utils/logging.h"
#include "utils/system.h"

Expand All @@ -11,14 +8,17 @@
using namespace std;


Evaluator::Evaluator(const string &description,
Evaluator::Evaluator(const shared_ptr<AbstractTask> &task,
const string &description,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations)
: description(description),
use_for_reporting_minima(use_for_reporting_minima),
use_for_boosting(use_for_boosting),
use_for_counting_evaluations(use_for_counting_evaluations) {
use_for_counting_evaluations(use_for_counting_evaluations),
task(task),
task_proxy(*task) {
}

bool Evaluator::dead_ends_are_reliable() const {
Expand Down Expand Up @@ -68,20 +68,3 @@ bool Evaluator::is_estimate_cached(const State &) const {
int Evaluator::get_cached_estimate(const State &) const {
ABORT("Called get_cached_estimate when estimate is not cached.");
}

static PluginTypePlugin<Evaluator> _type_plugin(
"Evaluator",
"An evaluator specification is either a newly created evaluator "
"instance or an evaluator that has been defined previously. "
"This page describes how one can specify a new evaluator instance. "
"For re-using evaluators, see OptionSyntax#Evaluator_Predefinitions.\n\n"
"If the evaluator is a heuristic, "
"definitions of //properties// in the descriptions below:\n\n"
" * **admissible:** h(s) <= h*(s) for all states s\n"
" * **consistent:** h(s) <= c(s, s') + h(s') for all states s "
"connected to states s' by an action with cost c(s, s')\n"
" * **safe:** h(s) = infinity is only true for states "
"with h*(s) = infinity\n"
" * **preferred operators:** this heuristic identifies "
"preferred operators ",
"evaluator", "heuristic");
9 changes: 9 additions & 0 deletions src/search/evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define EVALUATOR_H

#include "evaluation_result.h"
#include "task_proxy.h"

#include <memory>
#include <set>

class EvaluationContext;
Expand All @@ -14,8 +16,15 @@ class Evaluator {
const bool use_for_boosting;
const bool use_for_counting_evaluations;

protected:
// Hold a reference to the task implementation and pass it to objects that need it.
const std::shared_ptr<AbstractTask> task;
// Use task_proxy to access task information.
const TaskProxy task_proxy;

public:
Evaluator(
const std::shared_ptr<AbstractTask> &task,
const std::string &description = "<none>",
bool use_for_reporting_minima = false,
bool use_for_boosting = false,
Expand Down
20 changes: 20 additions & 0 deletions src/search/evaluator_builder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "evaluator.h"
#include "plugin.h"
#include "plugin_builder.h"

static PluginTypePlugin<PluginBuilder<Evaluator>> _type_plugin(
"Evaluator",
"An evaluator specification is either a newly created evaluator "
"instance or an evaluator that has been defined previously. "
"This page describes how one can specify a new evaluator instance. "
"For re-using evaluators, see OptionSyntax#Evaluator_Predefinitions.\n\n"
"If the evaluator is a heuristic, "
"definitions of //properties// in the descriptions below:\n\n"
" * **admissible:** h(s) <= h*(s) for all states s\n"
" * **consistent:** h(s) <= c(s, s') + h(s') for all states s "
"connected to states s' by an action with cost c(s, s')\n"
" * **safe:** h(s) = infinity is only true for states "
"with h*(s) = infinity\n"
" * **preferred operators:** this heuristic identifies "
"preferred operators ",
"evaluator", "heuristic");
4 changes: 3 additions & 1 deletion src/search/evaluators/combining_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ using namespace std;

namespace combining_evaluator {
CombiningEvaluator::CombiningEvaluator(
const shared_ptr<AbstractTask> &task,
const vector<shared_ptr<Evaluator>> &subevaluators_)
: subevaluators(subevaluators_) {
: Evaluator(task),
subevaluators(subevaluators_) {
all_dead_ends_are_reliable = true;
for (const shared_ptr<Evaluator> &subevaluator : subevaluators)
if (!subevaluator->dead_ends_are_reliable())
Expand Down
1 change: 1 addition & 0 deletions src/search/evaluators/combining_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CombiningEvaluator : public Evaluator {
virtual int combine_values(const std::vector<int> &values) = 0;
public:
explicit CombiningEvaluator(
const std::shared_ptr<AbstractTask> &task,
const std::vector<std::shared_ptr<Evaluator>> &subevaluators_);
virtual ~CombiningEvaluator() override;

Expand Down
12 changes: 12 additions & 0 deletions src/search/evaluators/combining_evaluator_builder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "combining_evaluator_builder.h"

#include "combining_evaluator.h"

using namespace std;

namespace combining_evaluator {
CombiningEvaluatorBuilder::CombiningEvaluatorBuilder(
const vector<shared_ptr<PluginBuilder<Evaluator>>> &subevaluators_) // TODO: could directly get from options
: subevaluators(subevaluators_) {
}
}
Loading