Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Data Structures | Macros | Typedefs | Enumerations | Functions
semantic_memory.h File Reference
#include <portability.h>
#include <stack>
#include <set>
#include <list>
#include <vector>
#include <queue>
#include "soar_module.h"
#include "soar_db.h"

Go to the source code of this file.

Data Structures

struct  smem_chunk_struct
struct  smem_chunk_value_constant
struct  smem_chunk_value_lti
union  smem_chunk_value_union
struct  smem_compare_activated_lti
struct  smem_compare_weighted_cue_elements
struct  smem_data_struct
class  smem_db_lib_version_stat
class  smem_db_predicate< T >
class  smem_mem_high_stat
class  smem_mem_usage_stat
class  smem_param_container
class  smem_path_param
class  smem_stat_container
class  smem_statement_container
class  smem_timer
class  smem_timer_container
class  smem_timer_level_predicate
struct  smem_vis_lti_struct
struct  smem_weighted_cue_element_struct

Macros

#define SMEM_ACT_HISTORY_ENTRIES   10
#define SMEM_ACT_LOW   -1000000000
#define SMEM_ACT_MAX   static_cast<uint64_t>( static_cast<uint64_t>( 0 - 1 ) / static_cast<uint64_t>(2) )
#define SMEM_LTI_UNKNOWN_LEVEL   0
#define SMEM_SCHEMA   "smem7_"
#define SMEM_SIGNATURE   SMEM_SCHEMA "signature"
#define SMEM_WEB_NULL   0
#define SMEM_WEB_NULL_STR   "0"

Typedefs

typedef struct action_struct action
typedef struct condition_struct condition
typedef std::pair< double,
smem_lti_id
smem_activated_lti
typedef struct smem_chunk_struct smem_chunk
typedef std::set< smem_chunk * > smem_chunk_set
typedef union
smem_chunk_value_union 
smem_chunk_value
typedef struct smem_data_struct smem_data
typedef uint64_t smem_hash_id
typedef uint64_t smem_lti_id
typedef std::list< smem_lti_idsmem_lti_list
typedef std::set< smem_lti_idsmem_lti_set
typedef std::set< Symbol
*, std::less< Symbol * >
, soar_module::soar_memory_pool_allocator
< Symbol * > > 
smem_pooled_symbol_set
typedef std::priority_queue
< smem_activated_lti,
std::vector
< smem_activated_lti >
, smem_compare_activated_lti
smem_prioritized_activated_lti_queue
typedef std::priority_queue
< smem_weighted_cue_element
*, std::vector
< smem_weighted_cue_element * >
, smem_compare_weighted_cue_elements
smem_prioritized_weighted_cue
typedef std::list
< smem_chunk_value * > 
smem_slot
typedef std::map< Symbol
*, smem_slot * > 
smem_slot_map
typedef std::map< std::string,
smem_chunk * > 
smem_str_to_chunk_map
typedef std::list< Symbol * > smem_sym_list
typedef std::map< Symbol
*, smem_chunk * > 
smem_sym_to_chunk_map
typedef struct smem_vis_lti_struct smem_vis_lti
typedef struct
smem_weighted_cue_element_struct 
smem_weighted_cue_element
typedef std::list
< smem_weighted_cue_element * > 
smem_weighted_cue_list
typedef std::list< wme * > smem_wme_list
typedef std::list< preference
*, soar_module::soar_memory_pool_allocator
< preference * > > 
smem_wme_stack

Enumerations

enum  smem_cue_element_type
enum  smem_query_levels
enum  smem_storage_type
enum  smem_variable_key

Functions

void smem_attach (agent *my_agent)
bool smem_backup_db (agent *my_agent, const char *file_name, std::string *err)
void smem_close (agent *my_agent)
Bool smem_count_ltis (agent *my_agent, void *item, void *userdata)
bool smem_enabled (agent *my_agent)
void smem_go (agent *my_agent, bool store_only)
smem_lti_id smem_lti_get_id (agent *my_agent, char name_letter, uint64_t name_number)
Symbolsmem_lti_soar_make (agent *my_agent, smem_lti_id lti, char name_letter, uint64_t name_number, goal_stack_level level)
bool smem_parse_chunks (agent *my_agent, const char *chunks, std::string **err_msg)
void smem_print_lti (agent *my_agent, smem_lti_id lti_id, unsigned int depth, std::string *return_val)
void smem_print_store (agent *my_agent, std::string *return_val)
void smem_reset (agent *my_agent, Symbol *state)
void smem_reset_id_counters (agent *my_agent)
bool smem_valid_production (condition *lhs_top, action *rhs_top)
void smem_visualize_lti (agent *my_agent, smem_lti_id lti_id, unsigned int depth, std::string *return_val)
void smem_visualize_store (agent *my_agent, std::string *return_val)

