Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Data Fields
epmem_graph_statement_container Class Reference

#include <episodic_memory.h>

Inherits soar_module::sqlite_statement_container.

Public Member Functions

 epmem_graph_statement_container (agent *new_agent)
- Public Member Functions inherited from soar_module::sqlite_statement_container
void add_structure (const char *new_structure)
 sqlite_statement_container (sqlite_database *new_db)
void structure ()
virtual ~sqlite_statement_container ()
- Public Member Functions inherited from soar_module::statement_container
void add (statement *new_statement)
void clean ()
void prepare ()
 statement_container ()
virtual ~statement_container ()

Data Fields

soar_module::sqlite_statementadd_edge_now
soar_module::sqlite_statementadd_edge_point
soar_module::sqlite_statementadd_edge_range
soar_module::sqlite_statementadd_edge_unique
soar_module::sqlite_statementadd_node_now
soar_module::sqlite_statementadd_node_point
soar_module::sqlite_statementadd_node_range
soar_module::sqlite_statementadd_node_unique
soar_module::sqlite_statementadd_time
soar_module::sqlite_statementdelete_edge_now
soar_module::sqlite_statementdelete_node_now
soar_module::sqlite_statementfind_edge_unique
soar_module::sqlite_statementfind_edge_unique_shared
soar_module::sqlite_statementfind_lti
soar_module::sqlite_statementfind_lti_promotion_time
soar_module::sqlite_statementfind_node_unique
soar_module::sqlite_statementget_edges
soar_module::sqlite_statementget_nodes
soar_module::sqlite_statementnext_episode
soar_module::sqlite_statement_poolpool_dummy
soar_module::sqlite_statement_poolpool_find_edge_queries [2][2]
soar_module::sqlite_statement_poolpool_find_interval_queries [2][2][3]
soar_module::sqlite_statement_poolpool_find_lti_queries [2][3]
soar_module::sqlite_statementprev_episode
soar_module::sqlite_statementpromote_id
soar_module::sqlite_statementupdate_edge_unique_last
soar_module::sqlite_statementvalid_episode

Additional Inherited Members

- Protected Attributes inherited from soar_module::sqlite_statement_container
sqlite_databasemy_db
std::list< const char * > * structures

Detailed Description

Definition at line 328 of file episodic_memory.h.

Constructor & Destructor Documentation

epmem_graph_statement_container::epmem_graph_statement_container ( agent new_agent)

Definition at line 587 of file episodic_memory.cpp.

References soar_module::statement_container::add(), add_edge_now, add_edge_point, add_edge_range, add_edge_unique, add_node_now, add_node_point, add_node_range, add_node_unique, soar_module::sqlite_statement_container::add_structure(), add_time, delete_edge_now, delete_node_now, agent_struct::epmem_db, EPMEM_RANGE_END, EPMEM_RANGE_EP, EPMEM_RANGE_POINT, EPMEM_RANGE_START, EPMEM_RIT_STATE_EDGE, EPMEM_RIT_STATE_NODE, agent_struct::epmem_timers, find_edge_unique, find_edge_unique_shared, find_lti, find_lti_promotion_time, find_node_unique, get_edges, get_nodes, epmem_timer_container::ncb_edge, epmem_timer_container::ncb_node, next_episode, pool_dummy, pool_find_edge_queries, pool_find_interval_queries, pool_find_lti_queries, prev_episode, promote_id, update_edge_unique_last, and valid_episode.

