39 using namespace opencog;
63 throw InvalidParamException(TRACE_INFO,
"Needs a valid source atom");
67 vector<Rule*> chosen_rules;
70 for (
Rule* rule : rules) {
77 derived_rules.insert(derived_rules.end(),hs.begin(),hs.end());
80 if (not derived_rules.empty())
82 chosen_rules.push_back(rule);
117 gcb.implicand = bl->get_implicand();
122 [] (std::vector<std::map<Handle,Handle>>& vec_map,
const Handle& h) {
123 for (
auto& map: vec_map)
124 for(
auto& it:map) {
if (it.second == h) map.erase(it.first);}
129 del_by_value(gcb.term_groundings, implicant_vardecl);
130 del_by_value(gcb.var_groundings, implicant_vardecl);
133 for (
const auto& termg_map : gcb.term_groundings) {
134 for (
const auto& it : termg_map) {
135 if (it.second == sourcecpy) {
143 for (
Handle nr : new_candidate_rules) {
144 if (find(derived_rules.begin(), derived_rules.end(), nr) == derived_rules.end()) {
149 derived_rules.push_back(h);
156 return derived_rules;
172 for (
Handle h : impl_members) {
175 output_expanded.insert(hs.begin(), hs.end());
178 for (
Handle h : output_expanded) {
180 derived_rules.insert(derived_rules.end(), result.begin(), result.end());
183 return derived_rules;
196 for (
auto hn : neighbors) {
197 if (hn->getType() != VARIABLE_NODE) {
200 for (
auto r : roots) {
201 if (find(inputs.begin(), inputs.end(), r) == inputs.end() and r->getType()
214 map<Handle, float> tournament_elem;
222 tournament_elem[
t] = fitness;
226 tournament_elem[
t] =
t->getSTI();
229 throw RuntimeException(TRACE_INFO,
230 "Unknown source selection mode.");
238 for (
size_t i = 0; i < tournament_elem.size(); i++) {
271 for (
auto iter = product.begin(); iter != product.end();) {
273 iter = product.erase(iter);
282 const Handle& parent_varlist)
289 oset =
LinkCast(parent_varlist)->getOutgoingSet();
291 oset.push_back(parent_varlist);
296 for (
const Handle& h : oset) {
297 Type t = h->getType();
299 if (VARIABLE_NODE == t && fv.
varset.count(h) == 1)
300 final_oset.push_back(h);
301 else if (TYPED_VARIABLE_LINK == t
303 final_oset.push_back(h);
322 const std::vector<std::map<Handle, Handle>>& var_groundings)
324 std::vector<std::map<Handle, Handle>> filtered_vgmap_list;
327 for (
const auto& varg_map : var_groundings) {
328 std::map<Handle, Handle> filtered;
330 for (
const auto& iv : varg_map){
331 if (find(vars.begin(), vars.end(), iv.first) != vars.end()){
332 filtered[iv.first] = iv.second;
336 filtered_vgmap_list.push_back(filtered);
343 for (
auto& vgmap : filtered_vgmap_list) {
352 himplicant,
LinkCast(hrule)->getOutgoingSet()[0]);
354 hvarlist, himplicant, himplicand })));
355 derived_rules.push_back(hderived_rule);
362 return derived_rules;
374 if (h->
getType() == ABSENT_LINK)
static bool contains_atomtype(const Handle &clause, Type atom_type)
HandleSeq get_potential_sources(void)
std::set< Handle > varset
HandleSeq get_implicant_seq()
void set_fcmem(FCMemory *fcmem)
HandleSeq get_products(void)
std::vector< Handle > HandleSeq
a list of handles
DefaultForwardChainerCB(AtomSpace &as, source_selection_mode ts_mode=TV_FITNESS_BASED)
Handle get_cur_source(void)
source_selection_mode _ts_mode
virtual HandleSeq choose_premises(FCMemory &fcmem)
static BindLinkPtr BindLinkCast(const Handle &h)
HandleSeq unify(Handle source, Handle target, Rule *rule)
Type tournament_select(map< Type, float > tfitnes_map)
UnorderedHandleSet get_distant_neighbors(const Handle &h, int dist)
bool is_valid_implicant(const Handle &h)
HandleSeq subatom_unify(Handle source, Rule *rule)
static const Handle UNDEFINED
bool isin_potential_sources(Handle h)
#define createVariableList
bool isin_selected_sources(Handle h)
std::shared_ptr< BindLink > BindLinkPtr
Handle substitute(const Handle &expr, const std::map< Handle, Handle > &vars)
static LinkPtr LinkCast(const Handle &h)
virtual Handle choose_next_source(FCMemory &fcmem)
Handle gen_sub_varlist(const Handle &parent, const Handle &parent_varlist)
HandleSeq substitute_rule_part(AtomSpace &as, Handle hrule, const std::set< Handle > &vars, const std::vector< std::map< Handle, Handle >> &var_groundings)
vector< Rule * > & get_rules()
UnorderedHandleSet get_all_unique_atoms(Handle h)
void get_root_links(Handle h, HandleSeq &parents)
virtual vector< Rule * > choose_rules(FCMemory &fcmem)
unsigned short Type
type of Atoms, represented as short integer (16 bits)
std::unordered_set< Handle, handle_hash > UnorderedHandleSet
a hash that associates the handle to its unique identificator
float tv_fitness(Handle h)
std::map< Handle, std::vector< Handle > > rule_derivations
virtual HandleSeq apply_rule(FCMemory &fcmem)
void search_set(const Handle &h)
Handle add_atom(AtomPtr atom, bool async=false)