diff --git a/Core/SoarKernel/src/semantic_memory/semantic_memory.h b/Core/SoarKernel/src/semantic_memory/semantic_memory.h index 41f2aa28ee..b77bb18b95 100644 --- a/Core/SoarKernel/src/semantic_memory/semantic_memory.h +++ b/Core/SoarKernel/src/semantic_memory/semantic_memory.h @@ -164,7 +164,7 @@ class SMem_Manager /* Methods for retrieving an LTM structure to be installed in STM */ void add_triple_to_recall_buffer(symbol_triple_list& my_list, Symbol* id, Symbol* attr, Symbol* value); void install_buffered_triple_list(Symbol* state, wme_set& cue_wmes, symbol_triple_list& my_list, bool meta, bool stripLTILinks = false); - void install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* lti, bool activate_lti, symbol_triple_list& meta_wmes, symbol_triple_list& retrieval_wmes, smem_install_type install_type = wm_install, uint64_t depth = 1, std::set* visited = NULL); + void install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* lti, bool activate_lti, symbol_triple_list& meta_wmes, symbol_triple_list& retrieval_wmes, smem_install_type install_type = wm_install, uint64_t depth = 1, std::set* visited = NULL, std::queue>* to_install = NULL); void install_recall_buffer(Symbol* state, wme_set& cue_wmes, symbol_triple_list& meta_wmes, symbol_triple_list& retrieval_wmes, bool stripLTILinks = false); /* Methods to update/store LTM in smem database */ diff --git a/Core/SoarKernel/src/semantic_memory/smem_instance.cpp b/Core/SoarKernel/src/semantic_memory/smem_instance.cpp index 5b64348a55..ebd0fe40cd 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_instance.cpp +++ b/Core/SoarKernel/src/semantic_memory/smem_instance.cpp @@ -200,7 +200,7 @@ uint64_t SMem_Manager::get_current_LTI_for_iSTI(Symbol* pISTI, bool useLookupTab } -void SMem_Manager::install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* sti, bool activate_lti, symbol_triple_list& meta_wmes, symbol_triple_list& retrieval_wmes, smem_install_type install_type, uint64_t depth, std::set* visited) +void SMem_Manager::install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* sti, bool activate_lti, symbol_triple_list& meta_wmes, symbol_triple_list& retrieval_wmes, smem_install_type install_type, uint64_t depth, std::set* visited, std::queue>* to_install) { //////////////////////////////////////////////////////////////////////////// timers->ncb_retrieval->start(); @@ -266,9 +266,10 @@ void SMem_Manager::install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* sti, bool triggered = false; /* This previously would only return the children if there were no impasse wmes, input wmes and slots for sti */ - if (visited == NULL) + if (to_install == NULL) { triggered = true; + to_install = new std::queue>; visited = new std::set; } @@ -279,7 +280,7 @@ void SMem_Manager::install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* sti, // get direct children: attr_type, attr_hash, value_type, value_hash, value_letter, value_num, value_lti expand_q->bind_int(1, pLTI_ID); - std::set children; + //std::set children; while (expand_q->execute() == soar_module::row) { @@ -292,7 +293,7 @@ void SMem_Manager::install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* sti, value_sym = get_current_iSTI_for_LTI(static_cast(expand_q->column_int(4)), sti->id->level, 'L'); if (depth > 1) { - children.insert(value_sym); + to_install->push(std::make_pair(value_sym, depth-1)); } } else @@ -315,19 +316,24 @@ void SMem_Manager::install_memory(Symbol* state, uint64_t pLTI_ID, Symbol* sti, expand_q->reinitialize(); //Attempt to find children for the case of depth. - std::set::iterator iterator; - std::set::iterator end = children.end(); - for (iterator = children.begin(); iterator != end; ++iterator) + Symbol* a_child; + uint64_t new_depth; + visited->insert(pLTI_ID); + while (triggered && !to_install->empty()) { - if (visited->find((*iterator)->id->LTI_ID) == visited->end()) + a_child = to_install->front().first; + new_depth = to_install->front().second; + to_install->pop(); + if (visited->find(a_child->id->LTI_ID) == visited->end()) { - visited->insert((*iterator)->id->LTI_ID); - install_memory(state, (*iterator)->id->LTI_ID, (*iterator), false, meta_wmes, retrieval_wmes, install_type, depth - 1, visited);//choosing not to bla children of retrived node + install_memory(state, a_child->id->LTI_ID, a_child, false, meta_wmes, retrieval_wmes, install_type, new_depth, visited, to_install);//choosing not to bla children of retrived node + visited->insert(a_child->id->LTI_ID); } } if (triggered) { + delete to_install; delete visited; }