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
episodic_memory.h File Reference
#include <portability.h>
#include <map>
#include <list>
#include <stack>
#include <set>
#include <queue>
#include "soar_module.h"
#include "soar_db.h"

Go to the source code of this file.

Data Structures

class  epmem_common_statement_container
struct  epmem_data_struct
class  epmem_db_lib_version_stat
class  epmem_db_predicate< T >
struct  epmem_edge_struct
class  epmem_graph_statement_container
struct  epmem_id_reservation_struct
struct  epmem_interval_comparator
struct  epmem_interval_struct
struct  epmem_literal_struct
class  epmem_mem_high_stat
class  epmem_mem_usage_stat
class  epmem_param_container
class  epmem_path_param
struct  epmem_pedge_comparator
struct  epmem_pedge_struct
struct  epmem_rit_state_param_struct
struct  epmem_rit_state_struct
class  epmem_stat_container
class  epmem_timer
class  epmem_timer_container
class  epmem_timer_level_predicate
struct  epmem_triple_struct
struct  epmem_uedge_struct

Macros

#define EPMEM_DNF   2
#define EPMEM_HASH_ACCEPTABLE   1
#define EPMEM_LN_2   0.693147180559945
#define EPMEM_MEMID_NONE   0
#define EPMEM_NODE_NEG   1
#define EPMEM_NODE_POS   0
#define EPMEM_NODEID_BAD   -1
#define EPMEM_NODEID_ROOT   0
#define EPMEM_RANGE_END   1
#define EPMEM_RANGE_EP   0
#define EPMEM_RANGE_NOW   1
#define EPMEM_RANGE_POINT   2
#define EPMEM_RANGE_START   0
#define EPMEM_RIT_OFFSET_INIT   -1
#define EPMEM_RIT_ROOT   0
#define EPMEM_RIT_STATE_EDGE   1
#define EPMEM_RIT_STATE_NODE   0

Typedefs

