Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Data Structures | Macros | Typedefs | Functions
rete.h File Reference
#include <stdio.h>

Go to the source code of this file.

Data Structures

union  token_struct::token_a_union
struct  token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct
struct  token_struct::token_a_union::token_in_hash_table_data_struct
struct  token_struct

Macros

#define DUPLICATE_PRODUCTION   3 /* the prod. was a duplicate */
#define NO_REFRACTED_INST   0 /* no refracted inst. was given */
#define REFRACTED_INST_DID_NOT_MATCH   2 /* there was no match for it */
#define REFRACTED_INST_MATCHED   1 /* there was a match for the inst. */

Typedefs

typedef struct action_struct action
typedef struct agent_struct agent
typedef char Bool
typedef unsigned char byte
typedef struct condition_struct condition
typedef struct instantiation_struct instantiation
typedef byte ms_trace_type
typedef struct production_struct production
typedef struct rete_node_struct rete_node
typedef union symbol_union Symbol
typedef struct token_struct token
typedef struct wme_struct wme
typedef byte wme_trace_type

Functions

byte add_production_to_rete (agent *thisAgent, production *p, condition *lhs_top, instantiation *refracted_inst, Bool warn_on_duplicates, Bool ignore_rhs=false)
void add_wme_to_rete (agent *thisAgent, wme *w)
Bool any_assertions_or_retractions_ready (agent *thisAgent)
void consume_last_postponed_assertion (agent *thisAgent)
uint64_t count_rete_tokens_for_production (agent *thisAgent, production *prod)
void excise_production_from_rete (agent *thisAgent, production *p)
void get_all_node_count_stats (agent *thisAgent)
Bool get_next_nil_goal_retraction (agent *thisAgent, struct instantiation_struct **inst)
Bool get_next_retraction (agent *thisAgent, struct instantiation_struct **inst)
int get_node_count_statistic (agent *thisAgent, char *node_type_name, char *column_name, uint64_t *result)
Symbolget_symbol_from_rete_loc (unsigned short levels_up, byte field_num, struct token_struct *tok, wme *w)
void init_rete (agent *thisAgent)
Bool load_rete_net (agent *thisAgent, FILE *source_file)
void p_node_to_conditions_and_nots (agent *thisAgent, struct rete_node_struct *p_node, struct token_struct *tok, wme *w, condition **dest_top_cond, condition **dest_bottom_cond, not_struct **dest_nots, action **dest_rhs)
Bool postpone_assertion (agent *thisAgent, production **prod, struct token_struct **tok, wme **w)
void print_match_set (agent *thisAgent, wme_trace_type wtt, ms_trace_type mst)
void print_partial_match_information (agent *thisAgent, struct rete_node_struct *p_node, wme_trace_type wtt)
void remove_wme_from_rete (agent *thisAgent, wme *w)
void restore_postponed_assertions (agent *thisAgent)
Bool save_rete_net (agent *thisAgent, FILE *dest_file, Bool use_rete_net_64)
void xml_match_set (agent *thisAgent, wme_trace_type wtt, ms_trace_type mst)
void xml_partial_match_information (agent *thisAgent, rete_node *p_node, wme_trace_type wtt)

Macro Definition Documentation

#define DUPLICATE_PRODUCTION   3 /* the prod. was a duplicate */
#define NO_REFRACTED_INST   0 /* no refracted inst. was given */

Definition at line 116 of file rete.h.

Referenced by add_production_to_rete().

#define REFRACTED_INST_DID_NOT_MATCH   2 /* there was no match for it */

Definition at line 118 of file rete.h.

Referenced by add_production_to_rete(), and chunk_instantiation().

#define REFRACTED_INST_MATCHED   1 /* there was a match for the inst. */

Definition at line 117 of file rete.h.

Referenced by add_production_to_rete(), and chunk_instantiation().

Typedef Documentation

typedef struct action_struct action

Definition at line 73 of file rete.h.

typedef struct agent_struct agent

Definition at line 76 of file rete.h.

typedef char Bool

Definition at line 64 of file rete.h.

typedef unsigned char byte

Definition at line 67 of file rete.h.

typedef struct condition_struct condition

Definition at line 72 of file rete.h.

Definition at line 70 of file rete.h.

Definition at line 69 of file rete.h.

typedef struct production_struct production

Definition at line 71 of file rete.h.

typedef struct rete_node_struct rete_node

Definition at line 75 of file rete.h.

typedef union symbol_union Symbol

Definition at line 77 of file rete.h.

typedef struct token_struct token
typedef struct wme_struct wme

Definition at line 74 of file rete.h.

Definition at line 68 of file rete.h.

Function Documentation

byte add_production_to_rete ( agent thisAgent,
production p,
condition lhs_top,
instantiation refracted_inst,
Bool  warn_on_duplicates,
Bool  ignore_rhs = false 
)

Definition at line 3709 of file rete.cpp.

References production_struct::action_list, adjust_sharing_factors_from_here_to_top, production_struct::already_fired, action_struct::attr, rete_node_struct::b, build_network_for_condition_list(), CHUNK_PRODUCTION_TYPE, rl_param_container::chunk_stop, deallocate_symbol_list_removing_references(), destructively_reverse_list(), discard_chunk_varnames, agent_struct::dummy_top_node, DUPLICATE_PRODUCTION, rete_node_struct::first_child, fixup_rhs_value_variable_references(), get_new_tc_number(), get_nvn_for_condition_list(), soar_module::constant_param< T >::get_value(), ms_change_struct::goal, action_struct::id, symbol_union::id, insert_at_head_of_dll, ms_change_struct::inst, production_struct::instantiations, ms_change_struct::level, MAKE_ACTION, make_new_production_node(), agent_struct::ms_change_pool, agent_struct::ms_retractions, identifier_struct::ms_retractions, production_struct::name, action_struct::next, rete_node_struct::next_sibling, NIL, agent_struct::nil_goal_retractions, NO_REFRACTED_INST, rete_node_struct::node_type, soar_module::on, rete_node_struct::rete_node_b_union::p, P_BNODE, ms_change_struct::p_node, production_struct::p_node, p_node_data_struct::parents_nvn, pop_bindings_and_deallocate_list_of_variables(), preference_is_binary(), action_struct::preference_type, print_with_symbols(), instantiation_struct::prod, p_node_data_struct::prod, PRODUCTION_JUST_ADDED_CALLBACK, action_struct::referent, REFRACTED_INST_DID_NOT_MATCH, REFRACTED_INST_MATCHED, remove_from_dll, instantiation_struct::rete_token, instantiation_struct::rete_wme, production_struct::rhs_unbound_variables, agent_struct::rl_params, same_rhs(), soar_invoke_callbacks(), symbol_to_string(), p_node_data_struct::tentative_retractions, TRUE, production_struct::type, action_struct::type, update_max_rhs_unbound_variables(), update_node_with_matches_from_above(), action_struct::value, and xml_generate_warning().

Referenced by chunk_instantiation(), parse_production(), and rl_build_template_instantiation().

