Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
semantic_memory.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: semantic_memory.h
9  *
10  * =======================================================================
11  */
12 
13 #ifndef SEMANTIC_MEMORY_H
14 #define SEMANTIC_MEMORY_H
15 
16 #include <portability.h>
17 
18 #include <stack>
19 #include <set>
20 #include <list>
21 #include <vector>
22 #include <queue>
23 
24 #include "soar_module.h"
25 #include "soar_db.h"
26 
28 // SMem Experimentation
29 //
30 // If defined, we hijack the main SMem function
31 // for tight-loop experimentation/timing.
32 //
34 
35 //#define SMEM_EXPERIMENT
36 
37 
39 // SMem Parameters
41 
42 class smem_path_param;
43 
45 {
46  public:
47  enum db_choices { memory, file };
51 
54 
59 
61 
65 
67 
72 
75 
77 
79 
80  smem_param_container( agent *new_agent );
81 };
82 
84 {
85  protected:
87 
88  public:
89  smem_path_param( const char *new_name, const char *new_value, soar_module::predicate<const char *> *new_val_pred, soar_module::predicate<const char *> *new_prot_pred, agent *new_agent );
90  virtual void set_value( const char *new_value );
91 };
92 
93 template <typename T>
95 {
96  public:
97  smem_db_predicate( agent *new_agent );
98  bool operator() ( T val );
99 };
100 
101 
103 // SMem Statistics
105 
107 class smem_mem_usage_stat;
108 class smem_mem_high_stat;
109 
111 {
112  public:
116 
122 
125 
127 };
128 
129 //
130 
132 {
133  protected:
135 
136  public:
137  smem_db_lib_version_stat( agent* new_agent, const char* new_name, const char* new_value, soar_module::predicate< const char* >* new_prot_pred );
138  const char* get_value();
139 };
140 
141 //
142 
144 {
145  protected:
147 
148  public:
149  smem_mem_usage_stat( agent *new_agent, const char *new_name, int64_t new_value, soar_module::predicate<int64_t> *new_prot_pred );
150  int64_t get_value();
151 };
152 
153 //
154 
156 {
157  protected:
159 
160  public:
161  smem_mem_high_stat( agent *new_agent, const char *new_name, int64_t new_value, soar_module::predicate<int64_t> *new_prot_pred );
162  int64_t get_value();
163 };
164 
165 
167 // SMem Timers
169 
171 {
172  public:
181 
183 };
184 
185 class smem_timer_level_predicate: public soar_module::agent_predicate<soar_module::timer::timer_level>
186 {
187  public:
188  smem_timer_level_predicate( agent *new_agent );
190 };
191 
193 {
194  public:
195  smem_timer( const char *new_name, agent *new_agent, soar_module::timer::timer_level new_level );
196 };
197 
198 
200 // SMem Statements
202 
204 {
205  public:
209 
213 
224 
232 
236 
238 
242 
246 
250 
254 
258 
262 
268 
272 
277 
278  smem_statement_container( agent *new_agent );
279 };
280 
281 
283 // Soar Constants
285 
287 {
289 };
290 
291 #define SMEM_ACT_MAX static_cast<uint64_t>( static_cast<uint64_t>( 0 - 1 ) / static_cast<uint64_t>(2) )
292 
293 #define SMEM_LTI_UNKNOWN_LEVEL 0
294 
295 #define SMEM_WEB_NULL 0
296 #define SMEM_WEB_NULL_STR "0"
297 
298 #define SMEM_ACT_HISTORY_ENTRIES 10
299 #define SMEM_ACT_LOW -1000000000
300 
301 // provides a distinct prefix to be used by all
302 // tables for two reasons:
303 // - distinguish from other modules
304 // - distinguish between smem versions
305 #define SMEM_SCHEMA "smem7_"
306 
307 // empty table used to verify proper structure
308 #define SMEM_SIGNATURE SMEM_SCHEMA "signature"
309 
311 // Soar Integration Types
313 
314 // represents the unique identification of a
315 // long-term identifier
316 typedef uint64_t smem_lti_id;
317 
318 // represents a temporal hash
319 typedef uint64_t smem_hash_id;
320 
321 // represents a collection of long-term identifiers
322 typedef std::list<smem_lti_id> smem_lti_list;
323 typedef std::set<smem_lti_id> smem_lti_set;
324 
325 // a list of symbols
326 typedef std::list<Symbol *> smem_sym_list;
327 
328 // ways to store an identifier
330 
331 // represents a list of wmes
332 typedef std::list<wme *> smem_wme_list;
333 
334 // represents a set of symbols
335 #ifdef USE_MEM_POOL_ALLOCATORS
336 typedef std::set< Symbol*, std::less< Symbol* >, soar_module::soar_memory_pool_allocator< Symbol* > > smem_pooled_symbol_set;
337 #else
338 typedef std::set< Symbol* > smem_pooled_symbol_set;
339 #endif
340 
341 // list used primarily like a stack
342 #ifdef USE_MEM_POOL_ALLOCATORS
343 typedef std::list< preference*, soar_module::soar_memory_pool_allocator< preference* > > smem_wme_stack;
344 #else
345 typedef std::list< preference* > smem_wme_stack;
346 #endif
347 
348 // data associated with each state
349 typedef struct smem_data_struct
350 {
351  uint64_t last_cmd_time[2]; // last update to smem.command
352  uint64_t last_cmd_count[2]; // last update to smem.command
353 
354  smem_wme_stack* smem_wmes; // wmes in last smem
355 } smem_data;
356 
357 //
358 
360 
362 {
363  uint64_t weight;
364 
369 
372 
374 
376 {
378  {
379  return ( a->weight > b->weight );
380  }
381 };
382 
383 typedef std::priority_queue<smem_weighted_cue_element *, std::vector<smem_weighted_cue_element *>, smem_compare_weighted_cue_elements> smem_prioritized_weighted_cue;
384 typedef std::list<smem_weighted_cue_element *> smem_weighted_cue_list;
385 
386 typedef std::pair< double, smem_lti_id > smem_activated_lti;
387 
389 {
390  bool operator() ( const smem_activated_lti a, const smem_activated_lti b ) const
391  {
392  return ( b.first > a.first );
393  }
394 };
395 
396 typedef std::priority_queue< smem_activated_lti, std::vector<smem_activated_lti>, smem_compare_activated_lti> smem_prioritized_activated_lti_queue;
397 
398 //
399 
401 typedef std::set<smem_chunk *> smem_chunk_set;
403 typedef std::list<smem_chunk_value *> smem_slot;
404 typedef std::map<Symbol *, smem_slot *> smem_slot_map;
405 
407 {
410 
412  uint64_t lti_number;
413 
415 };
416 
418 {
421 };
422 
424 {
427 };
428 
430 {
433 };
434 
435 typedef std::map<std::string, smem_chunk *> smem_str_to_chunk_map;
436 typedef std::map<Symbol *, smem_chunk *> smem_sym_to_chunk_map;
437 
438 //
439 
440 typedef struct smem_vis_lti_struct
441 {
442  public:
444  std::string lti_name;
445  unsigned int level;
446 } smem_vis_lti;
447 
448 //
449 
451 
452 
454 // Soar Functions (see cpp for comments)
456 
457 extern bool smem_enabled( agent *my_agent );
458 extern void smem_attach( agent *my_agent );
459 
460 extern bool smem_parse_chunks( agent *my_agent, const char *chunks, std::string **err_msg );
461 
462 extern void smem_visualize_store( agent *my_agent, std::string *return_val );
463 extern void smem_visualize_lti( agent *my_agent, smem_lti_id lti_id, unsigned int depth, std::string *return_val );
464 extern void smem_print_store( agent *my_agent, std::string *return_val );
465 extern void smem_print_lti( agent *my_agent, smem_lti_id lti_id, unsigned int depth, std::string *return_val );
466 
468 typedef struct action_struct action;
469 
470 extern Bool smem_count_ltis( agent *my_agent, void *item, void *userdata );
471 extern bool smem_valid_production( condition *lhs_top, action *rhs_top );
472 
473 extern smem_lti_id smem_lti_get_id( agent *my_agent, char name_letter, uint64_t name_number );
474 extern Symbol *smem_lti_soar_make( agent *my_agent, smem_lti_id lti, char name_letter, uint64_t name_number, goal_stack_level level );
475 
476 extern void smem_reset( agent *my_agent, Symbol *state );
477 extern void smem_reset_id_counters( agent *my_agent );
478 extern void smem_close( agent *my_agent );
479 
480 // perform smem actions
481 extern void smem_go( agent *my_agent, bool store_only );
482 extern bool smem_backup_db( agent* my_agent, const char* file_name, std::string *err );
483 
484 #endif