Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wma.h
Go to the documentation of this file.
1 /*************************************************************************
2  * PLEASE SEE THE FILE "COPYING" (INCLUDED WITH THIS SOFTWARE PACKAGE)
3  * FOR LICENSE AND COPYRIGHT INFORMATION.
4  *************************************************************************/
5 
6 /*************************************************************************
7  *
8  * file: wma.h
9  *
10  * =======================================================================
11  */
12 
13 #ifndef WMA_H
14 #define WMA_H
15 
16 #include <string>
17 #include <queue>
18 #include "soar_module.h"
19 
20 typedef struct wme_struct wme;
21 
23 // WMA Constants
25 
29 #define WMA_DECAY_HISTORY 10
30 
35 #define WMA_REFERENCES_PER_DECISION 50
36 
42 #define WMA_ACTIVATION_NONE 1.0
43 #define WMA_TIME_SUM_NONE 2.71828182845905
44 
48 #define WMA_ACTIVATION_LOW -1000000000
49 
53 #define WMA_FORGOTTEN_CYCLE 0
54 
56 // WMA Parameters
58 
60 class wma_decay_param;
61 
63 {
64  public:
69 
72 
75 
77 
78  // performance
81 
82  wma_param_container( agent* new_agent );
83 };
84 
86 {
87  public:
88  wma_activation_param( const char* new_name, soar_module::boolean new_value, soar_module::predicate<soar_module::boolean>* new_prot_pred, agent* new_agent );
89  virtual void set_value( soar_module::boolean new_value );
90 
91  private:
93 };
94 
96 {
97  public:
98  wma_decay_param( const char* new_name, double new_value, soar_module::predicate<double>* new_val_pred, soar_module::predicate<double>* new_prot_pred );
99  virtual void set_value( double new_value );
100 };
101 
102 template <typename T>
104 {
105  public:
106  wma_activation_predicate( agent* new_agent );
107  bool operator() ( T val );
108 };
109 
111 // WMA Statistics
113 
115 {
116  public:
118 
119  wma_stat_container( agent* new_agent );
120 };
121 
122 
124 // WMA Timers
126 
128 {
129  public:
132 
134 };
135 
136 class wma_timer_level_predicate: public soar_module::agent_predicate< soar_module::timer::timer_level >
137 {
138  public:
139  wma_timer_level_predicate( agent *new_agent );
141 };
142 
144 {
145  public:
146  wma_timer( const char *new_name, agent *new_agent, timer_level new_level );
147 };
148 
149 
151 // WMA Types
153 
154 typedef uint64_t wma_reference;
155 typedef uint64_t wma_d_cycle;
156 
158 {
162 
163 typedef struct wma_history_struct
164 {
166  unsigned int next_p;
167  unsigned int history_ct;
168 
172 } wma_history;
173 
174 // attached to o-supported WMEs to keep track of its activation.
176 {
177  // the wme that this element goes with
179 
180  // when a WME is removed from working memory, the data
181  // structure is not necessarily deallocated right away
182  // because its reference count has not fallen to zero.
183  // This flag indicates that the WME is in this "limbo" state.
185 
186  // notes the awkward period between first activation
187  // and dealing with history changes
189 
190  // how many times this wme has been referenced so far
191  // this cycle
193 
194  // when and how often this wme has been referenced in recent
195  // history.
197 
198  // if forgetting is enabled, this tells us when we think
199  // we need to forget this wme
201 
203 
204 #ifdef USE_MEM_POOL_ALLOCATORS
205 typedef std::set< wma_decay_element*, std::less< wma_decay_element* >, soar_module::soar_memory_pool_allocator< wma_decay_element* > > wma_decay_set;
206 typedef std::map< wma_d_cycle, wma_decay_set*, std::less< wma_d_cycle >, soar_module::soar_memory_pool_allocator< std::pair< wma_d_cycle, wma_decay_set* > > > wma_forget_p_queue;
207 typedef std::set< wma_d_cycle, std::less< wma_d_cycle >, soar_module::soar_memory_pool_allocator< wma_d_cycle > > wma_decay_cycle_set;
208 
209 typedef std::set< wme*, std::less< wme* >, soar_module::soar_memory_pool_allocator< wme* > > wma_pooled_wme_set;
210 typedef std::map< Symbol*, uint64_t, std::less< Symbol* >, soar_module::soar_memory_pool_allocator< std::pair< Symbol*, uint64_t > > > wma_sym_reference_map;
211 #else
212 typedef std::set< wma_decay_element* > wma_decay_set;
213 typedef std::map< wma_d_cycle, wma_decay_set* > wma_forget_p_queue;
214 typedef std::set< wma_d_cycle > wma_decay_cycle_set;
215 
216 typedef std::set< wme* > wma_pooled_wme_set;
217 typedef std::map< Symbol*, uint64_t > wma_sym_reference_map;
218 #endif
219 
221 
223 // Parameter Functions
225 
226 // shortcut for determining if WMA is enabled
227 extern bool wma_enabled( agent* my_agent );
228 
229 
231 // Add/Remove Decay Element/Set
233 
234 // generic call to activate a wme
235 extern void wma_activate_wme( agent* my_agent, wme* w, wma_reference num_references = 1, wma_pooled_wme_set* o_set = NULL, bool o_only = false );
236 
237 // Removes a decay element from an existing WME so that
238 // it is no longer activated.
239 extern void wma_remove_decay_element( agent* my_agent, wme* w );
240 
241 // Removes an o-support set from an existing preference
242 extern void wma_remove_pref_o_set( agent* my_agent, preference* pref );
243 
245 // Updating Activation
247 
252 extern void wma_activate_wmes_in_pref( agent* my_agent, preference* pref );
253 
259 extern void wma_activate_wmes_tested_in_prods( agent* my_agent );
260 
265 extern void wma_go( agent* my_agent, wma_go_action go_action );
266 
267 
269 // Retrieving Activation
271 
275 extern double wma_get_wme_activation( agent* my_agent, wme* w, bool log_result );
276 
280 extern void wma_get_wme_history( agent* my_agent, wme* w, std::string& buffer );
281 
282 #endif