typedef struct epmem_data_struct epmem_data
typedef struct epmem_edge_struct epmem_edge
typedef uint64_t epmem_hash_id
typedef std::map
< epmem_node_id, epmem_id_pool * > 
epmem_hashed_id_pool
typedef std::map
< epmem_node_id, Symbol * > 
epmem_id_mapping
typedef std::pair
< epmem_node_id, epmem_node_id
epmem_id_pair
typedef std::list< epmem_id_pairepmem_id_pool
typedef std::map
< epmem_node_id, epmem_wme_set * > 
epmem_id_ref_counter
typedef std::map
< epmem_node_id, bool,
std::less< epmem_node_id >
, soar_module::soar_memory_pool_allocator
< std::pair< epmem_node_id,
bool > > > 
epmem_id_removal_map
typedef struct
epmem_id_reservation_struct 
epmem_id_reservation
typedef struct
epmem_interval_struct 
epmem_interval
typedef std::priority_queue
< epmem_interval
*, std::vector< epmem_interval * >
, epmem_interval_comparator
epmem_interval_pq
typedef std::set
< epmem_interval *, std::less
< epmem_interval * >
, soar_module::soar_memory_pool_allocator
< epmem_interval * > > 
epmem_interval_set
typedef struct epmem_literal_struct epmem_literal
typedef std::deque
< epmem_literal * > 
epmem_literal_deque
typedef struct std::pair
< epmem_literal
*, epmem_node_id
epmem_literal_node_pair
typedef std::map
< epmem_literal_node_pair, int
epmem_literal_node_pair_int_map
typedef std::map
< epmem_literal
*, epmem_node_pair
epmem_literal_node_pair_map
typedef std::set< epmem_literal * > epmem_literal_set
typedef std::deque< epmem_node_idepmem_node_deque
typedef int64_t epmem_node_id
typedef
soar_module::primitive_stat
< epmem_node_id
epmem_node_id_stat
typedef std::map
< epmem_node_id, int
epmem_node_int_map
typedef struct std::pair
< epmem_node_id, epmem_node_id
epmem_node_pair
typedef std::set
< epmem_node_pair, std::less
< epmem_node_pair >
, soar_module::soar_memory_pool_allocator
< epmem_node_pair > > 
epmem_node_pair_set
typedef std::set
< epmem_node_id, std::less
< epmem_node_id >
, soar_module::soar_memory_pool_allocator
< epmem_node_id > > 
epmem_node_set
typedef std::map
< epmem_node_id, Symbol * > 
epmem_node_symbol_map
typedef std::map
< epmem_node_id,
epmem_hashed_id_pool * > 
epmem_parent_id_pool
typedef struct epmem_pedge_struct epmem_pedge
typedef std::priority_queue
< epmem_pedge *, std::vector
< epmem_pedge * >
, epmem_pedge_comparator
epmem_pedge_pq
typedef std::set< epmem_pedge * > epmem_pedge_set
typedef std::map
< epmem_node_id, epmem_id_pool * > 
epmem_return_id_pool
typedef struct
epmem_rit_state_struct 
epmem_rit_state
typedef struct
epmem_rit_state_param_struct 
epmem_rit_state_param
typedef std::map< Symbol *, intepmem_symbol_int_map
typedef struct std::pair
< Symbol *, epmem_literal * > 
epmem_symbol_literal_pair
typedef std::map
< epmem_symbol_literal_pair,
int
epmem_symbol_literal_pair_int_map
typedef struct std::pair
< Symbol *, epmem_node_id
epmem_symbol_node_pair
typedef std::map
< epmem_symbol_node_pair, int
epmem_symbol_node_pair_int_map
typedef std::set< Symbol
*, std::less< Symbol * >
, soar_module::soar_memory_pool_allocator
< Symbol * > > 
epmem_symbol_set
typedef std::list< Symbol
*, soar_module::soar_memory_pool_allocator
< Symbol * > > 
epmem_symbol_stack
typedef uint64_t epmem_time_id
typedef
soar_module::primitive_stat
< epmem_time_id
epmem_time_id_stat
typedef std::vector
< epmem_time_id
epmem_time_list
typedef struct epmem_triple_struct epmem_triple
typedef std::map< epmem_triple,
epmem_pedge * > 
epmem_triple_pedge_map
typedef std::map< epmem_triple,
epmem_uedge *, std::less
< epmem_triple >
, soar_module::soar_memory_pool_allocator
< std::pair< const
epmem_triple, epmem_uedge * > > > 
epmem_triple_uedge_map
typedef struct epmem_uedge_struct epmem_uedge
typedef std::list< wme * > epmem_wme_list
typedef std::map< wme
*, epmem_literal * > 
epmem_wme_literal_map
typedef std::set< wme
*, std::less< wme * >
, soar_module::soar_memory_pool_allocator
< wme * > > 
epmem_wme_set
typedef std::list< preference
*, soar_module::soar_memory_pool_allocator
< preference * > > 
epmem_wme_stack

Enumerations

enum  epmem_variable_key

Functions

bool epmem_backup_db (agent *my_agent, const char *file_name, std::string *err)
void epmem_close (agent *my_agent)
bool epmem_enabled (agent *my_agent)
void epmem_go (agent *my_agent, bool allow_store=true)
void epmem_print_episode (agent *my_agent, epmem_time_id memory_id, std::string *buf)
void epmem_reset (agent *my_agent, Symbol *state=NULL)
void epmem_schedule_promotion (agent *my_agent, Symbol *id)
void epmem_visualize_episode (agent *my_agent, epmem_time_id memory_id, std::string *buf)

Macro Definition Documentation

#define EPMEM_DNF   2

Definition at line 67 of file episodic_memory.h.

#define EPMEM_HASH_ACCEPTABLE   1

Definition at line 53 of file episodic_memory.h.

Referenced by _epmem_store_level().

#define EPMEM_LN_2   0.693147180559945

Definition at line 65 of file episodic_memory.h.

Referenced by epmem_rit_insert_interval().

#define EPMEM_MEMID_NONE   0
#define EPMEM_NODE_NEG   1

Definition at line 56 of file episodic_memory.h.

Referenced by epmem_process_query().

#define EPMEM_NODE_POS   0

Definition at line 55 of file episodic_memory.h.

Referenced by epmem_process_query().

#define EPMEM_NODEID_BAD   -1
#define EPMEM_NODEID_ROOT   0
#define EPMEM_RANGE_END   1
#define EPMEM_RANGE_EP   0
#define EPMEM_RANGE_NOW   1

