1 #include <portability.h>
177 const char *msg =
"Database set to file";
182 value->assign( new_value );
187 template <
typename T>
190 template <
typename T>
346 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"symbols_float (id INTEGER PRIMARY KEY, sym_const REAL)" );
347 add_structure(
"CREATE UNIQUE INDEX " SMEM_SCHEMA
"symbols_float_const ON " SMEM_SCHEMA
"symbols_float (sym_const)" );
348 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"symbols_str (id INTEGER PRIMARY KEY, sym_const TEXT)" );
349 add_structure(
"CREATE UNIQUE INDEX " SMEM_SCHEMA
"symbols_str_const ON " SMEM_SCHEMA
"symbols_str (sym_const)" );
351 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"lti (id INTEGER PRIMARY KEY, letter INTEGER, num INTEGER, child_ct INTEGER, act_value REAL, access_n INTEGER, access_t INTEGER, access_1 INTEGER)" );
352 add_structure(
"CREATE UNIQUE INDEX " SMEM_SCHEMA
"lti_letter_num ON " SMEM_SCHEMA
"lti (letter, num)" );
353 add_structure(
"CREATE INDEX " SMEM_SCHEMA
"lti_t ON " SMEM_SCHEMA
"lti (access_t)" );
355 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"history (id INTEGER PRIMARY KEY, t1 INTEGER, t2 INTEGER, t3 INTEGER, t4 INTEGER, t5 INTEGER, t6 INTEGER, t7 INTEGER, t8 INTEGER, t9 INTEGER, t10 INTEGER)" );
357 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"web (parent_id INTEGER, attr INTEGER, val_const INTEGER, val_lti INTEGER, act_value REAL)" );
358 add_structure(
"CREATE INDEX " SMEM_SCHEMA
"web_parent_attr_val_lti ON " SMEM_SCHEMA
"web (parent_id, attr, val_const, val_lti)" );
359 add_structure(
"CREATE INDEX " SMEM_SCHEMA
"web_attr_val_lti_cycle ON " SMEM_SCHEMA
"web (attr, val_const, val_lti, act_value)" );
360 add_structure(
"CREATE INDEX " SMEM_SCHEMA
"web_attr_cycle ON " SMEM_SCHEMA
"web (attr, act_value)" );
362 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"ct_attr (attr INTEGER PRIMARY KEY, ct INTEGER)" );
364 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"ct_const (attr INTEGER, val_const INTEGER, ct INTEGER)" );
365 add_structure(
"CREATE UNIQUE INDEX " SMEM_SCHEMA
"ct_const_attr_val ON " SMEM_SCHEMA
"ct_const (attr, val_const)" );
367 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"ct_lti (attr INTEGER, val_lti INTEGER, ct INTEGER)" );
368 add_structure(
"CREATE UNIQUE INDEX " SMEM_SCHEMA
"ct_lti_attr_val ON " SMEM_SCHEMA
"ct_lti (attr, val_lti)" );
371 add_structure(
"CREATE TABLE " SMEM_SCHEMA
"ascii (ascii_num INTEGER PRIMARY KEY, ascii_chr TEXT)" );
374 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (65,'A')" );
375 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (66,'B')" );
376 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (67,'C')" );
377 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (68,'D')" );
378 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (69,'E')" );
379 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (70,'F')" );
380 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (71,'G')" );
381 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (72,'H')" );
382 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (73,'I')" );
383 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (74,'J')" );
384 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (75,'K')" );
385 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (76,'L')" );
386 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (77,'M')" );
387 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (78,'N')" );
388 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (79,'O')" );
389 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (80,'P')" );
390 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (81,'Q')" );
391 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (82,'R')" );
392 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (83,'S')" );
393 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (84,'T')" );
394 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (85,'U')" );
395 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (86,'V')" );
396 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (87,'W')" );
397 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (88,'X')" );
398 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (89,'Y')" );
399 add_structure(
"INSERT INTO " SMEM_SCHEMA
"ascii (ascii_num, ascii_chr) VALUES (90,'Z')" );
458 lti_add =
new soar_module::sqlite_statement( new_db,
"INSERT INTO " SMEM_SCHEMA
"lti (letter,num,child_ct,act_value,access_n,access_t,access_1) VALUES (?,?,?,?,?,?,?)" );
487 web_expand =
new soar_module::sqlite_statement( new_db,
"SELECT tsh_a.sym_type AS attr_type, tsh_a.id AS attr_hash, vcl.sym_type AS value_type, vcl.id AS value_hash, vcl.letter AS value_letter, vcl.num AS value_num, vcl.val_lti AS value_lti FROM ((" SMEM_SCHEMA
"web w LEFT JOIN " SMEM_SCHEMA
"symbols_type tsh_v ON w.val_const=tsh_v.id) vc LEFT JOIN " SMEM_SCHEMA
"lti AS lti ON vc.val_lti=lti.id) vcl INNER JOIN " SMEM_SCHEMA
"symbols_type tsh_a ON vcl.attr=tsh_a.id WHERE parent_id=?" );
503 web_lti_all =
new soar_module::sqlite_statement( new_db,
"SELECT parent_id, act_value FROM " SMEM_SCHEMA
"web w WHERE attr=? AND val_const=" SMEM_WEB_NULL_STR
" AND val_lti=? ORDER BY act_value DESC" );
578 history_get =
new soar_module::sqlite_statement( new_db,
"SELECT t1,t2,t3,t4,t5,t6,t7,t8,t9,t10 FROM " SMEM_SCHEMA
"history WHERE id=?" );
581 history_push =
new soar_module::sqlite_statement( new_db,
"UPDATE " SMEM_SCHEMA
"history SET t10=t9,t9=t8,t8=t7,t8=t7,t7=t6,t6=t5,t5=t4,t4=t3,t3=t2,t2=t1,t1=? WHERE id=?" );
584 history_add =
new soar_module::sqlite_statement( new_db,
"INSERT INTO " SMEM_SCHEMA
"history (id,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) VALUES (?,?,0,0,0,0,0,0,0,0,0)" );
595 vis_value_const =
new soar_module::sqlite_statement( new_db,
"SELECT parent_id, tsh1.sym_type AS attr_type, tsh1.id AS attr_hash, tsh2.sym_type AS val_type, tsh2.id AS val_hash FROM " SMEM_SCHEMA
"web w, " SMEM_SCHEMA
"symbols_type tsh1, " SMEM_SCHEMA
"symbols_type tsh2 WHERE (w.attr=tsh1.id) AND (w.val_const=tsh2.id)" );
598 vis_value_lti =
new soar_module::sqlite_statement( new_db,
"SELECT parent_id, tsh.sym_type AS attr_type, tsh.id AS attr_hash, val_lti FROM " SMEM_SCHEMA
"web w, " SMEM_SCHEMA
"symbols_type tsh WHERE (w.attr=tsh.id) AND (val_lti<>" SMEM_WEB_NULL_STR
")" );
635 return_val->push_back( w );
642 return_val->push_back( w );
652 return_val->push_back( w );
672 if ( my_list.empty() )
687 pref->on_goal_list =
true;
714 if ( my_justification_list !=
NIL )
720 my_justification!=
NIL;
721 my_justification=next_justification )
723 next_justification = my_justification->
next;
725 if ( my_justification->in_ms )
730 for ( just_pref=my_justification->preferences_generated; just_pref!=
NIL; just_pref=just_pref->
inst_next )
782 var_get->
bind_int( 1, variable_id );
800 var_set->
bind_int( 1, variable_value );
801 var_set->
bind_int( 2, variable_id );
811 var_create->
bind_int( 1, variable_id );
812 var_create->
bind_int( 2, variable_value );
854 if ( !return_val && add_on_fail )
881 if ( !return_val && add_on_fail )
908 if ( !return_val && add_on_fail )
933 if ( ( !sym->common.smem_hash ) || ( sym->common.smem_valid != my_agent->
smem_validation ) )
935 sym->common.smem_hash =
NIL;
938 switch ( sym->common.symbol_type )
954 sym->common.smem_hash = return_val;
958 return_val = sym->common.smem_hash;
970 int64_t return_val =
NIL;
984 double return_val =
NIL;
1008 Symbol *return_val = NULL;
1046 uint64_t t_n = ( time_now - access_1 );
1066 for (
int i=0; i<available_history; i++ )
1069 static_cast<double>( -d ) );
1077 double apx_numerator = (
static_cast<double>( n -
SMEM_ACT_HISTORY_ENTRIES ) * ( pow( static_cast<double>( t_n ), 1.0-d ) - pow( static_cast<double>( t_k ), 1.0-d ) ) );
1078 double apx_denominator = ( ( 1.0-d ) * static_cast<double>( t_n - t_k ) );
1080 sum += ( apx_numerator / apx_denominator );
1111 time_diff = ( time_now - *b );
1113 if ( time_diff > 0 )
1115 std::list< smem_lti_id > to_update;
1124 for ( std::list< smem_lti_id >::iterator it=to_update.begin(); it!=to_update.end(); it++ )
1141 uint64_t prev_access_n = 0;
1142 uint64_t prev_access_t = 0;
1143 uint64_t prev_access_1 = 0;
1169 double new_activation = 0.0;
1173 new_activation =
static_cast<double>( time_now );
1177 new_activation =
static_cast<double>( prev_access_n + ( ( add_access )?(1):(0) ) );
1181 if ( prev_access_n == 0 )
1201 new_activation =
smem_lti_calc_base( my_agent, lti, time_now+( ( add_access )?(1):(0) ), prev_access_n+( ( add_access )?(1):(0) ), prev_access_1 );
1237 return new_activation;
1257 valid_ltis->insert( referent );
1284 valid_ltis->insert( sym );
1300 bool return_val =
true;
1302 std::set<Symbol *> valid_ltis;
1303 std::set<Symbol *>::iterator lti_p;
1320 int action_counter = 0;
1322 for ( a=rhs_top; a!=
NIL; a=a->
next )
1329 bool good_pass =
true;
1330 bool good_action =
true;
1331 while ( good_pass && action_counter )
1335 for ( a=rhs_top; a!=
NIL; a=a->
next )
1339 good_action =
false;
1356 else if ( valid_ltis.find(
id ) != valid_ltis.end() )
1389 return_val = ( action_counter == 0 );
1402 uint64_t* counter =
reinterpret_cast<uint64_t*
>( userdata );
1474 return id->id.smem_lti;
1486 if ( return_val ==
NIL )
1518 name_letter -=
static_cast<uint64_t
>(
'A' );
1521 uint64_t *letter_ct =& my_agent->
id_counter[ name_letter ];
1524 if ( (*letter_ct) <= letter_max )
1526 (*letter_ct) = ( letter_max + 1 );
1557 uint64_t pair_count = 0;
1560 std::set<smem_lti_id> distinct_attr;
1569 distinct_attr.insert( child_attr );
1592 for (std::set<smem_lti_id>::iterator a=distinct_attr.begin(); a!=distinct_attr.end(); a++)
1615 uint64_t existing_edges = 0;
1616 if ( remove_old_children )
1627 print( my_agent, buf );
1643 std::set<smem_hash_id> attr_new;
1644 std::set< std::pair<smem_hash_id, smem_hash_id> > const_new;
1645 std::set< std::pair<smem_hash_id, smem_lti_id> > lti_new;
1647 smem_slot_map::iterator s;
1648 smem_slot::iterator v;
1654 for ( s=children->begin(); s!=children->end(); s++ )
1657 if ( remove_old_children )
1659 attr_new.insert( attr_hash );
1668 attr_new.insert( attr_hash );
1672 for ( v=s->second->begin(); v!=s->second->end(); v++ )
1678 if ( remove_old_children )
1680 const_new.insert( std::make_pair< smem_hash_id, smem_hash_id >( attr_hash, value_hash ) );
1690 const_new.insert( std::make_pair< smem_hash_id, smem_hash_id >( attr_hash, value_hash ) );
1699 snprintf_with_symbols( my_agent, buf, 256,
"=>SMEM: (%y ^%y %y)\n", print_id, s->first, (*v)->val_const.val_value );
1701 print( my_agent, buf );
1707 value_lti = (*v)->val_lti.val_value->lti_id;
1708 if ( value_lti ==
NIL )
1710 value_lti =
smem_lti_add_id( my_agent, (*v)->val_lti.val_value->lti_letter, (*v)->val_lti.val_value->lti_number );
1711 (*v)->val_lti.val_value->lti_id = value_lti;
1713 if ( (*v)->val_lti.val_value->soar_id !=
NIL )
1715 (*v)->val_lti.val_value->soar_id->id.smem_lti = value_lti;
1718 (*v)->val_lti.val_value->soar_id->id.smem_valid = my_agent->
epmem_validation;
1723 if ( remove_old_children )
1725 lti_new.insert( std::make_pair< smem_hash_id, smem_lti_id >( attr_hash, value_lti ) );
1735 lti_new.insert( std::make_pair< smem_hash_id, smem_lti_id >( attr_hash, value_lti ) );
1744 snprintf_with_symbols( my_agent, buf, 256,
"=>SMEM: (%y ^%y %y)\n", print_id, s->first, (*v)->val_lti.val_value->soar_id );
1746 print( my_agent, buf );
1762 uint64_t new_edges = ( existing_edges + const_new.size() + lti_new.size() );
1767 after_above = ( new_edges >= thresh );
1770 if ( existing_edges < thresh )
1803 for ( std::set< std::pair< smem_hash_id, smem_hash_id > >::iterator p=const_new.begin(); p!=const_new.end(); p++ )
1841 for ( std::set< std::pair< smem_hash_id, smem_lti_id > >::iterator p=lti_new.begin(); p!=lti_new.end(); p++ )
1879 for ( std::set< smem_hash_id >::iterator a=attr_new.begin(); a!=attr_new.end(); a++ )
1916 smem_wme_list::iterator w;
1925 smem_sym_to_chunk_map::iterator c_p;
1929 smem_slot_map::iterator s_p;
1930 smem_slot::iterator v_p;
1934 for ( w=children->begin(); w!=children->end(); w++ )
1951 c =& sym_to_chunk[ (*w)->value ];
1957 (*c)->
lti_id = (*w)->value->id.smem_lti;
1958 (*c)->lti_letter = (*w)->value->id.name_letter;
1959 (*c)->lti_number = (*w)->value->id.name_number;
1961 (*c)->soar_id = (*w)->value;
1966 shorties.push_back( (*c)->soar_id );
1982 for ( s_p=slots.begin(); s_p!=slots.end(); s_p++ )
1984 for ( v_p=s_p->second->begin(); v_p!=s_p->second->end(); v_p++ )
1993 for ( c_p=sym_to_chunk.begin(); c_p!=sym_to_chunk.end(); c_p++ )
2003 for ( smem_sym_list::iterator shorty=shorties.begin(); shorty!=shorties.end(); shorty++ )
2026 bool lti_created_here =
false;
2038 lti_created_here =
true;
2049 if ( lti_created_here )
2070 expand_q->
bind_int( 1, parent_id );
2141 bool good_wme =
true;
2154 if ( attr_hash !=
NIL )
2161 if ( value_hash !=
NIL )
2182 if ( value_lti ==
NIL )
2214 weighted_pq.push( new_cue_element );
2215 new_cue_element = NULL;
2243 bool good_cue =
true;
2265 for ( smem_wme_list::iterator cue_p=cue->begin(); cue_p!=cue->end(); cue_p++ )
2267 cue_wmes.insert( (*cue_p) );
2283 for ( smem_wme_list::iterator cue_p=cue->begin(); cue_p!=cue->end(); cue_p++ )
2285 cue_wmes.insert( (*cue_p) );
2299 while ( !weighted_pq.empty() )
2301 weighted_cue.push_back( weighted_pq.top() );
2308 while ( !weighted_pq.empty() )
2310 delete weighted_pq.top();
2317 if ( good_cue && !weighted_cue.empty() )
2320 smem_weighted_cue_list::iterator cand_set;
2321 smem_weighted_cue_list::iterator next_element;
2322 for ( next_element=weighted_cue.begin(); next_element!=weighted_cue.end(); next_element++ )
2324 if ( (*next_element)->pos_element )
2326 cand_set = next_element;
2332 smem_lti_set::iterator prohibit_p;
2350 std::set< smem_lti_id > to_update;
2356 for ( std::set< smem_lti_id >::iterator it=to_update.begin(); it!=to_update.end(); it++ )
2372 bool more_rows =
true;
2373 bool use_db =
false;
2374 bool has_feature =
false;
2386 while ( ( king_id ==
NIL ) && ( ( more_rows ) || ( !plentiful_parents.empty() ) ) )
2396 else if ( plentiful_parents.empty() )
2402 use_db = ( q->
column_double( 1 ) > plentiful_parents.top().first );
2412 cand = plentiful_parents.top().second;
2413 plentiful_parents.pop();
2418 prohibit_p = prohibit->find( cand );
2419 if ( prohibit_p == prohibit->end() )
2423 for ( next_element=weighted_cue.begin(); next_element!=weighted_cue.end(); next_element++ )
2426 if ( (*next_element) == (*cand_set) )
2431 if ( (*next_element)->element_type ==
attr_t )
2440 q2->
bind_int( 3, (*next_element)->value_hash );
2442 else if ( (*next_element)->element_type ==
value_lti_t )
2446 q2->
bind_int( 3, (*next_element)->value_lti );
2451 q2->
bind_int( 2, (*next_element)->attr_hash );
2454 good_cand = ( ( (*next_element)->pos_element )?( has_feature ):( !has_feature ) );
2471 for ( next_element=weighted_cue.begin(); next_element!=weighted_cue.end(); next_element++ )
2473 delete (*next_element);
2481 if ( king_id !=
NIL )
2545 if ( state == NULL )
2579 const char *db_path;
2582 db_path =
":memory:";
2597 print( my_agent, buf );
2648 std::string cache_sql(
"PRAGMA cache_size = " );
2650 cache_sql.append( str );
2839 smem_slot_map::iterator s;
2840 smem_slot::iterator v;
2843 while ( !chunk->
slots->empty() )
2845 s = chunk->
slots->begin();
2851 for ( v=s->second->begin(); v!=s->second->end(); v=s->second->erase(v) )
2874 chunk->
slots->erase( s );
2878 delete chunk->
slots;
2879 chunk->
slots = NULL;
2893 std::string *return_val =
new std::string;
2898 to_string( (*lexeme).id_number, num );
2900 return_val->append( 1, (*lexeme).id_letter );
2901 return_val->append( num );
2903 (*id_letter) = (*lexeme).id_letter;
2904 (*id_number) = (*lexeme).id_number;
2908 return_val->assign( (*lexeme).string );
2910 (*id_letter) =
static_cast<char>( toupper( (*lexeme).string[1] ) );
2923 return_val =
make_sym_constant( my_agent, static_cast<const char *>( (*lexeme).string ) );
2939 bool return_val =
false;
2942 new_chunk->
slots = NULL;
2944 std::string *chunk_name = NULL;
2947 uint64_t temp_number;
2982 uint64_t intermediate_counter = 1;
2985 std::string temp_key;
2986 std::string *temp_key2;
2994 intermediate_parent = new_chunk;
3003 if ( chunk_attr !=
NIL )
3017 temp_chunk->
lti_number = ( intermediate_counter++ );
3027 s->push_back( chunk_value );
3030 std::string temp_key3;
3031 to_string( temp_chunk->
lti_number, temp_key3 );
3032 temp_key.assign(
"<" );
3033 temp_key.append( 1, temp_chunk->
lti_letter );
3034 temp_key.append(
"#" );
3035 temp_key.append( temp_key3 );
3036 temp_key.append(
">" );
3039 (*chunks)[ temp_key ] = temp_chunk;
3042 newbies->insert( temp_chunk );
3045 intermediate_parent = temp_chunk;
3056 if ( chunk_attr !=
NIL )
3058 bool first_value =
true;
3103 smem_str_to_chunk_map::iterator p = chunks->find( (*temp_key2) );
3106 if ( p != chunks->end() )
3125 (*chunks)[ (*temp_key2) ] = temp_chunk;
3128 newbies->insert( temp_chunk );
3135 if ( chunk_value !=
NIL )
3142 if ( first_value && !s->empty() )
3147 s->push_back( chunk_value );
3157 first_value =
false;
3159 }
while ( chunk_value !=
NIL );
3177 smem_chunk **p =& (*chunks)[ (*chunk_name ) ];
3184 newbies->insert( new_chunk );
3193 new_chunk->
slots = NULL;
3199 smem_slot_map::iterator ss_p;
3200 smem_slot::iterator s_p;
3206 for ( ss_p=new_chunk->
slots->begin(); ss_p!=new_chunk->
slots->end(); ss_p++ )
3209 source_slot = ss_p->second;
3212 for ( s_p=source_slot->begin(); s_p!=source_slot->end(); s_p++ )
3215 target_slot->push_back( (*s_p) );
3223 delete new_chunk->
slots;
3224 new_chunk->
slots = NULL;
3228 newbies->insert( (*p) );
3250 bool return_val =
false;
3251 uint64_t clause_count = 0;
3263 bool good_chunk =
true;
3266 smem_str_to_chunk_map::iterator c_old;
3269 smem_chunk_set::iterator c_new;
3282 for ( c_new=newbies.begin(); c_new!=newbies.end(); c_new++ )
3284 if ( (*c_new)->lti_id ==
NIL )
3287 if ( (*c_new)->lti_number ==
NIL )
3290 (*c_new)->lti_number = ( my_agent->
id_counter[ (*c_new)->lti_letter -
static_cast<char>(
'A') ]++ );
3291 (*c_new)->lti_id =
smem_lti_add_id( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
3296 if ( (*c_new)->lti_id ==
NIL )
3299 (*c_new)->lti_id =
smem_lti_get_id( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
3302 if ( (*c_new)->lti_id ==
NIL )
3304 (*c_new)->lti_id =
smem_lti_add_id( my_agent, (*c_new)->lti_letter, (*c_new)->lti_number );
3308 if ( id_parent !=
NIL )
3324 for ( c_new=newbies.begin(); c_new!=newbies.end(); c_new++ )
3326 if ( (*c_new)->slots !=
NIL )
3333 for ( c_new=newbies.begin(); c_new!=newbies.end(); c_new++ )
3346 return_val = good_chunk;
3350 for ( c_old=chunks.begin(); c_old!=chunks.end(); c_old++ )
3360 to_string( clause_count, num );
3362 (*err_msg) =
new std::string(
"Error parsing clause #" );
3363 (*err_msg)->append( num );
3384 smem_wme_list::iterator w_p;
3396 enum path_type { blank_slate, cmd_bad, cmd_retrieve, cmd_query, cmd_store } path;
3398 unsigned int time_slot = ( ( store_only )?(1):(0) );
3405 std::queue<Symbol *> syms;
3408 std::queue<int> levels;
3410 bool do_wm_phase =
false;
3415 while ( state != NULL )
3433 while ( !syms.empty() )
3436 parent_sym = syms.front();
3439 parent_level = levels.front();
3445 for ( w_p=wmes->begin(); w_p!=wmes->end(); w_p++ )
3447 if ( ( ( store_only ) && ( ( parent_level != 0 ) || ( (*w_p)->attr == my_agent->
smem_sym_store ) ) ) ||
3448 ( ( !store_only ) && ( ( parent_level != 0 ) || ( (*w_p)->attr != my_agent->
smem_sym_store ) ) ) )
3459 ( parent_level == 0 ) &&
3462 syms.push( (*w_p)->value );
3463 levels.push( parent_level + 1 );
3499 if ( new_cue && wme_count )
3503 retrieval_wmes.clear();
3514 for ( w_p=cmds->begin(); w_p!=cmds->end(); w_p++ )
3516 cue_wmes.insert( (*w_p) );
3518 if ( path != cmd_bad )
3524 ( path == blank_slate ) )
3526 retrieve = (*w_p)->value;
3527 path = cmd_retrieve;
3537 ( ( path == blank_slate ) || ( path == cmd_query ) ) &&
3541 query = (*w_p)->value;
3552 ( ( path == blank_slate ) || ( path == cmd_query ) ) &&
3553 ( negquery ==
NIL ) )
3556 negquery = (*w_p)->value;
3567 ( ( path == blank_slate ) || ( path == cmd_query ) ) &&
3568 ( (*w_p)->value->id.smem_lti !=
NIL ) )
3570 prohibit.push_back( (*w_p)->value );
3581 ( ( path == blank_slate ) || ( path == cmd_store ) ) )
3583 store.push_back( (*w_p)->value );
3599 if ( ( path == cmd_query ) && ( query == NULL ) )
3605 if ( path == blank_slate )
3615 if ( path != cmd_bad )
3621 if ( path == cmd_retrieve )
3641 else if ( path == cmd_query )
3644 smem_sym_list::iterator sym_p;
3646 for ( sym_p=prohibit.begin(); sym_p!=prohibit.end(); sym_p++ )
3648 prohibit_lti.insert( (*sym_p)->id.smem_lti );
3651 smem_process_query( my_agent, state, query, negquery, &( prohibit_lti ), cue_wmes, meta_wmes, retrieval_wmes );
3656 else if ( path == cmd_store )
3658 smem_sym_list::iterator sym_p;
3670 for ( sym_p=store.begin(); sym_p!=store.end(); sym_p++ )
3697 if ( !meta_wmes.empty() || !retrieval_wmes.empty() )
3704 soar_module::symbol_triple_list::iterator mw_it;
3706 for ( mw_it=retrieval_wmes.begin(); mw_it!=retrieval_wmes.end(); mw_it++ )
3714 retrieval_wmes.clear();
3716 for ( mw_it=meta_wmes.begin(); mw_it!=meta_wmes.end(); mw_it++ )
3747 if ( store_only && mirroring_on && ( !my_agent->
smem_changed_ids->empty() ) )
3762 if ( (*it)->id.slots )
3801 #ifndef SMEM_EXPERIMENT
3805 #else // SMEM_EXPERIMENT
3807 #endif // SMEM_EXPERIMENT
3814 bool return_val =
false;
3834 err->assign(
"Semantic database is not currently connected." );
3853 return_val->append(
"digraph smem {" );
3854 return_val->append(
"\n" );
3857 return_val->append(
"node [ shape = doublecircle ];" );
3858 return_val->append(
"\n" );
3860 std::map< smem_lti_id, std::string > lti_names;
3861 std::map< smem_lti_id, std::string >::iterator n_p;
3867 uint64_t lti_number;
3869 std::string *lti_name;
3870 std::string temp_str;
3879 lti_letter =
static_cast<char>( q->
column_int( 1 ) );
3880 lti_number =
static_cast<uint64_t
>( q->
column_int( 2 ) );
3882 lti_name =& lti_names[ lti_id ];
3883 lti_name->push_back( lti_letter );
3885 to_string( lti_number, temp_str );
3886 lti_name->append( temp_str );
3888 return_val->append( (*lti_name) );
3889 return_val->append(
" [ label=\"" );
3890 return_val->append( (*lti_name) );
3891 return_val->append(
"\\n[" );
3894 to_string( temp_double, temp_str, 3,
true );
3895 if ( temp_double >= 0 )
3897 return_val->append(
"+" );
3899 return_val->append( temp_str );
3901 return_val->append(
"]\"" );
3902 return_val->append(
" ];" );
3903 return_val->append(
"\n" );
3907 if ( !lti_names.empty() )
3911 std::map< smem_lti_id, std::list<std::string> > lti_terminals;
3912 std::map< smem_lti_id, std::list<std::string> >::iterator t_p;
3913 std::list<std::string>::iterator a_p;
3915 std::list<std::string> *my_terminals;
3916 std::list<std::string>::size_type terminal_num;
3918 return_val->append(
"\n" );
3921 return_val->append(
"node [ shape = plaintext ];" );
3922 return_val->append(
"\n" );
3929 my_terminals =& lti_terminals[ lti_id ];
3930 lti_name =& lti_names[ lti_id ];
3933 return_val->append( (*lti_name) );
3934 return_val->append(
"_" );
3937 terminal_num = my_terminals->size();
3938 to_string( terminal_num, temp_str );
3939 return_val->append( temp_str );
3942 return_val->append(
" [ label = \"" );
3954 to_string( temp_int, temp_str );
3959 to_string( temp_double, temp_str );
3967 return_val->append( temp_str );
3980 to_string( temp_int, temp_str );
3985 to_string( temp_double, temp_str );
3993 my_terminals->push_back( temp_str );
3997 return_val->append(
"\" ];" );
3998 return_val->append(
"\n" );
4004 unsigned int terminal_counter;
4006 for ( n_p=lti_names.begin(); n_p!=lti_names.end(); n_p++ )
4008 t_p = lti_terminals.find( n_p->first );
4010 if ( t_p != lti_terminals.end() )
4012 terminal_counter = 0;
4014 for ( a_p=t_p->second.begin(); a_p!=t_p->second.end(); a_p++ )
4016 return_val->append( n_p->second );
4017 return_val ->append(
" -> " );
4018 return_val->append( n_p->second );
4019 return_val->append(
"_" );
4021 to_string( terminal_counter, temp_str );
4022 return_val->append( temp_str );
4023 return_val->append(
" [ label=\"" );
4025 return_val->append( (*a_p) );
4027 return_val->append(
"\" ];" );
4028 return_val->append(
"\n" );
4045 lti_name =& lti_names[ lti_id ];
4046 return_val->append( (*lti_name) );
4047 return_val->append(
" -> " );
4051 lti_name =& lti_names[ lti_id ];
4052 return_val->append( (*lti_name) );
4053 return_val->append(
" [ label =\"" );
4065 to_string( temp_int, temp_str );
4070 to_string( temp_double, temp_str );
4078 return_val->append( temp_str );
4082 return_val->append(
"\" ];" );
4083 return_val->append(
"\n" );
4091 return_val->append(
"}" );
4092 return_val->append(
"\n" );
4098 std::string return_val2;
4102 uint64_t child_counter;
4104 std::string temp_str;
4105 std::string temp_str2;
4109 std::queue<smem_vis_lti *> bfs;
4113 std::map< smem_lti_id, smem_vis_lti* > close_list;
4114 std::map< smem_lti_id, smem_vis_lti* >::iterator cl_p;
4117 return_val->append(
"digraph smem_lti {" );
4118 return_val->append(
"\n" );
4123 new_lti->
lti_id = lti_id;
4139 to_string( temp_int, temp_str );
4140 new_lti->
lti_name.append( temp_str );
4146 bfs.push( new_lti );
4147 close_list.insert( std::make_pair< smem_lti_id, smem_vis_lti* >( lti_id, new_lti ) );
4153 while ( !bfs.empty() )
4155 parent_lti = bfs.front();
4178 to_string( temp_int, temp_str );
4179 new_lti->
lti_name.append( temp_str );
4194 to_string( temp_int, temp_str );
4199 to_string( temp_double, temp_str );
4208 return_val2.append( parent_lti->
lti_name );
4209 return_val2.append(
" -> " );
4210 return_val2.append( new_lti->
lti_name );
4211 return_val2.append(
" [ label = \"" );
4212 return_val2.append( temp_str );
4213 return_val2.append(
"\" ];" );
4214 return_val2.append(
"\n" );
4219 cl_p = close_list.find( new_lti->
lti_id );
4220 if ( cl_p == close_list.end() )
4222 close_list.insert( std::make_pair< smem_lti_id, smem_vis_lti* >( new_lti->
lti_id, new_lti ) );
4224 if ( ( depth == 0 ) || ( new_lti->
level < depth ) )
4226 bfs.push( new_lti );
4243 temp_str2.assign( parent_lti->
lti_name );
4244 temp_str2.append(
"_" );
4246 to_string( child_counter, temp_str );
4247 temp_str2.append( temp_str );
4259 to_string( temp_int, temp_str );
4264 to_string( temp_double, temp_str );
4273 return_val2.append(
"node [ shape = plaintext ];" );
4274 return_val2.append(
"\n" );
4275 return_val2.append( temp_str2 );
4276 return_val2.append(
" [ label=\"" );
4277 return_val2.append( temp_str );
4278 return_val2.append(
"\" ];" );
4279 return_val2.append(
"\n" );
4293 to_string( temp_int, temp_str );
4298 to_string( temp_double, temp_str );
4307 return_val2.append( parent_lti->
lti_name );
4308 return_val2.append(
" -> " );
4309 return_val2.append( temp_str2 );
4310 return_val2.append(
" [ label = \"" );
4311 return_val2.append( temp_str );
4312 return_val2.append(
"\" ];" );
4313 return_val2.append(
"\n" );
4323 return_val2.append(
"}" );
4324 return_val2.append(
"\n" );
4330 return_val->append(
"node [ shape = doublecircle ];" );
4331 return_val->append(
"\n" );
4333 for ( cl_p=close_list.begin(); cl_p!=close_list.end(); cl_p++ )
4335 return_val->append( cl_p->second->lti_name );
4336 return_val->append(
" [ label=\"" );
4337 return_val->append( cl_p->second->lti_name );
4338 return_val->append(
"\\n[" );
4344 to_string( temp_double, temp_str, 3,
true );
4345 if ( temp_double >= 0 )
4347 return_val->append(
"+" );
4349 return_val->append( temp_str );
4353 return_val->append(
"]\"" );
4354 return_val->append(
" ];" );
4355 return_val->append(
"\n" );
4357 delete cl_p->second;
4362 return_val->append( return_val2 );
4367 std::set< smem_lti_id > next;
4369 std::string temp_str, temp_str2, temp_str3;
4373 std::map< std::string, std::list< std::string > > augmentations;
4374 std::map< std::string, std::list< std::string > >::iterator lti_slot;
4375 std::list< std::string >::iterator slot_val;
4382 return_val->append(
"(@" );
4383 return_val->push_back( lti_letter );
4384 to_string( lti_number, temp_str );
4385 return_val->append( temp_str );
4400 to_string( temp_int, temp_str );
4405 to_string( temp_double, temp_str );
4417 temp_str2.push_back(
'@' );
4420 temp_str2.push_back( static_cast<char>( expand_q->
column_int( 4 ) ) );
4424 to_string( temp_int, temp_str3 );
4425 temp_str2.append( temp_str3 );
4428 next.insert( static_cast< smem_lti_id >( expand_q->
column_int( 6 ) ) );
4440 to_string( temp_int, temp_str2 );
4445 to_string( temp_double, temp_str2 );
4454 augmentations[ temp_str ].push_back( temp_str2 );
4460 for ( lti_slot=augmentations.begin(); lti_slot!=augmentations.end(); lti_slot++ )
4462 return_val->append(
" ^" );
4463 return_val->append( lti_slot->first );
4465 for ( slot_val=lti_slot->second.begin(); slot_val!=lti_slot->second.end(); slot_val++ )
4467 return_val->append(
" " );
4468 return_val->append( (*slot_val) );
4472 augmentations.clear();
4474 return_val->append(
" [" );
4475 to_string( lti_act, temp_str, 3,
true );
4478 return_val->append(
"+" );
4480 return_val->append( temp_str );
4481 return_val->append(
"]" );
4482 return_val->append(
")\n" );
4503 std::set< smem_lti_id > visited;
4504 std::pair< std::set< smem_lti_id >::iterator,
bool > visited_ins_result;
4506 std::queue< std::pair< smem_lti_id, unsigned int > > to_visit;
4507 std::pair< smem_lti_id, unsigned int > c;
4509 std::set< smem_lti_id > next;
4510 std::set< smem_lti_id >::iterator next_it;
4520 to_visit.push( std::make_pair< smem_lti_id, unsigned int >( lti_id, 1 ) );
4521 visited.insert( lti_id );
4523 while ( !to_visit.empty() )
4525 c = to_visit.front();
4529 for ( i=1; i<c.second; i++ )
4531 return_val->append(
" " );
4549 if ( c.second < depth )
4551 for ( next_it=next.begin(); next_it!=next.end(); next_it++ )
4553 visited_ins_result = visited.insert( (*next_it) );
4554 if ( visited_ins_result.second )
4556 to_visit.push( std::make_pair< smem_lti_id, unsigned int >( (*next_it), c.second+1 ) );