{
rete_node *bottom_node, *p_node;
rete_node_level bottom_depth;
list *vars_bound;
ms_change *msc;
byte production_addition_result;
/* --- build the network for all the conditions --- */
build_network_for_condition_list (thisAgent, lhs_top, 1, thisAgent->dummy_top_node,
&bottom_node, &bottom_depth, &vars_bound);
/* --- change variable names in RHS to Rete location references or
unbound variable indices --- */
list* rhs_unbound_vars_for_new_prod = NIL;
uint64_t num_rhs_unbound_vars_for_new_prod = 0;
tc_number rhs_unbound_vars_tc = get_new_tc_number(thisAgent);
for (a=p->action_list; a!=NIL; a=a->next) {
fixup_rhs_value_variable_references (thisAgent, &(a->value), bottom_depth,
rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
if (a->type==MAKE_ACTION) {
fixup_rhs_value_variable_references (thisAgent, &(a->id), bottom_depth,
rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
fixup_rhs_value_variable_references (thisAgent, &(a->attr), bottom_depth,
rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
fixup_rhs_value_variable_references (thisAgent, &(a->referent), bottom_depth,
rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
}
}
/* --- clean up variable bindings created by build_network...() --- */
update_max_rhs_unbound_variables (thisAgent, num_rhs_unbound_vars_for_new_prod);
/* --- look for an existing p node that matches --- */
for (p_node=bottom_node->first_child; p_node!=NIL;
p_node=p_node->next_sibling) {
if (p_node->node_type != P_BNODE) continue;
if ( !ignore_rhs && !same_rhs (p_node->b.p.prod->action_list, p->action_list, thisAgent->rl_params->chunk_stop->get_value()==soar_module::on)) continue;
/* --- duplicate production found --- */
if (warn_on_duplicates)
{
std::stringstream output;
output << "\nIgnoring "
<< symbol_to_string( thisAgent, p->name, TRUE, 0, 0 )
<< " because it is a duplicate of "
<< symbol_to_string( thisAgent, p_node->b.p.prod->name, TRUE, 0, 0 )
<< " ";
xml_generate_warning( thisAgent, output.str().c_str() );
print_with_symbols (thisAgent, "\nIgnoring %y because it is a duplicate of %y ",
p->name, p_node->b.p.prod->name);
}
deallocate_symbol_list_removing_references (thisAgent, rhs_unbound_vars_for_new_prod);
}
/* --- build a new p node --- */
p_node = make_new_production_node (thisAgent, bottom_node, p);
/* KJC 1/28/98 left these comments in to support REW comments below
but commented out the operand_mode code */
/* RCHONG: begin 10.11 */
/*
in operand, we don't want to refract the instantiation. consider
this situation: a PE chunk was created during the IE phase. that
instantiation shouldn't be applied and we prevent this from
happening (see chunk_instantiation() in chunk.c). we eventually get
to the OUTPUT_PHASE, then the QUIESCENCE_PHASE. up to this point,
the chunk hasn't done it's thing. we start the PE_PHASE. now, it
is at this time that the just-built PE chunk should match and fire.
if we were to refract the chunk, it wouldn't fire it at this point
and it's actions would never occur. by not refracting it, we allow
the chunk to match and fire.
caveat: we must refract justifications, otherwise they would fire
and in doing so would produce more chunks/justifications.
if ((thisAgent->operand_mode == TRUE) && 1)
if (refracted_inst != NIL) {
if (refracted_inst->prod->type != JUSTIFICATION_PRODUCTION_TYPE)
refracted_inst = NIL;
}
*/
/* RCHONG: end 10.11 */
/* REW: begin 09.15.96 */
/* In Operand2, for now, we want both chunks and justifications to be
treated as refracted instantiations, at least for now. At some point,
this issue needs to be re-visited for chunks that immediately match with
a different instantiation and a different type of support than the
original, chunk-creating instantion. */
/* REW: end 09.15.96 */
/* --- handle initial refraction by adding it to tentative_retractions --- */
if (refracted_inst) {
insert_at_head_of_dll (p->instantiations, refracted_inst, next, prev);
refracted_inst->rete_token = NIL;
refracted_inst->rete_wme = NIL;
allocate_with_pool (thisAgent, &thisAgent->ms_change_pool, &msc);
msc->inst = refracted_inst;
msc->p_node = p_node;
/* REW: begin 08.20.97 */
/* Because the RETE 'artificially' refracts this instantiation (ie, it is
not actually firing -- the original instantiation fires but not the
chunk), we make the refracted instantiation of the chunk a nil_goal
retraction, rather than associating it with the activity of its match
goal. In p_node_left_addition, where the tentative assertion will be
generated, we make it a point to look at the goal value and exrtac
from the appropriate list; here we just make a a simplifying
assumption that the goal is NIL (although, in reality), it never will
be. */
/* This initialization is necessary (for at least safety reasons, for all
msc's, regardless of the mode */
msc->level = 0;
msc->goal = NIL;
#ifdef DEBUG_WATERFALL
print_with_symbols(thisAgent, "\n %y is a refracted instantiation",
refracted_inst->prod->name);
#endif
msc, next_in_level, prev_in_level);
/* REW: end 08.20.97 */
#ifdef BUG_139_WORKAROUND
msc->p_node->b.p.prod->already_fired = 0; /* RPM workaround for bug #139; mark prod as not fired yet */
#endif
insert_at_head_of_dll (thisAgent->ms_retractions, msc, next, prev);
}
/* --- call new node's add_left routine with all the parent's tokens --- */
/* --- store result indicator --- */
if (! refracted_inst) {
production_addition_result = NO_REFRACTED_INST;
} else {
remove_from_dll (p->instantiations, refracted_inst, next, prev);
if (p_node->b.p.tentative_retractions) {
production_addition_result = REFRACTED_INST_DID_NOT_MATCH;
msc = p_node->b.p.tentative_retractions;
remove_from_dll (thisAgent->ms_retractions, msc, next, prev);
/* REW: begin 10.03.97 */ /* BUGFIX 2.125 */
if (msc->goal) {
next_in_level, prev_in_level);
} else {
msc, next_in_level, prev_in_level);
}
/* REW: end 10.03.97 */
free_with_pool (&thisAgent->ms_change_pool, msc);
} else {
production_addition_result = REFRACTED_INST_MATCHED;
}
}
/* --- if not a chunk, store variable name information --- */
deallocate_symbol_list_removing_references (thisAgent, rhs_unbound_vars_for_new_prod);
} else {
p->p_node->b.p.parents_nvn = get_nvn_for_condition_list (thisAgent, lhs_top, NIL);
destructively_reverse_list (rhs_unbound_vars_for_new_prod);
}
/* --- invoke callback functions --- */
soar_invoke_callbacks (thisAgent, PRODUCTION_JUST_ADDED_CALLBACK, static_cast<soar_call_data>(p));
//#ifdef _WINDOWS
// add_production_to_stat_lists(new_prod);
//#endif
return production_addition_result;
}
void add_wme_to_rete ( agent thisAgent,
wme w 
)

Definition at line 1556 of file rete.cpp.

References wme_struct::acceptable, add_wme_to_aht(), agent_struct::all_wmes_in_rete, agent_struct::alpha_hash_tables, wme_struct::attr, soar_module::connected, agent_struct::epmem_db, wme_struct::epmem_id, identifier_struct::epmem_id, agent_struct::epmem_id_ref_counts, EPMEM_NODEID_BAD, wme_struct::epmem_valid, identifier_struct::epmem_valid, agent_struct::epmem_validation, agent_struct::epmem_wme_adds, soar_module::status_object< T >::get_status(), soar_module::constant_param< T >::get_value(), wme_struct::id, symbol_union::id, IDENTIFIER_SYMBOL_TYPE, insert_at_head_of_dll, smem_param_container::mirroring, NIL, agent_struct::num_wmes_in_rete, soar_module::on, wme_struct::right_mems, agent_struct::smem_changed_ids, smem_enabled(), agent_struct::smem_ignore_changes, identifier_struct::smem_lti, agent_struct::smem_params, symbol_add_ref(), wme_struct::tokens, uint32_t(), wme_struct::value, and xor_op().

Referenced by do_buffered_wm_changes().