Definition at line 60 of file episodic_memory.h.

Referenced by epmem_process_query().

#define EPMEM_RANGE_POINT   2
#define EPMEM_RANGE_START   0
#define EPMEM_RIT_OFFSET_INIT   -1

Definition at line 64 of file episodic_memory.h.

Referenced by epmem_init_db(), and epmem_rit_insert_interval().

#define EPMEM_RIT_ROOT   0
#define EPMEM_RIT_STATE_EDGE   1
#define EPMEM_RIT_STATE_NODE   0

Typedef Documentation

typedef struct epmem_data_struct epmem_data
typedef struct epmem_edge_struct epmem_edge
typedef uint64_t epmem_hash_id

Definition at line 81 of file episodic_memory.h.

Definition at line 445 of file episodic_memory.h.

typedef std::map<epmem_node_id, Symbol *> epmem_id_mapping

Definition at line 440 of file episodic_memory.h.

Definition at line 443 of file episodic_memory.h.

Definition at line 444 of file episodic_memory.h.

Definition at line 465 of file episodic_memory.h.

typedef std::map< epmem_node_id, bool, std::less< epmem_node_id >, soar_module::soar_memory_pool_allocator< std::pair< epmem_node_id, bool > > > epmem_id_removal_map

Definition at line 454 of file episodic_memory.h.

Definition at line 522 of file episodic_memory.h.

typedef std::priority_queue<epmem_interval*, std::vector<epmem_interval*>, epmem_interval_comparator> epmem_interval_pq

Definition at line 638 of file episodic_memory.h.

Definition at line 547 of file episodic_memory.h.

Definition at line 519 of file episodic_memory.h.

typedef std::deque<epmem_literal*> epmem_literal_deque

Definition at line 531 of file episodic_memory.h.

typedef struct std::pair< epmem_literal *, epmem_node_id > epmem_literal_node_pair

Definition at line 527 of file episodic_memory.h.

Definition at line 535 of file episodic_memory.h.

Definition at line 534 of file episodic_memory.h.

typedef std::set<epmem_literal*> epmem_literal_set

Definition at line 542 of file episodic_memory.h.

typedef std::deque<epmem_node_id> epmem_node_deque

Definition at line 532 of file episodic_memory.h.

typedef int64_t epmem_node_id

Definition at line 78 of file episodic_memory.h.

Definition at line 170 of file episodic_memory.h.

typedef std::map<epmem_node_id, int> epmem_node_int_map

Definition at line 537 of file episodic_memory.h.

typedef struct std::pair< epmem_node_id, epmem_node_id > epmem_node_pair

Definition at line 528 of file episodic_memory.h.

Definition at line 549 of file episodic_memory.h.

Definition at line 548 of file episodic_memory.h.

Definition at line 536 of file episodic_memory.h.

Definition at line 446 of file episodic_memory.h.

Definition at line 520 of file episodic_memory.h.

typedef std::priority_queue<epmem_pedge*, std::vector<epmem_pedge*>, epmem_pedge_comparator> epmem_pedge_pq

Definition at line 625 of file episodic_memory.h.

typedef std::set<epmem_pedge*> epmem_pedge_set

Definition at line 543 of file episodic_memory.h.

Definition at line 447 of file episodic_memory.h.

typedef std::map<Symbol*, int> epmem_symbol_int_map

Definition at line 533 of file episodic_memory.h.

typedef struct std::pair< Symbol *, epmem_literal * > epmem_symbol_literal_pair

Definition at line 525 of file episodic_memory.h.

Definition at line 538 of file episodic_memory.h.

typedef struct std::pair< Symbol *, epmem_node_id > epmem_symbol_node_pair

Definition at line 526 of file episodic_memory.h.

Definition at line 539 of file episodic_memory.h.

Definition at line 455 of file episodic_memory.h.

Definition at line 451 of file episodic_memory.h.

typedef uint64_t epmem_time_id

Definition at line 84 of file episodic_memory.h.

Definition at line 169 of file episodic_memory.h.

typedef std::vector<epmem_time_id> epmem_time_list

Definition at line 391 of file episodic_memory.h.

Definition at line 518 of file episodic_memory.h.