{
soar_module::sqlite_database *new_db = new_agent->epmem_db;
//
add_structure( "CREATE TABLE IF NOT EXISTS times (id INTEGER PRIMARY KEY)" );
add_structure( "CREATE TABLE IF NOT EXISTS node_now (id INTEGER,start INTEGER)" );
add_structure( "CREATE INDEX IF NOT EXISTS node_now_start ON node_now (start)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS node_now_id_start ON node_now (id,start DESC)" );
add_structure( "CREATE TABLE IF NOT EXISTS edge_now (id INTEGER,start INTEGER)" );
add_structure( "CREATE INDEX IF NOT EXISTS edge_now_start ON edge_now (start)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS edge_now_id_start ON edge_now (id,start DESC)" );
add_structure( "CREATE TABLE IF NOT EXISTS node_point (id INTEGER,start INTEGER)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS node_point_id_start ON node_point (id,start DESC)" );
add_structure( "CREATE INDEX IF NOT EXISTS node_point_start ON node_point (start)" );
add_structure( "CREATE TABLE IF NOT EXISTS edge_point (id INTEGER,start INTEGER)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS edge_point_id_start ON edge_point (id,start DESC)" );
add_structure( "CREATE INDEX IF NOT EXISTS edge_point_start ON edge_point (start)" );
add_structure( "CREATE TABLE IF NOT EXISTS node_range (rit_node INTEGER,start INTEGER,end INTEGER,id INTEGER)" );
add_structure( "CREATE INDEX IF NOT EXISTS node_range_lower ON node_range (rit_node,start)" );
add_structure( "CREATE INDEX IF NOT EXISTS node_range_upper ON node_range (rit_node,end)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS node_range_id_start ON node_range (id,start DESC)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS node_range_id_end_start ON node_range (id,end DESC,start)" );
add_structure( "CREATE TABLE IF NOT EXISTS edge_range (rit_node INTEGER,start INTEGER,end INTEGER,id INTEGER)" );
add_structure( "CREATE INDEX IF NOT EXISTS edge_range_lower ON edge_range (rit_node,start)" );
add_structure( "CREATE INDEX IF NOT EXISTS edge_range_upper ON edge_range (rit_node,end)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS edge_range_id_start ON edge_range (id,start DESC)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS edge_range_id_end_start ON edge_range (id,end DESC,start)" );
add_structure( "CREATE TABLE IF NOT EXISTS node_unique (child_id INTEGER PRIMARY KEY AUTOINCREMENT,parent_id INTEGER,attrib INTEGER, value INTEGER)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS node_unique_parent_attrib_value ON node_unique (parent_id,attrib,value)" );
add_structure( "CREATE TABLE IF NOT EXISTS edge_unique (parent_id INTEGER PRIMARY KEY AUTOINCREMENT,q0 INTEGER,w INTEGER,q1 INTEGER, last INTEGER)" );
add_structure( "CREATE INDEX IF NOT EXISTS edge_unique_q0_w_last ON edge_unique (q0,w,last)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS edge_unique_q0_w_q1 ON edge_unique (q0,w,q1)" );
add_structure( "CREATE TABLE IF NOT EXISTS lti (parent_id INTEGER PRIMARY KEY, letter INTEGER, num INTEGER, time_id INTEGER)" );
add_structure( "CREATE UNIQUE INDEX IF NOT EXISTS lti_letter_num ON lti (letter,num)" );
// adding an ascii table just to make lti queries easier when inspecting database
add_structure( "CREATE TABLE IF NOT EXISTS ascii (ascii_num INTEGER PRIMARY KEY, ascii_chr TEXT)" );
add_structure( "DELETE FROM ascii" );
{
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (65,'A')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (66,'B')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (67,'C')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (68,'D')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (69,'E')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (70,'F')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (71,'G')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (72,'H')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (73,'I')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (74,'J')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (75,'K')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (76,'L')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (77,'M')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (78,'N')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (79,'O')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (80,'P')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (81,'Q')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (82,'R')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (83,'S')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (84,'T')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (85,'U')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (86,'V')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (87,'W')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (88,'X')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (89,'Y')" );
add_structure( "INSERT INTO ascii (ascii_num, ascii_chr) VALUES (90,'Z')" );
}
//
add_time = new soar_module::sqlite_statement( new_db, "INSERT INTO times (id) VALUES (?)" );
//
add_node_now = new soar_module::sqlite_statement( new_db, "INSERT INTO node_now (id,start) VALUES (?,?)" );
delete_node_now = new soar_module::sqlite_statement( new_db, "DELETE FROM node_now WHERE id=?" );
add_node_point = new soar_module::sqlite_statement( new_db, "INSERT INTO node_point (id,start) VALUES (?,?)" );
add_node_range = new soar_module::sqlite_statement( new_db, "INSERT INTO node_range (rit_node,start,end,id) VALUES (?,?,?,?)" );
add_node_unique = new soar_module::sqlite_statement( new_db, "INSERT INTO node_unique (parent_id,attrib,value) VALUES (?,?,?)" );
find_node_unique = new soar_module::sqlite_statement( new_db, "SELECT child_id FROM node_unique WHERE parent_id=? AND attrib=? AND value=?" );
//
add_edge_now = new soar_module::sqlite_statement( new_db, "INSERT INTO edge_now (id,start) VALUES (?,?)" );
delete_edge_now = new soar_module::sqlite_statement( new_db, "DELETE FROM edge_now WHERE id=?" );
add_edge_point = new soar_module::sqlite_statement( new_db, "INSERT INTO edge_point (id,start) VALUES (?,?)" );
add_edge_range = new soar_module::sqlite_statement( new_db, "INSERT INTO edge_range (rit_node,start,end,id) VALUES (?,?,?,?)" );
add_edge_unique = new soar_module::sqlite_statement( new_db, "INSERT INTO edge_unique (q0,w,q1,last) VALUES (?,?,?,?)" );
find_edge_unique = new soar_module::sqlite_statement( new_db, "SELECT parent_id, q1 FROM edge_unique WHERE q0=? AND w=?" );
find_edge_unique_shared = new soar_module::sqlite_statement( new_db, "SELECT parent_id, q1 FROM edge_unique WHERE q0=? AND w=? AND q1=?" );
//
valid_episode = new soar_module::sqlite_statement( new_db, "SELECT COUNT(*) AS ct FROM times WHERE id=?" );
next_episode = new soar_module::sqlite_statement( new_db, "SELECT id FROM times WHERE id>? ORDER BY id ASC LIMIT 1" );
prev_episode = new soar_module::sqlite_statement( new_db, "SELECT id FROM times WHERE id<? ORDER BY id DESC LIMIT 1" );
get_nodes = new soar_module::sqlite_statement( new_db, "SELECT f.child_id, f.parent_id, h1.sym_const, h2.sym_const, h1.sym_type, h2.sym_type FROM node_unique f, temporal_symbol_hash h1, temporal_symbol_hash h2 WHERE f.child_id IN (SELECT n.id FROM node_now n WHERE n.start<= ? UNION ALL SELECT p.id FROM node_point p WHERE p.start=? UNION ALL SELECT e1.id FROM node_range e1, rit_left_nodes lt WHERE e1.rit_node=lt.min AND e1.end >= ? UNION ALL SELECT e2.id FROM node_range e2, rit_right_nodes rt WHERE e2.rit_node = rt.node AND e2.start <= ?) AND f.attrib=h1.id AND f.value=h2.id ORDER BY f.child_id ASC", new_agent->epmem_timers->ncb_node );
get_edges = new soar_module::sqlite_statement( new_db, "SELECT f.q0, h.sym_const, f.q1, h.sym_type, lti.letter, lti.num FROM edge_unique f INNER JOIN temporal_symbol_hash h ON f.w=h.id LEFT JOIN lti ON (f.q1=lti.parent_id AND lti.time_id <= ?) WHERE f.parent_id IN (SELECT n.id FROM edge_now n WHERE n.start<= ? UNION ALL SELECT p.id FROM edge_point p WHERE p.start = ? UNION ALL SELECT e1.id FROM edge_range e1, rit_left_nodes lt WHERE e1.rit_node=lt.min AND e1.end >= ? UNION ALL SELECT e2.id FROM edge_range e2, rit_right_nodes rt WHERE e2.rit_node = rt.node AND e2.start <= ?) ORDER BY f.q0 ASC, f.q1 ASC", new_agent->epmem_timers->ncb_edge );
//
promote_id = new soar_module::sqlite_statement( new_db, "INSERT OR IGNORE INTO lti (parent_id,letter,num,time_id) VALUES (?,?,?,?)" );
find_lti = new soar_module::sqlite_statement( new_db, "SELECT parent_id FROM lti WHERE letter=? AND num=?" );
find_lti_promotion_time = new soar_module::sqlite_statement( new_db, "SELECT time_id FROM lti WHERE parent_id=?" );
//
update_edge_unique_last = new soar_module::sqlite_statement( new_db, "UPDATE edge_unique SET last=? WHERE parent_id=?" );
//
// init statement pools
{
int j, k, m;
const char* epmem_find_edge_queries[2][2] = {
{
"SELECT child_id, value, ? FROM node_unique WHERE parent_id=? AND attrib=?",
"SELECT child_id, value, ? FROM node_unique WHERE parent_id=? AND attrib=? AND value=?"
},
{
"SELECT parent_id, q1, last FROM edge_unique WHERE q0=? AND w=? AND ?<last ORDER BY last DESC",
"SELECT parent_id, q1, last FROM edge_unique WHERE q0=? AND w=? AND q1=? AND ?<last"
}
};
{
for ( k=0; k<=1; k++ )
{
pool_find_edge_queries[ j ][ k ] = new soar_module::sqlite_statement_pool( new_agent, new_db, epmem_find_edge_queries[ j ][ k ] );
}
}
//
// Because the DB records when things are /inserted/, we need to offset
// the start by 1 to /remove/ them at the right time. Ditto to even
// include those intervals correctly
const char *epmem_find_interval_queries[2][2][3] =
{
{
{
"SELECT (e.start - 1) AS start FROM node_range e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC",
"SELECT (e.start - 1) AS start FROM node_now e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC",
"SELECT (e.start - 1) AS start FROM node_point e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC"
},
{
"SELECT e.end AS end FROM node_range e WHERE e.id=? AND e.end>0 AND e.start<=? ORDER BY e.end DESC",
"SELECT ? AS end FROM node_now e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC",
"SELECT e.start AS end FROM node_point e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC"
}
},
{
{
"SELECT (e.start - 1) AS start FROM edge_range e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC",
"SELECT (e.start - 1) AS start FROM edge_now e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC",
"SELECT (e.start - 1) AS start FROM edge_point e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC"
},
{
"SELECT e.end AS end FROM edge_range e WHERE e.id=? AND e.end>0 AND e.start<=? ORDER BY e.end DESC",
"SELECT ? AS end FROM edge_now e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC",
"SELECT e.start AS end FROM edge_point e WHERE e.id=? AND e.start<=? ORDER BY e.start DESC"
}
},
};
{
{
{
pool_find_interval_queries[ j ][ k ][ m ] = new soar_module::sqlite_statement_pool( new_agent, new_db, epmem_find_interval_queries[ j ][ k ][ m ] );
}
}
}
//
// notice that the start and end queries in epmem_find_lti_queries are _asymetric_
// in that the the starts have ?<e.start and the ends have ?<=e.start
// this small difference means that the start of the very first interval
// (ie. the one where the start is at or before the promotion time) will be ignored
// then we can simply add a single epmem_interval to the queue, and it will
// terminate any LTI interval appropriately
const char *epmem_find_lti_queries[2][3] =
{
{
"SELECT (e.start - 1) AS start FROM edge_range e WHERE e.id=? AND ?<e.start AND e.start<=? ORDER BY e.start DESC",
"SELECT (e.start - 1) AS start FROM edge_now e WHERE e.id=? AND ?<e.start AND e.start<=? ORDER BY e.start DESC",
"SELECT (e.start - 1) AS start FROM edge_point e WHERE e.id=? AND ?<e.start AND e.start<=? ORDER BY e.start DESC"
},
{
"SELECT e.end AS end FROM edge_range e WHERE e.id=? AND e.end>0 AND ?<=e.start AND e.start<=? ORDER BY e.end DESC",
"SELECT ? AS end FROM edge_now e WHERE e.id=? AND ?<=e.start AND e.start<=? ORDER BY e.start",
"SELECT e.start AS end FROM edge_point e WHERE e.id=? AND ?<=e.start AND e.start<=? ORDER BY e.start DESC"
}
};
{
{
pool_find_lti_queries[ k ][ m ] = new soar_module::sqlite_statement_pool( new_agent, new_db, epmem_find_lti_queries[ k ][ m ] );
}
}
//
pool_dummy = new soar_module::sqlite_statement_pool( new_agent, new_db, "SELECT ? as start" );
}
}