Macro Definition Documentation

#define SMEM_ACT_HISTORY_ENTRIES   10

Definition at line 298 of file semantic_memory.h.

Referenced by smem_lti_calc_base().

#define SMEM_ACT_LOW   -1000000000

Definition at line 299 of file semantic_memory.h.

Referenced by smem_lti_calc_base().

#define SMEM_ACT_MAX   static_cast<uint64_t>( static_cast<uint64_t>( 0 - 1 ) / static_cast<uint64_t>(2) )

Definition at line 291 of file semantic_memory.h.

Referenced by smem_lti_activate(), smem_process_query(), and smem_store_chunk().

#define SMEM_LTI_UNKNOWN_LEVEL   0
#define SMEM_SCHEMA   "smem7_"
#define SMEM_SIGNATURE   SMEM_SCHEMA "signature"

Definition at line 308 of file semantic_memory.h.

Referenced by smem_init_db().

#define SMEM_WEB_NULL   0
#define SMEM_WEB_NULL_STR   "0"

Typedef Documentation

typedef struct action_struct action

Definition at line 468 of file semantic_memory.h.

typedef struct condition_struct condition

Definition at line 467 of file semantic_memory.h.

typedef std::pair< double, smem_lti_id > smem_activated_lti

Definition at line 386 of file semantic_memory.h.

typedef struct smem_chunk_struct smem_chunk

Definition at line 400 of file semantic_memory.h.

typedef std::set<smem_chunk *> smem_chunk_set

Definition at line 401 of file semantic_memory.h.

Definition at line 402 of file semantic_memory.h.

typedef struct smem_data_struct smem_data
typedef uint64_t smem_hash_id

Definition at line 319 of file semantic_memory.h.

typedef uint64_t smem_lti_id

Definition at line 316 of file semantic_memory.h.

Definition at line 322 of file semantic_memory.h.

typedef std::set<smem_lti_id> smem_lti_set

Definition at line 323 of file semantic_memory.h.

Definition at line 336 of file semantic_memory.h.

Definition at line 396 of file semantic_memory.h.

Definition at line 383 of file semantic_memory.h.

Definition at line 403 of file semantic_memory.h.

typedef std::map<Symbol *, smem_slot *> smem_slot_map

Definition at line 404 of file semantic_memory.h.

typedef std::map<std::string, smem_chunk *> smem_str_to_chunk_map

Definition at line 435 of file semantic_memory.h.

Definition at line 326 of file semantic_memory.h.

typedef std::map<Symbol *, smem_chunk *> smem_sym_to_chunk_map

Definition at line 436 of file semantic_memory.h.

Definition at line 384 of file semantic_memory.h.

Definition at line 332 of file semantic_memory.h.

Definition at line 343 of file semantic_memory.h.

Enumeration Type Documentation

Enumerator:
attr_t 
value_const_t 
value_lti_t 

Definition at line 359 of file semantic_memory.h.

Enumerator:
qry_search 
qry_full 

Definition at line 450 of file semantic_memory.h.

Enumerator:
store_level 
store_recursive 

Definition at line 329 of file semantic_memory.h.

Enumerator:
var_max_cycle 
var_num_nodes 
var_num_edges 
var_act_thresh 
var_act_mode 

Definition at line 286 of file semantic_memory.h.

Function Documentation

void smem_attach ( agent my_agent)
bool smem_backup_db ( agent my_agent,
const char *  file_name,
std::string *  err 
)
void smem_close ( agent my_agent)
Bool smem_count_ltis ( agent my_agent,
void *  item,
void *  userdata 
)

Definition at line 1396 of file semantic_memory.cpp.

References symbol_union::id, NIL, and identifier_struct::smem_lti.

Referenced by reset_id_counters().

{
Symbol *id = static_cast<symbol_union *>(item);
if ( id->id.smem_lti != NIL )
{
uint64_t* counter = reinterpret_cast<uint64_t*>( userdata );
(*counter)++;
}
return false;
}
bool smem_enabled ( agent my_agent)
void smem_go ( agent my_agent,
bool  store_only 
)

Definition at line 3797 of file semantic_memory.cpp.

References smem_respond_to_cmd(), agent_struct::smem_timers, soar_module::timer::start(), soar_module::timer::stop(), and smem_timer_container::total.

Referenced by do_one_top_level_phase().