Definition at line 540 of file episodic_memory.h.

Definition at line 546 of file episodic_memory.h.

Definition at line 521 of file episodic_memory.h.

Definition at line 394 of file episodic_memory.h.

typedef std::map<wme*, epmem_literal*> epmem_wme_literal_map

Definition at line 541 of file episodic_memory.h.

typedef std::set< wme*, std::less< wme* >, soar_module::soar_memory_pool_allocator< wme* > > epmem_wme_set

Definition at line 450 of file episodic_memory.h.

Definition at line 420 of file episodic_memory.h.

Enumeration Type Documentation

Enumerator:
var_rit_offset_1 
var_rit_leftroot_1 
var_rit_rightroot_1 
var_rit_minstep_1 
var_rit_offset_2 
var_rit_leftroot_2 
var_rit_rightroot_2 
var_rit_minstep_2 
var_next_id 

Definition at line 42 of file episodic_memory.h.

Function Documentation

bool epmem_backup_db ( agent my_agent,
const char *  file_name,
std::string *  err 
)
void epmem_close ( agent my_agent)

Definition at line 1340 of file episodic_memory.cpp.

References epmem_common_statement_container::commit, soar_module::connected, soar_module::sqlite_database::disconnect(), agent_struct::epmem_db, agent_struct::epmem_id_ref_counts, agent_struct::epmem_id_replacement, agent_struct::epmem_id_repository, agent_struct::epmem_params, agent_struct::epmem_promotions, EPMEM_RANGE_END, EPMEM_RANGE_EP, EPMEM_RANGE_POINT, EPMEM_RANGE_START, EPMEM_RIT_STATE_EDGE, EPMEM_RIT_STATE_NODE, agent_struct::epmem_stmts_common, agent_struct::epmem_stmts_graph, agent_struct::epmem_wme_adds, soar_module::statement::execute(), soar_module::status_object< T >::get_status(), soar_module::constant_param< T >::get_value(), epmem_param_container::lazy_commit, soar_module::on, soar_module::op_reinit, epmem_graph_statement_container::pool_dummy, epmem_graph_statement_container::pool_find_edge_queries, epmem_graph_statement_container::pool_find_interval_queries, epmem_graph_statement_container::pool_find_lti_queries, and symbol_remove_ref().

Referenced by destroy_soar_agent().

{
{
// if lazy, commit
{
}
// de-allocate statement pools
{
int j, k, m;
{
for ( k=0; k<=1; k++ )
{
delete my_agent->epmem_stmts_graph->pool_find_edge_queries[ j ][ k ];
}
}
{
{
{
delete my_agent->epmem_stmts_graph->pool_find_interval_queries[ j ][ k ][ m ];
}
}
}
{
{
delete my_agent->epmem_stmts_graph->pool_find_lti_queries[ k ][ m ];
}
}
delete my_agent->epmem_stmts_graph->pool_dummy;
}
// de-allocate statements
delete my_agent->epmem_stmts_common;
delete my_agent->epmem_stmts_graph;
// de-allocate local data structures
{
epmem_parent_id_pool::iterator p;
epmem_hashed_id_pool::iterator p_p;
for ( p=my_agent->epmem_id_repository->begin(); p!=my_agent->epmem_id_repository->end(); p++ )
{
for ( p_p=p->second->begin(); p_p!=p->second->end(); p_p++ )
{
delete p_p->second;
}
delete p->second;
}
my_agent->epmem_id_repository->clear();
my_agent->epmem_id_replacement->clear();
for ( epmem_id_ref_counter::iterator rf_it=my_agent->epmem_id_ref_counts->begin(); rf_it!=my_agent->epmem_id_ref_counts->end(); rf_it++ )
{
delete rf_it->second;
}
my_agent->epmem_id_ref_counts->clear();
my_agent->epmem_wme_adds->clear();
for ( epmem_symbol_set::iterator p_it=my_agent->epmem_promotions->begin(); p_it!=my_agent->epmem_promotions->end(); p_it++ )
{
symbol_remove_ref( my_agent, (*p_it) );
}
my_agent->epmem_promotions->clear();
}
// close the database
my_agent->epmem_db->disconnect();
}
#ifdef EPMEM_EXPERIMENT
if ( epmem_exp_output )
{
epmem_exp_output->close();
delete epmem_exp_output;
epmem_exp_output = NULL;
if ( epmem_exp_timer )
{
delete epmem_exp_timer;
}
}
#endif
}
bool epmem_enabled ( agent my_agent)
void epmem_go ( agent my_agent,
bool  allow_store = true 
)

Definition at line 5853 of file episodic_memory.cpp.

References epmem_consider_new_episode(), epmem_respond_to_cmd(), agent_struct::epmem_timers, soar_module::timer::start(), soar_module::timer::stop(), and epmem_timer_container::total.

Referenced by do_one_top_level_phase().

{
my_agent->epmem_timers->total->start();
#ifndef EPMEM_EXPERIMENT
if ( allow_store )
{
}
epmem_respond_to_cmd( my_agent );
#else // EPMEM_EXPERIMENT
_epmem_exp( my_agent );
epmem_respond_to_cmd( my_agent );
#endif // EPMEM_EXPERIMENT
my_agent->epmem_timers->total->stop();
}
void epmem_print_episode ( agent my_agent,
epmem_time_id  memory_id,
std::string *  buf 
)

Definition at line 4488 of file episodic_memory.cpp.

References _epmem_print_sti(), soar_module::sqlite_statement::bind_int(), soar_module::sqlite_statement::column_double(), soar_module::sqlite_statement::column_int(), soar_module::sqlite_statement::column_text(), soar_module::sqlite_statement::column_type(), soar_module::disconnected, agent_struct::epmem_db, epmem_init_db(), EPMEM_MEMID_NONE, epmem_rit_clear_left_right(), epmem_rit_prep_left_right(), EPMEM_RIT_STATE_EDGE, agent_struct::epmem_rit_state_graph, EPMEM_RIT_STATE_NODE, agent_struct::epmem_stmts_graph, epmem_valid_episode(), soar_module::statement::execute(), FLOAT_CONSTANT_SYMBOL_TYPE, epmem_graph_statement_container::get_edges, epmem_graph_statement_container::get_nodes, soar_module::status_object< T >::get_status(), INT_CONSTANT_SYMBOL_TYPE, soar_module::null_t, soar_module::statement::reinitialize(), soar_module::row, and SYM_CONSTANT_SYMBOL_TYPE.