{
uint32_t hi, ha, hv;
/* --- add w to all_wmes_in_rete --- */
insert_at_head_of_dll (thisAgent->all_wmes_in_rete, w, rete_next, rete_prev);
thisAgent->num_wmes_in_rete++;
/* --- it's not in any right memories or tokens yet --- */
w->tokens = NIL;
/* --- add w to the appropriate alpha_mem in each of 8 possible tables --- */
hi = w->id->common.hash_id;
ha = w->attr->common.hash_id;
hv = w->value->common.hash_id;
if (w->acceptable) {
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[8], xor_op( 0, 0, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[9], xor_op(hi, 0, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[10], xor_op( 0,ha, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[11], xor_op(hi,ha, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[12], xor_op( 0, 0,hv), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[13], xor_op(hi, 0,hv), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[14], xor_op( 0,ha,hv), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[15], xor_op(hi,ha,hv), w);
} else {
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[0], xor_op( 0, 0, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[1], xor_op(hi, 0, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[2], xor_op( 0,ha, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[3], xor_op(hi,ha, 0), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[4], xor_op( 0, 0,hv), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[5], xor_op(hi, 0,hv), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[6], xor_op( 0,ha,hv), w);
add_wme_to_aht (thisAgent, thisAgent->alpha_hash_tables[7], xor_op(hi,ha,hv), w);
}
{
if ( thisAgent->epmem_db->get_status() == soar_module::connected )
{
// if identifier-valued and short-term, known value
if ( ( w->value->common.symbol_type == IDENTIFIER_SYMBOL_TYPE ) &&
( w->value->id.epmem_valid == thisAgent->epmem_validation ) &&
( !w->value->id.smem_lti ) )
{
// add id ref count
(*thisAgent->epmem_id_ref_counts)[ w->value->id.epmem_id ]->insert( w );
}
// if known id
if ( ( w->id->id.epmem_id != EPMEM_NODEID_BAD ) && ( w->id->id.epmem_valid == thisAgent->epmem_validation ) )
{
// add to add set
thisAgent->epmem_wme_adds->insert( w->id );
}
}
}
if ( ( w->id->id.smem_lti ) && ( !thisAgent->smem_ignore_changes ) && smem_enabled( thisAgent ) && ( thisAgent->smem_params->mirroring->get_value() == soar_module::on ) )
{
std::pair< smem_pooled_symbol_set::iterator, bool > insert_result = thisAgent->smem_changed_ids->insert( w->id );
if ( insert_result.second )
{
}
}
}
Bool any_assertions_or_retractions_ready ( agent thisAgent)

Definition at line 1097 of file rete.cpp.

References agent_struct::bottom_goal, FALSE, identifier_struct::higher_goal, symbol_union::id, identifier_struct::ms_i_assertions, identifier_struct::ms_o_assertions, identifier_struct::ms_retractions, agent_struct::nil_goal_retractions, and TRUE.

Referenced by determine_highest_active_production_level_in_stack_apply().

{
Symbol *goal;
/* REW: begin 08.20.97 */
/* Determining if assertions or retractions are ready require looping over
all goals in Waterfall/Operand2 */
if (thisAgent->nil_goal_retractions) return TRUE;
/* Loop from bottom to top because we expect activity at
the bottom usually */
for (goal=thisAgent->bottom_goal;goal;goal=goal->id.higher_goal) {
/* if there are any assertions or retrctions for this goal,
return TRUE */
if (goal->id.ms_o_assertions || goal->id.ms_i_assertions ||
return TRUE;
}
/* if there are no nil_goal_retractions and no assertions or retractions
for any goal then return FALSE -- there aren't any productions
ready to fire or retract */
return FALSE;
/* REW: end 08.20.97 */
}
void consume_last_postponed_assertion ( agent thisAgent)

Definition at line 1215 of file rete.cpp.

References agent_struct::ms_change_pool, agent_struct::postponed_assertions, and remove_from_dll.

Referenced by do_preference_phase().

{
assert (thisAgent->postponed_assertions);
ms_change *msc = thisAgent->postponed_assertions;
// get the most recently postponed assertion
remove_from_dll (thisAgent->postponed_assertions, msc, next, prev);
// kill it
free_with_pool (&thisAgent->ms_change_pool, msc);
}
uint64_t count_rete_tokens_for_production ( agent thisAgent,
production prod 
)
void excise_production_from_rete ( agent thisAgent,
production p 
)

Definition at line 3910 of file rete.cpp.

References rete_node_struct::a, adjust_sharing_factors_from_here_to_top, rete_node_struct::b, deallocate_node_varnames(), deallocate_rete_node(), agent_struct::dummy_top_node, rete_node_struct::first_child, ms_change_struct::next_of_node, NIL, rete_node_struct::rete_node_a_union::np, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, production_struct::p_node, rete_node_struct::parent, node_varnames_struct::parent, p_node_data_struct::parents_nvn, PRODUCTION_JUST_ABOUT_TO_BE_EXCISED_CALLBACK, remove_node_from_parents_list_of_children(), remove_token_and_subtree(), agent_struct::rete_node_pool, soar_invoke_callbacks(), p_node_data_struct::tentative_retractions, non_pos_node_data_struct::tokens, and update_stats_for_destroying_node().

Referenced by excise_production().

{
rete_node *p_node, *parent;
ms_change *msc;
soar_invoke_callbacks (thisAgent, PRODUCTION_JUST_ABOUT_TO_BE_EXCISED_CALLBACK, static_cast<soar_call_data>(p));
//#ifdef _WINDOWS
// remove_production_from_stat_lists(prod_to_be_excised);
//#endif
p_node = p->p_node;
p->p_node = NIL; /* mark production as not being in the rete anymore */
parent = p_node->parent;
/* --- deallocate the variable name information --- */
if (p_node->b.p.parents_nvn)
deallocate_node_varnames (thisAgent, parent, thisAgent->dummy_top_node,
p_node->b.p.parents_nvn);
/* --- cause all existing instantiations to retract, by removing any
tokens at the node --- */
while (p_node->a.np.tokens) remove_token_and_subtree (thisAgent, p_node->a.np.tokens);
/* --- At this point, there are no tentative_assertion's. Now set
the p_node field of all tentative_retractions to NIL, to indicate
that the p_node is being excised --- */
for (msc=p_node->b.p.tentative_retractions; msc!=NIL; msc=msc->next_of_node)
msc->p_node = NIL;
/* --- finally, excise the p_node --- */
update_stats_for_destroying_node (thisAgent, p_node); /* clean up rete stats stuff */
free_with_pool (&thisAgent->rete_node_pool, p_node);
/* --- update sharing factors on the path from here to the top node --- */
/* --- and propogate up the net --- */
if (! parent->first_child)
deallocate_rete_node (thisAgent, parent);
}
void get_all_node_count_stats ( agent thisAgent)

Definition at line 7729 of file rete.cpp.

References agent_struct::actual, DUMMY_MATCHES_BNODE, agent_struct::if_no_merging, agent_struct::if_no_sharing, init_bnode_type_names(), MEMORY_BNODE, MP_BNODE, POSITIVE_BNODE, agent_struct::rete_node_counts, agent_struct::rete_node_counts_if_no_sharing, UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, and UNHASHED_POSITIVE_BNODE.

Referenced by get_node_count_statistic().

{
int i;
//
// This sanity check should no longer be neccessary.
//
/* --- sanity check: make sure we've got names for all the bnode types --- */
//for (i=0; i<256; i++)
// if (thisAgent->rete_node_counts[i] &&
// (*bnode_type_names[i] == 0)) {
// print (thisAgent, "Internal eror: unknown node type [%d] has nonzero count.\n",i);
// }
/* --- calculate the three arrays --- */
for (i=0; i<256; i++) {
thisAgent->actual[i] = thisAgent->rete_node_counts[i];
thisAgent->if_no_merging[i] = thisAgent->rete_node_counts[i];
thisAgent->if_no_sharing[i] = thisAgent->rete_node_counts_if_no_sharing[i];
}
/* --- don't want the dummy matches node to show up as a real node --- */
thisAgent->actual[DUMMY_MATCHES_BNODE] = 0;
/* --- If no merging or sharing, each MP node would be 1 Mem + 1 Pos --- */
thisAgent->if_no_merging[MEMORY_BNODE] += thisAgent->if_no_merging[MP_BNODE];
thisAgent->if_no_merging[POSITIVE_BNODE] += thisAgent->if_no_merging[MP_BNODE];
thisAgent->if_no_merging[MP_BNODE] = 0;
thisAgent->if_no_sharing[MEMORY_BNODE] += thisAgent->if_no_sharing[MP_BNODE];
thisAgent->if_no_sharing[POSITIVE_BNODE] += thisAgent->if_no_sharing[MP_BNODE];
thisAgent->if_no_sharing[MP_BNODE] = 0;
}
Bool get_next_nil_goal_retraction ( agent thisAgent,
struct instantiation_struct **  inst 
)

Definition at line 1292 of file rete.cpp.

References rete_node_struct::b, FALSE, ms_change_struct::inst, agent_struct::ms_change_pool, agent_struct::ms_retractions, agent_struct::nil_goal_retractions, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, remove_from_dll, p_node_data_struct::tentative_retractions, and TRUE.

Referenced by do_preference_phase().

{
ms_change *msc;
if (! thisAgent->nil_goal_retractions) return FALSE;
msc = thisAgent->nil_goal_retractions;
/* Remove this retraction from the NIL goal list */
next_in_level, prev_in_level);
/* next and prev set and used in Operand2 exactly as used in Soar 7 --
so we have to make sure and delete this retraction from the regular
list */
remove_from_dll (thisAgent->ms_retractions, msc, next, prev);
if (msc->p_node) {
}
*inst = msc->inst;
free_with_pool (&thisAgent->ms_change_pool, msc);
return TRUE;
}
Bool get_next_retraction ( agent thisAgent,
struct instantiation_struct **  inst 
)

Definition at line 1256 of file rete.cpp.

References agent_struct::active_goal, agent_struct::active_level, rete_node_struct::b, FALSE, symbol_union::id, ms_change_struct::inst, agent_struct::ms_change_pool, agent_struct::ms_retractions, identifier_struct::ms_retractions, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, remove_from_dll, p_node_data_struct::tentative_retractions, and TRUE.

Referenced by do_preference_phase().

{
ms_change *msc;
/* just do the retractions for the current level */
/* initialization condition (2.107/2.111) */
if (thisAgent->active_level == 0) return FALSE;
if (! thisAgent->active_goal->id.ms_retractions) return FALSE;
msc = thisAgent->active_goal->id.ms_retractions;
/* remove from the complete retraction list */
remove_from_dll (thisAgent->ms_retractions, msc, next, prev);
/* and remove from the Waterfall-specific list */
msc, next_in_level, prev_in_level);
if (msc->p_node)
*inst = msc->inst;
free_with_pool (&thisAgent->ms_change_pool, msc);
return TRUE;
}
int get_node_count_statistic ( agent thisAgent,
char *  node_type_name,
char *  column_name,
uint64_t *  result 
)

Definition at line 7771 of file rete.cpp.

References agent_struct::actual, bnode_type_names, get_all_node_count_stats(), agent_struct::if_no_merging, and agent_struct::if_no_sharing.

{
int i;
uint64_t tot;
if (!strcmp("total", node_type_name))
{
if (!strcmp("actual", column_name))
{
for (tot=0, i=0; i<256; i++) tot+=thisAgent->actual[i];
*result = tot;
}
else if (!strcmp("if-no-merging", column_name))
{
for (tot=0, i=0; i<256; i++) tot+=thisAgent->if_no_merging[i];
*result = tot;
}
#ifdef SHARING_FACTORS
else if (!strcmp("if-no-sharing", column_name))
{
for (tot=0, i=0; i<256; i++) tot+=thisAgent->if_no_sharing[i];
*result = tot;
}
#endif
else
{
return 0;
}
}
else
{
for (i=0; i<256; i++)
if (!strcmp(bnode_type_names[i], node_type_name))
{
if (!strcmp("actual", column_name))
{
*result = thisAgent->actual[i];
}
else if (!strcmp("if-no-merging", column_name))
{
*result = thisAgent->if_no_merging[i];
}
#ifdef SHARING_FACTORS
else if (!strcmp("if-no-sharing", column_name))
{
*result = thisAgent->if_no_sharing[i];
}
#endif
else
{
return 0;
}
return 1;
}
return 0;
}
return 1;
}
Symbol* get_symbol_from_rete_loc ( unsigned short  levels_up,
byte  field_num,
struct token_struct tok,
wme w 
)

Definition at line 4573 of file rete.cpp.

References wme_struct::attr, wme_struct::id, token_struct::parent, wme_struct::value, and token_struct::w.

Referenced by calculate_support_for_instantiation_preferences(), instantiate_rhs_value(), p_node_left_addition(), and shouldCreateInstantiation().

{
while (levels_up) {
levels_up--;
w = tok->w;
tok = tok->parent;
}
if (field_num==0) return w->id;
if (field_num==1) return w->attr;
return w->value;
}
void init_rete ( agent thisAgent)

Definition at line 9049 of file rete.cpp.

References allocate_memory_and_zerofill(), agent_struct::alpha_hash_tables, agent_struct::alpha_mem_pool, constant_equal_rete_test_routine(), constant_greater_or_equal_rete_test_routine(), constant_greater_rete_test_routine(), constant_less_or_equal_rete_test_routine(), constant_less_rete_test_routine(), constant_not_equal_rete_test_routine(), CONSTANT_RELATIONAL_RETE_TEST, constant_same_type_rete_test_routine(), DISJUNCTION_RETE_TEST, disjunction_rete_test_routine(), FALSE, hash_alpha_mem(), HASH_TABLE_MEM_USAGE, ID_IS_GOAL_RETE_TEST, id_is_goal_rete_test_routine(), ID_IS_IMPASSE_RETE_TEST, id_is_impasse_rete_test_routine(), init_bnode_type_names(), init_dummy_top_node(), init_left_and_right_addition_routines(), init_memory_pool(), init_test_type_conversion_tables(), agent_struct::left_ht, LEFT_HT_SIZE, make_hash_table(), agent_struct::max_rhs_unbound_variables, MISCELLANEOUS_MEM_USAGE, agent_struct::ms_change_pool, agent_struct::node_varnames_pool, RELATIONAL_EQUAL_RETE_TEST, RELATIONAL_GREATER_OR_EQUAL_RETE_TEST, RELATIONAL_GREATER_RETE_TEST, RELATIONAL_LESS_OR_EQUAL_RETE_TEST, RELATIONAL_LESS_RETE_TEST, RELATIONAL_NOT_EQUAL_RETE_TEST, RELATIONAL_SAME_TYPE_RETE_TEST, agent_struct::rete_node_pool, agent_struct::rete_test_pool, agent_struct::rhs_variable_bindings, agent_struct::right_ht, RIGHT_HT_SIZE, agent_struct::right_mem_pool, agent_struct::token_pool, TRUE, variable_equal_rete_test_routine(), variable_greater_or_equal_rete_test_routine(), variable_greater_rete_test_routine(), variable_less_or_equal_rete_test_routine(), variable_less_rete_test_routine(), variable_not_equal_rete_test_routine(), VARIABLE_RELATIONAL_RETE_TEST, and variable_same_type_rete_test_routine().

Referenced by init_soar_agent().

{
/*
This function consists of two parts. The first initializes variables
pertaining to a particular agent. The second initializes some important
globals (bnode type names, addition routines, and test routines).
Originally, these two parts were ordered the other way.
The globals should only be initialized once (when the rete for the first
agent is initialized), whereas everything else should be initialized on
every call to the function (i.e. whenever the rete for a new agent is
initialized).
Therefore, the order has been switched so that the agent-specific
variables are initialized first. Once this is done, a simple test of a
static boolean variable indicates whether or not the globals have already
been initialized. If they have, then the function exits prematurely.
As far as I can see, this switch has no undesired effects, since the
agent-specific function calls in the first part do not depend upon the
global variables defined in the second part.
-AJC (8/9/02)
*/
int i;
init_memory_pool (thisAgent, &thisAgent->alpha_mem_pool, sizeof(alpha_mem),
"alpha mem");
init_memory_pool (thisAgent, &thisAgent->rete_test_pool, sizeof(rete_test),
"rete test");
init_memory_pool (thisAgent, &thisAgent->rete_node_pool, sizeof(rete_node),
"rete node");
init_memory_pool (thisAgent, &thisAgent->node_varnames_pool,sizeof(node_varnames),
"node varnames");
init_memory_pool (thisAgent, &thisAgent->token_pool, sizeof(token), "token");
init_memory_pool (thisAgent, &thisAgent->right_mem_pool, sizeof(right_mem),
"right mem");
init_memory_pool (thisAgent, &thisAgent->ms_change_pool, sizeof(ms_change),
"ms change");
for (i=0; i<16; i++)
thisAgent->alpha_hash_tables[i] = make_hash_table (thisAgent, 0, hash_alpha_mem);
(thisAgent, sizeof(char *) * LEFT_HT_SIZE, HASH_TABLE_MEM_USAGE);
(thisAgent, sizeof(char *) * RIGHT_HT_SIZE, HASH_TABLE_MEM_USAGE);
init_dummy_top_node(thisAgent);
thisAgent->max_rhs_unbound_variables = 1;
thisAgent->rhs_variable_bindings = (Symbol **)
/* This is still not thread-safe. -AJC (8/9/02) */
static Bool bInit = FALSE;
if (bInit)
return;
bInit = TRUE;
//
// rete_test_routines is now statically initialized.
//
//for (i=0; i<256; i++) rete_test_routines[i] = error_rete_test_routine;
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[CONSTANT_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
rete_test_routines[VARIABLE_RELATIONAL_RETE_TEST +
}
Bool load_rete_net ( agent thisAgent,
FILE *  source_file 
)

Definition at line 7568 of file rete.cpp.

References agent_struct::all_wmes_in_rete, agent_struct::dummy_top_node, excise_all_productions(), FALSE, init_agent_memory(), NUM_PRODUCTION_TYPES, agent_struct::num_productions_of_type, print(), reinitialize_soar(), rete_fs_file, rete_net_64, reteload_all_symbols(), reteload_alpha_memories(), reteload_eight_bytes(), reteload_free_am_table(), reteload_free_symbol_table(), reteload_node_and_children(), reteload_one_byte(), reteload_string(), reteload_string_buf, and TRUE.

{
int format_version_num;
uint64_t i, count;
/* RDF: 20020814 RDF Cleaning up the agent working memory and production
memory to avoid unecessary errors in this function. */
reinitialize_soar(thisAgent);
/* DONE clearing old productions */
/* --- check for empty system --- */
if (thisAgent->all_wmes_in_rete) {
print (thisAgent, "Internal error: load_rete_net() called with nonempty WM.\n");
return FALSE;
}
for (i=0; i<NUM_PRODUCTION_TYPES; i++)
if (thisAgent->num_productions_of_type[i]) {
print (thisAgent, "Internal error: load_rete_net() called with nonempty PM.\n");
return FALSE;
}
// BADBAD: this is global, used in retesave_one_byte
rete_fs_file = source_file;
/* --- read file header, make sure it's a valid file --- */
reteload_string(source_file);
if (strcmp(reteload_string_buf,"SoarCompactReteNet\n")) {
print (thisAgent, "This file isn't a Soar fastsave file.\n");
return FALSE;
}
format_version_num = reteload_one_byte(source_file);
switch(format_version_num)
{
case 3:
// Since there's already a global, I'm putting the 32- or 64-bit switch out there globally
rete_net_64 = FALSE; // used by reteload_eight_bytes
break;
case 4:
// Since there's already a global, I'm putting the 32- or 64-bit switch out there globally
rete_net_64 = TRUE; // used by reteload_eight_bytes
break;
default:
print (thisAgent, "This file is in a format (version %d) I don't understand.\n", format_version_num);
return FALSE;
}
reteload_all_symbols(thisAgent,source_file);
reteload_alpha_memories(thisAgent,source_file);
count = reteload_eight_bytes(source_file);
while (count--) reteload_node_and_children (thisAgent, thisAgent->dummy_top_node,source_file);
/* --- clean up auxilliary tables --- */
/* RDF: 20020814 Now adding the top state and io symbols and wmes */
init_agent_memory(thisAgent);
return TRUE;
}
void p_node_to_conditions_and_nots ( agent thisAgent,
struct rete_node_struct p_node,
struct token_struct tok,
wme w,
condition **  dest_top_cond,
condition **  dest_bottom_cond,
not_struct **  dest_nots,
action **  dest_rhs 
)

Definition at line 4525 of file rete.cpp.

References production_struct::action_list, rete_node_struct::b, copy_action_list_and_substitute_varnames(), agent_struct::dummy_top_node, cons_struct::first, agent_struct::highest_rhs_unboundvar_index, NIL, rete_node_struct::rete_node_b_union::p, rete_node_struct::parent, p_node_data_struct::parents_nvn, p_node_data_struct::prod, reset_variable_generator(), cons_struct::rest, rete_node_to_conditions(), production_struct::rhs_unbound_variables, and agent_struct::rhs_variable_bindings.

Referenced by create_instantiation(), print_partial_match_information(), print_production(), rl_build_template_instantiation(), and xml_partial_match_information().

{
cons *c;
Symbol **cell;
int64_t index;
production *prod;
prod = p_node->b.p.prod;
not_struct *nots_found_in_production = NIL;
if (tok==NIL) w=NIL; /* just for safety */
reset_variable_generator (thisAgent, NIL, NIL); /* we'll be gensymming new vars */
p_node->parent,
p_node->b.p.parents_nvn,
thisAgent->dummy_top_node,
tok, w, NIL,
dest_top_cond, dest_bottom_cond,
nots_found_in_production);
if (tok) *dest_nots = nots_found_in_production;
nots_found_in_production = NIL; /* just for safety */
if (dest_rhs)
{
{
cell = thisAgent->rhs_variable_bindings;
for (c=prod->rhs_unbound_variables; c!=NIL; c=c->rest)
{
*(cell++) = static_cast<symbol_union *>(c->first);
}
}
prod->action_list,
*dest_bottom_cond);
index = 0;
cell = thisAgent->rhs_variable_bindings;
while (index++ <= thisAgent->highest_rhs_unboundvar_index) *(cell++) = NIL;
}
}
Bool postpone_assertion ( agent thisAgent,
production **  prod,
struct token_struct **  tok,
wme **  w 
)

Definition at line 1147 of file rete.cpp.

References agent_struct::active_goal, rete_node_struct::b, FALSE, agent_struct::FIRING_TYPE, symbol_union::id, insert_at_head_of_dll, identifier_struct::ms_i_assertions, agent_struct::ms_i_assertions, identifier_struct::ms_o_assertions, agent_struct::ms_o_assertions, NIL, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, PE_PRODS, agent_struct::postponed_assertions, p_node_data_struct::prod, remove_from_dll, p_node_data_struct::tentative_assertions, ms_change_struct::tok, TRUE, and ms_change_struct::w.

Referenced by do_preference_phase().

{
ms_change *msc = NIL;
/* REW: begin 09.15.96 */
/* REW: begin 08.20.97 */
/* In Waterfall, we return only assertions that match in the
currently active goal */
if (thisAgent->active_goal) { /* Just do asserts for current goal */
if (thisAgent->FIRING_TYPE == PE_PRODS) {
if (! thisAgent->active_goal->id.ms_o_assertions) return FALSE;
msc = thisAgent->active_goal->id.ms_o_assertions;
remove_from_dll (thisAgent->ms_o_assertions, msc, next, prev);
msc, next_in_level, prev_in_level);
} else {
/* IE PRODS */
if (! thisAgent->active_goal->id.ms_i_assertions) return FALSE;
msc = thisAgent->active_goal->id.ms_i_assertions;
remove_from_dll (thisAgent->ms_i_assertions, msc, next, prev);
msc, next_in_level, prev_in_level);
}
} else {
/* If there is not an active goal, then there should not be any
assertions. If there are, then we generate and error message
and abort. */
if ((thisAgent->ms_i_assertions) ||
(thisAgent->ms_o_assertions)) {
// Commented out 11/2007
// laird: I would like us to remove that error message that happens
// in Obscurebot. It just freaks people out and we have yet to see an error in Soar because of it.
//char msg[BUFFER_MSG_SIZE];
//strncpy(msg,"\nrete.c: Error: No active goal, but assertions are on the assertion list.", BUFFER_MSG_SIZE);
//msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
//abort_with_fatal_error(thisAgent, msg);
}
return FALSE; /* if we are in an initiazation and there are no
assertions, just retrurn FALSE to terminate
the procedure. */
}
/* REW: end 08.20.97 */
/* REW: end 09.15.96 */
*prod = msc->p_node->b.p.prod;
*tok = msc->tok;
*w = msc->w;
// save the assertion on the postponed list
insert_at_head_of_dll (thisAgent->postponed_assertions, msc, next, prev);
return TRUE;
}
void print_match_set ( agent thisAgent,
wme_trace_type  wtt,
ms_trace_type  mst 
)

Definition at line 8073 of file rete.cpp.

References allocate_memory(), rete_node_struct::b, free_memory(), ms_change_struct::goal, match_set_trace::goal, in_ms_trace_same_goal(), ms_change_struct::inst, MISCELLANEOUS_MEM_USAGE, MS_ASSERT, MS_ASSERT_RETRACT, agent_struct::ms_i_assertions, agent_struct::ms_o_assertions, MS_RETRACT, agent_struct::ms_retractions, production_struct::name, ms_change_struct::next, match_set_trace::next, NIL, NONE_WME_TRACE, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, token_struct::parent, print(), print_instantiation_with_wmes(), print_whole_token(), print_with_symbols(), instantiation_struct::prod, p_node_data_struct::prod, match_set_trace::sym, ms_change_struct::tok, ms_change_struct::w, and token_struct::w.

{
ms_change *msc;
token temp_token;
MS_trace *ms_trace = NIL, *tmp;
/* --- Print assertions --- */
/* REW: begin 09.15.96 */
if (mst == MS_ASSERT_RETRACT || mst == MS_ASSERT) {
print (thisAgent, "O Assertions:\n");
for (msc=thisAgent->ms_o_assertions; msc!=NIL; msc=msc->next) {
if(wtt != NONE_WME_TRACE) {
print_with_symbols (thisAgent, " %y ", msc->p_node->b.p.prod->name);
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
print_with_symbols(thisAgent, " [%y] ", msc->goal);
/* REW: end 08.20.97 */
temp_token.parent = msc->tok;
temp_token.w = msc->w;
print_whole_token (thisAgent, &temp_token, wtt);
print (thisAgent, "\n");
}
else {
/* REW: begin 10.22.97 */
ms_trace, msc->goal))!=NIL) {
/* REW: end 10.22.97 */
tmp->count++;
}
else {
tmp = static_cast<match_set_trace *>(allocate_memory(thisAgent, sizeof(MS_trace), MISCELLANEOUS_MEM_USAGE));
tmp->sym = msc->p_node->b.p.prod->name;
tmp->count = 1;
tmp->next = ms_trace;
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
tmp->goal = msc->goal;
/* REW: end 08.20.97 */
ms_trace = tmp;
}
}
}
if (wtt == NONE_WME_TRACE) {
while (ms_trace) {
tmp = ms_trace; ms_trace = tmp->next;
print_with_symbols (thisAgent, " %y ", tmp->sym);
/* REW: begin 08.20.97 */
/* BUG: for now this will print the goal of the first
assertion inspected, even though there can be multiple
assertions at different levels.
See 2.110 in the OPERAND-CHANGE-LOG. */
print_with_symbols(thisAgent, " [%y] ", tmp->goal);
/* REW: end 08.20.97 */
if (tmp->count > 1)
print(thisAgent, "(%d)\n", tmp->count);
else
print(thisAgent, "\n");
}
}
}
if (mst == MS_ASSERT_RETRACT || mst == MS_ASSERT) {
print (thisAgent, "I Assertions:\n");
for (msc=thisAgent->ms_i_assertions; msc!=NIL; msc=msc->next) {
if(wtt != NONE_WME_TRACE) {
print_with_symbols (thisAgent, " %y ", msc->p_node->b.p.prod->name);
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
print_with_symbols(thisAgent, " [%y] ", msc->goal);
/* REW: end 08.20.97 */
temp_token.parent = msc->tok;
temp_token.w = msc->w;
print_whole_token (thisAgent, &temp_token, wtt);
print (thisAgent, "\n");
}
else {
/* REW: begin 10.22.97 */
ms_trace, msc->goal))!=NIL) {
/* REW: end 10.22.97 */
tmp->count++;
}
else {
tmp = static_cast<match_set_trace *>(allocate_memory(thisAgent, sizeof(MS_trace),
tmp->sym = msc->p_node->b.p.prod->name;
tmp->count = 1;
tmp->next = ms_trace;
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
tmp->goal = msc->goal;
/* REW: end 08.20.97 */
ms_trace = tmp;
}
}
}
if (wtt == NONE_WME_TRACE) {
while (ms_trace) {
tmp = ms_trace; ms_trace = tmp->next;
print_with_symbols (thisAgent, " %y ", tmp->sym);
/* REW: begin 08.20.97 */
/* BUG: for now this will print the goal of the first
assertion inspected, even though there can be multiple
assertions at different levels.
See 2.110 in the OPERAND-CHANGE-LOG. */
print_with_symbols(thisAgent, " [%y] ", tmp->goal);
/* REW: end 08.20.97 */
if (tmp->count > 1)
print(thisAgent, "(%d)\n", tmp->count);
else
print(thisAgent, "\n");
}
}
}
/* REW: end 09.15.96 */
/* --- Print retractions --- */
if (mst == MS_ASSERT_RETRACT || mst == MS_RETRACT) {
print (thisAgent, "Retractions:\n");
for (msc=thisAgent->ms_retractions; msc!=NIL; msc=msc->next) {
if(wtt != NONE_WME_TRACE) {
print (thisAgent, " ");
print_instantiation_with_wmes (thisAgent, msc->inst, wtt, -1);
print (thisAgent, "\n");
} else {
if(msc->inst->prod) {
/* REW: begin 10.22.97 */
if((tmp = in_ms_trace_same_goal(msc->inst->prod->name,
ms_trace, msc->goal))!=NIL) {
/* REW: end 10.22.97 */
tmp->count++;
} else {
tmp = static_cast<match_set_trace *>(allocate_memory(thisAgent, sizeof(MS_trace),
tmp->sym = msc->inst->prod->name;
tmp->count = 1;
tmp->next = ms_trace;
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
tmp->goal = msc->goal;
/* REW: end 08.20.97 */
ms_trace = tmp;
}
}
}
}
if(wtt == NONE_WME_TRACE) {
while (ms_trace) {
tmp = ms_trace; ms_trace = tmp->next;
print_with_symbols (thisAgent, " %y ", tmp->sym);
/* REW: begin 08.20.97 */
/* BUG: for now this will print the goal of the first assertion
inspected, even though there can be multiple assertions at
different levels.
See 2.110 in the OPERAND-CHANGE-LOG. */
if (tmp->goal)
print_with_symbols(thisAgent, " [%y] ", tmp->goal);
else
print(thisAgent, " [NIL] ");
/* REW: end 08.20.97 */
if(tmp->count > 1)
print(thisAgent, "(%d)\n", tmp->count);
else
print(thisAgent, "\n");
}
}
}
}
void print_partial_match_information ( agent thisAgent,
struct rete_node_struct p_node,
wme_trace_type  wtt 
)

Definition at line 8017 of file rete.cpp.

References deallocate_condition_list(), deallocate_token_list(), agent_struct::dummy_top_node, get_all_left_tokens_emerging_from_node(), token_struct::next_of_node, NIL, NONE_WME_TRACE, p_node_to_conditions_and_nots(), rete_node_struct::parent, ppmi_aux(), print(), and print_whole_token().

{
condition *top_cond, *bottom_cond;
int64_t n;
token *tokens, *t;
p_node_to_conditions_and_nots (thisAgent, p_node, NIL, NIL, &top_cond, &bottom_cond,
NIL, NIL);
n = ppmi_aux (thisAgent, p_node->parent, thisAgent->dummy_top_node, bottom_cond,
wtt, 0);
print (thisAgent, "\n%d complete matches.\n", n);
if (n && (wtt!=NONE_WME_TRACE)) {
print (thisAgent, "*** Complete Matches ***\n");
tokens = get_all_left_tokens_emerging_from_node (thisAgent, p_node->parent);
for (t=tokens; t!=NIL; t=t->next_of_node) {
print_whole_token (thisAgent, t, wtt);
print (thisAgent, "\n");
}
deallocate_token_list (thisAgent, tokens);
}
deallocate_condition_list (thisAgent, top_cond);
}
void remove_wme_from_rete ( agent thisAgent,
wme w 
)

Definition at line 1740 of file rete.cpp.

References _epmem_process_ids(), _epmem_remove_wme(), token_struct::a, agent_struct::all_wmes_in_rete, right_mem_struct::am, rete_node_struct::b, alpha_mem_struct::beta_nodes, soar_module::connected, agent_struct::epmem_db, FALSE, rete_node_struct::first_child, soar_module::status_object< T >::get_status(), soar_module::constant_param< T >::get_value(), wme_struct::id, symbol_union::id, left_addition_routines(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, make_mp_bnode_left_unlinked(), smem_param_container::mirroring, MP_BNODE, token_struct::token_a_union::neg, token_struct::negrm_tokens, posneg_node_data_struct::next_from_alpha_mem, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_type, agent_struct::num_wmes_in_rete, soar_module::on, token_struct::parent, POSITIVE_BNODE, rete_node_struct::rete_node_b_union::posneg, remove_from_dll, remove_token_and_subtree(), remove_wme_from_alpha_mem(), wme_struct::right_mems, alpha_mem_struct::right_mems, right_node_activation(), agent_struct::smem_changed_ids, smem_enabled(), agent_struct::smem_ignore_changes, identifier_struct::smem_lti, agent_struct::smem_params, symbol_add_ref(), agent_struct::token_pool, wme_struct::tokens, UNHASHED_MP_BNODE, UNHASHED_POSITIVE_BNODE, and unlink_from_left_mem.

Referenced by do_buffered_wm_changes().

{
right_mem *rm;
alpha_mem *am;
rete_node *node, *next, *child;
token *tok, *left;
{
if ( thisAgent->epmem_db->get_status() == soar_module::connected )
{
_epmem_remove_wme( thisAgent, w );
_epmem_process_ids( thisAgent );
}
}
if ( ( w->id->id.smem_lti ) && ( !thisAgent->smem_ignore_changes ) && smem_enabled( thisAgent ) && ( thisAgent->smem_params->mirroring->get_value() == soar_module::on ) )
{
std::pair< smem_pooled_symbol_set::iterator, bool > insert_result = thisAgent->smem_changed_ids->insert( w->id );
if ( insert_result.second )
{
}
}
/* --- remove w from all_wmes_in_rete --- */
remove_from_dll (thisAgent->all_wmes_in_rete, w, rete_next, rete_prev);
thisAgent->num_wmes_in_rete--;
/* --- remove w from each alpha_mem it's in --- */
while (w->right_mems) {
rm = w->right_mems;
am = rm->am;
/* --- found the alpha memory, first remove the wme from it --- */
remove_wme_from_alpha_mem (thisAgent, rm);
#ifdef DO_ACTIVATION_STATS_ON_REMOVALS
/* --- if doing statistics stuff, then activate each attached node --- */
for (node=am->beta_nodes; node!=NIL; node=next) {
}
#endif
/* --- for left unlinking, then if the alpha memory just went to
zero, left unlink any attached Pos or MP nodes --- */
if (am->right_mems==NIL) {
for (node=am->beta_nodes; node!=NIL; node=next) {
switch (node->node_type) {
break;
case MP_BNODE:
break;
} /* end of switch (node->node_type) */
}
}
}
/* --- tree-based removal of all tokens that involve w --- */
while (w->tokens) {
tok = w->tokens;
node = tok->node;
if (! tok->parent) {
/* Note: parent pointer is NIL only on negative node negrm tokens */
left = tok->a.neg.left_token;
free_with_pool (&thisAgent->token_pool, tok);
if (! left->negrm_tokens) { /* just went to 0, so call children */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,left,NIL);
}
} else {
}
}
}
void restore_postponed_assertions ( agent thisAgent)

Definition at line 1227 of file rete.cpp.

References agent_struct::active_goal, rete_node_struct::b, agent_struct::FIRING_TYPE, symbol_union::id, insert_at_head_of_dll, identifier_struct::ms_i_assertions, agent_struct::ms_i_assertions, identifier_struct::ms_o_assertions, agent_struct::ms_o_assertions, NIL, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, PE_PRODS, agent_struct::postponed_assertions, remove_from_dll, and p_node_data_struct::tentative_assertions.

Referenced by do_preference_phase().

{
while(thisAgent->postponed_assertions) {
ms_change *msc = thisAgent->postponed_assertions;
// get the most recently postponed assertion
remove_from_dll (thisAgent->postponed_assertions, msc, next, prev);
assert (msc != NIL);
// do the reverse of postpone_assertion
assert (thisAgent->active_goal);
if (thisAgent->FIRING_TYPE == PE_PRODS) {
msc, next_in_level, prev_in_level);
insert_at_head_of_dll (thisAgent->ms_o_assertions, msc, next, prev);
} else {
// IE
msc, next_in_level, prev_in_level);
insert_at_head_of_dll (thisAgent->ms_i_assertions, msc, next, prev);
}
}
}
Bool save_rete_net ( agent thisAgent,
FILE *  dest_file,
Bool  use_rete_net_64 
)

