Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Functions
utilities.cpp File Reference
#include <portability.h>
#include "agent.h"
#include "misc.h"
#include "utilities.h"
#include "gdatastructs.h"
#include "wmem.h"
#include "print.h"
#include "xml.h"
#include <time.h>

Go to the source code of this file.

Functions

void get_context_var_info (agent *agnt, Symbol **dest_goal, Symbol **dest_attr_of_slot, Symbol **dest_current_value)
uint64_t get_derived_kernel_time_usec (agent *thisAgent)
void get_lexeme_from_string (agent *agnt, const char *the_lexeme)
double get_number_from_symbol (Symbol *sym)
bool is_whole_number (const std::string &str)
bool is_whole_number (const char *str)
bool read_id_or_context_var_from_string (agent *agnt, const char *the_lexeme, Symbol **result_id)
Symbolread_identifier_or_context_variable (agent *agnt)
void stats_close (agent *my_agent)
void stats_db_store (agent *my_agent, const uint64_t &dc_time, const uint64_t &dc_wm_changes, const uint64_t &dc_firing_counts)
void stats_init_db (agent *my_agent)

Function Documentation

void get_context_var_info ( agent agnt,
Symbol **  dest_goal,
Symbol **  dest_attr_of_slot,
Symbol **  dest_current_value 
)

Definition at line 105 of file utilities.cpp.

References agent_struct::bottom_goal, find_variable(), identifier_struct::higher_goal, symbol_union::id, identifier_struct::level, agent_struct::lexeme, NIL, agent_struct::o_context_variable, identifier_struct::operator_slot, agent_struct::operator_symbol, agent_struct::s_context_variable, agent_struct::so_context_variable, agent_struct::ss_context_variable, agent_struct::sso_context_variable, agent_struct::sss_context_variable, agent_struct::state_symbol, lexeme_info::string, agent_struct::to_context_variable, agent_struct::top_goal, agent_struct::ts_context_variable, wme_struct::value, and slot_struct::wmes.

Referenced by read_id_or_context_var_from_string(), and read_identifier_or_context_variable().

{
Symbol *v, *g;
int levels_up;
wme *w;
v = find_variable (agnt, agnt->lexeme.string);
if (v==agnt->s_context_variable) {
levels_up = 0;
*dest_attr_of_slot = agnt->state_symbol;
} else if (v==agnt->o_context_variable) {
levels_up = 0;
*dest_attr_of_slot = agnt->operator_symbol;
} else if (v==agnt->ss_context_variable) {
levels_up = 1;
*dest_attr_of_slot = agnt->state_symbol;
} else if (v==agnt->so_context_variable) {
levels_up = 1;
*dest_attr_of_slot = agnt->operator_symbol;
} else if (v==agnt->sss_context_variable) {
levels_up = 2;
*dest_attr_of_slot = agnt->state_symbol;
} else if (v==agnt->sso_context_variable) {
levels_up = 2;
*dest_attr_of_slot = agnt->operator_symbol;
} else if (v==agnt->ts_context_variable) {
levels_up = agnt->top_goal ? agnt->bottom_goal->id.level-agnt->top_goal->id.level : 0;
*dest_attr_of_slot = agnt->state_symbol;
} else if (v==agnt->to_context_variable) {
levels_up = agnt->top_goal ? agnt->bottom_goal->id.level-agnt->top_goal->id.level : 0;
*dest_attr_of_slot = agnt->operator_symbol;
} else {
*dest_goal = NIL;
*dest_attr_of_slot = NIL;
*dest_current_value = NIL;
return;
}
g = agnt->bottom_goal;
while (g && levels_up) {
g = g->id.higher_goal;
levels_up--;
}
*dest_goal = g;
if (!g) {
*dest_current_value = NIL;
return;
}
if (*dest_attr_of_slot==agnt->state_symbol) {
*dest_current_value = g;
} else {
*dest_current_value = w ? w->value : NIL;
}
}
uint64_t get_derived_kernel_time_usec ( agent thisAgent)