{
// if this is before the first episode, initialize db components
{
epmem_init_db( my_agent );
}
// if bad memory, bail
buf->clear();
if ( ( memory_id == EPMEM_MEMID_NONE ) ||
!epmem_valid_episode( my_agent, memory_id ) )
{
return;
}
// fill episode map
std::map< epmem_node_id, std::string > ltis;
std::map< epmem_node_id, std::map< std::string, std::list< std::string > > > ep;
{
std::string temp_s, temp_s2, temp_s3;
double temp_d;
int64_t temp_i;
my_q = my_agent->epmem_stmts_graph->get_edges;
{
int64_t w_type;
bool val_is_short_term;
epmem_rit_prep_left_right( my_agent, memory_id, memory_id, &( my_agent->epmem_rit_state_graph[ EPMEM_RIT_STATE_EDGE ] ) );
// query for edges
my_q->bind_int( 1, memory_id );
my_q->bind_int( 2, memory_id );
my_q->bind_int( 3, memory_id );
my_q->bind_int( 4, memory_id );
my_q->bind_int( 5, memory_id );
while ( my_q->execute() == soar_module::row )
{
q0 = my_q->column_int( 0 );
q1 = my_q->column_int( 2 );
w_type = my_q->column_int( 3 );
val_is_short_term = ( my_q->column_type( 4 ) == soar_module::null_t );
switch ( w_type )
{
temp_i = static_cast<int64_t>( my_q->column_int( 1 ) );
to_string( temp_i, temp_s );
break;
temp_d = my_q->column_double( 1 );
to_string( temp_d, temp_s );
break;
temp_s.assign( const_cast<char *>( reinterpret_cast<const char *>( my_q->column_text( 1 ) ) ) );
break;
}
if ( val_is_short_term )
{
temp_s2 = _epmem_print_sti( q1 );
}
else
{
temp_s2.assign( "@" );
temp_s2.push_back( static_cast< char >( my_q->column_int( 4 ) ) );
temp_i = static_cast< uint64_t >( my_q->column_int( 5 ) );
to_string( temp_i, temp_s3 );
temp_s2.append( temp_s3 );
ltis[ q1 ] = temp_s2;
}
ep[ q0 ][ temp_s ].push_back( temp_s2 );
}
my_q->reinitialize();
}
my_q = my_agent->epmem_stmts_graph->get_nodes;
{
epmem_node_id parent_id;
int64_t attr_type, value_type;
epmem_rit_prep_left_right( my_agent, memory_id, memory_id, &( my_agent->epmem_rit_state_graph[ EPMEM_RIT_STATE_NODE ] ) );
my_q->bind_int( 1, memory_id );
my_q->bind_int( 2, memory_id );
my_q->bind_int( 3, memory_id );
my_q->bind_int( 4, memory_id );
while ( my_q->execute() == soar_module::row )
{
parent_id = my_q->column_int( 1 );
attr_type = my_q->column_int( 4 );
value_type = my_q->column_int( 5 );
switch ( attr_type )
{
temp_i = static_cast<int64_t>( my_q->column_int( 2 ) );
to_string( temp_i, temp_s );
break;
temp_d = my_q->column_double( 2 );
to_string( temp_d, temp_s );
break;
temp_s.assign( const_cast<char *>( reinterpret_cast<const char *>( my_q->column_text( 2 ) ) ) );
break;
}
switch ( value_type )
{
temp_i = static_cast<int64_t>( my_q->column_int( 3 ) );
to_string( temp_i, temp_s2 );
break;
temp_d = my_q->column_double( 3 );
to_string( temp_d, temp_s2 );
break;
temp_s2.assign( const_cast<char *>( reinterpret_cast<const char *>( my_q->column_text( 3 ) ) ) );
break;
}
ep[ parent_id ][ temp_s ].push_back( temp_s2 );
}
my_q->reinitialize();
}
}
// output
{
std::map< epmem_node_id, std::string >::iterator lti_it;
std::map< epmem_node_id, std::map< std::string, std::list< std::string > > >::iterator ep_it;
std::map< std::string, std::list< std::string > >::iterator slot_it;
std::list< std::string >::iterator val_it;
for ( ep_it=ep.begin(); ep_it!=ep.end(); ep_it++ )
{
buf->append( "(" );
// id
lti_it = ltis.find( ep_it->first );
if ( lti_it == ltis.end() )
{
buf->append( _epmem_print_sti( ep_it->first ) );
}
else
{
buf->append( lti_it->second );
}
// attr
for ( slot_it=ep_it->second.begin(); slot_it!=ep_it->second.end(); slot_it++ )
{
buf->append( " ^" );
buf->append( slot_it->first );
for ( val_it=slot_it->second.begin(); val_it!=slot_it->second.end(); val_it++ )
{
buf->append( " " );
buf->append( *val_it );
}
}
buf->append( ")\n" );
}
}
}
void epmem_reset ( agent my_agent,
Symbol state = NULL 
)

Definition at line 1466 of file episodic_memory.cpp.

References identifier_struct::epmem_info, EPMEM_MEMID_NONE, epmem_data_struct::epmem_wmes, symbol_union::id, epmem_data_struct::last_cmd_count, epmem_data_struct::last_cmd_time, epmem_data_struct::last_memory, epmem_data_struct::last_ol_time, identifier_struct::lower_goal, and agent_struct::top_goal.

Referenced by remove_existing_context_and_descendents().

{
if ( state == NULL )
{
state = my_agent->top_goal;
}
while( state )
{
epmem_data *data = state->id.epmem_info;
data->last_ol_time = 0;
data->last_cmd_time = 0;
data->last_cmd_count = 0;
// this will be called after prefs from goal are already removed,
// so just clear out result stack
data->epmem_wmes->clear();
state = state->id.lower_goal;
}
}
void epmem_schedule_promotion ( agent my_agent,
Symbol id 
)
void epmem_visualize_episode ( agent my_agent,
epmem_time_id  memory_id,
std::string *  buf 
)

Definition at line 4672 of file episodic_memory.cpp.