Field Documentation

soar_module::sqlite_statement* epmem_graph_statement_container::add_edge_now

Definition at line 345 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_new_episode().

soar_module::sqlite_statement* epmem_graph_statement_container::add_edge_point
soar_module::sqlite_statement* epmem_graph_statement_container::add_edge_range

Definition at line 348 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_init_db().

soar_module::sqlite_statement* epmem_graph_statement_container::add_edge_unique

Definition at line 350 of file episodic_memory.h.

Referenced by _epmem_store_level(), and epmem_graph_statement_container().

soar_module::sqlite_statement* epmem_graph_statement_container::add_node_now

Definition at line 335 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_new_episode().

soar_module::sqlite_statement* epmem_graph_statement_container::add_node_point
soar_module::sqlite_statement* epmem_graph_statement_container::add_node_range

Definition at line 338 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_init_db().

soar_module::sqlite_statement* epmem_graph_statement_container::add_node_unique

Definition at line 340 of file episodic_memory.h.

Referenced by _epmem_store_level(), and epmem_graph_statement_container().

soar_module::sqlite_statement* epmem_graph_statement_container::add_time

Definition at line 331 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_new_episode().

soar_module::sqlite_statement* epmem_graph_statement_container::delete_edge_now

Definition at line 346 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_new_episode().

