Skip to content

Commit 97299e0

Browse files
committed
add the possibility to use precondition counts as a feature
1 parent f58e596 commit 97299e0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/search/drivers/sbfws/features/features.cxx

+31
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
#include <utils/loader.hxx>
88
#include <utils/printers/binding.hxx>
99
#include <utils/binding_iterator.hxx>
10+
#include <utils/config.hxx>
1011
#include <constraints/registry.hxx>
1112
#include <languages/fstrips/language.hxx>
13+
#include <problem.hxx>
14+
#include <actions/actions.hxx>
1215

1316
namespace fs = fs0::language::fstrips;
1417

@@ -34,6 +37,10 @@ FeatureSelector<StateT>::select() {
3437
template <typename StateT>
3538
bool
3639
FeatureSelector<StateT>::has_extra_features() const {
40+
41+
// TODO This is a hack, should use a specially named feature in extra.json perhaps¿??
42+
if (Config::instance().getOption<bool>("use_precondition_counts", false)) return true;
43+
3744
// TODO - This is repeating work that is done afterwards when loading the features - can be optimized
3845
try {
3946
auto data = Loader::loadJSONObject(_info.getDataDir() + "/extra.json");
@@ -71,8 +78,27 @@ lapkt::novelty::NoveltyFeature<State>* generate_arbitrary_feature(const ProblemI
7178
}
7279
}
7380

81+
void process_precondition_count(const ProblemInfo& info, std::vector<lapkt::novelty::NoveltyFeature<State>*>& features) {
82+
const auto& actions = Problem::getInstance().getGroundActions();
83+
84+
for (const GroundAction* action:actions) {
85+
auto precondition = dynamic_cast<const fs::Conjunction*>(action->getPrecondition());
86+
if (!precondition) throw std::runtime_error("Cannot use precondition-counts as a feature for non-conjunctive preconditions");
87+
ConditionSetFeature* feature = new ConditionSetFeature();
88+
for (const auto atom:precondition->getConjuncts()) feature->addCondition(atom);
89+
90+
features.push_back(feature);
91+
}
92+
93+
LPT_INFO("cout", "Added " << actions.size() << " precondition-count features");
94+
}
95+
7496
void process_feature(const ProblemInfo& info, const std::string& feat_name, std::vector<lapkt::novelty::NoveltyFeature<State>*>& features) {
97+
//! Some specially-named features receive a distinct treatment
98+
// if (feat_name == "precondition_count") return process_precondition_count(info, features);
99+
75100

101+
// Otherwise, we apply thestandard treatment
76102
unsigned symbol_id = info.getSymbolId(feat_name);
77103
const SymbolData& sdata = info.getSymbolData(symbol_id);
78104
const Signature& signature = sdata.getSignature();
@@ -91,6 +117,10 @@ template <typename StateT>
91117
void
92118
FeatureSelector<StateT>::add_extra_features(const ProblemInfo& info, std::vector<FeatureT*>& features) {
93119

120+
if (Config::instance().getOption<bool>("use_precondition_counts", false)) {
121+
process_precondition_count(info, features);
122+
}
123+
94124
try {
95125
auto data = Loader::loadJSONObject(info.getDataDir() + "/extra.json");
96126
const auto& features_node = data["features"];
@@ -102,6 +132,7 @@ FeatureSelector<StateT>::add_extra_features(const ProblemInfo& info, std::vector
102132
} catch(const std::exception& e) {
103133
return; // No extra.json file could be loaded, therefore we assume there's no extra feature info.
104134
}
135+
105136
}
106137

107138
// explicit template instantiation

0 commit comments

Comments
 (0)