References soar_module::sqlite_statement::bind_int(), soar_module::sqlite_statement::column_double(), soar_module::sqlite_statement::column_int(), soar_module::sqlite_statement::column_text(), soar_module::sqlite_statement::column_type(), soar_module::disconnected, agent_struct::epmem_db, epmem_init_db(), EPMEM_MEMID_NONE, epmem_rit_clear_left_right(), epmem_rit_prep_left_right(), EPMEM_RIT_STATE_EDGE, agent_struct::epmem_rit_state_graph, EPMEM_RIT_STATE_NODE, agent_struct::epmem_stmts_graph, epmem_valid_episode(), soar_module::statement::execute(), FLOAT_CONSTANT_SYMBOL_TYPE, epmem_graph_statement_container::get_edges, epmem_graph_statement_container::get_nodes, soar_module::status_object< T >::get_status(), INT_CONSTANT_SYMBOL_TYPE, soar_module::null_t, soar_module::statement::reinitialize(), soar_module::row, and SYM_CONSTANT_SYMBOL_TYPE.

{
// if this is before the first episode, initialize db components
{
epmem_init_db( my_agent );
}
// if bad memory, bail
buf->clear();
if ( ( memory_id == EPMEM_MEMID_NONE ) ||
!epmem_valid_episode( my_agent, memory_id ) )
{
return;
}
// init
{
buf->append( "digraph epmem {\n" );
}
// taken heavily from install
{
// first identifiers (i.e. reconstruct)
my_q = my_agent->epmem_stmts_graph->get_edges;
{
// for printing
std::map< epmem_node_id, std::string > stis;
std::map< epmem_node_id, std::pair< std::string, std::string > > ltis;
std::list< std::string > edges;
std::map< epmem_node_id, std::string >::iterator sti_p;
std::map< epmem_node_id, std::pair< std::string, std::string > >::iterator lti_p;
// relates to finite automata: q1 = d(q0, w)
epmem_node_id q0; // id
epmem_node_id q1; // attribute
int64_t w_type; // we support any constant attribute symbol
std::string temp, temp2, temp3, temp4;
double temp_d;
int64_t temp_i;
bool val_is_short_term;
char val_letter;
uint64_t val_num;
// 0 is magic
temp.assign( "ID_0" );
stis.insert( std::make_pair< epmem_node_id, std::string >( 0, temp ) );
// prep rit
epmem_rit_prep_left_right( my_agent, memory_id, memory_id, &( my_agent->epmem_rit_state_graph[ EPMEM_RIT_STATE_EDGE ] ) );
// query for edges
my_q->bind_int( 1, memory_id );
my_q->bind_int( 2, memory_id );
my_q->bind_int( 3, memory_id );
my_q->bind_int( 4, memory_id );
my_q->bind_int( 5, memory_id );
while ( my_q->execute() == soar_module::row )
{
// q0, w, q1, w_type, letter, num
q0 = my_q->column_int( 0 );
q1 = my_q->column_int( 2 );
w_type = my_q->column_int( 3 );
// "ID_Q0"
temp.assign( "ID_" );
to_string( q0, temp2 );
temp.append( temp2 );
// "ID_Q1"
temp3.assign( "ID_" );
to_string( q1, temp2 );
temp3.append( temp2 );
val_is_short_term = ( my_q->column_type( 4 ) == soar_module::null_t );
if ( val_is_short_term )
{
sti_p = stis.find( q1 );
if ( sti_p == stis.end() )
{
stis.insert( std::make_pair< epmem_node_id, std::string >( q1, temp3 ) );
}
}
else
{
lti_p = ltis.find( q1 );
if ( lti_p == ltis.end() )
{
// "L#"
val_letter = static_cast<char>( my_q->column_int( 4 ) );
to_string( val_letter, temp4 );
val_num = static_cast<uint64_t>( my_q->column_int( 5 ) );
to_string( val_num, temp2 );
temp4.append( temp2 );
ltis.insert( std::make_pair< epmem_node_id, std::pair< std::string, std::string > >( q1, std::make_pair< std::string, std::string >( temp3, temp4 ) ) );
}
}
// " -> ID_Q1"
temp.append( " -> " );
temp.append( temp3 );
// " [ label="w" ];\n"
temp.append( " [ label=\"" );
switch ( w_type )
{
temp_i = static_cast<int64_t>( my_q->column_int( 1 ) );
to_string( temp_i, temp2 );
break;
temp_d = my_q->column_double( 1 );
to_string( temp_d, temp2 );
break;
temp2.assign( const_cast<char *>( reinterpret_cast<const char *>( my_q->column_text( 1 ) ) ) );
break;
}
temp.append( temp2 );
temp.append( "\" ];\n" );
edges.push_back( temp );
}
my_q->reinitialize();
// identifiers
{
// short-term
{
buf->append( "node [ shape = circle ];\n" );
for ( sti_p=stis.begin(); sti_p!=stis.end(); sti_p++ )
{
buf->append( sti_p->second );
buf->append( " " );
}
buf->append( ";\n" );
}
// long-term
{
buf->append( "node [ shape = doublecircle ];\n" );
for ( lti_p=ltis.begin(); lti_p!=ltis.end(); lti_p++ )
{
buf->append( lti_p->second.first );
buf->append( " [ label=\"" );
buf->append( lti_p->second.second );
buf->append( "\" ];\n" );
}
buf->append( "\n" );
}
}
// edges
{
std::list< std::string >::iterator e_p;
for ( e_p=edges.begin(); e_p!=edges.end(); e_p++ )
{
buf->append( (*e_p) );
}
}
}
// then node_unique
my_q = my_agent->epmem_stmts_graph->get_nodes;
{
epmem_node_id child_id;
epmem_node_id parent_id;
int64_t attr_type;
int64_t value_type;
std::list< std::string > edges;
std::list< std::string > consts;
std::string temp, temp2;
double temp_d;
int64_t temp_i;
epmem_rit_prep_left_right( my_agent, memory_id, memory_id, &( my_agent->epmem_rit_state_graph[ EPMEM_RIT_STATE_NODE ] ) );
my_q->bind_int( 1, memory_id );
my_q->bind_int( 2, memory_id );
my_q->bind_int( 3, memory_id );
my_q->bind_int( 4, memory_id );
while ( my_q->execute() == soar_module::row )
{
// f.child_id, f.parent_id, f.name, f.value, f.attr_type, f.value_type
child_id = my_q->column_int( 0 );
parent_id = my_q->column_int( 1 );
attr_type = my_q->column_int( 4 );
value_type = my_q->column_int( 5 );
temp.assign( "ID_" );
to_string( parent_id, temp2 );
temp.append( temp2 );
temp.append( " -> C_" );
to_string( child_id, temp2 );
temp.append( temp2 );
temp.append( " [ label=\"" );
// make a symbol to represent the attribute
switch ( attr_type )
{
temp_i = static_cast<int64_t>( my_q->column_int( 2 ) );
to_string( temp_i, temp2 );
break;
temp_d = my_q->column_double( 2 );
to_string( temp_d, temp2 );
break;
temp2.assign( const_cast<char *>( reinterpret_cast<const char *>( my_q->column_text( 2 ) ) ) );
break;
}
temp.append( temp2 );
temp.append( "\" ];\n" );
edges.push_back( temp );
temp.assign( "C_" );
to_string( child_id, temp2 );
temp.append( temp2 );
temp.append( " [ label=\"" );
// make a symbol to represent the value
switch ( value_type )
{
temp_i = static_cast<int64_t>( my_q->column_int( 3 ) );
to_string( temp_i, temp2 );
break;
temp_d = my_q->column_double( 3 );
to_string( temp_d, temp2 );
break;
temp2.assign( const_cast<char *>( reinterpret_cast<const char *>( my_q->column_text( 3 ) ) ) );
break;
}
temp.append( temp2 );
temp.append( "\" ];\n" );
consts.push_back( temp );
}
my_q->reinitialize();
// constant nodes
{
std::list< std::string >::iterator e_p;
buf->append( "node [ shape = plaintext ];\n" );
for ( e_p=consts.begin(); e_p!=consts.end(); e_p++ )
{
buf->append( (*e_p) );
}
}
// edges
{
std::list< std::string >::iterator e_p;
for ( e_p=edges.begin(); e_p!=edges.end(); e_p++ )
{
buf->append( (*e_p) );
}
}
}
}
// close
{
buf->append( "\n}\n" );
}
}