30 using namespace opencog;
35 #define dbgprt(f, varargs...) printf(f, ##varargs)
37 #define dbgprt(f, varargs...)
46 _type_restrictions(NULL),
112 Handle& start,
size_t& width)
118 if (t != VARIABLE_NODE) {
127 if (CHOICE_LINK == t)
138 size_t deepest = depth;
141 size_t thinnest = SIZE_MAX;
144 for (
Handle hunt : ll->getOutgoingSet())
146 size_t brdepth = depth + 1;
147 size_t brwid = SIZE_MAX;
151 if (QUOTE_LINK == hunt->getType())
152 hunt =
LinkCast(hunt)->getOutgoingAtom(0);
157 and (brwid < thinnest
158 or (brwid == thinnest and deepest < brdepth)))
179 const std::set<Handle>& evl,
183 size_t thinnest = SIZE_MAX;
189 size_t nc = clauses.size();
190 for (
size_t i=0; i < nc; i++)
193 if (0 < evl.count(clauses[i]))
continue;
196 size_t width = SIZE_MAX;
200 and (width < thinnest
201 or (width == thinnest and depth > deepest)))
269 _root = clauses[bestclause];
270 dbgprt(
"Search start node: %s\n", best_start->toShortString().c_str());
279 size_t sz = iset.size();
280 for (
size_t i = 0; i < sz; i++)
283 dbgprt(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
284 dbgprt(
"Loop candidate (%lu/%lu):\n%s\n", i+1, sz,
289 if (found)
return true;
388 dbgprt(
"Attempt to use node-neighbor search\n");
391 if (found)
return true;
399 dbgprt(
"Cannot use node-neighbor search, use no-var search\n");
400 _search_fail =
false;
402 if (found)
return true;
403 if (not _search_fail)
return false;
410 dbgprt(
"Cannot use no-var search, use link-type search\n");
411 _search_fail =
false;
413 if (found)
return true;
414 if (not _search_fail)
return false;
422 dbgprt(
"Cannot use link-type search, use variable-type search\n");
423 _search_fail =
false;
439 if (QUOTE_LINK == t)
return;
440 if (CHOICE_LINK == t)
return;
443 if (NULL == lll)
return;
452 const HandleSeq& oset = lll->getOutgoingSet();
453 for (
const Handle& h : oset)
471 size_t count = SIZE_MAX;
473 for (
const Handle& cl: clauses)
511 for (
const Handle& h : handle_set)
513 dbgprt(
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n");
514 dbgprt(
"Loop candidate (%lu/%lu):\n%s\n", ++i, handle_set.size(),
515 h->toShortString().c_str());
517 if (found)
return true;
540 size_t count = SIZE_MAX;
551 const std::set<Type>& typeset = tit->second;
552 dbgprt(
"Type-restictions set size = %lu\n", typeset.size());
553 for (
Type t : typeset)
556 dbgprt(
"Type = %s has %lu atoms in the atomspace\n",
558 if (0 < num and num < count)
560 for (
const Handle& cl : clauses)
573 dbgprt(
"New minimum count of %lu\n", count);
582 dbgprt(
"New minimum count of %lu (nonroot)\n", count);
593 dbgprt(
"There were no type restrictions! That must be wrong!\n");
594 if (0 == clauses.size())
610 dbgprt(
"Atomspace reported %lu atoms\n", handle_set.size());
615 for (
const Handle& h : handle_set)
617 dbgprt(
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n");
618 dbgprt(
"Loop candidate (%lu/%lu):\n%s\n", ++i, handle_set.size(),
619 h->toShortString().c_str());
621 if (found)
return true;
651 if (0 == evl.count(clauses[0]))
657 dbgprt(
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n");
658 dbgprt(
"Non-search: no variables, no non-evaluatable clauses\n");
virtual Handle find_thinnest(const HandleSeq &, const std::set< Handle > &, Handle &, size_t &)
bool explore_neighborhood(const Handle &, const Handle &, const Handle &)
virtual bool neighbor_search(PatternMatchEngine *)
InitiateSearchCB(AtomSpace *)
std::vector< Handle > HandleSeq
a list of handles
std::set< Handle > evaluatable_holders
std::set< Handle > varset
std::set< Handle > evaluatable_terms
virtual std::string toShortString(std::string indent="")=0
ClassServer & _classserver
std::shared_ptr< Link > LinkPtr
void get_handles_by_type(HandleSeq &appendToHandles, Type type, bool subclass=false) const
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
virtual IncomingSet get_incoming_set(const Handle &h)
const Variables * _variables
virtual bool link_type_search(PatternMatchEngine *)
static const Handle UNDEFINED
const VariableTypeMap * _type_restrictions
virtual void find_rarest(const Handle &, Handle &, size_t &)
const std::set< Handle > * _dynamic
std::set< Handle > least_holders
int get_num_atoms_of_type(Type type, bool subclass=false) const
const std::string & getTypeName(Type type)
virtual bool no_search(PatternMatchEngine *)
static LinkPtr LinkCast(const Handle &h)
std::vector< LinkPtr > IncomingSet
virtual Handle find_starter(const Handle &, size_t &, Handle &, size_t &)
unsigned short Type
type of Atoms, represented as short integer (16 bits)
size_t getIncomingSetSize()
Get the size of the incoming set.
virtual bool variable_search(PatternMatchEngine *)
virtual bool initiate_search(PatternMatchEngine *)
void search_set(const Handle &h)
#define dbgprt(f, varargs...)
virtual void set_pattern(const Variables &, const Pattern &)