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

Issue911 #10

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 @@ -37,8 +37,8 @@ void PhOConstraints::initialize_constraints(
it.
*/
pattern_generator = nullptr;
pdbs = pattern_collection_info.get_pdbs();
TaskProxy task_proxy(*task);
pdbs = pattern_collection_info.get_pdbs(task_proxy);
constraint_offset = constraints.size();
for (const shared_ptr<pdbs::PatternDatabase> &pdb : *pdbs) {
constraints.emplace_back(0, infinity);
Expand Down
9 changes: 5 additions & 4 deletions src/search/pdbs/canonical_pdbs_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ 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) {
int num_variables = TaskProxy(*task).get_variables().size();
int num_variables = task_proxy.get_variables().size();
/*
NOTE: Dominance pruning could also be computed without having access
to the PDBs, but since we want to delete patterns, we also want to
Expand All @@ -58,7 +59,7 @@ CanonicalPDBs get_canonical_pdbs_from_options(

// Do not dump pattern collections for size reasons.
dump_pattern_collection_generation_statistics(
"Canonical PDB heuristic", timer(), pattern_collection_info, false);
task_proxy, "Canonical PDB heuristic", timer(), pattern_collection_info, false);
return CanonicalPDBs(pdbs, pattern_cliques);
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_collection_generator_combo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PatternCollectionInformation PatternCollectionGeneratorCombo::generate(

PatternCollectionInformation pci(task_proxy, patterns);
dump_pattern_collection_generation_statistics(
"Combo generator", timer(), pci);
task_proxy, "Combo generator", timer(), pci);
return pci;
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_collection_generator_genetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ PatternCollectionInformation PatternCollectionGeneratorGenetic::generate(
assert(best_patterns);
PatternCollectionInformation pci(task_proxy, best_patterns);
dump_pattern_collection_generation_statistics(
"Genetic generator", timer(), pci);
task_proxy, "Genetic generator", timer(), pci);
return pci;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ PatternCollectionInformation PatternCollectionGeneratorHillclimbing::generate(

PatternCollectionInformation pci = current_pdbs->get_pattern_collection_information();
dump_pattern_collection_generation_statistics(
"Hill climbing generator", timer(), pci);
task_proxy, "Hill climbing generator", timer(), pci);
return pci;
}

Expand Down
4 changes: 2 additions & 2 deletions src/search/pdbs/pattern_collection_generator_systematic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ PatternCollectionInformation PatternCollectionGeneratorSystematic::generate(
utils::g_log << "Generating patterns using the systematic generator..." << endl;
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 All @@ -277,7 +277,7 @@ PatternCollectionInformation PatternCollectionGeneratorSystematic::generate(
/* Do not dump the collection since it can be very large for
pattern_max_size >= 3. */
dump_pattern_collection_generation_statistics(
"Systematic generator", timer(), pci, false);
task_proxy, "Systematic generator", timer(), pci, false);
return pci;
}

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 @@ -18,8 +20,7 @@ namespace pdbs {
PatternCollectionInformation::PatternCollectionInformation(
const TaskProxy &task_proxy,
const shared_ptr<PatternCollection> &patterns)
: task_proxy(task_proxy),
patterns(patterns),
: patterns(patterns),
pdbs(nullptr),
pattern_cliques(nullptr) {
assert(patterns);
Expand Down Expand Up @@ -53,7 +54,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 @@ -68,7 +70,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;
utils::g_log << "Computing pattern cliques for pattern collection..." << endl;
Expand All @@ -95,13 +98,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;
}
}
18 changes: 7 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 pdbs {
/*
This class contains everything we know about a pattern collection. It will
Expand All @@ -21,13 +21,12 @@ 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;

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 @@ -40,13 +39,10 @@ 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
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_generator_greedy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PatternInformation PatternGeneratorGreedy::generate(const shared_ptr<AbstractTas

PatternInformation pattern_info(task_proxy, move(pattern));
dump_pattern_generation_statistics(
"Greedy generator", timer(), pattern_info);
task_proxy, "Greedy generator", timer(), pattern_info);
return pattern_info;
}

Expand Down
18 changes: 9 additions & 9 deletions src/search/pdbs/pattern_information.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ namespace pdbs {
PatternInformation::PatternInformation(
const TaskProxy &task_proxy,
Pattern pattern)
: task_proxy(task_proxy),
pattern(move(pattern)),
: pattern(move(pattern)),
pdb(nullptr) {
validate_and_normalize_pattern(task_proxy, this->pattern);
}

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);
}
}

bool PatternInformation::information_is_valid() const {
return !pdb || pdb->get_pattern() == pattern;
}

void PatternInformation::set_pdb(const shared_ptr<PatternDatabase> &pdb_) {
pdb = pdb_;
assert(information_is_valid());
Expand All @@ -36,8 +35,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 @@ -20,24 +20,19 @@ 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:
PatternInformation(const TaskProxy &task_proxy, Pattern pattern);

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 @@ -17,7 +17,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 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 @@ -29,18 +29,20 @@ int compute_total_pdb_size(
}

void dump_pattern_generation_statistics(
const TaskProxy &task_proxy,
const string &identifier,
utils::Duration runtime,
const PatternInformation &pattern_info) {
const Pattern &pattern = pattern_info.get_pattern();
utils::g_log << identifier << " pattern: " << pattern << endl;
utils::g_log << identifier << " number of variables: " << pattern.size() << endl;
utils::g_log << identifier << " PDB size: "
<< compute_pdb_size(pattern_info.get_task_proxy(), pattern) << endl;
<< compute_pdb_size(task_proxy, pattern) << endl;
utils::g_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 @@ -52,7 +54,7 @@ void dump_pattern_collection_generation_statistics(
utils::g_log << identifier << " number of patterns: " << pattern_collection.size()
<< endl;
utils::g_log << identifier << " total PDB size: "
<< compute_total_pdb_size(pci.get_task_proxy(), pattern_collection)
<< compute_total_pdb_size(task_proxy, pattern_collection)
<< endl;
utils::g_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 @@ -24,6 +24,7 @@ extern int compute_total_pdb_size(
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 @@ -35,6 +36,7 @@ extern void dump_pattern_generation_statistics(
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