OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AttentionalFocusCB.cc
Go to the documentation of this file.
1 /*
2  * AttentionalFocusCB.cc
3  *
4  * Copyright (C) 2014 Misgana Bayetta
5  *
6  * Author: Misgana Bayetta <misgana.bayetta@gmail.com> July 2014
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License v3 as
10  * published by the Free Software Foundation and including the exceptions
11  * at http://opencog.org/wiki/Licenses
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program; if not, write to:
20  * Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 #include "AttentionalFocusCB.h"
24 
25 using namespace opencog;
26 
27 // Uncomment below to enable debug print
28 // #define DEBUG
29 #ifdef DEBUG
30  #define dbgprt(f, varargs...) printf(f, ##varargs)
31 #else
32  #define dbgprt(f, varargs...)
33 #endif
34 
37 {
38  // Temporarily disable the AF mechanism during the URE development
39  // _as->setAttentionalFocusBoundary(AttentionValue::MINSTI);
40 }
41 
42 bool AttentionalFocusCB::node_match(const Handle& node1, const Handle& node2)
43 {
44  return node1 == node2 and
46 }
47 
48 bool AttentionalFocusCB::link_match(const LinkPtr& lpat, const LinkPtr& lsoln)
49 {
50  return DefaultPatternMatchCB::link_match(lpat, lsoln)
51  and lsoln->getSTI() > _as->get_attentional_focus_boundary();
52 }
53 
55 {
56  const IncomingSet &incoming_set = h->getIncomingSet();
57 
58  // Discard the part of the incoming set that is below the
59  // AF boundary. The PM will look only at those links that
60  // this callback returns; thus we avoid searching the low-AF
61  // parts of the hypergraph.
62  IncomingSet filtered_set;
63  for (const auto& l : incoming_set)
64  if (l->getSTI() > _as->get_attentional_focus_boundary())
65  filtered_set.push_back(l);
66 
67  // If nothing is in AF
68  if (filtered_set.empty())
69  {
70  // Returning the empty set abandons the search in this direction.
71  // Search will then backtrack and try a different direction.
72  // ... and that is exactly what should be happening.
73  return filtered_set;
74  }
75 
76  // The exploration of the set of patterns proceeds by going through
77  // the incoming set, one by one. So sorting the incoming set will
78  // cause the exploration to look at the highest STI atoms first.
79  std::sort(filtered_set.begin(), filtered_set.end(), compare_sti);
80 
81  return filtered_set;
82 }
IncomingSet getIncomingSet()
Definition: Atom.cc:321
std::shared_ptr< Link > LinkPtr
Definition: Atom.h:53
IncomingSet get_incoming_set(const Handle &)
virtual bool link_match(const LinkPtr &, const LinkPtr &)
std::vector< LinkPtr > IncomingSet
Definition: Atom.h:55
bool node_match(const Handle &, const Handle &)
AttentionValue::sti_t get_attentional_focus_boundary() const
Definition: AtomSpace.h:538
bool link_match(const LinkPtr &, const LinkPtr &)
AttentionValue::sti_t getSTI()
Handy-dandy convenience getters for attention values.
Definition: Atom.h:226
static bool compare_sti(LinkPtr lptr1, LinkPtr lptr2)