diff --git a/opencog/ure/forwardchainer/SourceSet.cc b/opencog/ure/forwardchainer/SourceSet.cc index faaf64acfc..bf8e5f5c8f 100644 --- a/opencog/ure/forwardchainer/SourceSet.cc +++ b/opencog/ure/forwardchainer/SourceSet.cc @@ -29,8 +29,12 @@ namespace opencog { -Source::Source(const Handle& bdy, const Handle& vdcl, double cpx) - : body(bdy), vardecl(vdcl), complexity(cpx), exhausted(false) +Source::Source(const Handle& bdy, const Handle& vdcl, double cpx, double cpx_fctr) + : body(bdy), + vardecl(vdcl), + complexity(cpx), + complexity_factor(cpx_fctr), + exhausted(false) { } @@ -137,11 +141,13 @@ void SourceSet::insert(const HandleSet& products, const Source& src, double prob // Calculate the complexity of the new sources double new_cpx = src.expand_complexity(prob); + double new_cpx_fctr = exp(-_config.get_complexity_penalty() * new_cpx); // Insert all new sources int new_sources = 0; for (const Handle& product : products) { - Source* new_src = new Source(product, empty_variable_list, new_cpx); + Source* new_src = new Source(product, empty_variable_list, + new_cpx, new_cpx_fctr); // Make sure it isn't already in the sources if (boost::binary_search(sources, *new_src)) { @@ -188,7 +194,7 @@ double SourceSet::get_weight(const Source& src) const double SourceSet::complexity_factor(const Source& src) const { - return exp(-_config.get_complexity_penalty() * src.complexity); + return src.complexity_factor; } std::string oc_to_string(const Source& src, const std::string& indent) diff --git a/opencog/ure/forwardchainer/SourceSet.h b/opencog/ure/forwardchainer/SourceSet.h index ab11f4e883..c4d79b57bf 100644 --- a/opencog/ure/forwardchainer/SourceSet.h +++ b/opencog/ure/forwardchainer/SourceSet.h @@ -58,7 +58,8 @@ class Source : public boost::totally_ordered public: Source(const Handle& body, const Handle& vardecl=Handle::UNDEFINED, - double complexity=0.0); + double complexity=0.0, + double complexity_factor=1.0); /** * Comparison operators. For operator< compare by complexity, or by @@ -86,13 +87,17 @@ class Source : public boost::totally_ordered std::string to_string(const std::string& indent=empty_string) const; // Body of the source - Handle body; + const Handle body; // Variable declaration, if any, associated to body - Handle vardecl; + const Handle vardecl; // Sum of the complexities of the steps involved in producing it. - double complexity; + const double complexity; + + // Proxy for the prior probability of the source, taking into + // account the complexity penalty. + const double complexity_factor; // True iff all rules that could expand the source have been tried bool exhausted;