{
my_agent->smem_timers->total->start();
#ifndef SMEM_EXPERIMENT
smem_respond_to_cmd( my_agent, store_only );
#else // SMEM_EXPERIMENT
#endif // SMEM_EXPERIMENT
my_agent->smem_timers->total->stop();
}
smem_lti_id smem_lti_get_id ( agent my_agent,
char  name_letter,
uint64_t  name_number 
)

Definition at line 1410 of file semantic_memory.cpp.

References soar_module::sqlite_statement::bind_int(), soar_module::sqlite_statement::column_int(), soar_module::statement::execute(), smem_statement_container::lti_get, NIL, soar_module::statement::reinitialize(), soar_module::row, smem_attach(), and agent_struct::smem_stmts.

Referenced by _epmem_install_id_wme(), make_symbol_for_current_lexeme(), parse_rhs_action(), smem_lti_soar_add(), and smem_parse_chunks().

{
smem_lti_id return_val = NIL;
// getting lti ids requires an open semantic database
smem_attach( my_agent );
// letter=? AND number=?
my_agent->smem_stmts->lti_get->bind_int( 1, static_cast<uint64_t>( name_letter ) );
my_agent->smem_stmts->lti_get->bind_int( 2, static_cast<uint64_t>( name_number ) );
if ( my_agent->smem_stmts->lti_get->execute() == soar_module::row )
{
return_val = my_agent->smem_stmts->lti_get->column_int( 0 );
}
return return_val;
}
Symbol* smem_lti_soar_make ( agent my_agent,
smem_lti_id  lti,
char  name_letter,
uint64_t  name_number,
goal_stack_level  level 
)

Definition at line 1478 of file semantic_memory.cpp.

References find_identifier(), symbol_union::id, identifier_struct::level, make_new_identifier(), NIL, identifier_struct::promotion_level, identifier_struct::smem_lti, SMEM_LTI_UNKNOWN_LEVEL, and symbol_add_ref().

Referenced by _epmem_install_id_wme(), make_symbol_for_current_lexeme(), parse_rhs_action(), and smem_install_memory().

{
Symbol *return_val;
// try to find existing
return_val = find_identifier( my_agent, name_letter, name_number );
// otherwise create
if ( return_val == NIL )
{
return_val = make_new_identifier( my_agent, name_letter, level, name_number );
}
else
{
symbol_add_ref( return_val );
if ( ( return_val->id.level == SMEM_LTI_UNKNOWN_LEVEL ) && ( level != SMEM_LTI_UNKNOWN_LEVEL ) )
{
return_val->id.level = level;
return_val->id.promotion_level = level;
}
}
// set lti field irrespective
return_val->id.smem_lti = lti;
return return_val;
}
bool smem_parse_chunks ( agent my_agent,
const char *  chunks,
std::string **  err_msg 
)

Definition at line 3248 of file semantic_memory.cpp.

References agent_struct::alternate_input_exit, agent_struct::alternate_input_string, agent_struct::alternate_input_suffix, agent_struct::current_char, epmem_schedule_promotion(), agent_struct::epmem_stats, agent_struct::epmem_validation, find_identifier(), get_lexeme(), soar_module::primitive_stat< T >::get_value(), symbol_union::id, agent_struct::id_counter, L_PAREN_LEXEME, agent_struct::lexeme, NIL, set_lexer_allow_ids(), smem_attach(), smem_deallocate_chunk(), identifier_struct::smem_lti, smem_lti_add_id(), smem_lti_get_id(), smem_parse_chunk(), smem_store_chunk(), identifier_struct::smem_time_id, identifier_struct::smem_valid, epmem_stat_container::time, and lexeme_info::type.