Definition at line 448 of file utilities.cpp.

References APPLY_PHASE, DECISION_PHASE, INPUT_PHASE, OUTPUT_PHASE, PREFERENCE_PHASE, PROPOSE_PHASE, agent_struct::timers_decision_cycle_phase, and WM_PHASE.

Referenced by do_one_top_level_phase().

{
#ifndef NO_TIMING_STUFF
return thisAgent->timers_decision_cycle_phase[INPUT_PHASE].get_usec()
+ thisAgent->timers_decision_cycle_phase[PROPOSE_PHASE].get_usec()
+ thisAgent->timers_decision_cycle_phase[APPLY_PHASE].get_usec()
+ thisAgent->timers_decision_cycle_phase[WM_PHASE].get_usec()
+ thisAgent->timers_decision_cycle_phase[OUTPUT_PHASE].get_usec()
+ thisAgent->timers_decision_cycle_phase[DECISION_PHASE].get_usec();
#else
return 0;
#endif
}
void get_lexeme_from_string ( agent agnt,
const char *  the_lexeme 
)

Definition at line 63 of file utilities.cpp.

References determine_type_of_constituent_string(), FALSE, lexeme_info::length, agent_struct::lexeme, lexeme_info::string, SYM_CONSTANT_LEXEME, TRUE, and lexeme_info::type.

Referenced by read_id_or_context_var_from_string().

{
int i;
const char * c;
bool sym_constant_start_found = FALSE;
bool sym_constant_end_found = FALSE;
for (c = the_lexeme, i = 0; *c; c++, i++)
{
if (*c == '|')
{
if (!sym_constant_start_found)
{
i--;
sym_constant_start_found = TRUE;
}
else
{
i--;
sym_constant_end_found = TRUE;
}
}
else
{
agnt->lexeme.string[i] = *c;
}
}
agnt->lexeme.string[i] = '\0'; /* Null terminate lexeme string */
agnt->lexeme.length = i;
if (sym_constant_end_found)
{
}
else
{
}
}
double get_number_from_symbol ( Symbol sym)

Definition at line 331 of file utilities.cpp.

References symbol_union::fc, FLOAT_CONSTANT_SYMBOL_TYPE, symbol_union::ic, INT_CONSTANT_SYMBOL_TYPE, int_constant_struct::value, and float_constant_struct::value.

Referenced by exploration_compute_value_of_candidate(), make_production(), reteload_node_and_children(), and rl_tabulate_reward_value_for_goal().

{
if ( sym->common.symbol_type == FLOAT_CONSTANT_SYMBOL_TYPE )
return sym->fc.value;
else if ( sym->common.symbol_type == INT_CONSTANT_SYMBOL_TYPE )
return static_cast<double>(sym->ic.value);
return 0.0;
}
bool is_whole_number ( const std::string &  str)

Definition at line 308 of file utilities.cpp.

References is_whole_number().

Referenced by is_whole_number(), and rl_get_template_id().

{
return is_whole_number(str.c_str());
}
bool is_whole_number ( const char *  str)

Definition at line 313 of file utilities.cpp.

{
if(!str || !*str)
return false;
do {
if(isdigit(*str))
++str;
else
return false;
} while(*str);
return true;
}
bool read_id_or_context_var_from_string ( agent agnt,
const char *  the_lexeme,
Symbol **  result_id 
)

Definition at line 20 of file utilities.cpp.

References find_identifier(), get_context_var_info(), get_lexeme_from_string(), symbol_union::id, lexeme_info::id_letter, lexeme_info::id_number, IDENTIFIER_LEXEME, IDENTIFIER_SYMBOL_TYPE, agent_struct::lexeme, lexeme_info::type, and VARIABLE_LEXEME.

