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

Issue906 #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/search/operator_counting/pho_constraints.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void PhOConstraints::initialize_constraints(
create pattern_generator locally and no longer need to explicitly reset
it.
*/
pdbs = pattern_collection_info.get_pdbs();
pattern_generator = nullptr;
TaskProxy task_proxy(*task);
pdbs = pattern_collection_info.get_pdbs(task_proxy);
named_vector::NamedVector<lp::LPConstraint> &constraints = lp.get_constraints();
constraint_offset = constraints.size();
for (const shared_ptr<pdbs::PatternDatabase> &pdb : *pdbs) {
Expand Down
7 changes: 4 additions & 3 deletions src/search/pdbs/canonical_pdbs_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ CanonicalPDBs get_canonical_pdbs_from_options(
computed before) so that their computation is not taken into account
for dominance pruning time.
*/
shared_ptr<PDBCollection> pdbs = pattern_collection_info.get_pdbs();
TaskProxy task_proxy(*task);
shared_ptr<PDBCollection> pdbs = pattern_collection_info.get_pdbs(task_proxy);
shared_ptr<vector<PatternClique>> pattern_cliques =
pattern_collection_info.get_pattern_cliques();
pattern_collection_info.get_pattern_cliques(task_proxy);

double max_time_dominance_pruning = opts.get<double>("max_time_dominance_pruning");
if (max_time_dominance_pruning > 0.0) {
Expand All @@ -58,7 +59,7 @@ CanonicalPDBs get_canonical_pdbs_from_options(
}

dump_pattern_collection_generation_statistics(
"Canonical PDB heuristic", timer(), pattern_collection_info, log);
task_proxy, "Canonical PDB heuristic", timer(), pattern_collection_info, log);
return CanonicalPDBs(pdbs, pattern_cliques);
}