Definition at line 7548 of file rete.cpp.

References agent_struct::all_productions_of_type, agent_struct::dummy_top_node, FALSE, JUSTIFICATION_PRODUCTION_TYPE, print(), rete_fs_file, rete_net_64, retesave_alpha_memories(), retesave_children_of_node(), retesave_one_byte(), retesave_string(), retesave_symbol_table(), and TRUE.

{
/* --- make sure there are no justifications present --- */
print (thisAgent, "Internal error: save_rete_net() with justifications present.\n");
return FALSE;
}
rete_fs_file = dest_file;
rete_net_64 = use_rete_net_64;
uint8_t version = use_rete_net_64 ? 4 : 3;
retesave_string ("SoarCompactReteNet\n",dest_file);
retesave_one_byte (version,dest_file); /* format version number */
retesave_symbol_table(thisAgent, dest_file);
retesave_alpha_memories(thisAgent,dest_file);
retesave_children_of_node (thisAgent, thisAgent->dummy_top_node,dest_file);
return TRUE;
}
void xml_match_set ( agent thisAgent,
wme_trace_type  wtt,
ms_trace_type  mst 
)

Definition at line 8660 of file rete.cpp.

References allocate_memory(), rete_node_struct::b, free_memory(), ms_change_struct::goal, match_set_trace::goal, in_ms_trace_same_goal(), ms_change_struct::inst, MISCELLANEOUS_MEM_USAGE, MS_ASSERT, MS_ASSERT_RETRACT, agent_struct::ms_i_assertions, agent_struct::ms_o_assertions, MS_RETRACT, agent_struct::ms_retractions, production_struct::name, ms_change_struct::next, match_set_trace::next, NIL, NONE_WME_TRACE, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, token_struct::parent, instantiation_struct::prod, p_node_data_struct::prod, match_set_trace::sym, ms_change_struct::tok, ms_change_struct::w, token_struct::w, xml_att_val(), xml_begin_tag(), xml_end_tag(), xml_instantiation_with_wmes(), and xml_whole_token().

{
ms_change *msc;
token temp_token;
MS_trace *ms_trace = NIL, *tmp;
/* --- Print assertions --- */
/* REW: begin 09.15.96 */
if (mst == MS_ASSERT_RETRACT || mst == MS_ASSERT) {
//print (thisAgent, "O Assertions:\n");
xml_begin_tag(thisAgent, kOAssertions) ;
for (msc=thisAgent->ms_o_assertions; msc!=NIL; msc=msc->next) {
if(wtt != NONE_WME_TRACE) {
xml_begin_tag(thisAgent, kTagProduction) ;
xml_att_val(thisAgent, kName, msc->p_node->b.p.prod->name) ;
xml_att_val(thisAgent, kGoal, msc->goal) ;
//print_with_symbols (thisAgent, " %y ", msc->p_node->b.p.prod->name);
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
//print_with_symbols(thisAgent, " [%y] ", msc->goal);
/* REW: end 08.20.97 */
temp_token.parent = msc->tok;
temp_token.w = msc->w;
xml_whole_token (thisAgent, &temp_token, wtt);
//print (thisAgent, "\n");
xml_end_tag(thisAgent, kTagProduction) ;
}
else {
/* REW: begin 10.22.97 */
ms_trace, msc->goal))!=NIL) {
/* REW: end 10.22.97 */
tmp->count++;
}
else {
tmp = static_cast<match_set_trace *>(allocate_memory(thisAgent, sizeof(MS_trace), MISCELLANEOUS_MEM_USAGE));
tmp->sym = msc->p_node->b.p.prod->name;
tmp->count = 1;
tmp->next = ms_trace;
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
tmp->goal = msc->goal;
/* REW: end 08.20.97 */
ms_trace = tmp;
}
}
}
if (wtt == NONE_WME_TRACE) {
while (ms_trace) {
xml_begin_tag(thisAgent, kTagProduction) ;
tmp = ms_trace; ms_trace = tmp->next;
xml_att_val(thisAgent, kName, tmp->sym) ;
xml_att_val(thisAgent, kGoal, tmp->goal) ;
if (tmp->count > 1)
xml_att_val(thisAgent, kCount, tmp->count) ; // DJP -- No idea what this count is
//print_with_symbols (thisAgent, " %y ", tmp->sym);
/* REW: begin 08.20.97 */
/* BUG: for now this will print the goal of the first
assertion inspected, even though there can be multiple
assertions at different levels.
See 2.110 in the OPERAND-CHANGE-LOG. */
//print_with_symbols(thisAgent, " [%y] ", tmp->goal);
/* REW: end 08.20.97 */
//if (tmp->count > 1)
// print(thisAgent, "(%d)\n", tmp->count);
//else
// print(thisAgent, "\n");
xml_end_tag(thisAgent, kTagProduction) ;
}
}
xml_end_tag(thisAgent, kOAssertions) ;
}
if (mst == MS_ASSERT_RETRACT || mst == MS_ASSERT) {
//print (thisAgent, "I Assertions:\n");
xml_begin_tag(thisAgent, kIAssertions) ;
for (msc=thisAgent->ms_i_assertions; msc!=NIL; msc=msc->next) {
if(wtt != NONE_WME_TRACE) {
//print_with_symbols (thisAgent, " %y ", msc->p_node->b.p.prod->name);
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
//print_with_symbols(thisAgent, " [%y] ", msc->goal);
xml_begin_tag(thisAgent, kTagProduction) ;
xml_att_val(thisAgent, kName, msc->p_node->b.p.prod->name) ;
xml_att_val(thisAgent, kGoal, msc->goal) ;
/* REW: end 08.20.97 */
temp_token.parent = msc->tok;
temp_token.w = msc->w;
xml_whole_token (thisAgent, &temp_token, wtt);
//print (thisAgent, "\n");
xml_end_tag(thisAgent, kTagProduction) ;
}
else {
/* REW: begin 10.22.97 */
ms_trace, msc->goal))!=NIL) {
/* REW: end 10.22.97 */
tmp->count++;
}
else {
tmp = static_cast<match_set_trace *>(allocate_memory(thisAgent, sizeof(MS_trace),
tmp->sym = msc->p_node->b.p.prod->name;
tmp->count = 1;
tmp->next = ms_trace;
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
tmp->goal = msc->goal;
/* REW: end 08.20.97 */
ms_trace = tmp;
}
}
}
if (wtt == NONE_WME_TRACE) {
while (ms_trace) {
tmp = ms_trace; ms_trace = tmp->next;
xml_begin_tag(thisAgent, kTagProduction) ;
xml_att_val(thisAgent, kName, tmp->sym) ;
xml_att_val(thisAgent, kGoal, tmp->goal) ;
if (tmp->count > 1)
xml_att_val(thisAgent, kCount, tmp->count) ; // DJP -- No idea what this count is
//print_with_symbols (thisAgent, " %y ", tmp->sym);
/* REW: begin 08.20.97 */
/* BUG: for now this will print the goal of the first
assertion inspected, even though there can be multiple
assertions at different levels.
See 2.110 in the OPERAND-CHANGE-LOG. */
//print_with_symbols(thisAgent, " [%y] ", tmp->goal);
/* REW: end 08.20.97 */
//if (tmp->count > 1)
// print(thisAgent, "(%d)\n", tmp->count);
//else
// print(thisAgent, "\n");
xml_end_tag(thisAgent, kTagProduction) ;
}
}
}
xml_end_tag(thisAgent, kIAssertions) ;
/* REW: end 09.15.96 */
if (mst == MS_ASSERT_RETRACT || mst == MS_RETRACT) {
xml_begin_tag(thisAgent, kRetractions) ;
//print (thisAgent, "Retractions:\n");
for (msc=thisAgent->ms_retractions; msc!=NIL; msc=msc->next) {
if(wtt != NONE_WME_TRACE) {
//print (thisAgent, " ");
xml_instantiation_with_wmes (thisAgent, msc->inst, wtt, -1);
//print (thisAgent, "\n");
} else {
if(msc->inst->prod) {
/* REW: begin 10.22.97 */
if((tmp = in_ms_trace_same_goal(msc->inst->prod->name,
ms_trace, msc->goal))!=NIL) {
/* REW: end 10.22.97 */
tmp->count++;
} else {
tmp = static_cast<match_set_trace *>(allocate_memory(thisAgent, sizeof(MS_trace),
tmp->sym = msc->inst->prod->name;
tmp->count = 1;
tmp->next = ms_trace;
/* REW: begin 08.20.97 */
/* Add match goal to the print of the matching production */
tmp->goal = msc->goal;
/* REW: end 08.20.97 */
ms_trace = tmp;
}
}
}
}
if(wtt == NONE_WME_TRACE) {
while (ms_trace) {
tmp = ms_trace; ms_trace = tmp->next;
xml_begin_tag(thisAgent, kTagProduction) ;
xml_att_val(thisAgent, kName, tmp->sym) ;
if (tmp->goal)
xml_att_val(thisAgent, kGoal, tmp->goal) ;
else
xml_att_val(thisAgent, kGoal, "NIL") ;
if (tmp->count > 1)
xml_att_val(thisAgent, kCount, tmp->count) ; // DJP -- No idea what this count is
//print_with_symbols (thisAgent, " %y ", tmp->sym);
/* REW: begin 08.20.97 */
/* BUG: for now this will print the goal of the first assertion
inspected, even though there can be multiple assertions at
different levels.
See 2.110 in the OPERAND-CHANGE-LOG. */
//if (tmp->goal)
// print_with_symbols(thisAgent, " [%y] ", tmp->goal);
//else
// print(thisAgent, " [NIL] ");
/* REW: end 08.20.97 */
//if(tmp->count > 1)
// print(thisAgent, "(%d)\n", tmp->count);
//else
// print(thisAgent, "\n");
xml_end_tag(thisAgent, kTagProduction) ;
}
}
}
}
void xml_partial_match_information ( agent thisAgent,
rete_node p_node,
wme_trace_type  wtt 
)

Definition at line 8988 of file rete.cpp.

References deallocate_condition_list(), deallocate_token_list(), agent_struct::dummy_top_node, get_all_left_tokens_emerging_from_node(), token_struct::next_of_node, NIL, NONE_WME_TRACE, p_node_to_conditions_and_nots(), rete_node_struct::parent, print(), xml_att_val(), xml_aux(), xml_begin_tag(), xml_end_tag(), and xml_whole_token().

{
condition *top_cond, *bottom_cond;
int64_t n;
token *tokens, *t;
xml_begin_tag(thisAgent, kTagProduction) ;
p_node_to_conditions_and_nots (thisAgent, p_node, NIL, NIL, &top_cond, &bottom_cond,
NIL, NIL);
n = xml_aux (thisAgent, p_node->parent, thisAgent->dummy_top_node, bottom_cond,
wtt, 0);
xml_att_val(thisAgent, kMatches, n) ;
//print (thisAgent, "\n%d complete matches.\n", n);
if (n && (wtt!=NONE_WME_TRACE)) {
print (thisAgent, "*** Complete Matches ***\n");
tokens = get_all_left_tokens_emerging_from_node (thisAgent, p_node->parent);
for (t=tokens; t!=NIL; t=t->next_of_node) {
xml_whole_token (thisAgent, t, wtt);
//print (thisAgent, "\n");
}
deallocate_token_list (thisAgent, tokens);
}
deallocate_condition_list (thisAgent, top_cond);
xml_end_tag(thisAgent, kTagProduction) ;
}