soar_module::sqlite_statement* epmem_graph_statement_container::delete_node_now

Definition at line 336 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_new_episode().

soar_module::sqlite_statement* epmem_graph_statement_container::find_edge_unique

Definition at line 351 of file episodic_memory.h.

Referenced by epmem_graph_statement_container().

soar_module::sqlite_statement* epmem_graph_statement_container::find_edge_unique_shared

Definition at line 352 of file episodic_memory.h.

Referenced by _epmem_store_level(), and epmem_graph_statement_container().

soar_module::sqlite_statement* epmem_graph_statement_container::find_lti
soar_module::sqlite_statement* epmem_graph_statement_container::find_lti_promotion_time

Definition at line 367 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_process_query().

soar_module::sqlite_statement* epmem_graph_statement_container::find_node_unique

Definition at line 341 of file episodic_memory.h.

Referenced by _epmem_store_level(), and epmem_graph_statement_container().

soar_module::sqlite_statement* epmem_graph_statement_container::get_edges
soar_module::sqlite_statement* epmem_graph_statement_container::get_nodes
soar_module::sqlite_statement* epmem_graph_statement_container::next_episode

Definition at line 357 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_next_episode().

soar_module::sqlite_statement_pool* epmem_graph_statement_container::pool_dummy
soar_module::sqlite_statement_pool* epmem_graph_statement_container::pool_find_edge_queries[2][2]
soar_module::sqlite_statement_pool* epmem_graph_statement_container::pool_find_interval_queries[2][2][3]
soar_module::sqlite_statement_pool* epmem_graph_statement_container::pool_find_lti_queries[2][3]
soar_module::sqlite_statement* epmem_graph_statement_container::prev_episode

Definition at line 358 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_previous_episode().

soar_module::sqlite_statement* epmem_graph_statement_container::promote_id

Definition at line 365 of file episodic_memory.h.

Referenced by _epmem_promote_id(), and epmem_graph_statement_container().

soar_module::sqlite_statement* epmem_graph_statement_container::update_edge_unique_last
soar_module::sqlite_statement* epmem_graph_statement_container::valid_episode

Definition at line 356 of file episodic_memory.h.

Referenced by epmem_graph_statement_container(), and epmem_valid_episode().


The documentation for this class was generated from the following files: