OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AttentionValue.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/AttentionValue.h
3  *
4  * Copyright (C) 2002-2007 Novamente LLC
5  * All Rights Reserved
6  *
7  * Written by Tony Lofthouse <tony_lofthouse@btinternet.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License v3 as
11  * published by the Free Software Foundation and including the exceptions
12  * at http://opencog.org/wiki/Licenses
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program; if not, write to:
21  * Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef _OPENCOG_ATTENTION_VALUE_H
26 #define _OPENCOG_ATTENTION_VALUE_H
27 
28 #include <string>
29 #include <limits.h>
30 
32 
33 namespace opencog
34 {
39 class AttentionValue;
41 typedef std::shared_ptr<AttentionValue> AttentionValuePtr;
42 #define createAV std::make_shared<AttentionValue>
43 
45  : public std::enable_shared_from_this<AttentionValue>
46 {
47 public:
48  typedef short sti_t;
49  typedef short lti_t;
50  typedef short vlti_t;
51 
52  static const int DISPOSABLE = 0;
53 
54  // CLASS CONSTANTS
55  static const sti_t DEFAULTATOMSTI;
56  static const lti_t DEFAULTATOMLTI;
57  static const vlti_t DEFAULTATOMVLTI;
58 
59  static const sti_t MAXSTI = SHRT_MAX;
60  static const lti_t MAXLTI = SHRT_MAX;
61  static const sti_t MINSTI = SHRT_MIN;
62  static const lti_t MINLTI = SHRT_MIN;
63 
66  static AttentionValuePtr instance = createAV();
67  return instance;
68  }
69 
70 private:
71 
72  //CLASS FIELDS
78 
83  void decaySTI();
84 
85  friend class ImportanceIndex; // The index can change the STI.
86 
87 public:
94  lti_t LTI = DEFAULTATOMLTI,
95  vlti_t VLTI = DEFAULTATOMVLTI)
96  : m_STI(STI), m_LTI(LTI), m_VLTI(VLTI<0 ? 0 : VLTI) {}
97 
99 
101  sti_t getSTI() const { return m_STI; }
102  float getScaledSTI() const { return (((float) m_STI) + 32768) / 65534; }
103 
105  lti_t getLTI() const { return m_LTI; }
106 
108  vlti_t getVLTI() const { return m_VLTI; }
109 
111  // @param none
112  std::string toString() const;
113 
115  // @param none
118 
121  // @param none
122  bool operator==(const AttentionValue& av) const {
123  return (m_STI == av.getSTI() && m_LTI == av.getLTI() && m_VLTI == av.getVLTI());
124  }
125  inline bool operator!=(const AttentionValue& rhs) const
126  { return !(*this == rhs); }
127 
129  struct STISort : public AtomComparator {
130  STISort() {};
131  virtual bool test(const AtomPtr&, const AtomPtr&) const;
132  };
133 
137  virtual bool test(const AtomPtr&, const AtomPtr&) const;
138  };
139 
143  virtual bool test(const AtomPtr&, const AtomPtr&) const;
144  };
145 };
146 
147 
149 } // namespace opencog
150 
151 #endif // _OPENCOG_ATTENTION_VALUE_H
virtual bool test(const AtomPtr &, const AtomPtr &) const
AttentionValue * rawclone() const
std::shared_ptr< Atom > AtomPtr
Definition: Handle.h:48
short vlti_t
very long-term importance type
bool operator!=(const AttentionValue &rhs) const
std::shared_ptr< AttentionValue > AttentionValuePtr
virtual bool test(const AtomPtr &, const AtomPtr &) const
bool operator==(const AttentionValue &av) const
short lti_t
long-term importance type
static AttentionValuePtr m_defaultAV
lti_t getLTI() const
return LTI property value
static const int DISPOSABLE
Status flag for vlti.
float getScaledSTI() const
static const lti_t DEFAULTATOMLTI
long-term importance default
virtual bool test(const AtomPtr &, const AtomPtr &) const
short sti_t
short-term importance type
sti_t m_STI
short-term importance
void decaySTI()
default attention value
std::string toString() const
Returns const string "[sti_val, lti_val, vlti_val]".
AttentionValuePtr clone() const
Returns An AttentionValue* cloned from this AttentionValue.
static AttentionValuePtr DEFAULT_AV()
to be used as default attention value
static const lti_t MAXLTI
static const sti_t DEFAULTATOMSTI
short-term importance default
vlti_t getVLTI() const
return VLTI property value
functor for comparing atom's attention value
static const lti_t MINLTI
static const sti_t MINSTI
AttentionValue(sti_t STI=DEFAULTATOMSTI, lti_t LTI=DEFAULTATOMLTI, vlti_t VLTI=DEFAULTATOMVLTI)
#define createAV
functor for comparing atom's attention value
sti_t getSTI() const
return STI property value
lti_t m_LTI
long-term importance
static const sti_t MAXSTI
static const vlti_t DEFAULTATOMVLTI
very long-term default
functor for comparing atom's attention value