7
7
#include < utils/loader.hxx>
8
8
#include < utils/printers/binding.hxx>
9
9
#include < utils/binding_iterator.hxx>
10
+ #include < utils/config.hxx>
10
11
#include < constraints/registry.hxx>
11
12
#include < languages/fstrips/language.hxx>
13
+ #include < problem.hxx>
14
+ #include < actions/actions.hxx>
12
15
13
16
namespace fs = fs0::language::fstrips;
14
17
@@ -34,6 +37,10 @@ FeatureSelector<StateT>::select() {
34
37
template <typename StateT>
35
38
bool
36
39
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
+
37
44
// TODO - This is repeating work that is done afterwards when loading the features - can be optimized
38
45
try {
39
46
auto data = Loader::loadJSONObject (_info.getDataDir () + " /extra.json" );
@@ -71,8 +78,27 @@ lapkt::novelty::NoveltyFeature<State>* generate_arbitrary_feature(const ProblemI
71
78
}
72
79
}
73
80
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
+
74
96
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
+
75
100
101
+ // Otherwise, we apply thestandard treatment
76
102
unsigned symbol_id = info.getSymbolId (feat_name);
77
103
const SymbolData& sdata = info.getSymbolData (symbol_id);
78
104
const Signature& signature = sdata.getSignature ();
@@ -91,6 +117,10 @@ template <typename StateT>
91
117
void
92
118
FeatureSelector<StateT>::add_extra_features(const ProblemInfo& info, std::vector<FeatureT*>& features) {
93
119
120
+ if (Config::instance ().getOption <bool >(" use_precondition_counts" , false )) {
121
+ process_precondition_count (info, features);
122
+ }
123
+
94
124
try {
95
125
auto data = Loader::loadJSONObject (info.getDataDir () + " /extra.json" );
96
126
const auto & features_node = data[" features" ];
@@ -102,6 +132,7 @@ FeatureSelector<StateT>::add_extra_features(const ProblemInfo& info, std::vector
102
132
} catch (const std::exception & e) {
103
133
return ; // No extra.json file could be loaded, therefore we assume there's no extra feature info.
104
134
}
135
+
105
136
}
106
137
107
138
// explicit template instantiation
0 commit comments