{
Symbol *id;
Symbol *g, *attr, *value;
get_lexeme_from_string(agnt, the_lexeme);
if (agnt->lexeme.type == IDENTIFIER_LEXEME)
{
id = find_identifier(agnt, agnt->lexeme.id_letter, agnt->lexeme.id_number);
if (!id)
{
return false;
}
else
{
*result_id = id;
return true;
}
}
{
get_context_var_info (agnt, &g, &attr, &value);
if ((!attr) || (!value))
{
return false;
}
if (value->common.symbol_type != IDENTIFIER_SYMBOL_TYPE)
{
return false;
}
*result_id = value;
return true;
}
return false;
}
Symbol* read_identifier_or_context_variable ( agent agnt)

Definition at line 165 of file utilities.cpp.

References find_identifier(), get_context_var_info(), symbol_union::id, lexeme_info::id_letter, lexeme_info::id_number, IDENTIFIER_LEXEME, IDENTIFIER_SYMBOL_TYPE, agent_struct::lexeme, NIL, print(), print_location_of_most_recent_lexeme(), print_with_symbols(), lexeme_info::string, lexeme_info::type, and VARIABLE_LEXEME.

{
Symbol *id;
Symbol *g, *attr, *value;
id = find_identifier (agnt, agnt->lexeme.id_letter, agnt->lexeme.id_number);
if (!id) {
print (agnt, "There is no identifier %c%lu.\n", agnt->lexeme.id_letter,
agnt->lexeme.id_number);
return NIL;
}
return id;
}
{
get_context_var_info (agnt, &g, &attr, &value);
if (!attr) {
print (agnt, "Expected identifier (or context variable)\n");
return NIL;
}
if (!value) {
print (agnt, "There is no current %s.\n", agnt->lexeme.string);
return NIL;
}
if (value->common.symbol_type!=IDENTIFIER_SYMBOL_TYPE) {
print (agnt, "The current %s ", agnt->lexeme.string);
print_with_symbols (agnt, "(%y) is not an identifier.\n", value);
return NIL;
}
return value;
}
print (agnt, "Expected identifier (or context variable)\n");
return NIL;
}
void stats_close ( agent my_agent)

Definition at line 435 of file utilities.cpp.

References soar_module::connected, soar_module::sqlite_database::disconnect(), soar_module::status_object< T >::get_status(), agent_struct::stats_db, and agent_struct::stats_stmts.

Referenced by destroy_soar_agent(), and reinitialize_soar().

{
{
// de-allocate common statements
delete my_agent->stats_stmts;
my_agent->stats_stmts = 0;
// close the database
my_agent->stats_db->disconnect();
}
}
void stats_db_store ( agent my_agent,
const uint64_t &  dc_time,
const uint64_t &  dc_wm_changes,
const uint64_t &  dc_firing_counts 
)
void stats_init_db ( agent my_agent)

Definition at line 341 of file utilities.cpp.

References soar_module::sqlite_database::connect(), soar_module::disconnected, soar_module::status_object< T >::get_errmsg(), soar_module::status_object< T >::get_status(), soar_module::statement_container::prepare(), print(), soar_module::problem, agent_struct::stats_db, agent_struct::stats_stmts, soar_module::sqlite_statement_container::structure(), and xml_generate_warning().

Referenced by stats_db_store().

{
return;
const char *db_path = ":memory:";
//const char *db_path = "C:\\Users\\voigtjr\\Desktop\\stats_debug.db";
// attempt connection
my_agent->stats_db->connect( db_path );
if ( my_agent->stats_db->get_status() == soar_module::problem )
{
char buf[256];
SNPRINTF( buf, 254, "DB ERROR: %s", my_agent->stats_db->get_errmsg() );
print( my_agent, buf );
xml_generate_warning( my_agent, buf );
}
else
{
// setup common structures/queries
my_agent->stats_stmts = new stats_statement_container( my_agent );
my_agent->stats_stmts->structure();
my_agent->stats_stmts->prepare();
}
}