Expand Down
4 changes: 3 additions & 1 deletion src/search/pdbs/cegar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ PatternCollectionInformation CEGAR::compute_pattern_collection() {
if (log.is_at_least_normal()) {
log << "CEGAR number of iterations: " << iteration << endl;
dump_pattern_collection_generation_statistics(
task_proxy,
"CEGAR",
timer.get_elapsed_time(),
pattern_collection_information,
Expand Down Expand Up @@ -708,7 +709,8 @@ PatternInformation generate_pattern_with_cegar(
}

Pattern &pattern = new_patterns->front();
shared_ptr<PDBCollection> new_pdbs = collection_info.get_pdbs();
TaskProxy task_proxy(*task);
shared_ptr<PDBCollection> new_pdbs = collection_info.get_pdbs(task_proxy);
shared_ptr<PatternDatabase> &pdb = new_pdbs->front();
PatternInformation result(TaskProxy(*task), move(pattern), log);
result.set_pdb(pdb);
Expand Down
4 changes: 3 additions & 1 deletion src/search/pdbs/pattern_collection_generator_multiple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ unordered_set<int> PatternCollectionGeneratorMultiple::get_blacklisted_variables
}

void PatternCollectionGeneratorMultiple::handle_generated_pattern(
const TaskProxy &task_proxy,
PatternInformation &&pattern_info,
set<Pattern> &generated_patterns,
shared_ptr<PDBCollection> &generated_pdbs,
Expand All @@ -90,7 +91,7 @@ void PatternCollectionGeneratorMultiple::handle_generated_pattern(
PDB, update collection size and reset time_point_of_last_new_pattern.
*/
time_point_of_last_new_pattern = timer.get_elapsed_time();
shared_ptr<PatternDatabase> pdb = pattern_info.get_pdb();
shared_ptr<PatternDatabase> pdb = pattern_info.get_pdb(task_proxy);
remaining_collection_size -= pdb->get_size();
generated_pdbs->push_back(move(pdb));
}
Expand Down Expand Up @@ -216,6 +217,7 @@ PatternCollectionInformation PatternCollectionGeneratorMultiple::compute_pattern
goals[goal_index],
move(blacklisted_variables));
handle_generated_pattern(
task_proxy,
move(pattern_info),
generated_patterns,
generated_pdbs,
Expand Down
1 change: 1 addition & 0 deletions src/search/pdbs/pattern_collection_generator_multiple.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PatternCollectionGeneratorMultiple : public PatternCollectionGenerator {
std::unordered_set<int> get_blacklisted_variables(
std::vector<int> &non_goal_variables);
void handle_generated_pattern(
const TaskProxy &task_proxy,
PatternInformation &&pattern_info,
std::set<Pattern> &generated_patterns,
std::shared_ptr<PDBCollection> &generated_pdbs,
Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_collection_generator_systematic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ PatternCollectionInformation PatternCollectionGeneratorSystematic::compute_patte
const shared_ptr<AbstractTask> &task) {
TaskProxy task_proxy(*task);
patterns = make_shared<PatternCollection>();
pattern_set.clear();
if (only_interesting_patterns) {
assert(pattern_set.empty());
build_patterns(task_proxy);
} else {
build_patterns_naive(task_proxy);
Expand Down
21 changes: 13 additions & 8 deletions src/search/pdbs/pattern_collection_information.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "pattern_cliques.h"
#include "validation.h"

#include "../task_proxy.h"

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

Expand All @@ -19,8 +21,7 @@ PatternCollectionInformation::PatternCollectionInformation(
const TaskProxy &task_proxy,
const shared_ptr<PatternCollection> &patterns,
utils::LogProxy &log)
: task_proxy(task_proxy),
patterns(patterns),
: patterns(patterns),
pdbs(nullptr),
pattern_cliques(nullptr),
log(log) {
Expand Down Expand Up @@ -55,7 +56,8 @@ bool PatternCollectionInformation::information_is_valid() const {
return true;
}

void PatternCollectionInformation::create_pdbs_if_missing() {
void PatternCollectionInformation::create_pdbs_if_missing(
const TaskProxy &task_proxy) {
assert(patterns);
if (!pdbs) {
utils::Timer timer;
Expand All @@ -75,7 +77,8 @@ void PatternCollectionInformation::create_pdbs_if_missing() {
}
}

void PatternCollectionInformation::create_pattern_cliques_if_missing() {
void PatternCollectionInformation::create_pattern_cliques_if_missing(
const TaskProxy &task_proxy) {
if (!pattern_cliques) {
utils::Timer timer;
if (log.is_at_least_normal()) {
Expand Down Expand Up @@ -106,13 +109,15 @@ shared_ptr<PatternCollection> PatternCollectionInformation::get_patterns() const
return patterns;
}

shared_ptr<PDBCollection> PatternCollectionInformation::get_pdbs() {
create_pdbs_if_missing();
shared_ptr<PDBCollection> PatternCollectionInformation::get_pdbs(
const TaskProxy &task_proxy) {
create_pdbs_if_missing(task_proxy);
return pdbs;
}

shared_ptr<vector<PatternClique>> PatternCollectionInformation::get_pattern_cliques() {
create_pattern_cliques_if_missing();
shared_ptr<vector<PatternClique>> PatternCollectionInformation::get_pattern_cliques(
const TaskProxy &task_proxy) {
create_pattern_cliques_if_missing(task_proxy);
return pattern_cliques;
}
}
17 changes: 6 additions & 11 deletions src/search/pdbs/pattern_collection_information.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include "types.h"

#include "../task_proxy.h"

#include <memory>

class TaskProxy;

namespace utils {
class LogProxy;
}
Expand All @@ -25,14 +25,13 @@ namespace pdbs {
as an interface for ownership transfer rather than sharing it.
*/
class PatternCollectionInformation {
TaskProxy task_proxy;
std::shared_ptr<PatternCollection> patterns;
std::shared_ptr<PDBCollection> pdbs;
std::shared_ptr<std::vector<PatternClique>> pattern_cliques;
utils::LogProxy &log;

void create_pdbs_if_missing();
void create_pattern_cliques_if_missing();
void create_pdbs_if_missing(const TaskProxy &task_proxy);
void create_pattern_cliques_if_missing(const TaskProxy &task_proxy);

bool information_is_valid() const;
public:
Expand All @@ -46,13 +45,9 @@ class PatternCollectionInformation {
void set_pattern_cliques(
const std::shared_ptr<std::vector<PatternClique>> &pattern_cliques);

TaskProxy get_task_proxy() const {
return task_proxy;
}

std::shared_ptr<PatternCollection> get_patterns() const;
std::shared_ptr<PDBCollection> get_pdbs();
std::shared_ptr<std::vector<PatternClique>> get_pattern_cliques();
std::shared_ptr<PDBCollection> get_pdbs(const TaskProxy &task_proxy);
std::shared_ptr<std::vector<PatternClique>> get_pattern_cliques(const TaskProxy &task_proxy);
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/search/pdbs/pattern_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ PatternCollectionInformation PatternCollectionGenerator::generate(
}
utils::Timer timer;
PatternCollectionInformation pci = compute_patterns(task);
TaskProxy task_proxy(*task);
dump_pattern_collection_generation_statistics(
name(), timer(), pci, log);
task_proxy, name(), timer(), pci, log);
return pci;
}

Expand All @@ -34,7 +35,9 @@ PatternInformation PatternGenerator::generate(
}
utils::Timer timer;
PatternInformation pattern_info = compute_pattern(task);
TaskProxy task_proxy(*task);
dump_pattern_generation_statistics(
task_proxy,
name(),
timer.stop(),
pattern_info,
Expand Down
10 changes: 5 additions & 5 deletions src/search/pdbs/pattern_information.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ PatternInformation::PatternInformation(
const TaskProxy &task_proxy,
Pattern pattern,
utils::LogProxy &log)
: task_proxy(task_proxy),
pattern(move(pattern)),
: pattern(move(pattern)),
pdb(nullptr) {
validate_and_normalize_pattern(task_proxy, this->pattern, log);
}
Expand All @@ -22,7 +21,7 @@ bool PatternInformation::information_is_valid() const {
return !pdb || pdb->get_pattern() == pattern;
}

void PatternInformation::create_pdb_if_missing() {
void PatternInformation::create_pdb_if_missing(const TaskProxy &task_proxy) {
if (!pdb) {
pdb = make_shared<PatternDatabase>(task_proxy, pattern);
}
Expand All @@ -37,8 +36,9 @@ const Pattern &PatternInformation::get_pattern() const {
return pattern;
}

shared_ptr<PatternDatabase> PatternInformation::get_pdb() {
create_pdb_if_missing();
shared_ptr<PatternDatabase> PatternInformation::get_pdb(
const TaskProxy &task_proxy) {
create_pdb_if_missing(task_proxy);
return pdb;
}
}
9 changes: 2 additions & 7 deletions src/search/pdbs/pattern_information.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ namespace pdbs {
ownership transfer, from the generator to the user.
*/
class PatternInformation {
TaskProxy task_proxy;
Pattern pattern;
std::shared_ptr<PatternDatabase> pdb;

void create_pdb_if_missing();
void create_pdb_if_missing(const TaskProxy &task_proxy);

bool information_is_valid() const;
public:
Expand All @@ -37,12 +36,8 @@ class PatternInformation {

void set_pdb(const std::shared_ptr<PatternDatabase> &pdb);

TaskProxy get_task_proxy() const {
return task_proxy;
}

const Pattern &get_pattern() const;
std::shared_ptr<PatternDatabase> get_pdb();
std::shared_ptr<PatternDatabase> get_pdb(const TaskProxy &task_proxy);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pdb_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ shared_ptr<PatternDatabase> get_pdb_from_options(const shared_ptr<AbstractTask>
shared_ptr<PatternGenerator> pattern_generator =
opts.get<shared_ptr<PatternGenerator>>("pattern");
PatternInformation pattern_info = pattern_generator->generate(task);
return pattern_info.get_pdb();
return pattern_info.get_pdb(TaskProxy(*task));
}

PDBHeuristic::PDBHeuristic(const plugins::Options &opts)
Expand Down
6 changes: 4 additions & 2 deletions src/search/pdbs/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ PatternCollectionInformation get_pattern_collection_info(
}

void dump_pattern_generation_statistics(
const TaskProxy &task_proxy,
const string &identifier,
utils::Duration runtime,
const PatternInformation &pattern_info,
Expand All @@ -111,12 +112,13 @@ void dump_pattern_generation_statistics(
log << identifier << " pattern: " << pattern << endl;
log << identifier << " number of variables: " << pattern.size() << endl;
log << identifier << " PDB size: "
<< compute_pdb_size(pattern_info.get_task_proxy(), pattern) << endl;
<< compute_pdb_size(task_proxy, pattern) << endl;
log << identifier << " computation time: " << runtime << endl;
}
}

void dump_pattern_collection_generation_statistics(
const TaskProxy &task_proxy,
const string &identifier,
utils::Duration runtime,
const PatternCollectionInformation &pci,
Expand All @@ -127,7 +129,7 @@ void dump_pattern_collection_generation_statistics(
<< endl;
log << identifier << " total PDB size: "
<< compute_total_pdb_size(
pci.get_task_proxy(), pattern_collection) << endl;
task_proxy, pattern_collection) << endl;
log << identifier << " computation time: " << runtime << endl;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/search/pdbs/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern PatternCollectionInformation get_pattern_collection_info(
prepended with the given string identifier.
*/
extern void dump_pattern_generation_statistics(
const TaskProxy &task_proxy,
const std::string &identifier,
utils::Duration runtime,
const PatternInformation &pattern_info,
Expand All @@ -59,6 +60,7 @@ extern void dump_pattern_generation_statistics(
prepended with the given string identifier.
*/
extern void dump_pattern_collection_generation_statistics(
const TaskProxy &task_proxy,
const std::string &identifier,
utils::Duration runtime,
const PatternCollectionInformation &pci,
Expand Down