{
bool return_val = false;
uint64_t clause_count = 0;
// parsing chunks requires an open semantic database
smem_attach( my_agent );
// copied primarily from cli_sp
my_agent->alternate_input_string = chunks_str;
my_agent->alternate_input_suffix = const_cast<char *>( ") " );
my_agent->current_char = ' ';
my_agent->alternate_input_exit = true;
set_lexer_allow_ids( my_agent, true );
bool good_chunk = true;
smem_str_to_chunk_map::iterator c_old;
smem_chunk_set newbies;
smem_chunk_set::iterator c_new;
// consume next token
get_lexeme( my_agent );
// while there are chunks to consume
while ( ( my_agent->lexeme.type == L_PAREN_LEXEME ) && ( good_chunk ) )
{
good_chunk = smem_parse_chunk( my_agent, &( chunks ), &( newbies ) );
if ( good_chunk )
{
// add all newbie lti's as appropriate
for ( c_new=newbies.begin(); c_new!=newbies.end(); c_new++ )
{
if ( (*c_new)->lti_id == NIL )
{
// deal differently with variable vs. lti
if ( (*c_new)->lti_number == NIL )
{
// add a new lti id (we have a guarantee this won't be in Soar's WM)
(*c_new)->lti_number = ( my_agent->id_counter[ (*c_new)->lti_letter - static_cast<char>('A') ]++ );
(*c_new)->lti_id = smem_lti_add_id( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
}
else
{
// should ALWAYS be the case (it's a newbie and we've initialized lti_id to NIL)
if ( (*c_new)->lti_id == NIL )
{
// get existing
(*c_new)->lti_id = smem_lti_get_id( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
// if doesn't exist, add it
if ( (*c_new)->lti_id == NIL )
{
(*c_new)->lti_id = smem_lti_add_id( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
// this could affect an existing identifier in Soar's WM
Symbol *id_parent = find_identifier( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
if ( id_parent != NIL )
{
// if so we make it an lti manually
id_parent->id.smem_lti = (*c_new)->lti_id;
id_parent->id.smem_time_id = my_agent->epmem_stats->time->get_value();
id_parent->id.smem_valid = my_agent->epmem_validation;
epmem_schedule_promotion( my_agent, id_parent );
}
}
}
}
}
}
// add all newbie contents (append, as opposed to replace, children)
for ( c_new=newbies.begin(); c_new!=newbies.end(); c_new++ )
{
if ( (*c_new)->slots != NIL )
{
smem_store_chunk( my_agent, (*c_new)->lti_id, (*c_new)->slots, false );
}
}
// deallocate *contents* of all newbies (need to keep around name->id association for future chunks)
for ( c_new=newbies.begin(); c_new!=newbies.end(); c_new++ )
{
smem_deallocate_chunk( my_agent, (*c_new), false );
}
// increment clause counter
clause_count++;
// clear newbie list
newbies.clear();
}
};
return_val = good_chunk;
// deallocate all chunks
{
for ( c_old=chunks.begin(); c_old!=chunks.end(); c_old++ )
{
smem_deallocate_chunk( my_agent, c_old->second, true );
}
}
// produce error message on failure
if ( !return_val )
{
std::string num;
to_string( clause_count, num );
(*err_msg) = new std::string( "Error parsing clause #" );
(*err_msg)->append( num );
}
return return_val;
}
void smem_print_lti ( agent my_agent,
smem_lti_id  lti_id,
unsigned int  depth,
std::string *  return_val 
)

Definition at line 4501 of file semantic_memory.cpp.

References _smem_print_lti(), soar_module::sqlite_statement::bind_int(), soar_module::sqlite_statement::column_double(), soar_module::sqlite_statement::column_int(), soar_module::statement::execute(), smem_statement_container::lti_letter_num, soar_module::statement::reinitialize(), smem_attach(), agent_struct::smem_stmts, and smem_statement_container::vis_lti_act.

{
std::set< smem_lti_id > visited;
std::pair< std::set< smem_lti_id >::iterator, bool > visited_ins_result;
std::queue< std::pair< smem_lti_id, unsigned int > > to_visit;
std::pair< smem_lti_id, unsigned int > c;
std::set< smem_lti_id > next;
std::set< smem_lti_id >::iterator next_it;
unsigned int i;
// vizualizing the store requires an open semantic database
smem_attach( my_agent );
// initialize queue/set
to_visit.push( std::make_pair< smem_lti_id, unsigned int >( lti_id, 1 ) );
visited.insert( lti_id );
while ( !to_visit.empty() )
{
c = to_visit.front();
to_visit.pop();
// output leading spaces ala depth
for ( i=1; i<c.second; i++ )
{
return_val->append( " " );
}
// get lti info
{
lti_q->bind_int( 1, c.first );
lti_q->execute();
act_q->bind_int( 1, c.first );
act_q->execute();
next = _smem_print_lti( my_agent, c.first, static_cast<char>( lti_q->column_int( 0 ) ), static_cast<uint64_t>( lti_q->column_int( 1 ) ), act_q->column_double( 0 ), return_val );
// done with lookup
lti_q->reinitialize();
act_q->reinitialize();
// consider further depth
if ( c.second < depth )
{
for ( next_it=next.begin(); next_it!=next.end(); next_it++ )
{
visited_ins_result = visited.insert( (*next_it) );
if ( visited_ins_result.second )
{
to_visit.push( std::make_pair< smem_lti_id, unsigned int >( (*next_it), c.second+1 ) );
}
}
}
}
}
}
void smem_print_store ( agent my_agent,
std::string *  return_val 
)

Definition at line 4487 of file semantic_memory.cpp.

References _smem_print_lti(), soar_module::sqlite_statement::column_double(), soar_module::sqlite_statement::column_int(), soar_module::statement::execute(), soar_module::statement::reinitialize(), soar_module::row, smem_attach(), agent_struct::smem_stmts, and smem_statement_container::vis_lti.

{
// vizualizing the store requires an open semantic database
smem_attach( my_agent );
// id, letter, number
while ( q->execute() == soar_module::row )
{
_smem_print_lti( my_agent, q->column_int( 0 ), static_cast<char>( q->column_int( 1 ) ), static_cast<uint64_t>( q->column_int( 2 ) ), q->column_double( 3 ), return_val );
}
}
void smem_reset ( agent my_agent,
Symbol state 
)

Definition at line 2543 of file semantic_memory.cpp.

References symbol_union::id, smem_data_struct::last_cmd_count, smem_data_struct::last_cmd_time, identifier_struct::lower_goal, identifier_struct::smem_info, smem_data_struct::smem_wmes, and agent_struct::top_goal.

Referenced by remove_existing_context_and_descendents().

{
if ( state == NULL )
{
state = my_agent->top_goal;
}
while( state )
{
smem_data *data = state->id.smem_info;
data->last_cmd_time[0] = 0;
data->last_cmd_time[1] = 0;
data->last_cmd_count[0] = 0;
data->last_cmd_count[1] = 0;
// this will be called after prefs from goal are already removed,
// so just clear out result stack
data->smem_wmes->clear();
state = state->id.lower_goal;
}
}
void smem_reset_id_counters ( agent my_agent)

Definition at line 1507 of file semantic_memory.cpp.

References soar_module::sqlite_statement::column_int(), soar_module::connected, soar_module::statement::execute(), soar_module::status_object< T >::get_status(), agent_struct::id_counter, smem_statement_container::lti_max, soar_module::statement::reinitialize(), soar_module::row, agent_struct::smem_db, and agent_struct::smem_stmts.

Referenced by reset_id_counters(), and smem_init_db().

{
if ( my_agent->smem_db->get_status() == soar_module::connected )
{
// letter, max
while ( my_agent->smem_stmts->lti_max->execute() == soar_module::row )
{
uint64_t name_letter = static_cast<uint64_t>( my_agent->smem_stmts->lti_max->column_int( 0 ) );
uint64_t letter_max = static_cast<uint64_t>( my_agent->smem_stmts->lti_max->column_int( 1 ) );
// shift to alphabet
name_letter -= static_cast<uint64_t>( 'A' );
// get count
uint64_t *letter_ct =& my_agent->id_counter[ name_letter ];
// adjust if necessary
if ( (*letter_ct) <= letter_max )
{
(*letter_ct) = ( letter_max + 1 );
}
}
}
}
bool smem_valid_production ( condition lhs_top,
action rhs_top 
)

Definition at line 1298 of file semantic_memory.cpp.

References _smem_lti_from_rhs_value(), _smem_lti_from_test(), action_struct::already_in_tc, action_struct::attr, action_struct::id, symbol_union::id, IDENTIFIER_SYMBOL_TYPE, MAKE_ACTION, action_struct::next, NIL, POSITIVE_CONDITION, rhs_value_to_symbol(), identifier_struct::smem_lti, action_struct::type, and action_struct::value.

Referenced by chunk_instantiation(), and make_production().

{
bool return_val = true;
std::set<Symbol *> valid_ltis;
std::set<Symbol *>::iterator lti_p;
// collect valid ltis
for ( condition *c=lhs_top; c!=NIL; c=c->next )
{
if ( c->type == POSITIVE_CONDITION )
{
_smem_lti_from_test( c->data.tests.attr_test, &valid_ltis );
_smem_lti_from_test( c->data.tests.value_test, &valid_ltis );
}
}
// validate ltis in actions
// copied primarily from add_all_variables_in_action
{
Symbol *id;
action *a;
int action_counter = 0;
for ( a=rhs_top; a!=NIL; a=a->next )
{
a->already_in_tc = false;
action_counter++;
}
// good_pass detects infinite loops
bool good_pass = true;
bool good_action = true;
while ( good_pass && action_counter )
{
good_pass = false;
for ( a=rhs_top; a!=NIL; a=a->next )
{
if ( !a->already_in_tc )
{
good_action = false;
if ( a->type == MAKE_ACTION )
{
id = rhs_value_to_symbol( a->id );
// non-identifiers are ok
if ( id->common.symbol_type != IDENTIFIER_SYMBOL_TYPE )
{
good_action = true;
}
// short-term identifiers are ok
else if ( id->id.smem_lti == NIL )
{
good_action = true;
}
// valid long-term identifiers are ok
else if ( valid_ltis.find( id ) != valid_ltis.end() )
{
good_action = true;
}
}
else
{
good_action = true;
}
// we've found a new good action
// mark as good, collect all goodies
if ( good_action )
{
a->already_in_tc = true;
// everyone has values
_smem_lti_from_rhs_value( a->value, &valid_ltis );
// function calls don't have attributes
if ( a->type == MAKE_ACTION )
{
_smem_lti_from_rhs_value( a->attr, &valid_ltis );
}
// note that we've dealt with another action
action_counter--;
good_pass = true;
}
}
}
};
return_val = ( action_counter == 0 );
}
return return_val;
}
void smem_visualize_lti ( agent my_agent,
smem_lti_id  lti_id,
unsigned int  depth,
std::string *  return_val 
)

Definition at line 4095 of file semantic_memory.cpp.

References soar_module::sqlite_statement::bind_int(), soar_module::sqlite_statement::column_double(), soar_module::sqlite_statement::column_int(), soar_module::statement::execute(), FLOAT_CONSTANT_SYMBOL_TYPE, INT_CONSTANT_SYMBOL_TYPE, smem_vis_lti_struct::level, smem_vis_lti_struct::lti_id, smem_statement_container::lti_letter_num, smem_vis_lti_struct::lti_name, soar_module::statement::reinitialize(), soar_module::row, smem_reverse_hash_float(), smem_reverse_hash_int(), smem_reverse_hash_str(), agent_struct::smem_stmts, SMEM_WEB_NULL, SYM_CONSTANT_SYMBOL_TYPE, smem_statement_container::vis_lti_act, and smem_statement_container::web_expand.

{
// buffer
std::string return_val2;
uint64_t child_counter;
std::string temp_str;
std::string temp_str2;
int64_t temp_int;
double temp_double;
std::queue<smem_vis_lti *> bfs;
smem_vis_lti *new_lti;
smem_vis_lti *parent_lti;
std::map< smem_lti_id, smem_vis_lti* > close_list;
std::map< smem_lti_id, smem_vis_lti* >::iterator cl_p;
// header
return_val->append( "digraph smem_lti {" );
return_val->append( "\n" );
// root
{
new_lti = new smem_vis_lti;
new_lti->lti_id = lti_id;
new_lti->level = 0;
// fake former linkage
{
// get just this lti
lti_q->bind_int( 1, lti_id );
lti_q->execute();
// letter
new_lti->lti_name.push_back( static_cast<char>( lti_q->column_int( 0 ) ) );
// number
temp_int = lti_q->column_int( 1 );
to_string( temp_int, temp_str );
new_lti->lti_name.append( temp_str );
// done with lookup
lti_q->reinitialize();
}
bfs.push( new_lti );
close_list.insert( std::make_pair< smem_lti_id, smem_vis_lti* >( lti_id, new_lti ) );
new_lti = NULL;
}
// optionally depth-limited breadth-first-search of children
while ( !bfs.empty() )
{
parent_lti = bfs.front();
bfs.pop();
child_counter = 0;
// get direct children: attr_type, attr_hash, value_type, value_hash, value_letter, value_num, value_lti
expand_q->bind_int( 1, parent_lti->lti_id );
while ( expand_q->execute() == soar_module::row )
{
// identifier vs. constant
if ( expand_q->column_int( 6 ) != SMEM_WEB_NULL )
{
new_lti = new smem_vis_lti;
new_lti->lti_id = expand_q->column_int( 6 );
new_lti->level = ( parent_lti->level + 1 );
// add node
{
// letter
new_lti->lti_name.push_back( static_cast<char>( expand_q->column_int( 4 ) ) );
// number
temp_int = expand_q->column_int( 5 );
to_string( temp_int, temp_str );
new_lti->lti_name.append( temp_str );
}
// add linkage
{
// get attribute
switch ( expand_q->column_int(0) )
{
smem_reverse_hash_str( my_agent, expand_q->column_int(1), temp_str );
break;
temp_int = smem_reverse_hash_int( my_agent, expand_q->column_int(1) );
to_string( temp_int, temp_str );
break;
temp_double = smem_reverse_hash_float( my_agent, expand_q->column_int(1) );
to_string( temp_double, temp_str );
break;
default:
temp_str.clear();
break;
}
// output linkage
return_val2.append( parent_lti->lti_name );
return_val2.append( " -> " );
return_val2.append( new_lti->lti_name );
return_val2.append( " [ label = \"" );
return_val2.append( temp_str );
return_val2.append( "\" ];" );
return_val2.append( "\n" );
}
// prevent looping
{
cl_p = close_list.find( new_lti->lti_id );
if ( cl_p == close_list.end() )
{
close_list.insert( std::make_pair< smem_lti_id, smem_vis_lti* >( new_lti->lti_id, new_lti ) );
if ( ( depth == 0 ) || ( new_lti->level < depth ) )
{
bfs.push( new_lti );
}
}
else
{
delete new_lti;
}
}
new_lti = NULL;
}
else
{
// add value node
{
// get node name
{
temp_str2.assign( parent_lti->lti_name );
temp_str2.append( "_" );
to_string( child_counter, temp_str );
temp_str2.append( temp_str );
}
// get value
switch ( expand_q->column_int(2) )
{
smem_reverse_hash_str( my_agent, expand_q->column_int(3), temp_str );
break;
temp_int = smem_reverse_hash_int( my_agent, expand_q->column_int(3) );
to_string( temp_int, temp_str );
break;
temp_double = smem_reverse_hash_float( my_agent, expand_q->column_int(3) );
to_string( temp_double, temp_str );
break;
default:
temp_str.clear();
break;
}
// output node
return_val2.append( "node [ shape = plaintext ];" );
return_val2.append( "\n" );
return_val2.append( temp_str2 );
return_val2.append( " [ label=\"" );
return_val2.append( temp_str );
return_val2.append( "\" ];" );
return_val2.append( "\n" );
}
// add linkage
{
// get attribute
switch ( expand_q->column_int(0) )
{
smem_reverse_hash_str( my_agent, expand_q->column_int(1), temp_str );
break;
temp_int = smem_reverse_hash_int( my_agent, expand_q->column_int(1) );
to_string( temp_int, temp_str );
break;
temp_double = smem_reverse_hash_float( my_agent, expand_q->column_int(1) );
to_string( temp_double, temp_str );
break;
default:
temp_str.clear();
break;
}
// output linkage
return_val2.append( parent_lti->lti_name );
return_val2.append( " -> " );
return_val2.append( temp_str2 );
return_val2.append( " [ label = \"" );
return_val2.append( temp_str );
return_val2.append( "\" ];" );
return_val2.append( "\n" );
}
child_counter++;
}
}
expand_q->reinitialize();
}
// footer
return_val2.append( "}" );
return_val2.append( "\n" );
// handle lti nodes at once
{
return_val->append( "node [ shape = doublecircle ];" );
return_val->append( "\n" );
for ( cl_p=close_list.begin(); cl_p!=close_list.end(); cl_p++ )
{
return_val->append( cl_p->second->lti_name );
return_val->append( " [ label=\"" );
return_val->append( cl_p->second->lti_name );
return_val->append( "\\n[" );
act_q->bind_int( 1, cl_p->first );
if ( act_q->execute() == soar_module::row )
{
temp_double = act_q->column_double( 0 );
to_string( temp_double, temp_str, 3, true );
if ( temp_double >= 0 )
{
return_val->append( "+" );
}
return_val->append( temp_str );
}
act_q->reinitialize();
return_val->append( "]\"" );
return_val->append( " ];" );
return_val->append( "\n" );
delete cl_p->second;
}
}
// transfer buffer after nodes
return_val->append( return_val2 );
}
void smem_visualize_store ( agent my_agent,
std::string *  return_val 
)

Definition at line 3847 of file semantic_memory.cpp.

References soar_module::sqlite_statement::column_double(), soar_module::sqlite_statement::column_int(), soar_module::statement::execute(), FLOAT_CONSTANT_SYMBOL_TYPE, INT_CONSTANT_SYMBOL_TYPE, soar_module::statement::reinitialize(), soar_module::row, smem_attach(), smem_reverse_hash_float(), smem_reverse_hash_int(), smem_reverse_hash_str(), agent_struct::smem_stmts, SYM_CONSTANT_SYMBOL_TYPE, smem_statement_container::vis_lti, smem_statement_container::vis_value_const, and smem_statement_container::vis_value_lti.

{
// vizualizing the store requires an open semantic database
smem_attach( my_agent );
// header
return_val->append( "digraph smem {" );
return_val->append( "\n" );
// LTIs
return_val->append( "node [ shape = doublecircle ];" );
return_val->append( "\n" );
std::map< smem_lti_id, std::string > lti_names;
std::map< smem_lti_id, std::string >::iterator n_p;
{
smem_lti_id lti_id;
char lti_letter;
uint64_t lti_number;
std::string *lti_name;
std::string temp_str;
int64_t temp_int;
double temp_double;
// id, letter, number
q = my_agent->smem_stmts->vis_lti;
while ( q->execute() == soar_module::row )
{
lti_id = q->column_int( 0 );
lti_letter = static_cast<char>( q->column_int( 1 ) );
lti_number = static_cast<uint64_t>( q->column_int( 2 ) );
lti_name =& lti_names[ lti_id ];
lti_name->push_back( lti_letter );
to_string( lti_number, temp_str );
lti_name->append( temp_str );
return_val->append( (*lti_name) );
return_val->append( " [ label=\"" );
return_val->append( (*lti_name) );
return_val->append( "\\n[" );
temp_double = q->column_double( 3 );
to_string( temp_double, temp_str, 3, true );
if ( temp_double >= 0 )
{
return_val->append( "+" );
}
return_val->append( temp_str );
return_val->append( "]\"" );
return_val->append( " ];" );
return_val->append( "\n" );
}
if ( !lti_names.empty() )
{
// terminal nodes first
{
std::map< smem_lti_id, std::list<std::string> > lti_terminals;
std::map< smem_lti_id, std::list<std::string> >::iterator t_p;
std::list<std::string>::iterator a_p;
std::list<std::string> *my_terminals;
std::list<std::string>::size_type terminal_num;
return_val->append( "\n" );
// proceed to terminal nodes
return_val->append( "node [ shape = plaintext ];" );
return_val->append( "\n" );
// parent_id, attr_type, attr_hash, val_type, val_hash
q = my_agent->smem_stmts->vis_value_const;
while ( q->execute() == soar_module::row )
{
lti_id = q->column_int( 0 );
my_terminals =& lti_terminals[ lti_id ];
lti_name =& lti_names[ lti_id ];
// parent prefix
return_val->append( (*lti_name) );
return_val->append( "_" );
// terminal count
terminal_num = my_terminals->size();
to_string( terminal_num, temp_str );
return_val->append( temp_str );
// prepare for value
return_val->append( " [ label = \"" );
// output value
{
switch ( q->column_int( 3 ) )
{
smem_reverse_hash_str( my_agent, q->column_int(4), temp_str );
break;
temp_int = smem_reverse_hash_int( my_agent, q->column_int(4) );
to_string( temp_int, temp_str );
break;
temp_double = smem_reverse_hash_float( my_agent, q->column_int(4) );
to_string( temp_double, temp_str );
break;
default:
temp_str.clear();
break;
}
return_val->append( temp_str );
}
// store terminal (attribute for edge label)
{
switch ( q->column_int(1) )
{
smem_reverse_hash_str( my_agent, q->column_int(2), temp_str );
break;
temp_int = smem_reverse_hash_int( my_agent, q->column_int(2) );
to_string( temp_int, temp_str );
break;
temp_double = smem_reverse_hash_float( my_agent, q->column_int(2) );
to_string( temp_double, temp_str );
break;
default:
temp_str.clear();
break;
}
my_terminals->push_back( temp_str );
}
// footer
return_val->append( "\" ];" );
return_val->append( "\n" );
}
// output edges
{
unsigned int terminal_counter;
for ( n_p=lti_names.begin(); n_p!=lti_names.end(); n_p++ )
{
t_p = lti_terminals.find( n_p->first );
if ( t_p != lti_terminals.end() )
{
terminal_counter = 0;
for ( a_p=t_p->second.begin(); a_p!=t_p->second.end(); a_p++ )
{
return_val->append( n_p->second );
return_val ->append( " -> " );
return_val->append( n_p->second );
return_val->append( "_" );
to_string( terminal_counter, temp_str );
return_val->append( temp_str );
return_val->append( " [ label=\"" );
return_val->append( (*a_p) );
return_val->append( "\" ];" );
return_val->append( "\n" );
terminal_counter++;
}
}
}
}
}
// then links to other LTIs
{
// parent_id, attr_type, attr_hash, val_lti
q = my_agent->smem_stmts->vis_value_lti;
while ( q->execute() == soar_module::row )
{
// source
lti_id = q->column_int( 0 );
lti_name =& lti_names[ lti_id ];
return_val->append( (*lti_name) );
return_val->append( " -> " );
// destination
lti_id = q->column_int( 3 );
lti_name =& lti_names[ lti_id ];
return_val->append( (*lti_name) );
return_val->append( " [ label =\"" );
// output attribute
{
switch ( q->column_int(1) )
{
smem_reverse_hash_str( my_agent, q->column_int(2), temp_str );
break;
temp_int = smem_reverse_hash_int( my_agent, q->column_int(2) );
to_string( temp_int, temp_str );
break;
temp_double = smem_reverse_hash_float( my_agent, q->column_int(2) );
to_string( temp_double, temp_str );
break;
default:
temp_str.clear();
break;
}
return_val->append( temp_str );
}
// footer
return_val->append( "\" ];" );
return_val->append( "\n" );
}
}
}
}
// footer
return_val->append( "}" );
return_val->append( "\n" );
}