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 | Variables
rete.cpp File Reference
#include <portability.h>
#include <stdlib.h>
#include "rete.h"
#include "kernel.h"
#include "mem.h"
#include "wmem.h"
#include "gdatastructs.h"
#include "explain.h"
#include "symtab.h"
#include "agent.h"
#include "print.h"
#include "production.h"
#include "init_soar.h"
#include "instantiations.h"
#include "rhsfun.h"
#include "lexer.h"
#include "xml.h"
#include "soar_TraceNames.h"
#include "reinforcement_learning.h"
#include "episodic_memory.h"
#include "semantic_memory.h"
#include "utilities.h"
#include "assert.h"
#include <sstream>

Go to the source code of this file.

Data Structures

struct  alpha_mem_struct
struct  beta_memory_node_data_struct
struct  cn_node_data_struct
struct  match_set_trace
struct  node_varnames_struct
struct  non_pos_node_data_struct
struct  p_node_data_struct
struct  pos_node_data_struct
struct  posneg_node_data_struct
union  rete_node_struct::rete_node_a_union
union  rete_node_struct::rete_node_b_union
struct  rete_node_struct
union  rete_test_struct::rete_test_data_union
struct  rete_test_struct
struct  right_mem_struct
struct  three_field_varnames_struct
struct  var_location_struct
union  node_varnames_struct::varname_data_union

Macros

#define activation_entry_sanity_check()   {}
#define activation_exit_sanity_check()   {}
#define adjust_sharing_factors_from_here_to_top(node, delta)   {}
#define CN_BNODE   0x42
#define CN_PARTNER_BNODE   0x43
#define CONSTANT_RELATIONAL_RETE_TEST   0x00
#define discard_chunk_varnames   TRUE
#define DISJUNCTION_RETE_TEST   0x20
#define DUMMY_MATCHES_BNODE   0x41
#define DUMMY_TOP_BNODE   0x40
#define EQUAL_TEST_TYPE   254
#define ERROR_TEST_TYPE   255
#define ertr   error_rete_test_routine
#define I_LIST   1 /* values for prod->OPERAND_which_assert_list */
#define ID_IS_GOAL_RETE_TEST   0x30
#define ID_IS_IMPASSE_RETE_TEST   0x31
#define init_sharing_stats_for_new_node(node)   {}
#define LEFT_HT_MASK   (LEFT_HT_SIZE - 1)
#define LEFT_HT_SIZE   (1 << LOG2_LEFT_HT_SIZE)
#define LOG2_LEFT_HT_SIZE   14
#define LOG2_RIGHT_HT_SIZE   14
#define MATCH_COUNT_STRING_BUFFER_SIZE   20
#define MEMORY_BNODE   0x03
#define MP_BNODE   0x07
#define NEGATIVE_BNODE   0x09
#define null_activation_stats_for_left_activation(node)   {}
#define null_activation_stats_for_right_activation(node)   {}
#define numcmp(x, y)   (((x) < (y)) ? -1 : (((x) > (y)) ? 1 : 0))
#define O_LIST   0 /* moved here from soarkernel.h. only used in rete.cpp */
#define P_BNODE   0x44
#define POSITIVE_BNODE   0x15
#define print_null_activation_stats()   {}
#define RELATIONAL_EQUAL_RETE_TEST   0x00
#define RELATIONAL_GREATER_OR_EQUAL_RETE_TEST   0x05
#define RELATIONAL_GREATER_RETE_TEST   0x03
#define RELATIONAL_LESS_OR_EQUAL_RETE_TEST   0x04
#define RELATIONAL_LESS_RETE_TEST   0x02
#define RELATIONAL_NOT_EQUAL_RETE_TEST   0x01
#define RELATIONAL_SAME_TYPE_RETE_TEST   0x06
#define relink_to_left_mem(node)
#define RIGHT_HT_MASK   (RIGHT_HT_SIZE - 1)
#define RIGHT_HT_SIZE   (1 << LOG2_RIGHT_HT_SIZE)
#define set_sharing_factor(node, sf)   {}
#define token_added(node)   {}
#define UNHASHED_MEMORY_BNODE   0x02
#define UNHASHED_MP_BNODE   0x06
#define UNHASHED_NEGATIVE_BNODE   0x08
#define UNHASHED_POSITIVE_BNODE   0x14
#define unlink_from_left_mem(node)
#define unlink_from_right_mem(node)
#define VARIABLE_RELATIONAL_RETE_TEST   0x10
#define XML_CONDITION_LIST_TEMP_SIZE   10000

Typedefs

typedef struct alpha_mem_struct alpha_mem
typedef struct
beta_memory_node_data_struct 
beta_memory_node_data
typedef struct cn_node_data_struct cn_node_data
typedef struct match_set_trace MS_trace
typedef struct node_varnames_struct node_varnames
typedef struct
non_pos_node_data_struct 
non_pos_node_data
typedef struct p_node_data_struct p_node_data
typedef struct pos_node_data_struct pos_node_data
typedef struct
posneg_node_data_struct 
posneg_node_data
typedef struct rete_node_struct rete_node
typedef unsigned short rete_node_level
typedef struct rete_test_struct rete_test
typedef struct right_mem_struct right_mem
typedef struct
three_field_varnames_struct 
three_field_varnames
typedef struct var_location_struct var_location
typedef char varnames

Functions

void _epmem_process_ids (agent *my_agent)
void _epmem_remove_wme (agent *my_agent, wme *w)
void add_gensymmed_equality_test (agent *thisAgent, test *t, char first_letter)
void add_hash_info_to_id_test (agent *thisAgent, condition *cond, byte field_num, rete_node_level levels_up)
byte add_production_to_rete (agent *thisAgent, production *p, condition *lhs_top, instantiation *refracted_inst, Bool warn_on_duplicates, Bool ignore_rhs)
void add_rete_test_list_to_tests (agent *thisAgent, condition *cond, rete_test *rt)
void add_rete_tests_for_test (agent *thisAgent, test t, rete_node_level current_depth, byte field_num, rete_test **rt, Symbol **alpha_constant)
varnamesadd_unbound_varnames_in_test (agent *thisAgent, test t, varnames *starting_vn)
varnamesadd_var_to_varnames (agent *thisAgent, Symbol *var, varnames *old_varnames)
void add_varnames_to_test (agent *thisAgent, varnames *vn, test *t)
void add_wme_to_aht (agent *thisAgent, hash_table *ht, uint32_t hash_value, wme *w)
void add_wme_to_alpha_mem (agent *thisAgent, wme *w, alpha_mem *am)
void add_wme_to_rete (agent *thisAgent, wme *w)
uint32_t alpha_hash_value (Symbol *i, Symbol *a, Symbol *v, short num_bits)
Bool any_assertions_or_retractions_ready (agent *thisAgent)
Bool any_i_assertions_or_retractions_ready (agent *thisAgent)
void beta_memory_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void bind_variables_in_test (agent *thisAgent, test t, rete_node_level depth, byte field_num, Bool dense, list **varlist)
byte bnode_is_bottom_of_split_mp (byte x)
byte bnode_is_hashed (byte x)
byte bnode_is_memory (byte x)
byte bnode_is_negative (byte x)
byte bnode_is_positive (byte x)
byte bnode_is_posneg (byte x)
 Bool ((*(rete_test_routines[256]))(agent *thisAgent, rete_test *rt, token *left, wme *w))
void build_network_for_condition_list (agent *thisAgent, condition *cond_list, rete_node_level depth_of_first_cond, rete_node *parent, rete_node **dest_bottom_node, rete_node_level *dest_bottom_depth, list **dest_vars_bound)
void cn_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void cn_partner_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void collect_nots (agent *thisAgent, rete_test *rt, wme *right_wme, condition *cond, not_struct *&nots_found_in_production)
int64_t compare_symbols (Symbol *s1, Symbol *s2)
Bool constant_equal_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
Bool constant_greater_or_equal_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
Bool constant_greater_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
Bool constant_less_or_equal_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
Bool constant_less_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
Bool constant_not_equal_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
Bool constant_same_type_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
void consume_last_postponed_assertion (agent *thisAgent)
actioncopy_action_list_and_substitute_varnames (agent *thisAgent, action *actions, condition *cond)
rhs_value copy_rhs_value_and_substitute_varnames (agent *thisAgent, rhs_value rv, condition *cond, char first_letter)
uint64_t count_rete_tokens_for_production (agent *thisAgent, production *prod)
void deallocate_node_varnames (agent *thisAgent, rete_node *node, rete_node *cutoff, node_varnames *nvn)
void deallocate_rete_node (agent *thisAgent, rete_node *node)
void deallocate_rete_test_list (agent *thisAgent, rete_test *rt)
void deallocate_token_list (agent *thisAgent, token *t)
void deallocate_varnames (agent *thisAgent, varnames *vn)
Bool disjunction_rete_test_routine (agent *, rete_test *rt, token *, wme *w)
void dummy_matches_node_left_addition (agent *thisAgent, rete_node *, token *tok, wme *w)
rete_node_level dummy_to_varloc_depth (void *d)
byte dummy_to_varloc_field_num (void *d)
Bool error_rete_test_routine (agent *thisAgent, rete_test *rt, token *left, wme *w)
void excise_production_from_rete (agent *thisAgent, production *p)
Bool extract_rete_test_to_hash_with (agent *thisAgent, rete_test **rt, var_location *dest_hash_loc)
Symbolfield_from_wme (wme *_wme, byte field_num)
alpha_memfind_alpha_mem (agent *thisAgent, Symbol *id, Symbol *attr, Symbol *value, Bool acceptable)
Symbolfind_goal_for_match_set_change_assertion (agent *thisAgent, ms_change *msc)
Symbolfind_goal_for_match_set_change_retraction (ms_change *msc)
alpha_memfind_or_make_alpha_mem (agent *thisAgent, Symbol *id, Symbol *attr, Symbol *value, Bool acceptable)
Bool find_var_location (Symbol *var, rete_node_level current_depth, var_location *result)
void fixup_rhs_value_variable_references (agent *thisAgent, rhs_value *rv, rete_node_level bottom_depth, list *&rhs_unbound_vars_for_new_prod, uint64_t &num_rhs_unbound_vars_for_new_prod, tc_number rhs_unbound_vars_tc)
tokenget_all_left_tokens_emerging_from_node (agent *thisAgent, rete_node *node)
void get_all_node_count_stats (agent *thisAgent)
uint32_t get_next_alpha_mem_id (agent *thisAgent)
uint32_t get_next_beta_node_id (agent *thisAgent)
Bool get_next_nil_goal_retraction (agent *thisAgent, instantiation **inst)
Bool get_next_retraction (agent *thisAgent, instantiation **inst)
int get_node_count_statistic (agent *thisAgent, char *node_type_name, char *column_name, uint64_t *result)
node_varnamesget_nvn_for_condition_list (agent *thisAgent, condition *cond_list, node_varnames *parent_nvn)
Symbolget_symbol_from_rete_loc (unsigned short levels_up, byte field_num, token *tok, wme *w)
uint32_t hash_alpha_mem (void *item, short num_bits)
Bool id_is_goal_rete_test_routine (agent *, rete_test *, token *, wme *w)
Bool id_is_impasse_rete_test_routine (agent *, rete_test *, token *, wme *w)
MS_tracein_ms_trace (Symbol *sym, MS_trace *trace)
MS_tracein_ms_trace_same_goal (Symbol *sym, MS_trace *trace, Symbol *goal)
void init_bnode_type_names (agent *)
void init_dummy_top_node (agent *thisAgent)
void init_left_and_right_addition_routines ()
void init_new_rete_node_with_type (agent *thisAgent, rete_node *node, byte type)
void init_rete (agent *thisAgent)
void init_test_type_conversion_tables (void)
void insert_token_into_left_ht (agent *thisAgent, token *tok, uint32_t hv)
byte kind_of_relational_test (byte x)
void left_addition_routines (agent *thisAgent, rete_node *node, token *tok, wme *w)
token *& left_ht_bucket (agent *thisAgent, uint32_t hv)
void left_node_activation (rete_node *node, Bool)
Bool load_rete_net (agent *thisAgent, FILE *source_file)
void make_mp_bnode_left_linked (rete_node *node)
void make_mp_bnode_left_unlinked (rete_node *node)
rete_nodemake_new_cn_node (agent *thisAgent, rete_node *parent, rete_node *bottom_of_subconditions)
rete_nodemake_new_mem_node (agent *thisAgent, rete_node *parent, byte node_type, var_location left_hash_loc)
rete_nodemake_new_mp_node (agent *thisAgent, rete_node *parent, byte node_type, var_location left_hash_loc, alpha_mem *am, rete_test *rt, Bool prefer_left_unlinking)
rete_nodemake_new_negative_node (agent *thisAgent, rete_node *parent, byte node_type, var_location left_hash_loc, alpha_mem *am, rete_test *rt)
rete_nodemake_new_positive_node (agent *thisAgent, rete_node *parent_mem, byte node_type, alpha_mem *am, rete_test *rt, Bool prefer_left_unlinking)
rete_nodemake_new_production_node (agent *thisAgent, rete_node *parent, production *new_prod)
rete_nodemake_node_for_negative_cond (agent *thisAgent, condition *cond, rete_node_level current_depth, rete_node *parent)
rete_nodemake_node_for_positive_cond (agent *thisAgent, condition *cond, rete_node_level current_depth, rete_node *parent)
node_varnamesmake_nvn_for_posneg_cond (agent *thisAgent, condition *cond, node_varnames *parent_nvn)
void mark_node_as_left_unlinked (rete_node *node)
void mark_node_as_right_unlinked (rete_node *node)
Bool match_left_and_right (agent *thisAgent, rete_test *_rete_test, token *left, wme *w)
rete_nodemerge_into_mp_node (agent *thisAgent, rete_node *mem_node)
unsigned mp_bnode_is_left_unlinked (rete_node *node)
void mp_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void mp_node_right_addition (agent *thisAgent, rete_node *node, wme *w)
rete_nodenearest_ancestor_with_same_am (rete_node *node, alpha_mem *am)
void negative_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void negative_node_right_addition (agent *thisAgent, rete_node *node, wme *w)
void new_left_token (token *New, rete_node *current_node, token *parent_tok, wme *parent_wme)
uint64_t node_is_left_unlinked (rete_node *node)
uint64_t node_is_right_unlinked (rete_node *node)
varnamesone_var_to_varnames (Symbol *x)
void p_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void p_node_left_removal (agent *thisAgent, rete_node *node, token *tok, wme *w)
void p_node_to_conditions_and_nots (agent *thisAgent, rete_node *p_node, token *tok, wme *w, condition **dest_top_cond, condition **dest_bottom_cond, not_struct **dest_nots, action **dest_rhs)
void pop_bindings_and_deallocate_list_of_variables (agent *thisAgent, list *vars)
void pop_var_binding (agent *thisAgent, void *v)
void positive_node_left_addition (agent *thisAgent, rete_node *node, token *New, Symbol *hash_referent)
void positive_node_right_addition (agent *thisAgent, rete_node *node, wme *w)
Bool postpone_assertion (agent *thisAgent, production **prod, struct token_struct **tok, wme **w)
int64_t ppmi_aux (agent *thisAgent, rete_node *node, rete_node *cutoff, condition *cond, wme_trace_type wtt, int indent)
void print_assertion (agent *thisAgent, ms_change *msc)
void print_match_set (agent *thisAgent, wme_trace_type wtt, ms_trace_type mst)
void print_partial_match_information (agent *thisAgent, rete_node *p_node, wme_trace_type wtt)
void print_retraction (agent *thisAgent, ms_change *msc)
void print_whole_token (agent *thisAgent, token *t, wme_trace_type wtt)
void push_var_binding (agent *thisAgent, Symbol *v, rete_node_level depth, byte field_num)
rete_nodereal_parent_node (rete_node *x)
void relink_to_right_mem (rete_node *node)
void remove_node_from_parents_list_of_children (rete_node *node)
void remove_ref_to_alpha_mem (agent *thisAgent, alpha_mem *am)
void remove_token_and_subtree (agent *thisAgent, token *tok)
void remove_token_from_left_ht (agent *thisAgent, token *tok, uint32_t hv)
void remove_wme_from_alpha_mem (agent *thisAgent, right_mem *rm)
void remove_wme_from_rete (agent *thisAgent, wme *w)
void restore_postponed_assertions (agent *thisAgent)
void rete_error_left (agent *thisAgent, rete_node *node, token *, wme *)
void rete_error_right (agent *thisAgent, rete_node *node, wme *)
void rete_node_to_conditions (agent *thisAgent, rete_node *node, node_varnames *nvn, rete_node *cutoff, token *tok, wme *w, condition *conds_for_cutoff_and_up, condition **dest_top_cond, condition **dest_bottom_cond, not_struct *&nots_found_in_production)
Bool rete_test_lists_are_identical (agent *thisAgent, rete_test *rt1, rete_test *rt2)
actionreteload_action_list (agent *thisAgent, FILE *f)
void reteload_all_symbols (agent *thisAgent, FILE *f)
void reteload_alpha_memories (agent *thisAgent, FILE *f)
alpha_memreteload_am_from_index (agent *thisAgent, FILE *f)
uint64_t reteload_eight_bytes (FILE *f)
uint32_t reteload_four_bytes (FILE *f)
void reteload_free_am_table (agent *thisAgent)
void reteload_free_symbol_table (agent *thisAgent)
void reteload_node_and_children (agent *thisAgent, rete_node *parent, FILE *f)
node_varnamesreteload_node_varnames (agent *thisAgent, rete_node *node, FILE *f)
uint8_t reteload_one_byte (FILE *f)
rete_testreteload_rete_test (agent *thisAgent, FILE *f)
rete_testreteload_rete_test_list (agent *thisAgent, FILE *f)
actionreteload_rhs_action (agent *thisAgent, FILE *f)
rhs_value reteload_rhs_value (agent *thisAgent, FILE *f)
void reteload_string (FILE *f)
Symbolreteload_symbol_from_index (agent *thisAgent, FILE *f)
uint16_t reteload_two_bytes (FILE *f)
varnamesreteload_varnames (agent *thisAgent, FILE *f)
void retesave_action_list (action *first_a, FILE *f)
Bool retesave_alpha_mem_and_assign_index (agent *thisAgent, void *item, void *userdata)
void retesave_alpha_memories (agent *thisAgent, FILE *f)
void retesave_children_of_node (agent *thisAgent, rete_node *node, FILE *f)
void retesave_eight_bytes (uint64_t w, FILE *f)
void retesave_four_bytes (uint32_t w, FILE *f)
void retesave_node_varnames (node_varnames *nvn, rete_node *node, FILE *f)
void retesave_one_byte (uint8_t b, FILE *)
void retesave_rete_node_and_children (agent *thisAgent, rete_node *node, FILE *f)
void retesave_rete_test (rete_test *rt, FILE *f)
void retesave_rete_test_list (rete_test *first_rt, FILE *f)
void retesave_rhs_action (action *a, FILE *f)
void retesave_rhs_value (rhs_value rv, FILE *f)
void retesave_string (const char *s, FILE *f)
Bool retesave_symbol_and_assign_index (agent *thisAgent, void *item, void *userdata)
void retesave_symbol_table (agent *thisAgent, FILE *f)
void retesave_two_bytes (uint16_t w, FILE *f)
void retesave_varnames (varnames *names, FILE *f)
void right_addition_routines (agent *thisAgent, rete_node *node, wme *w)
right_memright_ht_bucket (agent *thisAgent, uint32_t hv)
void right_node_activation (rete_node *node, Bool)
Bool same_rhs (action *rhs1, action *rhs2, bool rl_chunk_stop)
Bool save_rete_net (agent *thisAgent, FILE *dest_file, Bool use_rete_net_64)
Bool single_rete_tests_are_identical (agent *thisAgent, rete_test *rt1, rete_test *rt2)
rete_nodesplit_mp_node (agent *thisAgent, rete_node *mp_node)
hash_tabletable_for_tests (agent *thisAgent, Symbol *id, Symbol *attr, Symbol *value, Bool acceptable)
Bool test_is_constant_relational_test (byte x)
Bool test_is_not_equal_test (byte x)
Bool test_is_variable_relational_test (byte x)
void unhashed_beta_memory_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void unhashed_mp_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void unhashed_mp_node_right_addition (agent *thisAgent, rete_node *node, wme *w)
void unhashed_negative_node_left_addition (agent *thisAgent, rete_node *node, token *tok, wme *w)
void unhashed_negative_node_right_addition (agent *thisAgent, rete_node *node, wme *w)
void unhashed_positive_node_left_addition (agent *thisAgent, rete_node *node, token *New)
void unhashed_positive_node_right_addition (agent *thisAgent, rete_node *node, wme *w)
void update_max_rhs_unbound_variables (agent *thisAgent, uint64_t num_for_new_production)
void update_node_with_matches_from_above (agent *thisAgent, rete_node *child)
void update_stats_for_destroying_node (agent *thisAgent, rete_node *node)
Symbolvar_bound_in_reconstructed_conds (agent *thisAgent, condition *cond, byte where_field_num, rete_node_level where_levels_up)
bool var_is_bound (Symbol *v)
varnamesvar_list_to_varnames (cons *x)
Bool var_locations_equal (var_location v1, var_location v2)
Bool variable_equal_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
Bool variable_greater_or_equal_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
Bool variable_greater_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
Bool variable_less_or_equal_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
Bool variable_less_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
Bool variable_not_equal_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
Bool variable_same_type_rete_test_routine (agent *, rete_test *rt, token *left, wme *w)
void * varloc_to_dummy (rete_node_level depth, byte field_num)
Bool varnames_is_one_var (varnames *x)
uint64_t varnames_is_var_list (varnames *x)
Symbolvarnames_to_one_var (varnames *x)
listvarnames_to_var_list (varnames *x)
Bool wme_matches_alpha_mem (wme *w, alpha_mem *am)
int64_t xml_aux (agent *thisAgent, rete_node *node, rete_node *cutoff, condition *cond, wme_trace_type wtt, int indent)
void xml_condition (agent *thisAgent, condition *cond)
void xml_condition_list (agent *thisAgent, condition *conds, int indent, Bool internal)
void xml_instantiation_with_wmes (agent *thisAgent, instantiation *inst, wme_trace_type wtt, int action)
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)
Bool xml_pick_conds_with_matching_id_test (dl_cons *dc, agent *thisAgent)
void xml_whole_token (agent *thisAgent, token *t, wme_trace_type wtt)
uint32_t xor_op (uint32_t i, uint32_t a, uint32_t v)

Variables

const char * bnode_type_names [256]
byte relational_test_type_to_test_type [256]
FILE * rete_fs_file
Bool rete_net_64
char reteload_string_buf [4 *(1000+5)]
byte test_type_to_relational_test_type [256]

Macro Definition Documentation

#define activation_entry_sanity_check ( )    {}
#define activation_exit_sanity_check ( )    {}
#define adjust_sharing_factors_from_here_to_top (   node,
  delta 
)    {}
#define CN_BNODE   0x42
#define CN_PARTNER_BNODE   0x43
#define CONSTANT_RELATIONAL_RETE_TEST   0x00
#define discard_chunk_varnames   TRUE

Definition at line 120 of file rete.cpp.

Referenced by add_production_to_rete().

#define DISJUNCTION_RETE_TEST   0x20
#define DUMMY_MATCHES_BNODE   0x41
#define DUMMY_TOP_BNODE   0x40
#define EQUAL_TEST_TYPE   254

Definition at line 2935 of file rete.cpp.

Referenced by add_rete_test_list_to_tests(), and init_test_type_conversion_tables().

#define ERROR_TEST_TYPE   255

Definition at line 2936 of file rete.cpp.

#define ertr   error_rete_test_routine

Definition at line 4598 of file rete.cpp.

#define I_LIST   1 /* values for prod->OPERAND_which_assert_list */

Definition at line 411 of file rete.cpp.

Referenced by p_node_left_addition(), and p_node_left_removal().

#define ID_IS_GOAL_RETE_TEST   0x30
#define ID_IS_IMPASSE_RETE_TEST   0x31
#define init_sharing_stats_for_new_node (   node)    {}

Definition at line 877 of file rete.cpp.

Referenced by init_new_rete_node_with_type().

#define LEFT_HT_MASK   (LEFT_HT_SIZE - 1)

Definition at line 654 of file rete.cpp.

Referenced by insert_token_into_left_ht(), and left_ht_bucket().

#define LEFT_HT_SIZE   (1 << LOG2_LEFT_HT_SIZE)

Definition at line 651 of file rete.cpp.

Referenced by init_rete().

#define LOG2_LEFT_HT_SIZE   14

Definition at line 648 of file rete.cpp.

#define LOG2_RIGHT_HT_SIZE   14

Definition at line 649 of file rete.cpp.

#define MATCH_COUNT_STRING_BUFFER_SIZE   20

Referenced by ppmi_aux().

#define MEMORY_BNODE   0x03
#define MP_BNODE   0x07
#define NEGATIVE_BNODE   0x09
#define null_activation_stats_for_left_activation (   node)    {}

Definition at line 820 of file rete.cpp.

Referenced by left_node_activation().

#define null_activation_stats_for_right_activation (   node)    {}

Definition at line 819 of file rete.cpp.

Referenced by right_node_activation().

#define numcmp (   x,
 
)    (((x) < (y)) ? -1 : (((x) > (y)) ? 1 : 0))

Definition at line 4653 of file rete.cpp.

Referenced by compare_symbols().

#define O_LIST   0 /* moved here from soarkernel.h. only used in rete.cpp */

Definition at line 410 of file rete.cpp.

Referenced by p_node_left_addition(), and p_node_left_removal().

#define P_BNODE   0x44
#define POSITIVE_BNODE   0x15
#define print_null_activation_stats ( )    {}

Definition at line 821 of file rete.cpp.

#define RELATIONAL_EQUAL_RETE_TEST   0x00
#define RELATIONAL_GREATER_OR_EQUAL_RETE_TEST   0x05

Definition at line 242 of file rete.cpp.

Referenced by init_rete(), and init_test_type_conversion_tables().

#define RELATIONAL_GREATER_RETE_TEST   0x03

Definition at line 240 of file rete.cpp.

Referenced by init_rete(), and init_test_type_conversion_tables().

#define RELATIONAL_LESS_OR_EQUAL_RETE_TEST   0x04

Definition at line 241 of file rete.cpp.

Referenced by init_rete(), and init_test_type_conversion_tables().

#define RELATIONAL_LESS_RETE_TEST   0x02

Definition at line 239 of file rete.cpp.

Referenced by init_rete(), and init_test_type_conversion_tables().

#define RELATIONAL_NOT_EQUAL_RETE_TEST   0x01
#define RELATIONAL_SAME_TYPE_RETE_TEST   0x06

Definition at line 243 of file rete.cpp.

Referenced by init_rete(), and init_test_type_conversion_tables().

#define relink_to_left_mem (   node)
Value:
{ \
insert_at_head_of_dll ((node)->parent->b.mem.first_linked_child, (node), \
a.pos.next_from_beta_mem, \
a.pos.prev_from_beta_mem); }

Definition at line 566 of file rete.cpp.

Referenced by make_new_positive_node(), positive_node_right_addition(), split_mp_node(), and unhashed_positive_node_right_addition().

#define RIGHT_HT_MASK   (RIGHT_HT_SIZE - 1)

Definition at line 655 of file rete.cpp.

Referenced by add_wme_to_alpha_mem(), remove_wme_from_alpha_mem(), and right_ht_bucket().

#define RIGHT_HT_SIZE   (1 << LOG2_RIGHT_HT_SIZE)

Definition at line 652 of file rete.cpp.

Referenced by init_rete().

#define set_sharing_factor (   node,
  sf 
)    {}

Definition at line 878 of file rete.cpp.

Referenced by merge_into_mp_node(), split_mp_node(), and update_stats_for_destroying_node().

#define token_added (   node)    {}
#define UNHASHED_MEMORY_BNODE   0x02
#define UNHASHED_MP_BNODE   0x06
#define UNHASHED_NEGATIVE_BNODE   0x08
#define UNHASHED_POSITIVE_BNODE   0x14
#define unlink_from_left_mem (   node)
Value:
{ \
remove_from_dll ((node)->parent->b.mem.first_linked_child, (node), \
a.pos.next_from_beta_mem, \
a.pos.prev_from_beta_mem); \
mark_node_as_left_unlinked(node); }

Definition at line 574 of file rete.cpp.

Referenced by deallocate_rete_node(), make_new_positive_node(), positive_node_left_addition(), remove_wme_from_rete(), split_mp_node(), and unhashed_positive_node_left_addition().

#define unlink_from_right_mem (   node)
Value:
{ \
if ((node)->b.posneg.next_from_alpha_mem == NIL) \
(node)->b.posneg.alpha_mem_->last_beta_node = \
(node)->b.posneg.prev_from_alpha_mem; \
remove_from_dll ((node)->b.posneg.alpha_mem_->beta_nodes, (node), \
b.posneg.next_from_alpha_mem, \
b.posneg.prev_from_alpha_mem); \
mark_node_as_right_unlinked (node); }

Definition at line 531 of file rete.cpp.

Referenced by deallocate_rete_node(), make_new_negative_node(), make_new_positive_node(), mp_node_right_addition(), positive_node_right_addition(), remove_token_and_subtree(), unhashed_mp_node_right_addition(), and unhashed_positive_node_right_addition().

#define VARIABLE_RELATIONAL_RETE_TEST   0x10
#define XML_CONDITION_LIST_TEMP_SIZE   10000

Definition at line 8390 of file rete.cpp.

Referenced by xml_condition_list().

Typedef Documentation

typedef struct alpha_mem_struct alpha_mem
typedef struct match_set_trace MS_trace
typedef struct rete_node_struct rete_node
typedef unsigned short rete_node_level

Definition at line 259 of file rete.cpp.

typedef struct rete_test_struct rete_test
typedef struct right_mem_struct right_mem
typedef char varnames

Definition at line 2648 of file rete.cpp.

Function Documentation

void _epmem_process_ids ( agent my_agent)
inline

Definition at line 1691 of file rete.cpp.

References _epmem_remove_wme(), slot_struct::acceptable_preference_wmes, identifier_struct::epmem_id, agent_struct::epmem_id_removes, EPMEM_NODEID_BAD, identifier_struct::epmem_valid, agent_struct::epmem_validation, symbol_union::id, IDENTIFIER_SYMBOL_TYPE, identifier_struct::impasse_wmes, identifier_struct::input_wmes, wme_struct::next, slot_struct::next, NIL, identifier_struct::slots, and slot_struct::wmes.

Referenced by remove_wme_from_rete().

{
Symbol* id;
slot* s;
wme* w;
while ( !my_agent->epmem_id_removes->empty() )
{
id = my_agent->epmem_id_removes->front();
my_agent->epmem_id_removes->pop_front();
assert( id->common.symbol_type == IDENTIFIER_SYMBOL_TYPE );
if ( ( id->id.epmem_id != EPMEM_NODEID_BAD ) && ( id->id.epmem_valid == my_agent->epmem_validation ) )
{
// invalidate identifier encoding
id->id.epmem_id = EPMEM_NODEID_BAD;
id->id.epmem_valid = NIL;
// impasse wmes
for ( w=id->id.impasse_wmes; w!=NIL; w=w->next )
{
_epmem_remove_wme( my_agent, w );
}
// input wmes
for ( w=id->id.input_wmes; w!=NIL; w=w->next )
{
_epmem_remove_wme( my_agent, w );
}
// regular wmes
for ( s=id->id.slots; s!=NIL; s=s->next )
{
for ( w=s->wmes; w!=NIL; w=w->next )
{
_epmem_remove_wme( my_agent, w );
}
for ( w=s->acceptable_preference_wmes; w!=NIL; w=w->next )
{
_epmem_remove_wme( my_agent, w );
}
}
}
}
}
void _epmem_remove_wme ( agent my_agent,
wme w 
)
inline

Definition at line 1626 of file rete.cpp.

References agent_struct::epmem_edge_removals, wme_struct::epmem_id, identifier_struct::epmem_id, agent_struct::epmem_id_ref_counts, agent_struct::epmem_id_removes, agent_struct::epmem_id_replacement, agent_struct::epmem_node_removals, EPMEM_NODEID_BAD, wme_struct::epmem_valid, identifier_struct::epmem_valid, agent_struct::epmem_validation, symbol_union::id, IDENTIFIER_SYMBOL_TYPE, identifier_struct::level, NIL, identifier_struct::smem_lti, agent_struct::top_state, and wme_struct::value.

Referenced by _epmem_process_ids(), and remove_wme_from_rete().

{
bool was_encoded = false;
if ( w->value->common.symbol_type == IDENTIFIER_SYMBOL_TYPE )
{
bool lti = ( w->value->id.smem_lti != NIL );
if ( ( w->epmem_id != EPMEM_NODEID_BAD ) && ( w->epmem_valid == my_agent->epmem_validation ) )
{
was_encoded = true;
(*my_agent->epmem_edge_removals)[ w->epmem_id ] = true;
// return to the id pool
if ( !lti )
{
epmem_return_id_pool::iterator p = my_agent->epmem_id_replacement->find( w->epmem_id );
(*p->second).push_front( std::make_pair( w->value->id.epmem_id, w->epmem_id ) );
my_agent->epmem_id_replacement->erase( p );
}
}
// reduce the ref count on the value
if ( !lti && ( w->value->id.epmem_id != EPMEM_NODEID_BAD ) && ( w->value->id.epmem_valid == my_agent->epmem_validation ) )
{
epmem_wme_set* my_refs = (*my_agent->epmem_id_ref_counts)[ w->value->id.epmem_id ];
epmem_wme_set::iterator rc_it = my_refs->find( w );
if ( rc_it != my_refs->end() )
{
my_refs->erase( rc_it );
// recurse if no incoming edges from top-state (i.e. not in transitive closure of top-state)
bool recurse = true;
for ( rc_it=my_refs->begin(); ( recurse && rc_it!=my_refs->end() ); rc_it++ )
{
if ( ( !(*rc_it) ) || ( (*rc_it)->id->id.level == my_agent->top_state->id.level ) )
{
recurse = false;
}
}
if ( recurse )
{
my_refs->clear();
my_agent->epmem_id_removes->push_front( w->value );
}
}
}
}
else if ( ( w->epmem_id != EPMEM_NODEID_BAD ) && ( w->epmem_valid == my_agent->epmem_validation ) )
{
was_encoded = true;
(*my_agent->epmem_node_removals)[ w->epmem_id ] = true;
}
if ( was_encoded )
{
}
}
void add_gensymmed_equality_test ( agent thisAgent,
test t,
char  first_letter 
)

Definition at line 4003 of file rete.cpp.

References add_new_test_to_test(), generate_new_variable(), make_equality_test(), and symbol_remove_ref().

Referenced by add_rete_test_list_to_tests(), and rete_node_to_conditions().

{
Symbol *New;
test eq_test;
char prefix[2];
prefix[0] = first_letter;
prefix[1] = 0;
New = generate_new_variable (thisAgent, prefix);
eq_test = make_equality_test (New);
symbol_remove_ref (thisAgent, New);
add_new_test_to_test (thisAgent, t, eq_test);
}
void add_hash_info_to_id_test ( agent thisAgent,
condition cond,
byte  field_num,
rete_node_level  levels_up 
)
byte add_production_to_rete ( agent thisAgent,
production p,
condition lhs_top,
instantiation refracted_inst,
Bool  warn_on_duplicates,
Bool  ignore_rhs 
)

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_rete_test_list_to_tests ( agent thisAgent,
condition cond,
rete_test rt 
)

Definition at line 4071 of file rete.cpp.

References abort_with_fatal_error(), add_gensymmed_equality_test(), add_new_test_to_test(), three_field_tests_struct::attr_test, BUFFER_MSG_SIZE, agent_struct::complex_test_pool, rete_test_struct::rete_test_data_union::constant_referent, copy_symbol_list_adding_references(), rete_test_struct::data, complex_test_struct::data, condition_struct::data, rete_test_struct::rete_test_data_union::disjunction_list, complex_test_struct::test_info_union::disjunction_list, DISJUNCTION_RETE_TEST, DISJUNCTION_TEST, EQUAL_TEST_TYPE, var_location_struct::field_num, first_letter_from_test(), GOAL_ID_TEST, ID_IS_GOAL_RETE_TEST, ID_IS_IMPASSE_RETE_TEST, three_field_tests_struct::id_test, IMPASSE_ID_TEST, kind_of_relational_test(), var_location_struct::levels_up, make_equality_test_without_adding_reference(), make_test_from_complex_test(), rete_test_struct::next, NIL, complex_test_struct::test_info_union::referent, relational_test_type_to_test_type, rete_test_struct::right_field_num, symbol_add_ref(), test_includes_equality_test_for_symbol(), test_is_constant_relational_test(), test_is_variable_relational_test(), condition_struct::condition_main_data_union::tests, rete_test_struct::type, complex_test_struct::type, three_field_tests_struct::value_test, var_bound_in_reconstructed_conds(), and rete_test_struct::rete_test_data_union::variable_referent.

Referenced by rete_node_to_conditions().

{
Symbol *referent;
test New;
complex_test *new_ct;
byte test_type;
for ( ; rt!=NIL; rt=rt->next) {
allocate_with_pool (thisAgent, &thisAgent->complex_test_pool, &new_ct);
new_ct->type = GOAL_ID_TEST;
} else if (rt->type==ID_IS_IMPASSE_RETE_TEST) {
allocate_with_pool (thisAgent, &thisAgent->complex_test_pool, &new_ct);
new_ct->type = IMPASSE_ID_TEST;
} else if (rt->type==DISJUNCTION_RETE_TEST) {
allocate_with_pool (thisAgent, &thisAgent->complex_test_pool, &new_ct);
test_type =
referent = rt->data.constant_referent;
symbol_add_ref (referent);
if (test_type==EQUAL_TEST_TYPE) {
} else {
allocate_with_pool (thisAgent, &thisAgent->complex_test_pool, &new_ct);
new_ct->type = test_type;
new_ct->data.referent = referent;
}
test_type =
/* --- before calling var_bound_in_reconstructed_conds, make sure
there's an equality test in the referent location (add one if
there isn't one already there), otherwise there'd be no variable
there to test against --- */
(cond->data.tests.id_test, NIL))
add_gensymmed_equality_test (thisAgent, &(cond->data.tests.id_test), 's');
} else if (rt->data.variable_referent.field_num==1) {
(cond->data.tests.attr_test, NIL))
add_gensymmed_equality_test (thisAgent, &(cond->data.tests.attr_test), 'a');
} else {
}
}
referent = var_bound_in_reconstructed_conds (thisAgent, cond,
symbol_add_ref (referent);
if (test_type==EQUAL_TEST_TYPE) {
} else {
allocate_with_pool (thisAgent, &thisAgent->complex_test_pool, &new_ct);
new_ct->type = test_type;
new_ct->data.referent = referent;
}
} else {
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "Error: bad test_type in add_rete_test_to_test\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
New = NIL; /* unreachable, but without it gcc -Wall warns here */
}
if (rt->right_field_num==0)
add_new_test_to_test (thisAgent, &(cond->data.tests.id_test), New);
else if (rt->right_field_num==2)
add_new_test_to_test (thisAgent, &(cond->data.tests.value_test), New);
else
add_new_test_to_test (thisAgent, &(cond->data.tests.attr_test), New);
}
}
void add_rete_tests_for_test ( agent thisAgent,
test  t,
rete_node_level  current_depth,
byte  field_num,
rete_test **  rt,
Symbol **  alpha_constant 
)

Definition at line 2984 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, complex_test_from_test(), complex_test_struct::test_info_union::conjunct_list, CONJUNCTIVE_TEST, rete_test_struct::rete_test_data_union::constant_referent, CONSTANT_RELATIONAL_RETE_TEST, copy_symbol_list_adding_references(), rete_test_struct::data, complex_test_struct::data, rete_test_struct::rete_test_data_union::disjunction_list, complex_test_struct::test_info_union::disjunction_list, DISJUNCTION_RETE_TEST, DISJUNCTION_TEST, var_location_struct::field_num, find_var_location(), cons_struct::first, GOAL_ID_TEST, GREATER_OR_EQUAL_TEST, GREATER_TEST, ID_IS_GOAL_RETE_TEST, ID_IS_IMPASSE_RETE_TEST, IMPASSE_ID_TEST, LESS_OR_EQUAL_TEST, LESS_TEST, var_location_struct::levels_up, rete_test_struct::next, NIL, NOT_EQUAL_TEST, print_with_symbols(), complex_test_struct::test_info_union::referent, referent_of_equality_test(), RELATIONAL_EQUAL_RETE_TEST, cons_struct::rest, agent_struct::rete_test_pool, rete_test_struct::right_field_num, SAME_TYPE_TEST, symbol_add_ref(), symbol_to_string(), test_is_blank_or_equality_test(), test_is_blank_test(), test_type_to_relational_test_type, TRUE, rete_test_struct::type, complex_test_struct::type, rete_test_struct::rete_test_data_union::variable_referent, VARIABLE_RELATIONAL_RETE_TEST, and VARIABLE_SYMBOL_TYPE.

Referenced by make_node_for_negative_cond(), and make_node_for_positive_cond().

{
var_location where;
where.var_location_struct::field_num = 0;
where.var_location_struct::levels_up = 0;
cons *c;
rete_test *new_rt;
Symbol *referent;
if (test_is_blank_test(t)) return;
/* --- if constant test and alpha=NIL, install alpha test --- */
if ((referent->common.symbol_type!=VARIABLE_SYMBOL_TYPE) &&
(*alpha_constant==NIL)) {
*alpha_constant = referent;
return;
}
/* --- if constant, make = constant test --- */
if (referent->common.symbol_type!=VARIABLE_SYMBOL_TYPE) {
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = field_num;
new_rt->data.constant_referent = referent;
symbol_add_ref (referent);
new_rt->next = *rt;
*rt = new_rt;
return;
}
/* --- variable: if binding is for current field, do nothing --- */
if (! find_var_location (referent, current_depth, &where)) {
char msg[BUFFER_MSG_SIZE];
print_with_symbols (thisAgent, "Error: Rete build found test of unbound var: %y\n",
referent);
SNPRINTF (msg, BUFFER_MSG_SIZE, "Error: Rete build found test of unbound var: %s\n",
symbol_to_string(thisAgent, referent,TRUE, NIL, 0));
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
if ((where.levels_up==0) && (where.field_num==field_num)) return;
/* --- else make variable equality test --- */
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = field_num;
new_rt->data.variable_referent = where;
new_rt->next = *rt;
*rt = new_rt;
return;
}
switch (ct->type) {
case LESS_TEST:
/* --- if constant, make constant test --- */
if (ct->data.referent->common.symbol_type!=VARIABLE_SYMBOL_TYPE) {
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = field_num;
new_rt->next = *rt;
*rt = new_rt;
return;
}
/* --- else make variable test --- */
if (! find_var_location (ct->data.referent, current_depth, &where)) {
char msg[BUFFER_MSG_SIZE];
print_with_symbols (thisAgent, "Error: Rete build found test of unbound var: %y\n",
ct->data.referent);
SNPRINTF (msg, BUFFER_MSG_SIZE, "Error: Rete build found test of unbound var: %s\n",
symbol_to_string(thisAgent, ct->data.referent,TRUE, NIL, 0));
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = field_num;
new_rt->data.variable_referent = where;
new_rt->next = *rt;
*rt = new_rt;
return;
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = field_num;
new_rt->next = *rt;
*rt = new_rt;
return;
for (c=ct->data.conjunct_list; c!=NIL; c=c->rest) {
add_rete_tests_for_test (thisAgent, static_cast<char *>(c->first),
current_depth, field_num, rt, alpha_constant);
}
return;
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = 0;
new_rt->next = *rt;
*rt = new_rt;
return;
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &new_rt);
new_rt->right_field_num = 0;
new_rt->next = *rt;
*rt = new_rt;
return;
default:
{ char msg[BUFFER_MSG_SIZE];
SNPRINTF (msg, BUFFER_MSG_SIZE,"Error: found bad test type %d while building rete\n",
ct->type);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
} /* end of switch statement */
} /* end of function add_rete_tests_for_test() */
varnames* add_unbound_varnames_in_test ( agent thisAgent,
test  t,
varnames starting_vn 
)

Definition at line 2750 of file rete.cpp.

References add_var_to_varnames(), complex_test_from_test(), complex_test_struct::test_info_union::conjunct_list, CONJUNCTIVE_TEST, complex_test_struct::data, cons_struct::first, NIL, referent_of_equality_test(), cons_struct::rest, test_is_blank_or_equality_test(), test_is_blank_test(), complex_test_struct::type, var_is_bound(), and VARIABLE_SYMBOL_TYPE.

Referenced by make_nvn_for_posneg_cond().

{
cons *c;
Symbol *referent;
if (test_is_blank_test(t)) return starting_vn;
if (referent->common.symbol_type==VARIABLE_SYMBOL_TYPE)
if (! var_is_bound (referent))
starting_vn = add_var_to_varnames (thisAgent, referent, starting_vn);
return starting_vn;
}
if (ct->type==CONJUNCTIVE_TEST) {
for (c=ct->data.conjunct_list; c!=NIL; c=c->rest)
starting_vn = add_unbound_varnames_in_test (thisAgent, static_cast<char *>(c->first),
starting_vn);
}
return starting_vn;
}
varnames* add_var_to_varnames ( agent thisAgent,
Symbol var,
varnames old_varnames 
)

Definition at line 2680 of file rete.cpp.

References allocate_cons(), cons_struct::first, NIL, one_var_to_varnames(), cons_struct::rest, symbol_add_ref(), var_list_to_varnames(), varnames_is_one_var(), varnames_to_one_var(), and varnames_to_var_list().

Referenced by add_unbound_varnames_in_test().

{
cons *c1, *c2;
if (old_varnames == NIL)
return one_var_to_varnames(var);
if (varnames_is_one_var(old_varnames)) {
allocate_cons (thisAgent, &c1);
allocate_cons (thisAgent, &c2);
c1->first = var;
c1->rest = c2;
c2->first = varnames_to_one_var(old_varnames);
c2->rest = NIL;
}
/* --- otherwise old_varnames is a list --- */
allocate_cons (thisAgent, &c1);
c1->first = var;
c1->rest = varnames_to_var_list(old_varnames);
}
void add_varnames_to_test ( agent thisAgent,
varnames vn,
test t 
)

Definition at line 4233 of file rete.cpp.

References add_new_test_to_test(), cons_struct::first, make_equality_test(), NIL, cons_struct::rest, varnames_is_one_var(), varnames_to_one_var(), and varnames_to_var_list().

Referenced by rete_node_to_conditions().

{
test New;
cons *c;
if (vn == NIL) return;
add_new_test_to_test (thisAgent, t, New);
} else {
for (c=varnames_to_var_list(vn); c!=NIL; c=c->rest) {
New = make_equality_test (static_cast<Symbol *>(c->first));
add_new_test_to_test (thisAgent, t, New);
}
}
}
void add_wme_to_aht ( agent thisAgent,
hash_table ht,
uint32_t  hash_value,
wme w 
)

Definition at line 1526 of file rete.cpp.

References add_wme_to_alpha_mem(), rete_node_struct::b, alpha_mem_struct::beta_nodes, hash_table_struct::buckets, hash_table_struct::log2size, masks_for_n_low_order_bits, posneg_node_data_struct::next_from_alpha_mem, alpha_mem_struct::next_in_hash_table, NIL, rete_node_struct::node_type, rete_node_struct::rete_node_b_union::posneg, right_addition_routines(), and wme_matches_alpha_mem().

Referenced by add_wme_to_rete().

{
alpha_mem *am;
rete_node *node, *next;
hash_value = hash_value & masks_for_n_low_order_bits[ht->log2size];
am = reinterpret_cast<alpha_mem *>(*(ht->buckets+hash_value));
while (am!=NIL) {
if (wme_matches_alpha_mem (w,am)) {
/* --- found the right alpha memory, first add the wme --- */
add_wme_to_alpha_mem (thisAgent, w, am);
/* --- now call the beta nodes --- */
for (node=am->beta_nodes; node!=NIL; node=next) {
(*(right_addition_routines[node->node_type]))(thisAgent,node,w);
}
return; /* only one possible alpha memory per table could match */
}
}
}
void add_wme_to_alpha_mem ( agent thisAgent,
wme w,
alpha_mem am 
)

Definition at line 1412 of file rete.cpp.

References right_mem_struct::am, alpha_mem_struct::am_id, wme_struct::id, insert_at_head_of_dll, agent_struct::right_ht, RIGHT_HT_MASK, agent_struct::right_mem_pool, wme_struct::right_mems, alpha_mem_struct::right_mems, uint32_t(), and right_mem_struct::w.

Referenced by add_wme_to_aht(), and find_or_make_alpha_mem().

{
right_mem **header, *rm;
/* --- allocate new right_mem, fill it fields --- */
allocate_with_pool (thisAgent, &thisAgent->right_mem_pool, &rm);
rm->w = w;
rm->am = am;
/* --- add it to dll's for the hash bucket, alpha mem, and wme --- */
hv = am->am_id ^ w->id->common.hash_id;
header = reinterpret_cast<right_mem **>(thisAgent->right_ht) + (hv & RIGHT_HT_MASK);
insert_at_head_of_dll (*header, rm, next_in_bucket, prev_in_bucket);
insert_at_head_of_dll (am->right_mems, rm, next_in_am, prev_in_am);
}
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 )
{
}
}
}
uint32_t alpha_hash_value ( Symbol i,
Symbol a,
Symbol v,
short  num_bits 
)
inline

Definition at line 1373 of file rete.cpp.

References masks_for_n_low_order_bits.

Referenced by find_alpha_mem(), and hash_alpha_mem().

{
return
( ( (i ? i->common.hash_id : 0) ^
(a ? a->common.hash_id : 0) ^
(v ? v->common.hash_id : 0) ) &
}
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 */
}
Bool any_i_assertions_or_retractions_ready ( agent thisAgent)

Definition at line 1129 of file rete.cpp.

References agent_struct::ms_i_assertions, and agent_struct::ms_retractions.

{
return (thisAgent->ms_i_assertions || thisAgent->ms_retractions);
}
void beta_memory_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 4957 of file rete.cpp.

References token_struct::a, rete_node_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, field_from_wme(), beta_memory_node_data_struct::first_linked_child, token_struct::token_a_union::ht, insert_token_into_left_ht(), rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, left_node_activation(), rete_node_struct::rete_node_b_union::mem, new_left_token(), pos_node_data_struct::next_from_beta_mem, NIL, rete_node_struct::node_id, token_struct::parent, rete_node_struct::rete_node_a_union::pos, positive_node_left_addition(), token_struct::token_a_union::token_in_hash_table_data_struct::referent, token_added, agent_struct::token_pool, TRUE, uint32_t(), and token_struct::w.

Referenced by init_left_and_right_addition_routines().

{
Symbol *referent;
rete_node *child, *next;
token *New;
{
int levels_up;
token *t;
levels_up = node->left_hash_loc_levels_up;
if (levels_up==1) {
referent = field_from_wme (w, node->left_hash_loc_field_num);
} else { /* --- levels_up > 1 --- */
for (t=tok, levels_up -= 2; levels_up!=0; levels_up--) t=t->parent;
referent = field_from_wme (t->w, node->left_hash_loc_field_num);
}
}
hv = node->node_id ^ referent->common.hash_id;
/* --- build new left token, add it to the hash table --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
insert_token_into_left_ht (thisAgent, New, hv);
New->a.ht.referent = referent;
/* --- inform each linked child (positive join) node --- */
for (child=node->b.mem.first_linked_child; child!=NIL; child=next) {
next = child->a.pos.next_from_beta_mem;
positive_node_left_addition (thisAgent, child, New, referent);
}
}
void bind_variables_in_test ( agent thisAgent,
test  t,
rete_node_level  depth,
byte  field_num,
Bool  dense,
list **  varlist 
)
byte bnode_is_bottom_of_split_mp ( byte  x)
inline

Definition at line 348 of file rete.cpp.

Referenced by deallocate_rete_node(), real_parent_node(), and update_node_with_matches_from_above().

{ return ((x) & 0x10); }
byte bnode_is_hashed ( byte  x)
inline

Definition at line 343 of file rete.cpp.

{ return ((x) & 0x01); }
byte bnode_is_memory ( byte  x)
inline

Definition at line 344 of file rete.cpp.

{ return ((x) & 0x02); }
byte bnode_is_negative ( byte  x)
inline

Definition at line 346 of file rete.cpp.

{ return ((x) & 0x08); }
byte bnode_is_positive ( byte  x)
inline

Definition at line 345 of file rete.cpp.

Referenced by p_node_left_addition(), rete_node_to_conditions(), and update_node_with_matches_from_above().

{ return ((x) & 0x04); }
byte bnode_is_posneg ( byte  x)
inline

Definition at line 347 of file rete.cpp.

Referenced by deallocate_rete_node(), and nearest_ancestor_with_same_am().

{ return ((x) & 0x0C); }
Bool ( (*(rete_test_routines[256]))(agent *thisAgent, rete_test *rt, token *left, wme *w)  )
void build_network_for_condition_list ( agent thisAgent,
condition cond_list,
rete_node_level  depth_of_first_cond,
rete_node parent,
rete_node **  dest_bottom_node,
rete_node_level dest_bottom_depth,
list **  dest_vars_bound 
)

Definition at line 3448 of file rete.cpp.

References three_field_tests_struct::attr_test, rete_node_struct::b, bind_variables_in_test(), rete_node_struct::rete_node_b_union::cn, CN_BNODE, CONJUNCTIVE_NEGATION_CONDITION, condition_struct::data, rete_node_struct::first_child, three_field_tests_struct::id_test, make_new_cn_node(), make_node_for_negative_cond(), make_node_for_positive_cond(), condition_struct::condition_main_data_union::ncc, NEGATIVE_CONDITION, condition_struct::next, rete_node_struct::next_sibling, NIL, rete_node_struct::node_type, rete_node_struct::parent, node_varnames_struct::parent, cn_node_data_struct::partner, pop_bindings_and_deallocate_list_of_variables(), POSITIVE_CONDITION, condition_struct::condition_main_data_union::tests, ncc_info_struct::top, TRUE, condition_struct::type, and three_field_tests_struct::value_test.

Referenced by add_production_to_rete().

{
rete_node *node, *new_node, *child, *subconditions_bottom_node;
condition *cond;
rete_node_level current_depth;
list *vars_bound;
node = parent;
current_depth = depth_of_first_cond;
vars_bound = NIL;
for (cond=cond_list; cond!=NIL; cond=cond->next) {
switch (cond->type) {
new_node = make_node_for_positive_cond (thisAgent, cond, current_depth, node);
/* --- Add dense variable bindings for this condition --- */
bind_variables_in_test (thisAgent, cond->data.tests.id_test, current_depth, 0,
TRUE, &vars_bound);
bind_variables_in_test (thisAgent, cond->data.tests.attr_test, current_depth, 1,
TRUE, &vars_bound);
bind_variables_in_test (thisAgent, cond->data.tests.value_test, current_depth, 2,
TRUE, &vars_bound);
break;
new_node = make_node_for_negative_cond (thisAgent, cond, current_depth, node);
break;
/* --- first, make the subconditions part of the rete --- */
build_network_for_condition_list (thisAgent, cond->data.ncc.top, current_depth,
node, &subconditions_bottom_node, NIL, NIL);
/* --- look for an existing CN node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
if (child->node_type==CN_BNODE)
if (child->b.cn.partner->parent==subconditions_bottom_node) break;
/* --- share existing node or build new one --- */
if (child) {
new_node = child;
} else {
new_node = make_new_cn_node (thisAgent, node, subconditions_bottom_node);
}
break;
default:
new_node = NIL; /* unreachable, but without it gcc -Wall warns here */
}
node = new_node;
current_depth++;
}
/* --- return results to caller --- */
if (dest_bottom_node) *dest_bottom_node = node;
if (dest_bottom_depth) *dest_bottom_depth = current_depth-1;
if (dest_vars_bound) {
*dest_vars_bound = vars_bound;
} else {
}
}
void cn_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 5608 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::first_child, token_struct::token_a_union::ht, insert_token_into_left_ht(), left_addition_routines(), left_ht_bucket(), left_node_activation(), token_struct::negrm_tokens, new_left_token(), token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, rete_node_struct::node_type, token_struct::parent, token_added, agent_struct::token_pool, TRUE, uint32_t(), and token_struct::w.

Referenced by init_left_and_right_addition_routines().

{
token *t, *New;
rete_node *child;
hv = node->node_id ^ cast_and_possibly_truncate<uint32_t>(tok) ^ cast_and_possibly_truncate<uint32_t>(w);
/* --- look for a matching left token (since the partner node might have
heard about this new token already, in which case it would have done
the CN node's work already); if found, exit --- */
for (t=left_ht_bucket(thisAgent, hv); t!=NIL; t=t->a.ht.next_in_bucket)
if ((t->node==node)&&(t->parent==tok)&&(t->w==w)) return;
/* --- build left token, add it to the hash table --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
insert_token_into_left_ht (thisAgent, New, hv);
New->negrm_tokens = NIL;
/* --- pass the new token on to each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,NIL);
}
void cn_partner_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 5638 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, rete_node_struct::rete_node_b_union::cn, token_struct::first_child, token_struct::token_a_union::ht, insert_at_head_of_dll, insert_token_into_left_ht(), left_ht_bucket(), left_node_activation(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, token_struct::token_a_union::neg, token_struct::negrm_tokens, new_left_token(), token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, NIL, token_struct::node, rete_node_struct::node_id, token_struct::parent, rete_node_struct::parent, cn_node_data_struct::partner, real_parent_node(), remove_token_and_subtree(), token_added, agent_struct::token_pool, TRUE, uint32_t(), and token_struct::w.

Referenced by init_left_and_right_addition_routines().

{
rete_node *partner, *temp;
token *left, *negrm_tok;
partner = node->b.cn.partner;
/* --- build new negrm token --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &negrm_tok);
new_left_token (negrm_tok, node, tok, w);
/* --- advance (tok,w) up to the token from the top of the branch --- */
temp = node->parent;
while (temp != partner->parent) {
temp = real_parent_node (temp);
w = tok->w;
tok = tok->parent;
}
/* --- look for the matching left token --- */
hv = partner->node_id ^ cast_and_possibly_truncate<uint32_t>(tok) ^ cast_and_possibly_truncate<uint32_t>(w);
for (left=left_ht_bucket(thisAgent, hv); left!=NIL; left=left->a.ht.next_in_bucket)
if ((left->node==partner)&&(left->parent==tok)&&(left->w==w)) break;
/* --- if not found, create a new left token --- */
if (!left) {
token_added(partner);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &left);
new_left_token (left, partner, tok, w);
insert_token_into_left_ht (thisAgent, left, hv);
left->negrm_tokens = NIL;
}
/* --- add new negrm token to the left token --- */
negrm_tok->a.neg.left_token = left;
/* --- remove any descendent tokens of the left token --- */
while (left->first_child) remove_token_and_subtree (thisAgent, left->first_child);
}
void collect_nots ( agent thisAgent,
rete_test rt,
wme right_wme,
condition cond,
not_struct *&  nots_found_in_production 
)

Definition at line 4175 of file rete.cpp.

References rete_test_struct::rete_test_data_union::constant_referent, CONSTANT_RELATIONAL_RETE_TEST, rete_test_struct::data, field_from_wme(), var_location_struct::field_num, IDENTIFIER_SYMBOL_TYPE, var_location_struct::levels_up, not_struct::next, rete_test_struct::next, NIL, agent_struct::not_pool, RELATIONAL_NOT_EQUAL_RETE_TEST, rete_test_struct::right_field_num, not_struct::s1, not_struct::s2, symbol_add_ref(), test_is_not_equal_test(), rete_test_struct::type, var_bound_in_reconstructed_conds(), rete_test_struct::rete_test_data_union::variable_referent, and VARIABLE_RELATIONAL_RETE_TEST.

Referenced by rete_node_to_conditions().

{
not_struct *new_not;
Symbol *right_sym;
Symbol *referent;
for ( ; rt!=NIL; rt=rt->next) {
if (! test_is_not_equal_test(rt->type)) continue;
right_sym = field_from_wme (right_wme, rt->right_field_num);
if (right_sym->common.symbol_type != IDENTIFIER_SYMBOL_TYPE) continue;
referent = rt->data.constant_referent;
if (referent->common.symbol_type!=IDENTIFIER_SYMBOL_TYPE) continue;
allocate_with_pool (thisAgent, &thisAgent->not_pool, &new_not);
new_not->next = nots_found_in_production;
nots_found_in_production = new_not;
new_not->s1 = right_sym;
symbol_add_ref (right_sym);
new_not->s2 = referent;
symbol_add_ref (referent);
continue;
}
referent = var_bound_in_reconstructed_conds (thisAgent, cond,
if (referent->common.symbol_type!=IDENTIFIER_SYMBOL_TYPE) continue;
allocate_with_pool (thisAgent, &thisAgent->not_pool, &new_not);
new_not->next = nots_found_in_production;
nots_found_in_production = new_not;
new_not->s1 = right_sym;
symbol_add_ref (right_sym);
new_not->s2 = referent;
symbol_add_ref (referent);
continue;
}
}
}
int64_t compare_symbols ( Symbol s1,
Symbol s2 
)
inline

Definition at line 4658 of file rete.cpp.

References symbol_union::fc, FLOAT_CONSTANT_SYMBOL_TYPE, symbol_union::ic, symbol_union::id, IDENTIFIER_SYMBOL_TYPE, INT_CONSTANT_SYMBOL_TYPE, sym_constant_struct::name, identifier_struct::name_letter, identifier_struct::name_number, numcmp, symbol_union::sc, SYM_CONSTANT_SYMBOL_TYPE, int_constant_struct::value, and float_constant_struct::value.

Referenced by constant_greater_or_equal_rete_test_routine(), constant_greater_rete_test_routine(), constant_less_or_equal_rete_test_routine(), constant_less_rete_test_routine(), variable_greater_or_equal_rete_test_routine(), variable_greater_rete_test_routine(), variable_less_or_equal_rete_test_routine(), and variable_less_rete_test_routine().

{
switch (s1->common.symbol_type) {
switch (s2->common.symbol_type) {
return s1->ic.value - s2->ic.value;
return numcmp(s1->ic.value, s2->fc.value);
default:
return -1;
}
switch (s2->common.symbol_type) {
return numcmp(s1->fc.value, s2->ic.value);
return numcmp(s1->fc.value, s2->fc.value);
default:
return -1;
}
switch (s2->common.symbol_type) {
return 1;
return strcmp(s1->sc.name, s2->sc.name);
default:
return -1;
}
switch (s2->common.symbol_type) {
return 1;
if (s1->id.name_letter == s2->id.name_letter)
return static_cast<int64_t>(s1->id.name_number - s2->id.name_number);
else
return numcmp(s1->id.name_letter, s2->id.name_letter);
default:
return -1;
}
default:
return -1;
}
}
Bool constant_equal_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
Bool constant_greater_or_equal_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
Bool constant_greater_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
Bool constant_less_or_equal_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
Bool constant_less_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
Bool constant_not_equal_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
Bool constant_same_type_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)

Definition at line 4784 of file rete.cpp.

References rete_test_struct::rete_test_data_union::constant_referent, rete_test_struct::data, field_from_wme(), and rete_test_struct::right_field_num.

Referenced by init_rete().

{
Symbol *s1, *s2;
return static_cast<Bool>(s1->common.symbol_type == s2->common.symbol_type);
}
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);
}
action* copy_action_list_and_substitute_varnames ( agent thisAgent,
action actions,
condition cond 
)

Definition at line 4472 of file rete.cpp.

References agent_struct::action_pool, action_struct::attr, copy_rhs_value_and_substitute_varnames(), first_letter_from_rhs_value(), FUNCALL_ACTION, action_struct::id, action_struct::next, NIL, preference_is_binary(), action_struct::preference_type, action_struct::referent, action_struct::support, action_struct::type, and action_struct::value.

Referenced by p_node_to_conditions_and_nots().

{
action *old, *New, *prev, *first;
char first_letter;
prev = NIL;
first = NIL; /* unneeded, but without it gcc -Wall warns here */
old = actions;
while (old) {
allocate_with_pool (thisAgent, &thisAgent->action_pool, &New);
if (prev) prev->next = New; else first = New;
prev = New;
New->type = old->type;
New->support = old->support;
if (old->type==FUNCALL_ACTION) {
old->value, cond,
'v');
} else {
New->id = copy_rhs_value_and_substitute_varnames (thisAgent, old->id, cond, 's');
New->attr = copy_rhs_value_and_substitute_varnames (thisAgent, old->attr, cond,'a');
first_letter = first_letter_from_rhs_value (New->attr);
New->value = copy_rhs_value_and_substitute_varnames (thisAgent, old->value, cond,
first_letter);
cond, first_letter);
}
old = old->next;
}
if (prev) prev->next = NIL; else first = NIL;
return first;
}
rhs_value copy_rhs_value_and_substitute_varnames ( agent thisAgent,
rhs_value  rv,
condition cond,
char  first_letter 
)

Definition at line 4409 of file rete.cpp.

References allocate_cons(), cons_struct::first, funcall_list_to_rhs_value(), generate_new_variable(), agent_struct::highest_rhs_unboundvar_index, NIL, cons_struct::rest, rhs_value_is_funcall(), rhs_value_is_reteloc(), rhs_value_is_unboundvar(), rhs_value_to_funcall_list(), rhs_value_to_reteloc_field_num(), rhs_value_to_reteloc_levels_up(), rhs_value_to_symbol(), rhs_value_to_unboundvar(), agent_struct::rhs_variable_bindings, symbol_add_ref(), symbol_to_rhs_value(), and var_bound_in_reconstructed_conds().

Referenced by copy_action_list_and_substitute_varnames().

{
cons *c, *new_c, *prev_new_c;
list *fl, *new_fl;
Symbol *sym;
int64_t index;
char prefix[2];
sym = var_bound_in_reconstructed_conds (thisAgent, cond,
return symbol_to_rhs_value (sym);
}
{
index = static_cast<int64_t>(rhs_value_to_unboundvar(rv));
if (! *(thisAgent->rhs_variable_bindings+index))
{
prefix[0] = first_letter;
prefix[1] = 0;
sym = generate_new_variable (thisAgent, prefix);
*(thisAgent->rhs_variable_bindings+index) = sym;
if (thisAgent->highest_rhs_unboundvar_index < index)
{
thisAgent->highest_rhs_unboundvar_index = index;
}
}
else
{
sym = *(thisAgent->rhs_variable_bindings+index);
}
return symbol_to_rhs_value (sym);
}
allocate_cons (thisAgent, &new_fl);
new_fl->first = fl->first;
prev_new_c = new_fl;
for (c=fl->rest; c!=NIL; c=c->rest) {
allocate_cons (thisAgent, &new_c);
static_cast<char *>(c->first),
cond, first_letter);
prev_new_c->rest = new_c;
prev_new_c = new_c;
}
prev_new_c->rest = NIL;
return funcall_list_to_rhs_value (new_fl);
} else {
return rv;
}
}
uint64_t count_rete_tokens_for_production ( agent thisAgent,
production prod 
)
void deallocate_node_varnames ( agent thisAgent,
rete_node node,
rete_node cutoff,
node_varnames nvn 
)
void deallocate_rete_node ( agent thisAgent,
rete_node node 
)

Definition at line 2385 of file rete.cpp.

References rete_node_struct::a, abort_with_fatal_error(), posneg_node_data_struct::alpha_mem_, rete_node_struct::b, bnode_is_bottom_of_split_mp(), bnode_is_posneg(), BUFFER_MSG_SIZE, rete_node_struct::rete_node_b_union::cn, CN_BNODE, deallocate_rete_test_list(), agent_struct::dummy_top_node, rete_node_struct::first_child, merge_into_mp_node(), rete_node_struct::next_sibling, NIL, node_is_left_unlinked(), node_is_right_unlinked(), rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, P_BNODE, rete_node_struct::parent, cn_node_data_struct::partner, rete_node_struct::rete_node_b_union::posneg, remove_node_from_parents_list_of_children(), remove_ref_to_alpha_mem(), remove_token_and_subtree(), agent_struct::rete_node_pool, non_pos_node_data_struct::tokens, unlink_from_left_mem, unlink_from_right_mem, and update_stats_for_destroying_node().

Referenced by excise_production_from_rete().

{
/* --- don't deallocate the dummy top node --- */
if (node==thisAgent->dummy_top_node) return;
/* --- sanity check --- */
if (node->node_type==P_BNODE) {
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "Internal error: deallocate_rete_node() called on p-node.\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
parent = node->parent;
/* --- if a cn node, deallocate its partner first --- */
if (node->node_type==CN_BNODE) deallocate_rete_node (thisAgent, node->b.cn.partner);
/* --- clean up any tokens at the node --- */
while (node->a.np.tokens) remove_token_and_subtree (thisAgent, node->a.np.tokens);
/* --- stuff for posneg nodes only --- */
if (bnode_is_posneg(node->node_type)) {
/* --- right unlink the node, cleanup alpha memory --- */
}
/* --- remove the node from its parent's list --- */
/* --- for unmerged pos. nodes: unlink, maybe merge its parent --- */
/* --- if parent is mem node with just one child, merge them --- */
if (parent->first_child && (! parent->first_child->next_sibling)) {
merge_into_mp_node (thisAgent, parent);
parent = NIL;
}
}
update_stats_for_destroying_node (thisAgent, node); /* clean up rete stats stuff */
free_with_pool (&thisAgent->rete_node_pool, node);
/* --- if parent has no other children, deallocate it, and recurse --- */
/* Added check to make sure that parent wasn't deallocated in previous merge */
if ( parent && !parent->first_child) deallocate_rete_node (thisAgent, parent);
}
void deallocate_rete_test_list ( agent thisAgent,
rete_test rt 
)
void deallocate_token_list ( agent thisAgent,
token t 
)

Definition at line 7886 of file rete.cpp.

References token_struct::next_of_node, and agent_struct::token_pool.

Referenced by ppmi_aux(), print_partial_match_information(), xml_aux(), and xml_partial_match_information().

{
token *next;
while (t) {
next = t->next_of_node;
free_with_pool (&thisAgent->token_pool, t);
t = next;
}
}
void deallocate_varnames ( agent thisAgent,
varnames vn 
)

Definition at line 2703 of file rete.cpp.

References deallocate_symbol_list_removing_references(), NIL, symbol_remove_ref(), varnames_is_one_var(), varnames_to_one_var(), and varnames_to_var_list().

Referenced by deallocate_node_varnames().

{
Symbol *sym;
list *symlist;
if (vn == NIL) return;
symbol_remove_ref (thisAgent, sym);
} else {
symlist = varnames_to_var_list(vn);
}
}
Bool disjunction_rete_test_routine ( agent ,
rete_test rt,
token ,
wme w 
)
void dummy_matches_node_left_addition ( agent thisAgent,
rete_node ,
token tok,
wme w 
)

Definition at line 7858 of file rete.cpp.

References agent_struct::dummy_matches_node_tokens, token_struct::next_of_node, NIL, token_struct::node, token_struct::parent, agent_struct::token_pool, and token_struct::w.

Referenced by init_left_and_right_addition_routines().

{
token *New;
/* --- just add a token record to dummy_matches_node_tokens --- */
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
New->node = NIL;
New->parent = tok;
New->w = w;
thisAgent->dummy_matches_node_tokens = New;
}
rete_node_level dummy_to_varloc_depth ( void *  d)
inline

Definition at line 2491 of file rete.cpp.

Referenced by find_var_location().

{
return static_cast<rete_node_level>(reinterpret_cast<uintptr_t>(d) >> 2);
}
byte dummy_to_varloc_field_num ( void *  d)
inline

Definition at line 2497 of file rete.cpp.

Referenced by find_var_location().

{
return static_cast<byte>(reinterpret_cast<uintptr_t>(d) & 3);
}
Bool error_rete_test_routine ( agent thisAgent,
rete_test rt,
token left,
wme w 
)

Definition at line 4707 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, and FALSE.

{
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "Internal error: bad rete test type, hit error_rete_test_routine\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
return FALSE; /* unreachable, but without it, gcc -Wall warns here */
}
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);
}
Bool extract_rete_test_to_hash_with ( agent thisAgent,
rete_test **  rt,
var_location dest_hash_loc 
)

Definition at line 3203 of file rete.cpp.

References deallocate_rete_test_list(), FALSE, rete_test_struct::next, NIL, RELATIONAL_EQUAL_RETE_TEST, TRUE, and VARIABLE_RELATIONAL_RETE_TEST.

Referenced by make_node_for_negative_cond(), and make_node_for_positive_cond().

{
rete_test *prev, *current;
/* --- look through rt list, find the first variable equality test --- */
prev = NIL;
for (current = *rt; current!=NIL; prev=current, current=current->next)
if (current->type==VARIABLE_RELATIONAL_RETE_TEST +
if (!current) return FALSE; /* no variable equality test was found */
/* --- unlink it from rt --- */
if (prev) prev->next = current->next; else *rt = current->next;
/* --- extract info, and deallocate that single test --- */
*dest_hash_loc = current->data.variable_referent;
current->next = NIL;
deallocate_rete_test_list (thisAgent, current);
return TRUE;
}
Symbol* field_from_wme ( wme _wme,
byte  field_num 
)
inline
alpha_mem* find_alpha_mem ( agent thisAgent,
Symbol id,
Symbol attr,
Symbol value,
Bool  acceptable 
)

Definition at line 1452 of file rete.cpp.

References alpha_mem_struct::acceptable, alpha_hash_value(), alpha_mem_struct::attr, hash_table_struct::buckets, alpha_mem_struct::id, hash_table_struct::log2size, alpha_mem_struct::next_in_hash_table, NIL, table_for_tests(), uint32_t(), and alpha_mem_struct::value.

Referenced by find_or_make_alpha_mem().

{
alpha_mem *am;
uint32_t hash_value;
ht = table_for_tests (thisAgent, id, attr, value, acceptable);
hash_value = alpha_hash_value (id, attr, value, ht->log2size);
for (am = reinterpret_cast<alpha_mem *>(*(ht->buckets+hash_value)); am!=NIL;
if ((am->id==id) && (am->attr==attr) &&
(am->value==value) && (am->acceptable==acceptable))
return am;
return NIL;
}
Symbol* find_goal_for_match_set_change_assertion ( agent thisAgent,
ms_change msc 
)

Definition at line 1001 of file rete.cpp.

References abort_with_fatal_error(), rete_node_struct::b, BUFFER_MSG_SIZE, agent_struct::dummy_top_token, wme_struct::id, symbol_union::id, identifier_struct::isa_goal, identifier_struct::level, production_struct::name, NIL, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, token_struct::parent, print_with_symbols(), p_node_data_struct::prod, symbol_to_string(), ms_change_struct::tok, TRUE, ms_change_struct::w, and token_struct::w.

Referenced by p_node_left_addition().

{
wme *lowest_goal_wme;
goal_stack_level lowest_level_so_far;
token *tok;
#ifdef DEBUG_WATERFALL
print_with_symbols(thisAgent, "\nMatch goal for assertion: %y", msc->p_node->b.p.prod->name);
#endif
lowest_goal_wme = NIL;
lowest_level_so_far = -1;
if (msc->w) {
if (msc->w->id->id.isa_goal == TRUE) {
lowest_goal_wme = msc->w;
lowest_level_so_far = msc->w->id->id.level;
}
}
for (tok=msc->tok; tok!=thisAgent->dummy_top_token; tok=tok->parent) {
if (tok->w != NIL) {
/* print_wme(tok->w); */
if (tok->w->id->id.isa_goal == TRUE) {
if (lowest_goal_wme == NIL)
lowest_goal_wme = tok->w;
else {
if (tok->w->id->id.level > lowest_goal_wme->id->id.level)
lowest_goal_wme = tok->w;
}
}
}
}
if (lowest_goal_wme) {
#ifdef DEBUG_WATERFALL
print_with_symbols(thisAgent, " is [%y]", lowest_goal_wme->id);
#endif
return lowest_goal_wme->id;
}
{ char msg[BUFFER_MSG_SIZE];
print_with_symbols(thisAgent, "\nError: Did not find goal for ms_change assertion: %y\n", msc->p_node->b.p.prod->name);
SNPRINTF(msg, BUFFER_MSG_SIZE,"\nError: Did not find goal for ms_change assertion: %s\n",
symbol_to_string(thisAgent, msc->p_node->b.p.prod->name,TRUE,NIL, 0));
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
return 0;
}
Symbol* find_goal_for_match_set_change_retraction ( ms_change msc)

Definition at line 1055 of file rete.cpp.

References ms_change_struct::inst, instantiation_struct::match_goal, production_struct::name, NIL, print(), print_with_symbols(), and instantiation_struct::prod.

Referenced by p_node_left_removal().

{
#ifdef DEBUG_WATERFALL
print_with_symbols(thisAgent, "\nMatch goal level for retraction: %y", msc->inst->prod->name);
#endif
if (msc->inst->match_goal) {
/* If there is a goal, just return the goal */
#ifdef DEBUG_WATERFALL
print_with_symbols(thisAgent, " is [%y]", msc->inst->match_goal);
#endif
return msc->inst->match_goal;
} else {
#ifdef DEBUG_WATERFALL
print(" is NIL (nil goal retraction)");
#endif
return NIL;
}
}
alpha_mem* find_or_make_alpha_mem ( agent thisAgent,
Symbol id,
Symbol attr,
Symbol value,
Bool  acceptable 
)

Definition at line 1471 of file rete.cpp.

References alpha_mem_struct::acceptable, add_to_hash_table(), add_wme_to_alpha_mem(), agent_struct::all_wmes_in_rete, agent_struct::alpha_mem_pool, alpha_mem_struct::am_id, alpha_mem_struct::attr, alpha_mem_struct::beta_nodes, find_alpha_mem(), get_next_alpha_mem_id(), alpha_mem_struct::id, alpha_mem_struct::last_beta_node, right_mem_struct::next_in_am, alpha_mem_struct::next_in_hash_table, NIL, alpha_mem_struct::reference_count, wme_struct::rete_next, alpha_mem_struct::right_mems, symbol_add_ref(), table_for_tests(), alpha_mem_struct::value, right_mem_struct::w, and wme_matches_alpha_mem().

Referenced by make_node_for_negative_cond(), make_node_for_positive_cond(), and reteload_alpha_memories().

{
alpha_mem *am, *more_general_am;
wme *w;
right_mem *rm;
/* --- look for an existing alpha mem --- */
am = find_alpha_mem (thisAgent, id, attr, value, acceptable);
if (am) {
return am;
}
/* --- no existing alpha_mem found, so create a new one --- */
allocate_with_pool (thisAgent, &thisAgent->alpha_mem_pool, &am);
am->right_mems = NIL;
am->beta_nodes = NIL;
am->reference_count = 1;
am->id = id;
if (id) symbol_add_ref (id);
am->attr = attr;
if (attr) symbol_add_ref (attr);
am->value = value;
if (value) symbol_add_ref (value);
am->acceptable = acceptable;
am->am_id = get_next_alpha_mem_id(thisAgent);
ht = table_for_tests (thisAgent, id, attr, value, acceptable);
add_to_hash_table (thisAgent, ht, am);
/* --- fill new mem with any existing matching WME's --- */
more_general_am = NIL;
if (id)
more_general_am = find_alpha_mem (thisAgent, NIL, attr, value, acceptable);
if (!more_general_am && value)
more_general_am = find_alpha_mem (thisAgent, NIL, attr, NIL, acceptable);
if (more_general_am) {
/* --- fill new mem using the existing more general one --- */
for (rm=more_general_am->right_mems; rm!=NIL; rm=rm->next_in_am)
if (wme_matches_alpha_mem (rm->w, am))
add_wme_to_alpha_mem (thisAgent, rm->w, am);
} else {
/* --- couldn't find such an existing mem, so do it the hard way --- */
for (w=thisAgent->all_wmes_in_rete; w!=NIL; w=w->rete_next)
if (wme_matches_alpha_mem (w,am)) add_wme_to_alpha_mem (thisAgent, w, am);
}
return am;
}
Bool find_var_location ( Symbol var,
rete_node_level  current_depth,
var_location result 
)
void fixup_rhs_value_variable_references ( agent thisAgent,
rhs_value rv,
rete_node_level  bottom_depth,
list *&  rhs_unbound_vars_for_new_prod,
uint64_t &  num_rhs_unbound_vars_for_new_prod,
tc_number  rhs_unbound_vars_tc 
)

Definition at line 3616 of file rete.cpp.

References variable_struct::current_binding_value, var_location_struct::field_num, find_var_location(), cons_struct::first, var_location_struct::levels_up, NIL, push(), cons_struct::rest, reteloc_to_rhs_value(), rhs_value_is_funcall(), rhs_value_is_symbol(), rhs_value_to_funcall_list(), rhs_value_to_symbol(), symbol_add_ref(), symbol_remove_ref(), variable_struct::tc_num, unboundvar_to_rhs_value(), symbol_union::var, and VARIABLE_SYMBOL_TYPE.

Referenced by add_production_to_rete().

{
cons *c;
Symbol *sym;
var_location var_loc;
var_loc.var_location_struct::levels_up = 0;
var_loc.var_location_struct::field_num = 0;
uint64_t index;
if (rhs_value_is_symbol(*rv)) {
sym = rhs_value_to_symbol (*rv);
if (sym->common.symbol_type!=VARIABLE_SYMBOL_TYPE) return;
/* --- Found a variable. Is is bound on the LHS? --- */
if (find_var_location (sym, static_cast<rete_node_level>(bottom_depth+1), &var_loc)) {
/* --- Yes, replace it with reteloc --- */
symbol_remove_ref (thisAgent, sym);
*rv = reteloc_to_rhs_value (var_loc.field_num, var_loc.levels_up-1);
} else {
/* --- No, replace it with rhs_unboundvar --- */
if (sym->var.tc_num != rhs_unbound_vars_tc) {
push(thisAgent, sym, rhs_unbound_vars_for_new_prod);
sym->var.tc_num = rhs_unbound_vars_tc;
index = num_rhs_unbound_vars_for_new_prod++;
sym->var.current_binding_value = reinterpret_cast<Symbol *>(index);
} else {
index = reinterpret_cast<uint64_t>(sym->var.current_binding_value);
}
*rv = unboundvar_to_rhs_value (index);
symbol_remove_ref (thisAgent, sym);
}
return;
}
for (c=rhs_value_to_funcall_list(*rv)->rest; c!=NIL; c=c->rest)
fixup_rhs_value_variable_references (thisAgent, reinterpret_cast<rhs_value *>(&(c->first)),
bottom_depth, rhs_unbound_vars_for_new_prod,
num_rhs_unbound_vars_for_new_prod,
rhs_unbound_vars_tc);
}
}
token* get_all_left_tokens_emerging_from_node ( agent thisAgent,
rete_node node 
)
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;
}
uint32_t get_next_alpha_mem_id ( agent thisAgent)
inline

Definition at line 1405 of file rete.cpp.

References agent_struct::alpha_mem_id_counter.

Referenced by find_or_make_alpha_mem().

{
return thisAgent->alpha_mem_id_counter++;
}
uint32_t get_next_beta_node_id ( agent thisAgent)
inline

Definition at line 1864 of file rete.cpp.

References agent_struct::beta_node_id_counter.

Referenced by make_new_cn_node(), make_new_mem_node(), and make_new_negative_node().

{
return (thisAgent->beta_node_id_counter++);
}
Bool get_next_nil_goal_retraction ( agent thisAgent,
instantiation **  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,
instantiation **  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;
}
node_varnames* get_nvn_for_condition_list ( agent thisAgent,
condition cond_list,
node_varnames parent_nvn 
)

Definition at line 2806 of file rete.cpp.

References three_field_tests_struct::attr_test, bind_variables_in_test(), node_varnames_struct::varname_data_union::bottom_of_subconditions, CONJUNCTIVE_NEGATION_CONDITION, condition_struct::data, node_varnames_struct::data, FALSE, three_field_tests_struct::id_test, make_nvn_for_posneg_cond(), condition_struct::condition_main_data_union::ncc, NEGATIVE_CONDITION, condition_struct::next, NIL, agent_struct::node_varnames_pool, node_varnames_struct::parent, pop_bindings_and_deallocate_list_of_variables(), POSITIVE_CONDITION, condition_struct::condition_main_data_union::tests, ncc_info_struct::top, condition_struct::type, and three_field_tests_struct::value_test.

Referenced by add_production_to_rete().

{
node_varnames *New = 0;
condition *cond;
list *vars;
vars = NIL;
for (cond=cond_list; cond!=NIL; cond=cond->next) {
switch (cond->type) {
New = make_nvn_for_posneg_cond (thisAgent, cond, parent_nvn);
/* --- Add sparse variable bindings for this condition --- */
bind_variables_in_test (thisAgent, cond->data.tests.id_test, 0, 0, FALSE, &vars);
bind_variables_in_test (thisAgent, cond->data.tests.attr_test, 0, 0, FALSE, &vars);
bind_variables_in_test (thisAgent, cond->data.tests.value_test, 0, 0, FALSE, &vars);
break;
New = make_nvn_for_posneg_cond (thisAgent, cond, parent_nvn);
break;
allocate_with_pool (thisAgent, &thisAgent->node_varnames_pool, &New);
New->parent = parent_nvn;
get_nvn_for_condition_list (thisAgent, cond->data.ncc.top, parent_nvn);
break;
}
parent_nvn = New;
}
/* --- Pop the variable bindings for these conditions --- */
return parent_nvn;
}
Symbol* get_symbol_from_rete_loc ( unsigned short  levels_up,
byte  field_num,
token 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;
}
uint32_t hash_alpha_mem ( void *  item,
short  num_bits 
)

Definition at line 1383 of file rete.cpp.

References alpha_hash_value(), alpha_mem_struct::attr, alpha_mem_struct::id, and alpha_mem_struct::value.

Referenced by init_rete().

{
alpha_mem *am;
am = static_cast<alpha_mem_struct *>(item);
return alpha_hash_value (am->id, am->attr, am->value, num_bits);
}
Bool id_is_goal_rete_test_routine ( agent ,
rete_test ,
token ,
wme w 
)

Definition at line 4715 of file rete.cpp.

References wme_struct::id, symbol_union::id, and identifier_struct::isa_goal.

Referenced by init_rete().

{
return w->id->id.isa_goal;
}
Bool id_is_impasse_rete_test_routine ( agent ,
rete_test ,
token ,
wme w 
)

Definition at line 4719 of file rete.cpp.

References wme_struct::id, symbol_union::id, and identifier_struct::isa_impasse.

Referenced by init_rete().

{
return w->id->id.isa_impasse;
}
MS_trace* in_ms_trace ( Symbol sym,
MS_trace trace 
)

Definition at line 8055 of file rete.cpp.

References match_set_trace::next, and match_set_trace::sym.

{
MS_trace *tmp;
for(tmp = trace; tmp; tmp=tmp->next) {
if(tmp->sym == sym) return tmp;
}
return 0;
}
MS_trace* in_ms_trace_same_goal ( Symbol sym,
MS_trace trace,
Symbol goal 
)

Definition at line 8064 of file rete.cpp.

References match_set_trace::goal, match_set_trace::next, and match_set_trace::sym.

Referenced by print_match_set(), and xml_match_set().

{
MS_trace *tmp;
for(tmp = trace; tmp; tmp=tmp->next) {
if((tmp->sym == sym) && (goal == tmp->goal)) return tmp;
}
return 0;
}
void init_bnode_type_names ( agent )

Definition at line 7700 of file rete.cpp.

References bnode_type_names, CN_BNODE, CN_PARTNER_BNODE, DUMMY_MATCHES_BNODE, DUMMY_TOP_BNODE, MEMORY_BNODE, MP_BNODE, NEGATIVE_BNODE, P_BNODE, POSITIVE_BNODE, UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, UNHASHED_NEGATIVE_BNODE, and UNHASHED_POSITIVE_BNODE.

Referenced by get_all_node_count_stats(), and init_rete().

{
static bool bnode_initialzied = false;
//
// This should be properly locked.
//
if(!bnode_initialzied)
{
bnode_type_names[UNHASHED_MP_BNODE] = "unhashed mem-pos";
bnode_type_names[MP_BNODE] = "mem-pos";
bnode_type_names[UNHASHED_POSITIVE_BNODE] = "unhashed positive";
bnode_type_names[UNHASHED_NEGATIVE_BNODE] = "unhashed negative";
bnode_type_names[CN_BNODE] = "conj. neg.";
bnode_type_names[CN_PARTNER_BNODE] = "conj. neg. partner";
bnode_type_names[P_BNODE] = "production";
bnode_initialzied = true;
}
}
void init_dummy_top_node ( agent thisAgent)

Definition at line 1877 of file rete.cpp.

References rete_node_struct::a, DUMMY_TOP_BNODE, agent_struct::dummy_top_node, agent_struct::dummy_top_token, token_struct::first_child, rete_node_struct::first_child, init_new_rete_node_with_type(), token_struct::next_from_wme, token_struct::next_of_node, token_struct::next_sibling, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::rete_node_a_union::np, token_struct::parent, rete_node_struct::parent, token_struct::prev_from_wme, token_struct::prev_of_node, token_struct::prev_sibling, agent_struct::rete_node_pool, agent_struct::token_pool, non_pos_node_data_struct::tokens, and token_struct::w.

Referenced by init_rete().

{
/* --- create the dummy top node --- */
allocate_with_pool (thisAgent, &thisAgent->rete_node_pool,
&thisAgent->dummy_top_node);
thisAgent->dummy_top_node->parent = NIL;
/* --- create the dummy top token --- */
allocate_with_pool (thisAgent, &thisAgent->token_pool,
&thisAgent->dummy_top_token);
thisAgent->dummy_top_token->parent = NIL;
thisAgent->dummy_top_token->node = thisAgent->dummy_top_node;
thisAgent->dummy_top_token->w = NIL;
thisAgent->dummy_top_node->a.np.tokens = thisAgent->dummy_top_token;
}
void init_left_and_right_addition_routines ( )

Definition at line 9021 of file rete.cpp.

References beta_memory_node_left_addition(), CN_BNODE, cn_node_left_addition(), CN_PARTNER_BNODE, cn_partner_node_left_addition(), DUMMY_MATCHES_BNODE, dummy_matches_node_left_addition(), left_addition_routines(), MEMORY_BNODE, MP_BNODE, mp_node_left_addition(), mp_node_right_addition(), NEGATIVE_BNODE, negative_node_left_addition(), negative_node_right_addition(), P_BNODE, p_node_left_addition(), POSITIVE_BNODE, positive_node_right_addition(), right_addition_routines(), unhashed_beta_memory_node_left_addition(), UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, unhashed_mp_node_left_addition(), unhashed_mp_node_right_addition(), UNHASHED_NEGATIVE_BNODE, unhashed_negative_node_left_addition(), unhashed_negative_node_right_addition(), UNHASHED_POSITIVE_BNODE, and unhashed_positive_node_right_addition().

Referenced by init_rete().

void init_new_rete_node_with_type ( agent thisAgent,
rete_node node,
byte  type 
)
inline
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 +
}
void init_test_type_conversion_tables ( void  )

Definition at line 2938 of file rete.cpp.

References EQUAL_TEST_TYPE, FALSE, GREATER_OR_EQUAL_TEST, GREATER_TEST, LESS_OR_EQUAL_TEST, LESS_TEST, NOT_EQUAL_TEST, 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, relational_test_type_to_test_type, SAME_TYPE_TEST, test_type_to_relational_test_type, and TRUE.

Referenced by init_rete().

void insert_token_into_left_ht ( agent thisAgent,
token tok,
uint32_t  hv 
)
inline
byte kind_of_relational_test ( byte  x)
inline

Definition at line 247 of file rete.cpp.

Referenced by add_rete_test_list_to_tests().

{
return ((x) & 0x0F);
}
void left_addition_routines ( agent thisAgent,
rete_node node,
token tok,
wme w 
)
token* & left_ht_bucket ( agent thisAgent,
uint32_t  hv 
)
inline
void left_node_activation ( rete_node node,
Bool   
)
inline
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 make_mp_bnode_left_linked ( rete_node node)
inline

Definition at line 594 of file rete.cpp.

Referenced by merge_into_mp_node(), mp_node_right_addition(), and unhashed_mp_node_right_addition().

{
(node)->a.np.is_left_unlinked = 0;
}
void make_mp_bnode_left_unlinked ( rete_node node)
inline

Definition at line 589 of file rete.cpp.

Referenced by merge_into_mp_node(), mp_node_left_addition(), remove_wme_from_rete(), and unhashed_mp_node_left_addition().

{
(node)->a.np.is_left_unlinked = 1;
}
rete_node* make_new_cn_node ( agent thisAgent,
rete_node parent,
rete_node bottom_of_subconditions 
)

Definition at line 2273 of file rete.cpp.

References rete_node_struct::a, rete_node_struct::b, rete_node_struct::rete_node_b_union::cn, CN_BNODE, CN_PARTNER_BNODE, rete_node_struct::first_child, get_next_beta_node_id(), init_new_rete_node_with_type(), rete_node_struct::next_sibling, NIL, rete_node_struct::node_id, rete_node_struct::rete_node_a_union::np, rete_node_struct::parent, cn_node_data_struct::partner, remove_node_from_parents_list_of_children(), agent_struct::rete_node_pool, non_pos_node_data_struct::tokens, and update_node_with_matches_from_above().

Referenced by build_network_for_condition_list(), and reteload_node_and_children().

{
rete_node *node, *partner, *ncc_subconditions_top_node;
/* --- Find top node in the subconditions branch --- */
ncc_subconditions_top_node = NIL; /* unneeded, but avoids gcc -Wall warn */
for (node=bottom_of_subconditions; node!=parent; node=node->parent) {
ncc_subconditions_top_node = node;
}
allocate_with_pool (thisAgent, &thisAgent->rete_node_pool, &node);
allocate_with_pool (thisAgent, &thisAgent->rete_node_pool, &partner);
/* NOTE: for improved efficiency, <node> should be on the parent's
children list *after* the ncc subcontitions top node */
remove_node_from_parents_list_of_children (ncc_subconditions_top_node);
node->parent = parent;
node->next_sibling = parent->first_child;
ncc_subconditions_top_node->next_sibling = node;
parent->first_child = ncc_subconditions_top_node;
node->first_child = NIL;
node->a.np.tokens = NIL;
node->b.cn.partner = partner;
node->node_id = get_next_beta_node_id(thisAgent);
partner->parent = bottom_of_subconditions;
partner->next_sibling = bottom_of_subconditions->first_child;
bottom_of_subconditions->first_child = partner;
partner->first_child = NIL;
partner->a.np.tokens = NIL;
partner->b.cn.partner = node;
/* --- call partner's add_left routine with all the parent's tokens --- */
/* --- call new node's add_left routine with all the parent's tokens --- */
return node;
}
rete_node* make_new_mem_node ( agent thisAgent,
rete_node parent,
byte  node_type,
var_location  left_hash_loc 
)
rete_node* make_new_mp_node ( agent thisAgent,
rete_node parent,
byte  node_type,
var_location  left_hash_loc,
alpha_mem am,
rete_test rt,
Bool  prefer_left_unlinking 
)

Definition at line 2209 of file rete.cpp.

References make_new_mem_node(), make_new_positive_node(), MEMORY_BNODE, merge_into_mp_node(), MP_BNODE, POSITIVE_BNODE, UNHASHED_MEMORY_BNODE, and UNHASHED_POSITIVE_BNODE.

Referenced by make_node_for_positive_cond(), and reteload_node_and_children().

{
rete_node *mem_node, *pos_node;
byte mem_node_type, pos_node_type;
if (node_type==MP_BNODE) {
pos_node_type = POSITIVE_BNODE;
mem_node_type = MEMORY_BNODE;
} else {
pos_node_type = UNHASHED_POSITIVE_BNODE;
mem_node_type = UNHASHED_MEMORY_BNODE;
}
mem_node = make_new_mem_node (thisAgent, parent, mem_node_type, left_hash_loc);
pos_node = make_new_positive_node (thisAgent, mem_node, pos_node_type, am, rt,
prefer_left_unlinking);
return merge_into_mp_node (thisAgent, mem_node);
}
rete_node* make_new_negative_node ( agent thisAgent,
rete_node parent,
byte  node_type,
var_location  left_hash_loc,
alpha_mem am,
rete_test rt 
)

Definition at line 2235 of file rete.cpp.

References rete_node_struct::a, posneg_node_data_struct::alpha_mem_, rete_node_struct::b, var_location_struct::field_num, rete_node_struct::first_child, get_next_beta_node_id(), init_new_rete_node_with_type(), rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, var_location_struct::levels_up, posneg_node_data_struct::nearest_ancestor_with_same_am, nearest_ancestor_with_same_am(), rete_node_struct::next_sibling, NIL, rete_node_struct::node_id, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::parent, rete_node_struct::rete_node_b_union::posneg, relink_to_right_mem(), agent_struct::rete_node_pool, non_pos_node_data_struct::tokens, unlink_from_right_mem, and update_node_with_matches_from_above().

Referenced by make_node_for_negative_cond(), and reteload_node_and_children().

{
allocate_with_pool (thisAgent, &thisAgent->rete_node_pool, &node);
init_new_rete_node_with_type (thisAgent, node, node_type);
node->parent = parent;
node->next_sibling = parent->first_child;
parent->first_child = node;
node->first_child = NIL;
node->left_hash_loc_field_num = left_hash_loc.field_num;
node->left_hash_loc_levels_up = left_hash_loc.levels_up;
node->b.posneg.other_tests = rt;
node->b.posneg.alpha_mem_ = am;
node->a.np.tokens = NIL;
node->node_id = get_next_beta_node_id(thisAgent);
/* --- call new node's add_left routine with all the parent's tokens --- */
/* --- if no tokens arrived from parent, unlink the node --- */
if (! node->a.np.tokens) unlink_from_right_mem (node);
return node;
}
rete_node* make_new_positive_node ( agent thisAgent,
rete_node parent_mem,
byte  node_type,
alpha_mem am,
rete_test rt,
Bool  prefer_left_unlinking 
)

Definition at line 2039 of file rete.cpp.

References rete_node_struct::a, posneg_node_data_struct::alpha_mem_, rete_node_struct::b, rete_node_struct::first_child, init_new_rete_node_with_type(), posneg_node_data_struct::nearest_ancestor_with_same_am, nearest_ancestor_with_same_am(), rete_node_struct::next_sibling, NIL, node_is_right_unlinked(), rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::parent, rete_node_struct::rete_node_b_union::posneg, relink_to_left_mem, relink_to_right_mem(), agent_struct::rete_node_pool, alpha_mem_struct::right_mems, non_pos_node_data_struct::tokens, unlink_from_left_mem, and unlink_from_right_mem.

Referenced by make_new_mp_node(), make_node_for_positive_cond(), and reteload_node_and_children().

{
/* --- create the node data structure, fill in fields --- */
allocate_with_pool (thisAgent, &thisAgent->rete_node_pool, &node);
init_new_rete_node_with_type (thisAgent, node, node_type);
node->parent = parent_mem;
node->next_sibling = parent_mem->first_child;
parent_mem->first_child = node;
node->first_child = NIL;
node->b.posneg.other_tests = rt;
node->b.posneg.alpha_mem_ = am;
/* --- don't need to force WM through new node yet, as it's just a
join node with no children --- */
/* --- unlink the join node from one side if possible --- */
if (! parent_mem->a.np.tokens) unlink_from_right_mem (node);
if ((! am->right_mems) && ! node_is_right_unlinked (node))
if (prefer_left_unlinking && (! parent_mem->a.np.tokens) &&
(! am->right_mems)) {
}
return node;
}
rete_node* make_new_production_node ( agent thisAgent,
rete_node parent,
production new_prod 
)
rete_node* make_node_for_negative_cond ( agent thisAgent,
condition cond,
rete_node_level  current_depth,
rete_node parent 
)

Definition at line 3363 of file rete.cpp.

References add_rete_tests_for_test(), posneg_node_data_struct::alpha_mem_, three_field_tests_struct::attr_test, rete_node_struct::b, bind_variables_in_test(), condition_struct::data, deallocate_rete_test_list(), extract_rete_test_to_hash_with(), FALSE, var_location_struct::field_num, find_or_make_alpha_mem(), rete_node_struct::first_child, three_field_tests_struct::id_test, rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, var_location_struct::levels_up, make_new_negative_node(), NEGATIVE_BNODE, rete_node_struct::next_sibling, NIL, rete_node_struct::node_type, posneg_node_data_struct::other_tests, pop_bindings_and_deallocate_list_of_variables(), rete_node_struct::rete_node_b_union::posneg, remove_ref_to_alpha_mem(), rete_test_lists_are_identical(), condition_struct::test_for_acceptable_preference, condition_struct::condition_main_data_union::tests, UNHASHED_NEGATIVE_BNODE, and three_field_tests_struct::value_test.

Referenced by build_network_for_condition_list().

{
byte node_type;
Symbol *alpha_id, *alpha_attr, *alpha_value;
alpha_mem *am;
rete_test *rt;
Bool hash_this_node;
var_location left_hash_loc;
left_hash_loc.var_location_struct::field_num = 0;
left_hash_loc.var_location_struct::levels_up = 0;
list *vars_bound_here;
alpha_id = alpha_attr = alpha_value = NIL;
rt = NIL;
vars_bound_here = NIL;
/* --- Add sparse variable bindings for this condition --- */
bind_variables_in_test (thisAgent, cond->data.tests.id_test, current_depth, 0,
FALSE, &vars_bound_here);
bind_variables_in_test (thisAgent, cond->data.tests.attr_test, current_depth, 1,
FALSE, &vars_bound_here);
bind_variables_in_test (thisAgent, cond->data.tests.value_test, current_depth, 2,
FALSE, &vars_bound_here);
/* --- Get Rete tests, alpha constants, and hash location --- */
add_rete_tests_for_test (thisAgent, cond->data.tests.id_test, current_depth, 0,
&rt, &alpha_id);
hash_this_node = extract_rete_test_to_hash_with (thisAgent, &rt, &left_hash_loc);
add_rete_tests_for_test (thisAgent, cond->data.tests.attr_test, current_depth, 1,
&rt, &alpha_attr);
add_rete_tests_for_test (thisAgent, cond->data.tests.value_test, current_depth, 2,
&rt, &alpha_value);
/* --- Pop sparse variable bindings for this condition --- */
pop_bindings_and_deallocate_list_of_variables (thisAgent, vars_bound_here);
/* --- Get alpha memory --- */
am = find_or_make_alpha_mem (thisAgent, alpha_id, alpha_attr, alpha_value,
/* --- determine desired node type --- */
node_type = hash_this_node ? NEGATIVE_BNODE : UNHASHED_NEGATIVE_BNODE;
/* --- look for a matching existing node --- */
for (node=parent->first_child; node!=NIL; node=node->next_sibling)
if ((node->node_type==node_type) &&
(am == node->b.posneg.alpha_mem_) &&
((!hash_this_node) ||
((node->left_hash_loc_field_num==left_hash_loc.field_num) &&
(node->left_hash_loc_levels_up==left_hash_loc.levels_up))) &&
rete_test_lists_are_identical (thisAgent, node->b.posneg.other_tests, rt)) break;
if (node) { /* --- A matching node was found --- */
deallocate_rete_test_list (thisAgent, rt);
remove_ref_to_alpha_mem (thisAgent, am);
return node;
} else { /* --- No match was found, so create a new node --- */
node = make_new_negative_node (thisAgent, parent, node_type, left_hash_loc, am, rt);
return node;
}
}
rete_node* make_node_for_positive_cond ( agent thisAgent,
condition cond,
rete_node_level  current_depth,
rete_node parent 
)

Definition at line 3236 of file rete.cpp.

References add_rete_tests_for_test(), posneg_node_data_struct::alpha_mem_, three_field_tests_struct::attr_test, rete_node_struct::b, bind_variables_in_test(), condition_struct::data, deallocate_rete_test_list(), extract_rete_test_to_hash_with(), FALSE, var_location_struct::field_num, find_or_make_alpha_mem(), rete_node_struct::first_child, three_field_tests_struct::id_test, rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, var_location_struct::levels_up, make_new_mp_node(), make_new_positive_node(), MEMORY_BNODE, MP_BNODE, rete_node_struct::next_sibling, NIL, rete_node_struct::node_type, posneg_node_data_struct::other_tests, pop_bindings_and_deallocate_list_of_variables(), POSITIVE_BNODE, rete_node_struct::rete_node_b_union::posneg, remove_ref_to_alpha_mem(), rete_test_lists_are_identical(), split_mp_node(), condition_struct::test_for_acceptable_preference, condition_struct::condition_main_data_union::tests, UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, UNHASHED_POSITIVE_BNODE, and three_field_tests_struct::value_test.

Referenced by build_network_for_condition_list().

{
byte pos_node_type, mem_node_type, mp_node_type;
Symbol *alpha_id, *alpha_attr, *alpha_value;
rete_node *node, *mem_node, *mp_node;
alpha_mem *am;
rete_test *rt;
Bool hash_this_node;
var_location left_hash_loc;
left_hash_loc.var_location_struct::field_num = 0;
left_hash_loc.var_location_struct::levels_up = 0;
list *vars_bound_here;
alpha_id = alpha_attr = alpha_value = NIL;
rt = NIL;
vars_bound_here = NIL;
/* --- Add sparse variable bindings for this condition --- */
bind_variables_in_test (thisAgent, cond->data.tests.id_test, current_depth, 0,
FALSE, &vars_bound_here);
bind_variables_in_test (thisAgent, cond->data.tests.attr_test, current_depth, 1,
FALSE, &vars_bound_here);
bind_variables_in_test (thisAgent, cond->data.tests.value_test, current_depth, 2,
FALSE, &vars_bound_here);
/* --- Get Rete tests, alpha constants, and hash location --- */
add_rete_tests_for_test (thisAgent, cond->data.tests.id_test, current_depth, 0,
&rt, &alpha_id);
hash_this_node = extract_rete_test_to_hash_with (thisAgent, &rt, &left_hash_loc);
add_rete_tests_for_test (thisAgent, cond->data.tests.attr_test, current_depth, 1,
&rt, &alpha_attr);
add_rete_tests_for_test (thisAgent, cond->data.tests.value_test, current_depth, 2,
&rt, &alpha_value);
/* --- Pop sparse variable bindings for this condition --- */
pop_bindings_and_deallocate_list_of_variables (thisAgent, vars_bound_here);
/* --- Get alpha memory --- */
am = find_or_make_alpha_mem (thisAgent, alpha_id, alpha_attr, alpha_value,
/* --- Algorithm for adding node:
1. look for matching mem node; if found then
look for matching join node; create new one if no match
2. no matching mem node: look for mp node with matching mem
if found, if join part matches too, then done
else delete mp node, create mem node and 2 joins
if not matching mem node, create new mp node. */
/* --- determine desired node types --- */
if (hash_this_node) {
pos_node_type = POSITIVE_BNODE;
mem_node_type = MEMORY_BNODE;
mp_node_type = MP_BNODE;
} else {
pos_node_type = UNHASHED_POSITIVE_BNODE;
mem_node_type = UNHASHED_MEMORY_BNODE;
mp_node_type = UNHASHED_MP_BNODE;
}
/* --- look for a matching existing memory node --- */
for (mem_node=parent->first_child; mem_node!=NIL;
mem_node=mem_node->next_sibling)
if ((mem_node->node_type==mem_node_type) &&
((!hash_this_node) ||
((mem_node->left_hash_loc_field_num==left_hash_loc.field_num) &&
(mem_node->left_hash_loc_levels_up==left_hash_loc.levels_up))))
break;
if (mem_node) { /* -- A matching memory node was found --- */
/* --- look for a matching existing join node --- */
for (node=mem_node->first_child; node!=NIL; node=node->next_sibling)
if ((node->node_type==pos_node_type) &&
(am == node->b.posneg.alpha_mem_) &&
break;
if (node) { /* --- A matching join node was found --- */
deallocate_rete_test_list (thisAgent, rt);
remove_ref_to_alpha_mem (thisAgent, am);
return node;
} else { /* --- No match was found, so create a new node --- */
node = make_new_positive_node (thisAgent, mem_node, pos_node_type, am ,rt, FALSE);
return node;
}
}
/* --- No matching memory node was found; look for MP with matching M --- */
for (mp_node=parent->first_child; mp_node!=NIL;
mp_node=mp_node->next_sibling)
if ((mp_node->node_type==mp_node_type) &&
((!hash_this_node) ||
((mp_node->left_hash_loc_field_num==left_hash_loc.field_num) &&
(mp_node->left_hash_loc_levels_up==left_hash_loc.levels_up))))
break;
if (mp_node) { /* --- Found matching M part of MP --- */
if ((am == mp_node->b.posneg.alpha_mem_) &&
rete_test_lists_are_identical (thisAgent, mp_node->b.posneg.other_tests, rt)) {
/* --- Complete MP match was found --- */
deallocate_rete_test_list (thisAgent, rt);
remove_ref_to_alpha_mem (thisAgent, am);
return mp_node;
}
/* --- Delete MP node, replace it with M and two positive joins --- */
mem_node = split_mp_node (thisAgent, mp_node);
node = make_new_positive_node (thisAgent, mem_node, pos_node_type, am, rt, FALSE);
return node;
}
/* --- Didn't even find a matching M part of MP, so make a new MP node --- */
return make_new_mp_node (thisAgent, parent, mp_node_type, left_hash_loc, am, rt, FALSE);
}
node_varnames* make_nvn_for_posneg_cond ( agent thisAgent,
condition cond,
node_varnames parent_nvn 
)

Definition at line 2775 of file rete.cpp.

References add_unbound_varnames_in_test(), three_field_tests_struct::attr_test, three_field_varnames_struct::attr_varnames, bind_variables_in_test(), condition_struct::data, node_varnames_struct::data, FALSE, node_varnames_struct::varname_data_union::fields, three_field_tests_struct::id_test, three_field_varnames_struct::id_varnames, NIL, agent_struct::node_varnames_pool, node_varnames_struct::parent, pop_bindings_and_deallocate_list_of_variables(), condition_struct::condition_main_data_union::tests, three_field_tests_struct::value_test, and three_field_varnames_struct::value_varnames.

Referenced by get_nvn_for_condition_list().

{
list *vars_bound;
vars_bound = NIL;
allocate_with_pool (thisAgent, &thisAgent->node_varnames_pool, &New);
New->parent = parent_nvn;
/* --- fill in varnames for id test --- */
/* --- add sparse bindings for id, then get attr field varnames --- */
bind_variables_in_test (thisAgent, cond->data.tests.id_test, 0, 0, FALSE, &vars_bound);
/* --- add sparse bindings for attr, then get value field varnames --- */
bind_variables_in_test (thisAgent, cond->data.tests.attr_test, 0, 0, FALSE,&vars_bound);
/* --- Pop the variable bindings for these conditions --- */
return New;
}
void mark_node_as_left_unlinked ( rete_node node)
inline
void mark_node_as_right_unlinked ( rete_node node)
inline
Bool match_left_and_right ( agent thisAgent,
rete_test _rete_test,
token left,
wme w 
)
inline
rete_node* merge_into_mp_node ( agent thisAgent,
rete_node mem_node 
)

Definition at line 2145 of file rete.cpp.

References rete_node_struct::a, abort_with_fatal_error(), rete_node_struct::b, BUFFER_MSG_SIZE, rete_node_struct::first_child, init_new_rete_node_with_type(), rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, make_mp_bnode_left_linked(), make_mp_bnode_left_unlinked(), MEMORY_BNODE, MP_BNODE, token_struct::next_of_node, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, node_is_left_unlinked(), rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, rete_node_struct::parent, rete_node_struct::rete_node_b_union::posneg, remove_node_from_parents_list_of_children(), agent_struct::rete_node_pool, set_sharing_factor, non_pos_node_data_struct::tokens, UNHASHED_MP_BNODE, and update_stats_for_destroying_node().

Referenced by deallocate_rete_node(), and make_new_mp_node().

{
rete_node *pos_node, *mp_node, *parent;
rete_node pos_copy;
byte node_type;
token *t;
pos_node = mem_node->first_child;
parent = mem_node->parent;
/* --- sanity check: Mem node must have exactly one child --- */
if ((! pos_node) || pos_node->next_sibling) {
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "\nrete.c: Internal error: tried to merge_into_mp_node, but <>1 child\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
/* --- determine appropriate node type for new MP node --- */
if (mem_node->node_type==MEMORY_BNODE) {
node_type = MP_BNODE;
} else {
node_type = UNHASHED_MP_BNODE;
}
/* --- save a copy of the Pos data, then kill the Pos node --- */
pos_copy = *pos_node;
update_stats_for_destroying_node (thisAgent, pos_node); /* clean up rete stats stuff */
/* --- the old Pos node gets transmogrified into the new MP node --- */
mp_node = pos_node;
init_new_rete_node_with_type (thisAgent, mp_node, node_type);
set_sharing_factor (mp_node, pos_copy.sharing_factor);
mp_node->b.posneg = pos_copy.b.posneg;
/* --- transfer the Mem node's tokens to the MP node --- */
mp_node->a.np.tokens = mem_node->a.np.tokens;
for (t=mem_node->a.np.tokens; t!=NIL; t=t->next_of_node) t->node = mp_node;
mp_node->node_id = mem_node->node_id;
/* --- replace the Mem node with the new MP node --- */
mp_node->parent = parent;
mp_node->next_sibling = parent->first_child;
parent->first_child = mp_node;
mp_node->first_child = pos_copy.first_child;
update_stats_for_destroying_node (thisAgent, mem_node); /* clean up rete stats stuff */
free_with_pool (&thisAgent->rete_node_pool, mem_node);
/* --- set MP node's unlinking status according to pos_copy's --- */
return mp_node;
}
unsigned mp_bnode_is_left_unlinked ( rete_node node)
inline
void mp_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 5104 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, posneg_node_data_struct::alpha_mem_, right_mem_struct::am, alpha_mem_struct::am_id, rete_node_struct::b, FALSE, field_from_wme(), rete_node_struct::first_child, token_struct::token_a_union::ht, wme_struct::id, insert_token_into_left_ht(), left_addition_routines(), rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, left_node_activation(), make_mp_bnode_left_unlinked(), match_left_and_right(), mp_bnode_is_left_unlinked(), new_left_token(), rete_test_struct::next, right_mem_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, rete_node_struct::node_id, node_is_right_unlinked(), rete_node_struct::node_type, posneg_node_data_struct::other_tests, token_struct::parent, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, relink_to_right_mem(), right_ht_bucket(), alpha_mem_struct::right_mems, token_added, agent_struct::token_pool, TRUE, uint32_t(), token_struct::w, and right_mem_struct::w.

Referenced by init_left_and_right_addition_routines().

{
Symbol *referent;
rete_node *child;
token *New;
uint32_t right_hv;
right_mem *rm;
alpha_mem *am;
rete_test *rt;
Bool failed_a_test;
{
int levels_up;
token *t;
levels_up = node->left_hash_loc_levels_up;
if (levels_up==1) {
referent = field_from_wme (w, node->left_hash_loc_field_num);
} else { /* --- levels_up > 1 --- */
for (t=tok, levels_up -= 2; levels_up!=0; levels_up--) t=t->parent;
referent = field_from_wme (t->w, node->left_hash_loc_field_num);
}
}
hv = node->node_id ^ referent->common.hash_id;
/* --- build new left token, add it to the hash table --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
insert_token_into_left_ht (thisAgent, New, hv);
New->a.ht.referent = referent;
return;
}
am = node->b.posneg.alpha_mem_;
if (am->right_mems==NIL) {
return;
}
}
/* --- look through right memory for matches --- */
right_hv = am->am_id ^ referent->common.hash_id;
for (rm=right_ht_bucket(thisAgent, right_hv); rm!=NIL; rm=rm->next_in_bucket) {
if (rm->am != am) continue;
/* --- does rm->w match new? --- */
if (referent != rm->w->id) continue;
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, New, rm->w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,rm->w);
}
}
void mp_node_right_addition ( agent thisAgent,
rete_node node,
wme w 
)

Definition at line 5306 of file rete.cpp.

References token_struct::a, rete_node_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, FALSE, rete_node_struct::first_child, token_struct::token_a_union::ht, wme_struct::id, left_addition_routines(), left_ht_bucket(), make_mp_bnode_left_linked(), match_left_and_right(), mp_bnode_is_left_unlinked(), rete_test_struct::next, token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, right_node_activation(), non_pos_node_data_struct::tokens, TRUE, uint32_t(), and unlink_from_right_mem.

Referenced by init_left_and_right_addition_routines().

{
token *tok;
Symbol *referent;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
if (! node->a.np.tokens) {
return;
}
}
referent = w->id;
hv = node->node_id ^ referent->common.hash_id;
for (tok=left_ht_bucket(thisAgent, hv); tok!=NIL; tok=tok->a.ht.next_in_bucket) {
if (tok->node != node) continue;
/* --- does tok match w? --- */
if (tok->a.ht.referent != referent) continue;
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, tok, w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,tok,w);
}
}
rete_node* nearest_ancestor_with_same_am ( rete_node node,
alpha_mem am 
)
void negative_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 5391 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, posneg_node_data_struct::alpha_mem_, right_mem_struct::am, alpha_mem_struct::am_id, rete_node_struct::b, FALSE, field_from_wme(), token_struct::first_child, rete_node_struct::first_child, token_struct::token_a_union::ht, wme_struct::id, insert_at_head_of_dll, insert_token_into_left_ht(), left_addition_routines(), rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, left_node_activation(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, match_left_and_right(), token_struct::token_a_union::neg, token_struct::negrm_tokens, new_left_token(), rete_test_struct::next, right_mem_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, node_is_right_unlinked(), rete_node_struct::node_type, posneg_node_data_struct::other_tests, token_struct::parent, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, relink_to_right_mem(), right_ht_bucket(), token_added, agent_struct::token_pool, wme_struct::tokens, TRUE, uint32_t(), token_struct::w, and right_mem_struct::w.

Referenced by init_left_and_right_addition_routines().

{
uint32_t hv, right_hv;
Symbol *referent;
right_mem *rm;
alpha_mem *am;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
token *New;
{
int levels_up;
token *t;
levels_up = node->left_hash_loc_levels_up;
if (levels_up==1) {
referent = field_from_wme (w, node->left_hash_loc_field_num);
} else { /* --- levels_up > 1 --- */
for (t=tok, levels_up -= 2; levels_up!=0; levels_up--) t=t->parent;
referent = field_from_wme (t->w, node->left_hash_loc_field_num);
}
}
hv = node->node_id ^ referent->common.hash_id;
/* --- build new token, add it to the hash table --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
insert_token_into_left_ht (thisAgent, New, hv);
New->a.ht.referent = referent;
New->negrm_tokens = NIL;
/* --- look through right memory for matches --- */
am = node->b.posneg.alpha_mem_;
right_hv = am->am_id ^ referent->common.hash_id;
for (rm=right_ht_bucket(thisAgent, right_hv); rm!=NIL; rm=rm->next_in_bucket) {
if (rm->am != am) continue;
/* --- does rm->w match new? --- */
if (referent != rm->w->id) continue;
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, New, rm->w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
{ token *t;
allocate_with_pool (thisAgent, &thisAgent->token_pool, &t);
t->node = node;
t->parent = NIL;
t->w = rm->w;
t->a.neg.left_token = New;
}
}
/* --- if no matches were found, call each child node --- */
if (! New->negrm_tokens) {
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,NIL);
}
}
void negative_node_right_addition ( agent thisAgent,
rete_node node,
wme w 
)

Definition at line 5520 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, FALSE, token_struct::first_child, token_struct::token_a_union::ht, wme_struct::id, insert_at_head_of_dll, left_ht_bucket(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, match_left_and_right(), token_struct::token_a_union::neg, token_struct::negrm_tokens, rete_test_struct::next, token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, NIL, token_struct::node, rete_node_struct::node_id, posneg_node_data_struct::other_tests, token_struct::parent, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, remove_token_and_subtree(), right_node_activation(), agent_struct::token_pool, wme_struct::tokens, TRUE, uint32_t(), and token_struct::w.

Referenced by init_left_and_right_addition_routines().

{
token *tok;
Symbol *referent;
rete_test *rt;
Bool failed_a_test;
referent = w->id;
hv = node->node_id ^ referent->common.hash_id;
for (tok=left_ht_bucket(thisAgent, hv); tok!=NIL; tok=tok->a.ht.next_in_bucket) {
if (tok->node != node) continue;
/* --- does tok match w? --- */
if (tok->a.ht.referent != referent) continue;
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, tok, w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found: build new negrm token, remove descendent tokens --- */
{ token *t;
allocate_with_pool (thisAgent, &thisAgent->token_pool, &t);
t->node = node;
t->parent = NIL;
t->w = w;
t->a.neg.left_token = tok;
}
while (tok->first_child) remove_token_and_subtree (thisAgent, tok->first_child);
}
}
void new_left_token ( token New,
rete_node current_node,
token parent_tok,
wme parent_wme 
)
inline
uint64_t node_is_left_unlinked ( rete_node node)
inline
uint64_t node_is_right_unlinked ( rete_node node)
inline
varnames* one_var_to_varnames ( Symbol x)
inline

Definition at line 2659 of file rete.cpp.

Referenced by add_var_to_varnames(), and reteload_varnames().

{ return reinterpret_cast<varnames *>(x); }
void p_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)
shouldn't this be either 

symbol_to_rhs_value (act->id) == or act->id == rhs_value_to_symbol(temp..)

Definition at line 5718 of file rete.cpp.

References rete_node_struct::a, wme_struct::acceptable, ACCEPTABLE_PREFERENCE_TYPE, production_struct::action_list, activation_entry_sanity_check, activation_exit_sanity_check, add_to_growable_string(), production_struct::already_fired, wme_struct::attr, action_struct::attr, rete_node_struct::b, bnode_is_positive(), instantiation_struct::bottom_of_instantiated_conditions, condition_struct::bt, agent_struct::current_phase, DECLARED_I_SUPPORT, DECLARED_O_SUPPORT, production_struct::declared_support, DUMMY_TOP_BNODE, FALSE, find_goal_for_match_set_change_assertion(), free_growable_string(), get_symbol_from_rete_loc(), ms_change_struct::goal, I_LIST, wme_struct::id, action_struct::id, symbol_union::id, IE_PRODS, insert_at_head_of_dll, ms_change_struct::inst, production_struct::interrupt, identifier_struct::isa_goal, JUSTIFICATION_PRODUCTION_TYPE, left_node_activation(), ms_change_struct::level, identifier_struct::level, MAKE_ACTION, make_blank_growable_string(), agent_struct::ms_change_pool, identifier_struct::ms_i_assertions, agent_struct::ms_i_assertions, identifier_struct::ms_o_assertions, agent_struct::ms_o_assertions, agent_struct::ms_retractions, identifier_struct::ms_retractions, production_struct::name, new_left_token(), action_struct::next, ms_change_struct::next_of_node, token_struct::next_of_node, NIL, agent_struct::nil_goal_retractions, rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, O_LIST, agent_struct::o_support_calculation_type, production_struct::OPERAND_which_assert_list, agent_struct::operator_symbol, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, token_struct::parent, rete_node_struct::parent, PE_PRODS, action_struct::preference_type, condition_struct::prev, print(), PRINT_WARNINGS_SYSPARAM, print_with_symbols(), p_node_data_struct::prod, real_parent_node(), agent_struct::reason_for_stopping, remove_from_dll, instantiation_struct::rete_token, instantiation_struct::rete_wme, rhs_value_is_reteloc(), rhs_value_is_symbol(), rhs_value_to_reteloc_field_num(), rhs_value_to_reteloc_levels_up(), rhs_value_to_string(), rhs_value_to_symbol(), agent_struct::soar_verbose_flag, agent_struct::stop_soar, symbol_to_string(), agent_struct::sysparams, p_node_data_struct::tentative_assertions, p_node_data_struct::tentative_retractions, text_of_growable_string(), ms_change_struct::tok, token_added, agent_struct::token_pool, non_pos_node_data_struct::tokens, TRUE, production_struct::type, action_struct::type, UNDECLARED_SUPPORT, wme_struct::value, ms_change_struct::w, token_struct::w, bt_info_struct::wme_, xml_generate_verbose(), and xml_generate_warning().

Referenced by init_left_and_right_addition_routines().

{
ms_change *msc;
condition *cond;
token *current_token, *New;
wme *current_wme;
rete_node *current_node;
Bool match_found;
/* RCHONG: begin 10.11 */
int prod_type;
token *OPERAND_curr_tok, *temp_tok;
action *act;
Bool operator_proposal,op_elab;
char action_attr[50];
int pass;
wme *lowest_goal_wme;
/* RCHONG: end 10.11 */
/* --- build new left token (used only for tree-based remove) --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
/* --- check for match in tentative_retractions --- */
match_found = FALSE;
for (msc=node->b.p.tentative_retractions; msc!=NIL; msc=msc->next_of_node) {
match_found = TRUE;
current_token = tok;
current_wme = w;
current_node = node->parent;
while (current_node->node_type!=DUMMY_TOP_BNODE) {
if (bnode_is_positive(current_node->node_type))
if (current_wme != cond->bt.wme_) {
match_found=FALSE; break;
}
current_node = real_parent_node (current_node);
current_wme = current_token->w;
current_token = current_token->parent;
cond = cond->prev;
}
if (match_found) break;
}
#ifdef BUG_139_WORKAROUND
/* --- test workaround for bug #139: don't rematch justifications; let them be removed --- */
/* note that the justification is added to the retraction list when it is first created, so
we let it match the first time, but not after that */
if (match_found && node->b.p.prod->type == JUSTIFICATION_PRODUCTION_TYPE) {
if (node->b.p.prod->already_fired) {
return;
} else {
node->b.p.prod->already_fired = 1;
}
}
#endif
/* --- if match found tentative_retractions, remove it --- */
if (match_found) {
msc->inst->rete_token = tok;
msc->inst->rete_wme = w;
remove_from_dll (thisAgent->ms_retractions, msc, next, prev);
/* REW: begin 08.20.97 */
if (msc->goal) {
next_in_level, prev_in_level);
} else {
// RPM 6/05
// This if statement is to avoid a crash we get on most platforms in Soar 7 mode
// It's unknown what consequences it has, but the Soar 7 demos seem to work
// To return things to how they were, simply remove the if statement (but leave
// the remove_from_dll line).
// voigtjr 2009: returning things to how they were now that soar7 is removed
//if(thisAgent->nil_goal_retractions)
{
msc, next_in_level, prev_in_level);
}
}
/* REW: end 08.20.97 */
free_with_pool (&thisAgent->ms_change_pool, msc);
#ifdef DEBUG_RETE_PNODES
print_with_symbols (thisAgent, "\nRemoving tentative retraction: %y",
node->b.p.prod->name);
#endif
return;
}
/* --- no match found, so add new assertion --- */
#ifdef DEBUG_RETE_PNODES
print_with_symbols (thisAgent, "\nAdding tentative assertion: %y",
node->b.p.prod->name);
#endif
allocate_with_pool (thisAgent, &thisAgent->ms_change_pool, &msc);
msc->tok = tok;
msc->w = w;
msc->p_node = node;
msc->inst = NIL; /* just for safety */
/* REW: begin 08.20.97 */
/* initialize goal regardless of run mode */
msc->level = 0;
msc->goal = NIL;
/* REW: end 08.20.97 */
/* RCHONG: begin 10.11 */
/* (this is a RCHONG comment, but might also apply to Operand2...?)
what we have to do now is to, essentially, determine the kind of
support this production would get based on its present complete
matches. once i know the support, i can then know into which match
set list to put "msc".
this code is used to make separate PE productions from IE
productions by putting them into different match set lists. in
non-OPERAND, these matches would all go into one list.
BUGBUG i haven't tested this with a production that has more than
one match where the matches could have different support. is that
even possible???
*/
/* operand code removed 1/22/99 - kjc */
/* REW: begin 09.15.96 */
/* REW: begin 08.20.97 */
/* Find the goal and level for this ms change */
msc->level = msc->goal->id.level;
#ifdef DEBUG_WATERFALL
print("\n Level of goal is %d", msc->level);
#endif
/* REW: end 08.20.97 */
prod_type = IE_PRODS;
prod_type = PE_PRODS;
prod_type = IE_PRODS;
else if (node->b.p.prod->declared_support == UNDECLARED_SUPPORT) {
/*
check if the instantiation is proposing an operator. if it
is, then this instantiation is i-supported.
*/
operator_proposal = FALSE;
for (act = node->b.p.prod->action_list; act != NIL ; act = act->next) {
if ((act->type == MAKE_ACTION) &&
if ((strcmp(rhs_value_to_string (thisAgent, act->attr, action_attr, 50),
"operator") == NIL) &&
operator_proposal = TRUE;
prod_type = !PE_PRODS;
break;
}
}
}
if (operator_proposal == FALSE) {
/*
examine all the different matches for this productions
*/
for (OPERAND_curr_tok = node->a.np.tokens;
OPERAND_curr_tok != NIL;
OPERAND_curr_tok = OPERAND_curr_tok->next_of_node) {
/*
i'll need to make two passes over each set of wmes that
match this production. the first pass looks for the lowest
goal identifier. the second pass looks for a wme of the form:
(<lowest-goal-id> ^operator ...)
if such a wme is found, then this production is a PE_PROD.
otherwise, it's a IE_PROD.
admittedly, this implementation is kinda sloppy. i need to
clean it up some.
BUGBUG this check only looks at positive conditions. we
haven't really decided what testing the absence of the
operator will do. this code assumes that such a productions
(instantiation) would get i-support.
Modified 1/00 by KJC for o-support-mode == 3: prods that have ONLY operator
elaborations (<o> ^attr ^value) are IE_PROD. If prod has
both operator applications and <o> elabs, then it's PE_PROD
and the user is warned that <o> elabs will be o-supported.
*/
op_elab = FALSE;
lowest_goal_wme = NIL;
for (pass = 0; pass != 2; pass++) {
temp_tok = OPERAND_curr_tok;
while (temp_tok != NIL) {
while (temp_tok->w == NIL) {
temp_tok = temp_tok->parent;
if (temp_tok == NIL) break;
}
if (temp_tok == NIL) break;
if (temp_tok->w == NIL) break;
if (pass == 0) {
if (temp_tok->w->id->id.isa_goal == TRUE) {
if (lowest_goal_wme == NIL)
lowest_goal_wme = temp_tok->w;
else {
if (temp_tok->w->id->id.level >
lowest_goal_wme->id->id.level)
lowest_goal_wme = temp_tok->w;
}
}
} else {
if ((temp_tok->w->attr == thisAgent->operator_symbol) && (temp_tok->w->acceptable == FALSE) && (temp_tok->w->id == lowest_goal_wme->id)) {
if ((thisAgent->o_support_calculation_type == 3) || (thisAgent->o_support_calculation_type == 4)) {
/* iff RHS has only operator elaborations
then it's IE_PROD, otherwise PE_PROD, so
look for non-op-elabs in the actions KJC 1/00 */
/* We also need to check reteloc's to see if they
are referring to operator augmentations before determining
if this is an operator elaboration
*/
for (act = node->b.p.prod->action_list; act != NIL ; act = act->next) {
if (act->type == MAKE_ACTION) {
if ((rhs_value_is_symbol(act->id)) &&
temp_tok->w->value)) {
op_elab = TRUE;
} else if ( (thisAgent->o_support_calculation_type == 4)
op_elab = TRUE;
} else {
/* this is not an operator elaboration */
prod_type = PE_PRODS;
}
} // act->type == MAKE_ACTION
} // for
} else {
prod_type = PE_PRODS;
break;
}
}
} /* end if (pass == 0) ... */
temp_tok = temp_tok->parent;
} /* end while (temp_tok != NIL) ... */
if (prod_type == PE_PRODS) {
if ((thisAgent->o_support_calculation_type != 3) && (thisAgent->o_support_calculation_type != 4)) {
break;
} else if (op_elab == TRUE) {
/* warn user about mixed actions */
if ((thisAgent->o_support_calculation_type == 3) && thisAgent->sysparams[PRINT_WARNINGS_SYSPARAM]) {
print_with_symbols(thisAgent, "\nWARNING: operator elaborations mixed with operator applications\nget o_support in prod %y",
node->b.p.prod->name);
// XML generation
add_to_growable_string(thisAgent, &gs, "WARNING: operator elaborations mixed with operator applications\nget o_support in prod ");
add_to_growable_string(thisAgent, &gs, symbol_to_string(thisAgent, node->b.p.prod->name, true, 0, 0));
free_growable_string(thisAgent, gs);
prod_type = PE_PRODS;
break;
}
else if ((thisAgent->o_support_calculation_type == 4) && thisAgent->sysparams[PRINT_WARNINGS_SYSPARAM]) {
print_with_symbols(thisAgent, "\nWARNING: operator elaborations mixed with operator applications\nget i_support in prod %y",
node->b.p.prod->name);
// XML generation
add_to_growable_string(thisAgent, &gs, "WARNING: operator elaborations mixed with operator applications\nget i_support in prod ");
add_to_growable_string(thisAgent, &gs, symbol_to_string(thisAgent, node->b.p.prod->name, true, 0, 0));
free_growable_string(thisAgent, gs);
prod_type = IE_PRODS;
break;
}
}
}
} /* end for pass = */
} /* end for loop checking all matches */
/* BUG: IF you print lowest_goal_wme here, you don't get what
you'd expect. Instead of the lowest goal WME, it looks like
you get the lowest goal WME in the first/highest assertion of
all the matches for this production. So, if there is a single
match, you get the right number. If there are multiple matches
for the same production, you get the lowest goal of the
highest match goal production (or maybe just the first to
fire?). I don;t know for certain if this is the behavior
Ron C. wanted or if it's a bug --
i need to talk to him about it. */
} /* end if (operator_proposal == FALSE) */
} /* end UNDECLARED_SUPPORT */
if (prod_type == PE_PRODS) {
insert_at_head_of_dll (thisAgent->ms_o_assertions, msc, next, prev);
/* REW: begin 08.20.97 */
msc, next_in_level, prev_in_level);
/* REW: end 08.20.97 */
if (thisAgent->soar_verbose_flag == TRUE) {
print_with_symbols(thisAgent, "\n RETE: putting [%y] into ms_o_assertions",
node->b.p.prod->name);
char buf[256];
SNPRINTF(buf, 254, "RETE: putting [%s] into ms_o_assertions", symbol_to_string(thisAgent, node->b.p.prod->name, true, 0, 0));
xml_generate_verbose(thisAgent, buf);
}
}
else {
msc, next, prev);
/* REW: end 08.20.97 */
msc, next_in_level, prev_in_level);
/* REW: end 08.20.97 */
if (thisAgent->soar_verbose_flag == TRUE) {
print_with_symbols(thisAgent, "\n RETE: putting [%y] into ms_i_assertions",
node->b.p.prod->name);
char buf[256];
SNPRINTF(buf, 254, "RETE: putting [%s] into ms_i_assertions", symbol_to_string(thisAgent, node->b.p.prod->name, true, 0, 0));
xml_generate_verbose(thisAgent, buf);
}
}
/* REW: end 09.15.96 */
// :interrupt
if (node->b.p.prod->interrupt) {
node->b.p.prod->interrupt++;
thisAgent->stop_soar++;
// Note that this production name might not be completely accurate.
// If two productions match, the last matched production name will be
// saved, but if this production then gets retracted on the same
// elaboration cycle, while the first matching production remains
// on the assertion list, Soar will still halt, but the production
// named will be inaccurate.
print_with_symbols(thisAgent, "\n*** Production match-time interrupt (:interrupt), probably from %y\n", node->b.p.prod->name);
print(thisAgent, " [Phase] (Interrupt, Stop) is [%d] (%d,%d)\n", thisAgent->current_phase, node->b.p.prod->interrupt, thisAgent->stop_soar);
thisAgent->reason_for_stopping = ":interrupt";
}
/* RCHONG: end 10.11 */
}
void p_node_left_removal ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 6133 of file rete.cpp.

References abort_with_fatal_error(), activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, BUFFER_MSG_SIZE, find_goal_for_match_set_change_retraction(), ms_change_struct::goal, I_LIST, symbol_union::id, insert_at_head_of_dll, ms_change_struct::inst, production_struct::instantiations, production_struct::interrupt, JUSTIFICATION_PRODUCTION_TYPE, ms_change_struct::level, identifier_struct::level, identifier_struct::link_count, agent_struct::ms_change_pool, identifier_struct::ms_i_assertions, agent_struct::ms_i_assertions, identifier_struct::ms_o_assertions, agent_struct::ms_o_assertions, agent_struct::ms_retractions, identifier_struct::ms_retractions, production_struct::name, ms_change_struct::next, instantiation_struct::next, ms_change_struct::next_in_level, ms_change_struct::next_of_node, NIL, agent_struct::nil_goal_retractions, O_LIST, production_struct::OPERAND_which_assert_list, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, print(), print_with_symbols(), instantiation_struct::prod, p_node_data_struct::prod, remove_from_dll, instantiation_struct::rete_token, instantiation_struct::rete_wme, agent_struct::soar_verbose_flag, agent_struct::stop_soar, symbol_to_string(), p_node_data_struct::tentative_assertions, p_node_data_struct::tentative_retractions, ms_change_struct::tok, TRUE, production_struct::type, ms_change_struct::w, xml_generate_verbose(), and xml_generate_warning().

Referenced by remove_token_and_subtree().

{
ms_change *msc;
/* --- check for match in tentative_assertions --- */
for (msc=node->b.p.tentative_assertions; msc!=NIL; msc=msc->next_of_node) {
if ((msc->tok==tok) && (msc->w==w)) {
/* --- match found in tentative_assertions, so remove it --- */
// :interrupt
if (node->b.p.prod->interrupt > 1) {
node->b.p.prod->interrupt--;
thisAgent->stop_soar--;
if (thisAgent->soar_verbose_flag == TRUE) {
print(thisAgent, "RETRACTION (1) reset interrupt to READY -- (Interrupt, Stop) to (%d, %d)\n", node->b.p.prod->interrupt, thisAgent->stop_soar);
}
}
/* REW: begin 09.15.96 */
remove_from_dll (thisAgent->ms_o_assertions, msc, next, prev);
/* REW: begin 08.20.97 */
/* msc already defined for the assertion so the goal should be defined
as well. */
next_in_level, prev_in_level);
/* REW: end 08.20.97 */
}
else if (node->b.p.prod->OPERAND_which_assert_list == I_LIST) {
remove_from_dll (thisAgent->ms_i_assertions, msc, next, prev);
/* REW: begin 08.20.97 */
next_in_level, prev_in_level);
/* REW: end 08.20.97 */
}
/* REW: end 09.15.96 */
free_with_pool (&thisAgent->ms_change_pool, msc);
#ifdef DEBUG_RETE_PNODES
print_with_symbols (thisAgent, "\nRemoving tentative assertion: %y",
node->b.p.prod->name);
#endif
return;
}
} /* end of for loop */
/* --- find the instantiation corresponding to this token --- */
for (inst=node->b.p.prod->instantiations; inst!=NIL; inst=inst->next)
if ((inst->rete_token==tok)&&(inst->rete_wme==w)) break;
if (inst) {
/* --- add that instantiation to tentative_retractions --- */
#ifdef DEBUG_RETE_PNODES
print_with_symbols (thisAgent, "\nAdding tentative retraction: %y",
node->b.p.prod->name);
#endif
inst->rete_token = NIL;
inst->rete_wme = NIL;
allocate_with_pool (thisAgent, &thisAgent->ms_change_pool, &msc);
msc->inst = inst;
msc->p_node = node;
msc->tok = NIL; /* just for safety */
msc->w = NIL; /* just for safety */
/* REW: begin 08.20.97 */
msc->level = 0; /* just for safety */
msc->goal = NIL; /* just for safety */
/* REW: end 08.20.97 */
/* REW: begin 08.20.97 */
/* Determine what the goal of the msc is and add it to that
goal's list of retractions */
msc->level = msc->goal->id.level;
#ifdef DEBUG_WATERFALL
print("\n Level of retraction is: %d", msc->level);
#endif
if (msc->goal->id.link_count == 0) {
/* BUG (potential) (Operand2/Waterfall: 2.101)
When a goal is removed in the stack, it is not immediately garbage
collected, meaning that the goal pointer is still valid when the
retraction is created. So the goal for a retraction will always be
valid, even though, for retractions caused by goal removals, the
goal will be removed at the next WM phase. (You can see this by
printing the identifier for the goal in the elaboration cycle
after goal removal. It's still there, although nothing is attacjed
to it. One elab later, the identifier itself is removed.) Because
Waterfall needs to know if the goal is valid or not, I look at the
link_count on the symbol. A link_count of 0 is the trigger for the
garbage collection so this solution should work -- I just make the
pointer NIL to ensure that the retractions get added to the
NIL_goal_retraction list. However, if the link_count is never
*not* zero for an already removed goal, this solution will fail,
resulting in both the retraction never being able to fire and a
memory leak (because the items on the ms_change list on the symbol
will never be freed). */
/* print("\nThis goal is being removed. Changing msc goal pointer to NIL."); */
msc->goal = NIL;
}
/* Put on the original retraction list */
insert_at_head_of_dll (thisAgent->ms_retractions, msc, next, prev);
if (msc->goal) { /* Goal exists */
next_in_level, prev_in_level);
}
else { /* NIL Goal; put on the NIL Goal list */
msc, next_in_level, prev_in_level);
}
#ifdef DEBUG_WATERFALL
print_with_symbols(thisAgent, "\nRetraction: %y", msc->inst->prod->name);
print(" is active at level %d\n", msc->level);
{ ms_change *assertion;
print("\n Retractions list:\n");
for (assertion=thisAgent->ms_retractions;
assertion;
assertion=assertion->next) {
print_with_symbols(thisAgent, " Retraction: %y ",
assertion->p_node->b.p.prod->name);
print(" at level %d\n", assertion->level);
}
if (thisAgent->nil_goal_retractions) {
print("\nCurrent NIL Goal list:\n");
assertion = NIL;
for (assertion=thisAgent->nil_goal_retractions;
assertion;
assertion=assertion->next_in_level) {
print_with_symbols(thisAgent, " Retraction: %y ",
assertion->p_node->b.p.prod->name);
print(" at level %d\n", assertion->level);
if (assertion->goal) print("This assertion has non-NIL goal pointer.\n");
}
}
}
#endif
/* REW: end 08.20.97 */
return;
}
/* REW: begin 09.15.96 */
if (thisAgent->soar_verbose_flag == TRUE) {
print_with_symbols (thisAgent, "\n%y: ",node->b.p.prod->name);
char buf[256];
SNPRINTF(buf, 254, "%s: ", symbol_to_string(thisAgent, node->b.p.prod->name, true, 0, 0));
xml_generate_verbose(thisAgent, buf);
}
/* REW: end 09.15.96 */
#ifdef BUG_139_WORKAROUND
#ifdef BUG_139_WORKAROUND_WARNING
print(thisAgent, "\nWarning: can't find an existing inst to retract (BUG 139 WORKAROUND)\n");
xml_generate_warning(thisAgent, "Warning: can't find an existing inst to retract (BUG 139 WORKAROUND)");
#endif
return;
}
#endif
{ char msg[BUFFER_MSG_SIZE];
strncpy (msg,
"Internal error: can't find existing instantiation to retract\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
}
void p_node_to_conditions_and_nots ( agent thisAgent,
rete_node p_node,
token 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;
}
}
void pop_bindings_and_deallocate_list_of_variables ( agent thisAgent,
list vars 
)
void pop_var_binding ( agent thisAgent,
void *  v 
)
inline

Definition at line 2518 of file rete.cpp.

References free_cons(), cons_struct::rest, variable_struct::rete_binding_locations, and symbol_union::var.

Referenced by pop_bindings_and_deallocate_list_of_variables().

{
cons *c_xy312;
c_xy312 = static_cast<Symbol *>(v)->var.rete_binding_locations;
static_cast<Symbol *>(v)->var.rete_binding_locations = c_xy312->rest;
free_cons (thisAgent, c_xy312);
}
void positive_node_left_addition ( agent thisAgent,
rete_node node,
token New,
Symbol hash_referent 
)

Definition at line 5024 of file rete.cpp.

References activation_entry_sanity_check, activation_exit_sanity_check, posneg_node_data_struct::alpha_mem_, right_mem_struct::am, alpha_mem_struct::am_id, rete_node_struct::b, FALSE, rete_node_struct::first_child, wme_struct::id, left_addition_routines(), left_node_activation(), match_left_and_right(), rete_test_struct::next, right_mem_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, node_is_right_unlinked(), rete_node_struct::node_type, posneg_node_data_struct::other_tests, rete_node_struct::rete_node_b_union::posneg, relink_to_right_mem(), right_ht_bucket(), alpha_mem_struct::right_mems, TRUE, uint32_t(), unlink_from_left_mem, and right_mem_struct::w.

Referenced by beta_memory_node_left_addition().

{
uint32_t right_hv;
right_mem *rm;
alpha_mem *am;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
am = node->b.posneg.alpha_mem_;
if (am->right_mems==NIL) {
return;
}
}
/* --- look through right memory for matches --- */
right_hv = am->am_id ^ hash_referent->common.hash_id;
for (rm=right_ht_bucket(thisAgent, right_hv); rm!=NIL; rm=rm->next_in_bucket) {
if (rm->am != am) continue;
/* --- does rm->w match New? --- */
if (hash_referent != rm->w->id) continue;
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, New, rm->w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,rm->w);
}
}
void positive_node_right_addition ( agent thisAgent,
rete_node node,
wme w 
)

Definition at line 5227 of file rete.cpp.

References token_struct::a, rete_node_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, FALSE, rete_node_struct::first_child, token_struct::token_a_union::ht, wme_struct::id, left_addition_routines(), left_ht_bucket(), match_left_and_right(), rete_test_struct::next, token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, node_is_left_unlinked(), rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::parent, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, relink_to_left_mem, right_node_activation(), non_pos_node_data_struct::tokens, TRUE, uint32_t(), and unlink_from_right_mem.

Referenced by init_left_and_right_addition_routines().

{
token *tok;
Symbol *referent;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
if (node_is_left_unlinked(node)) {
if (! node->parent->a.np.tokens) {
return;
}
}
referent = w->id;
hv = node->parent->node_id ^ referent->common.hash_id;
for (tok=left_ht_bucket(thisAgent, hv); tok!=NIL; tok=tok->a.ht.next_in_bucket) {
if (tok->node != node->parent) continue;
/* --- does tok match w? --- */
if (tok->a.ht.referent != referent) continue;
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, tok, w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,tok,w);
}
}
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;
}
int64_t ppmi_aux ( agent thisAgent,
rete_node node,
rete_node cutoff,
condition cond,
wme_trace_type  wtt,
int  indent 
)

Definition at line 7928 of file rete.cpp.

References posneg_node_data_struct::alpha_mem_, rete_node_struct::b, ncc_info_struct::bottom, rete_node_struct::rete_node_b_union::cn, CONJUNCTIVE_NEGATION_CONDITION, condition_struct::data, deallocate_token_list(), FULL_WME_TRACE, get_all_left_tokens_emerging_from_node(), MATCH_COUNT_STRING_BUFFER_SIZE, condition_struct::condition_main_data_union::ncc, right_mem_struct::next_in_am, token_struct::next_of_node, NIL, NONE_WME_TRACE, node_varnames_struct::parent, cn_node_data_struct::partner, rete_node_struct::rete_node_b_union::posneg, condition_struct::prev, print(), print_condition(), print_spaces(), print_whole_token(), print_wme(), real_parent_node(), alpha_mem_struct::right_mems, wme_struct::timetag, TIMETAG_WME_TRACE, condition_struct::type, and right_mem_struct::w.

Referenced by print_partial_match_information().

{ /* number of spaces indent */
token *tokens, *t, *parent_tokens;
right_mem *rm;
int64_t matches_one_level_up;
int64_t matches_at_this_level;
#define MATCH_COUNT_STRING_BUFFER_SIZE 20
char match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE];
/* --- find the number of matches for this condition --- */
tokens = get_all_left_tokens_emerging_from_node (thisAgent, node);
matches_at_this_level = 0;
for (t=tokens; t!=NIL; t=t->next_of_node) matches_at_this_level++;
deallocate_token_list (thisAgent, tokens);
/* --- if we're at the cutoff node, we're done --- */
if (node==cutoff) return matches_at_this_level;
/* --- do stuff higher up --- */
parent = real_parent_node(node);
matches_one_level_up = ppmi_aux (thisAgent, parent, cutoff,
cond->prev, wtt, indent);
/* --- Form string for current match count: If an earlier cond had no
matches, just leave it blank; if this is the first 0, use ">>>>" --- */
if (! matches_one_level_up) {
strncpy (match_count_string, " ", MATCH_COUNT_STRING_BUFFER_SIZE);
match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE - 1] = 0; /* ensure null termination */
} else if (! matches_at_this_level) {
strncpy (match_count_string, ">>>>", MATCH_COUNT_STRING_BUFFER_SIZE);
match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE - 1] = 0; /* ensure null termination */
} else {
SNPRINTF (match_count_string, MATCH_COUNT_STRING_BUFFER_SIZE, "%4ld", static_cast<long int>(matches_at_this_level));
match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE - 1] = 0; /* ensure null termination */
}
/* --- print extra indentation spaces --- */
print_spaces (thisAgent, indent);
/* --- recursively print match counts for the NCC subconditions --- */
print (thisAgent, " -{\n");
ppmi_aux (thisAgent, real_parent_node(node->b.cn.partner),
parent,
cond->data.ncc.bottom,
wtt,
indent+5);
print_spaces (thisAgent, indent);
print (thisAgent, "%s }\n", match_count_string);
} else {
print (thisAgent, "%s", match_count_string);
print_condition (thisAgent, cond);
print (thisAgent, "\n");
/* --- if this is the first match-failure (0 matches), print info on
matches for left and right --- */
if (matches_one_level_up && (!matches_at_this_level)) {
if (wtt!=NONE_WME_TRACE) {
print_spaces (thisAgent, indent);
print (thisAgent, "*** Matches For Left ***\n");
parent_tokens = get_all_left_tokens_emerging_from_node (thisAgent, parent);
for (t=parent_tokens; t!=NIL; t=t->next_of_node) {
print_spaces (thisAgent, indent);
print_whole_token (thisAgent, t, wtt);
print (thisAgent, "\n");
}
deallocate_token_list (thisAgent, parent_tokens);
print_spaces (thisAgent, indent);
print (thisAgent, "*** Matches for Right ***\n");
print_spaces (thisAgent, indent);
for (rm=node->b.posneg.alpha_mem_->right_mems; rm!=NIL;
rm=rm->next_in_am) {
if (wtt==TIMETAG_WME_TRACE) print (thisAgent, "%lu", rm->w->timetag);
else if (wtt==FULL_WME_TRACE) print_wme (thisAgent, rm->w);
print (thisAgent, " ");
}
print (thisAgent, "\n");
}
} /* end of if (matches_one_level_up ...) */
}
/* --- return result --- */
return matches_at_this_level;
}
void print_assertion ( agent thisAgent,
ms_change msc 
)

Definition at line 1078 of file rete.cpp.

References rete_node_struct::b, production_struct::name, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, print(), print_with_symbols(), and p_node_data_struct::prod.

{
if (msc->p_node)
print_with_symbols(thisAgent, "\nAssertion: %y", msc->p_node->b.p.prod->name);
else
print(thisAgent, "\nAssertion exists but has no p_node");
}
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,
rete_node 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 print_retraction ( agent thisAgent,
ms_change msc 
)

Definition at line 1086 of file rete.cpp.

References rete_node_struct::b, production_struct::name, rete_node_struct::rete_node_b_union::p, ms_change_struct::p_node, print(), print_with_symbols(), and p_node_data_struct::prod.

{
if (msc->p_node)
print_with_symbols(thisAgent, "\nRetraction: %y", msc->p_node->b.p.prod->name);
else
print(thisAgent, "\nRetraction exists but has no p_node");
}
void print_whole_token ( agent thisAgent,
token t,
wme_trace_type  wtt 
)

Definition at line 7896 of file rete.cpp.

References agent_struct::dummy_top_token, FULL_WME_TRACE, NONE_WME_TRACE, token_struct::parent, print(), print_wme(), wme_struct::timetag, TIMETAG_WME_TRACE, and token_struct::w.

Referenced by ppmi_aux(), print_match_set(), and print_partial_match_information().

{
if (t==thisAgent->dummy_top_token) return;
print_whole_token (thisAgent, t->parent, wtt);
if (t->w) {
if (wtt==TIMETAG_WME_TRACE) print (thisAgent, "%lu", t->w->timetag);
else if (wtt==FULL_WME_TRACE) print_wme (thisAgent, t->w);
if (wtt!=NONE_WME_TRACE) print (thisAgent, " ");
}
}
void push_var_binding ( agent thisAgent,
Symbol v,
rete_node_level  depth,
byte  field_num 
)
inline

Definition at line 2506 of file rete.cpp.

References push(), variable_struct::rete_binding_locations, symbol_union::var, and varloc_to_dummy().

Referenced by bind_variables_in_test().

{
void *dummy_xy312;
dummy_xy312 = varloc_to_dummy (depth, field_num);
push(thisAgent, dummy_xy312, v->var.rete_binding_locations);
}
rete_node * real_parent_node ( rete_node x)
inline
void relink_to_right_mem ( rete_node node)
inline

Definition at line 502 of file rete.cpp.

References posneg_node_data_struct::alpha_mem_, rete_node_struct::b, alpha_mem_struct::beta_nodes, alpha_mem_struct::last_beta_node, posneg_node_data_struct::nearest_ancestor_with_same_am, posneg_node_data_struct::next_from_alpha_mem, NIL, node_is_right_unlinked(), rete_node_struct::rete_node_b_union::posneg, and posneg_node_data_struct::prev_from_alpha_mem.

Referenced by make_new_negative_node(), make_new_positive_node(), mp_node_left_addition(), negative_node_left_addition(), positive_node_left_addition(), unhashed_mp_node_left_addition(), unhashed_negative_node_left_addition(), and unhashed_positive_node_left_addition().

{
rete_node *rtrm_ancestor, *rtrm_prev;
/* find first ancestor that's linked */
rtrm_ancestor = (node)->b.posneg.nearest_ancestor_with_same_am;
while (rtrm_ancestor && node_is_right_unlinked(rtrm_ancestor))
rtrm_ancestor = rtrm_ancestor->b.posneg.nearest_ancestor_with_same_am;
if (rtrm_ancestor) {
/* insert just before that ancestor */
rtrm_prev = rtrm_ancestor->b.posneg.prev_from_alpha_mem;
(node)->b.posneg.next_from_alpha_mem = rtrm_ancestor;
(node)->b.posneg.prev_from_alpha_mem = rtrm_prev;
rtrm_ancestor->b.posneg.prev_from_alpha_mem = (node);
if (rtrm_prev) rtrm_prev->b.posneg.next_from_alpha_mem = (node);
else (node)->b.posneg.alpha_mem_->beta_nodes = (node);
} else {
/* no such ancestor, insert at tail of list */
rtrm_prev = (node)->b.posneg.alpha_mem_->last_beta_node;
(node)->b.posneg.prev_from_alpha_mem = rtrm_prev;
if (rtrm_prev) rtrm_prev->b.posneg.next_from_alpha_mem = (node);
else (node)->b.posneg.alpha_mem_->beta_nodes = (node);
}
}
void remove_node_from_parents_list_of_children ( rete_node node)

Definition at line 1910 of file rete.cpp.

References rete_node_struct::first_child, rete_node_struct::next_sibling, and rete_node_struct::parent.

Referenced by deallocate_rete_node(), excise_production_from_rete(), make_new_cn_node(), merge_into_mp_node(), and split_mp_node().

{
prev_sibling = node->parent->first_child;
if (prev_sibling == node) {
return;
}
while (prev_sibling->next_sibling != node)
prev_sibling = prev_sibling->next_sibling;
prev_sibling->next_sibling = node->next_sibling;
}
void remove_ref_to_alpha_mem ( agent thisAgent,
alpha_mem am 
)

Definition at line 1823 of file rete.cpp.

References alpha_mem_struct::acceptable, agent_struct::alpha_mem_pool, alpha_mem_struct::attr, alpha_mem_struct::id, alpha_mem_struct::reference_count, remove_from_hash_table(), remove_wme_from_alpha_mem(), alpha_mem_struct::right_mems, symbol_remove_ref(), table_for_tests(), and alpha_mem_struct::value.

Referenced by deallocate_rete_node(), make_node_for_negative_cond(), make_node_for_positive_cond(), and reteload_free_am_table().

{
if (am->reference_count!=0) return;
/* --- remove from hash table, and deallocate the alpha_mem --- */
ht = table_for_tests (thisAgent, am->id, am->attr, am->value, am->acceptable);
remove_from_hash_table (thisAgent, ht, am);
if (am->id) symbol_remove_ref (thisAgent, am->id);
if (am->attr) symbol_remove_ref (thisAgent, am->attr);
if (am->value) symbol_remove_ref (thisAgent, am->value);
while (am->right_mems) remove_wme_from_alpha_mem (thisAgent, am->right_mems);
free_with_pool (&thisAgent->alpha_mem_pool, am);
}
void remove_token_and_subtree ( agent thisAgent,
token tok 
)

Definition at line 6323 of file rete.cpp.

References token_struct::a, rete_node_struct::a, abort_with_fatal_error(), rete_node_struct::b, BUFFER_MSG_SIZE, CN_BNODE, CN_PARTNER_BNODE, FALSE, fast_remove_from_dll, token_struct::first_child, rete_node_struct::first_child, beta_memory_node_data_struct::first_linked_child, token_struct::token_a_union::ht, left_addition_routines(), left_node_activation(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, rete_node_struct::rete_node_b_union::mem, MEMORY_BNODE, MP_BNODE, mp_bnode_is_left_unlinked(), token_struct::token_a_union::neg, NEGATIVE_BNODE, token_struct::negrm_tokens, pos_node_data_struct::next_from_beta_mem, token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::next_negrm, token_struct::next_sibling, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, P_BNODE, p_node_left_removal(), token_struct::parent, rete_node_struct::rete_node_a_union::pos, token_struct::token_a_union::token_in_hash_table_data_struct::referent, remove_token_from_left_ht(), agent_struct::token_pool, wme_struct::tokens, non_pos_node_data_struct::tokens, TRUE, UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, UNHASHED_NEGATIVE_BNODE, unlink_from_right_mem, and token_struct::w.

Referenced by cn_partner_node_left_addition(), deallocate_rete_node(), excise_production_from_rete(), negative_node_right_addition(), remove_wme_from_rete(), and unhashed_negative_node_right_addition().

{
rete_node *node, *child, *next;
token *tok, *next_value_for_tok, *left, *t, *next_t;
byte node_type;
tok = root;
while (TRUE) {
/* --- move down to the leftmost leaf --- */
while (tok->first_child) tok = tok->first_child;
next_value_for_tok = tok->next_sibling ? tok->next_sibling : tok->parent;
/* --- cleanup stuff common to all types of nodes --- */
node = tok->node;
if (tok->w) fast_remove_from_dll (tok->w->tokens, tok, token,
node_type = node->node_type;
/* --- for merged Mem/Pos nodes --- */
if ((node_type==MP_BNODE)||(node_type==UNHASHED_MP_BNODE)) {
remove_token_from_left_ht (thisAgent, tok, node->node_id ^
(tok->a.ht.referent ?
tok->a.ht.referent->common.hash_id : 0));
if (! node->a.np.tokens) unlink_from_right_mem (node);
}
/* --- for P nodes --- */
} else if (node_type==P_BNODE) {
p_node_left_removal (thisAgent, node, tok->parent, tok->w);
/* --- for Negative nodes --- */
} else if ((node_type==NEGATIVE_BNODE) ||
(node_type==UNHASHED_NEGATIVE_BNODE)) {
remove_token_from_left_ht (thisAgent, tok, node->node_id ^
(tok->a.ht.referent ?
tok->a.ht.referent->common.hash_id : 0));
if (! node->a.np.tokens) unlink_from_right_mem (node);
for (t=tok->negrm_tokens; t!=NIL; t=next_t) {
next_t = t->a.neg.next_negrm;
free_with_pool (&thisAgent->token_pool, t);
}
/* --- for Memory nodes --- */
} else if ((node_type==MEMORY_BNODE)||(node_type==UNHASHED_MEMORY_BNODE)) {
remove_token_from_left_ht (thisAgent, tok, node->node_id ^
(tok->a.ht.referent ?
tok->a.ht.referent->common.hash_id : 0));
#ifdef DO_ACTIVATION_STATS_ON_REMOVALS
/* --- if doing statistics stuff, then activate each attached node --- */
for (child=node->b.mem.first_linked_child; child!=NIL; child=next) {
next = child->a.pos.next_from_beta_mem;
}
#endif
/* --- for right unlinking, then if the beta memory just went to
zero, right unlink any attached Pos nodes --- */
if (! node->a.np.tokens) {
for (child=node->b.mem.first_linked_child; child!=NIL; child=next) {
next = child->a.pos.next_from_beta_mem;
}
}
/* --- for CN nodes --- */
} else if (node_type==CN_BNODE) {
remove_token_from_left_ht (thisAgent, tok, node->node_id ^
static_cast<uint32_t>(reinterpret_cast<uint64_t>(tok->parent)) ^
static_cast<uint32_t>(reinterpret_cast<uint64_t>(tok->w))); // double cast necessary for avoiding precision loss warning
for (t=tok->negrm_tokens; t!=NIL; t=next_t) {
next_t = t->a.neg.next_negrm;
if (t->w) fast_remove_from_dll (t->w->tokens, t, token,
free_with_pool (&thisAgent->token_pool, t);
}
/* --- for CN Partner nodes --- */
} else if (node_type==CN_PARTNER_BNODE) {
left = tok->a.neg.left_token;
if (! left->negrm_tokens) { /* just went to 0, so call children */
for (child=left->node->first_child; child!=NIL;
child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,left,NIL);
}
} else {
char msg[BUFFER_MSG_SIZE];
SNPRINTF (msg, BUFFER_MSG_SIZE,
"Internal error: bad node type %d in remove_token_and_subtree\n",
node->node_type);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
free_with_pool (&thisAgent->token_pool, tok);
if (tok==root) break; /* if leftmost leaf was the root, we're done */
tok = next_value_for_tok; /* else go get the leftmost leaf again */
}
}
void remove_token_from_left_ht ( agent thisAgent,
token tok,
uint32_t  hv 
)
inline

Definition at line 693 of file rete.cpp.

References fast_remove_from_dll, and left_ht_bucket().

Referenced by remove_token_and_subtree().

void remove_wme_from_alpha_mem ( agent thisAgent,
right_mem rm 
)

Definition at line 1431 of file rete.cpp.

References right_mem_struct::am, alpha_mem_struct::am_id, wme_struct::id, remove_from_dll, agent_struct::right_ht, RIGHT_HT_MASK, agent_struct::right_mem_pool, wme_struct::right_mems, alpha_mem_struct::right_mems, uint32_t(), and right_mem_struct::w.

Referenced by remove_ref_to_alpha_mem(), and remove_wme_from_rete().

{
wme *w;
alpha_mem *am;
right_mem **header;
w = rm->w;
am = rm->am;
/* --- remove it from dll's for the hash bucket, alpha mem, and wme --- */
hv = am->am_id ^ w->id->common.hash_id;
header = reinterpret_cast<right_mem **>(thisAgent->right_ht) + (hv & RIGHT_HT_MASK);
remove_from_dll (*header, rm, next_in_bucket, prev_in_bucket);
remove_from_dll (am->right_mems, rm, next_in_am, prev_in_am);
/* --- deallocate it --- */
free_with_pool (&thisAgent->right_mem_pool, rm);
}
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);
}
}
}
void rete_error_left ( agent thisAgent,
rete_node node,
token ,
wme  
)

Definition at line 4941 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, and rete_node_struct::node_type.

{
char msg[BUFFER_MSG_SIZE];
SNPRINTF (msg, BUFFER_MSG_SIZE, "Rete net error: tried to left-activate node of type %d\n",
node->node_type);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
void rete_error_right ( agent thisAgent,
rete_node node,
wme  
)

Definition at line 4949 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, and rete_node_struct::node_type.

{
char msg[BUFFER_MSG_SIZE];
SNPRINTF (msg, BUFFER_MSG_SIZE, "Rete net error: tried to right-activate node of type %d\n",
node->node_type);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
void rete_node_to_conditions ( agent thisAgent,
rete_node node,
node_varnames nvn,
rete_node cutoff,
token tok,
wme w,
condition conds_for_cutoff_and_up,
condition **  dest_top_cond,
condition **  dest_bottom_cond,
not_struct *&  nots_found_in_production 
)

Definition at line 4288 of file rete.cpp.

References wme_struct::acceptable, alpha_mem_struct::acceptable, add_gensymmed_equality_test(), add_hash_info_to_id_test(), add_rete_test_list_to_tests(), add_varnames_to_test(), posneg_node_data_struct::alpha_mem_, wme_struct::attr, alpha_mem_struct::attr, three_field_tests_struct::attr_test, three_field_varnames_struct::attr_varnames, rete_node_struct::b, bnode_is_positive(), ncc_info_struct::bottom, node_varnames_struct::varname_data_union::bottom_of_subconditions, condition_struct::bt, rete_node_struct::rete_node_b_union::cn, CN_BNODE, collect_nots(), agent_struct::condition_pool, CONJUNCTIVE_NEGATION_CONDITION, condition_struct::data, node_varnames_struct::data, node_varnames_struct::varname_data_union::fields, first_letter_from_test(), wme_struct::id, alpha_mem_struct::id, three_field_tests_struct::id_test, three_field_varnames_struct::id_varnames, rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, make_blank_or_equality_test(), make_equality_test(), MP_BNODE, condition_struct::condition_main_data_union::ncc, NEGATIVE_BNODE, NEGATIVE_CONDITION, condition_struct::next, NIL, rete_node_struct::node_type, posneg_node_data_struct::other_tests, token_struct::parent, rete_node_struct::parent, node_varnames_struct::parent, cn_node_data_struct::partner, POSITIVE_BNODE, POSITIVE_CONDITION, rete_node_struct::rete_node_b_union::posneg, condition_struct::prev, real_parent_node(), condition_struct::test_for_acceptable_preference, test_includes_equality_test_for_symbol(), condition_struct::condition_main_data_union::tests, ncc_info_struct::top, condition_struct::type, wme_struct::value, alpha_mem_struct::value, three_field_tests_struct::value_test, three_field_varnames_struct::value_varnames, token_struct::w, and bt_info_struct::wme_.

Referenced by p_node_to_conditions_and_nots().

{
condition *cond;
alpha_mem *am;
allocate_with_pool (thisAgent, &thisAgent->condition_pool, &cond);
if (real_parent_node(node)==cutoff) {
cond->prev = conds_for_cutoff_and_up; /* if this is the top of an NCC, this
will get replaced by NIL later */
*dest_top_cond = cond;
} else {
nvn ? nvn->parent : NIL,
cutoff,
tok ? tok->parent : NIL,
tok ? tok->w : NIL,
conds_for_cutoff_and_up,
dest_top_cond, &(cond->prev),
nots_found_in_production);
cond->prev->next = cond;
}
cond->next = NIL;
*dest_bottom_cond = cond;
if (node->node_type==CN_BNODE) {
node->parent,
NIL,
NIL,
cond->prev,
&(cond->data.ncc.top),
&(cond->data.ncc.bottom),
nots_found_in_production);
cond->data.ncc.top->prev = NIL;
} else {
else
if (w && (cond->type==POSITIVE_CONDITION)) {
/* --- make simple tests and collect nots --- */
cond->bt.wme_ = w;
if (node->b.posneg.other_tests) /* don't bother if there are no tests*/
collect_nots (thisAgent, node->b.posneg.other_tests, w, cond,
nots_found_in_production);
} else {
am = node->b.posneg.alpha_mem_;
if (nvn) {
&(cond->data.tests.id_test));
&(cond->data.tests.attr_test));
&(cond->data.tests.value_test));
}
/* --- on hashed nodes, add equality test for the hash function --- */
if ((node->node_type==MP_BNODE) || (node->node_type==NEGATIVE_BNODE)) {
add_hash_info_to_id_test (thisAgent, cond,
} else if (node->node_type==POSITIVE_BNODE) {
add_hash_info_to_id_test (thisAgent, cond,
}
/* --- if there are other tests, add them too --- */
if (node->b.posneg.other_tests)
add_rete_test_list_to_tests (thisAgent, cond, node->b.posneg.other_tests);
/* --- if we threw away the variable names, make sure there's some
equality test in each of the three fields --- */
if (! nvn) {
(cond->data.tests.id_test, NIL))
add_gensymmed_equality_test (thisAgent, &(cond->data.tests.id_test), 's');
(cond->data.tests.attr_test, NIL))
add_gensymmed_equality_test (thisAgent, &(cond->data.tests.attr_test), 'a');
}
}
}
}
Bool rete_test_lists_are_identical ( agent thisAgent,
rete_test rt1,
rete_test rt2 
)

Definition at line 3183 of file rete.cpp.

References FALSE, rete_test_struct::next, single_rete_tests_are_identical(), and TRUE.

Referenced by make_node_for_negative_cond(), and make_node_for_positive_cond().

{
while (rt1 && rt2) {
if (! single_rete_tests_are_identical(thisAgent, rt1,rt2))
return FALSE;
rt1 = rt1->next;
rt2 = rt2->next;
}
if (rt1==rt2) return TRUE; /* make sure they both hit end-of-list */
return FALSE;
}
action* reteload_action_list ( agent thisAgent,
FILE *  f 
)

Definition at line 7116 of file rete.cpp.

References action_struct::next, NIL, reteload_eight_bytes(), and reteload_rhs_action().

Referenced by reteload_node_and_children().

{
action *a, *prev_a, *first_a;
uint64_t count;
count = reteload_eight_bytes (f);
prev_a = NIL;
first_a = NIL; /* unneeded, but without it gcc -Wall warns here */
while (count--) {
a = reteload_rhs_action (thisAgent,f );
if (prev_a) prev_a->next = a; else first_a = a;
prev_a = a;
}
if (prev_a) prev_a->next = NIL; else first_a = NIL;
return first_a;
}
void reteload_all_symbols ( agent thisAgent,
FILE *  f 
)

Definition at line 6690 of file rete.cpp.

References allocate_memory(), make_float_constant(), make_int_constant(), make_sym_constant(), make_variable(), MISCELLANEOUS_MEM_USAGE, reteload_eight_bytes(), agent_struct::reteload_num_syms, reteload_string(), reteload_string_buf, and agent_struct::reteload_symbol_table.

Referenced by load_rete_net().

{
uint64_t num_sym_constants, num_variables;
uint64_t num_int_constants, num_float_constants;
Symbol **current_place_in_symtab;
uint64_t i;
num_sym_constants = reteload_eight_bytes(f);
num_variables = reteload_eight_bytes(f);
num_int_constants = reteload_eight_bytes(f);
num_float_constants = reteload_eight_bytes(f);
thisAgent->reteload_num_syms = num_sym_constants + num_variables + num_int_constants
+ num_float_constants;
/* --- allocate memory for the symbol table --- */
thisAgent->reteload_symbol_table = (Symbol **)
allocate_memory (thisAgent, thisAgent->reteload_num_syms*sizeof(char *),MISCELLANEOUS_MEM_USAGE);
/* --- read in all the symbols from the file --- */
current_place_in_symtab = thisAgent->reteload_symbol_table;
for (i=0; i<num_sym_constants; i++) {
*(current_place_in_symtab++) = make_sym_constant (thisAgent, reteload_string_buf);
}
for (i=0; i<num_variables; i++) {
*(current_place_in_symtab++) = make_variable (thisAgent, reteload_string_buf);
}
for (i=0; i<num_int_constants; i++) {
*(current_place_in_symtab++) =
make_int_constant (thisAgent, strtol(reteload_string_buf,NULL,10));
}
for (i=0; i<num_float_constants; i++) {
*(current_place_in_symtab++) =
make_float_constant (thisAgent, strtod(reteload_string_buf,NULL));
}
}
void reteload_alpha_memories ( agent thisAgent,
FILE *  f 
)

Definition at line 6804 of file rete.cpp.

References allocate_memory(), FALSE, find_or_make_alpha_mem(), MISCELLANEOUS_MEM_USAGE, agent_struct::reteload_am_table, reteload_eight_bytes(), agent_struct::reteload_num_ams, reteload_one_byte(), reteload_symbol_from_index(), and TRUE.

Referenced by load_rete_net().

{
uint64_t i;
Symbol *id, *attr, *value;
Bool acceptable;
thisAgent->reteload_am_table = (alpha_mem **)
allocate_memory (thisAgent, thisAgent->reteload_num_ams*sizeof(char *),MISCELLANEOUS_MEM_USAGE);
for (i=0; i<thisAgent->reteload_num_ams; i++) {
id = reteload_symbol_from_index(thisAgent,f);
attr = reteload_symbol_from_index(thisAgent,f);
value = reteload_symbol_from_index(thisAgent,f);
acceptable = reteload_one_byte(f) ? TRUE : FALSE;
*(thisAgent->reteload_am_table+i) = find_or_make_alpha_mem (thisAgent,id,attr,value,acceptable);
}
}
alpha_mem* reteload_am_from_index ( agent thisAgent,
FILE *  f 
)

Definition at line 6821 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, agent_struct::reteload_am_table, reteload_eight_bytes(), and agent_struct::reteload_num_ams.

Referenced by reteload_node_and_children().

{
uint64_t amindex;
amindex = reteload_eight_bytes(f) - 1;
if (amindex >= thisAgent->reteload_num_ams) {
char msg[BUFFER_MSG_SIZE];
strncpy (msg,
"Internal error (file corrupted?): alpha mem count too small\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
return *(thisAgent->reteload_am_table+amindex);
}
uint64_t reteload_eight_bytes ( FILE *  f)

Definition at line 6582 of file rete.cpp.

References rete_net_64, reteload_four_bytes(), and reteload_one_byte().

Referenced by load_rete_net(), reteload_action_list(), reteload_all_symbols(), reteload_alpha_memories(), reteload_am_from_index(), reteload_node_and_children(), reteload_rhs_value(), reteload_symbol_from_index(), and reteload_varnames().

{
if (!rete_net_64)
uint64_t i;
uint64_t tmp;
i += (tmp << 8);
i += (tmp << 16);
i += (tmp << 24);
i += (tmp << 32);
i += (tmp << 40);
i += (tmp << 48);
i += (tmp << 56);
return i;
}
uint32_t reteload_four_bytes ( FILE *  f)

Definition at line 6558 of file rete.cpp.

References reteload_one_byte(), and uint32_t().

Referenced by reteload_eight_bytes().

{
i += (reteload_one_byte(f) << 8);
i += (reteload_one_byte(f) << 16);
i += (reteload_one_byte(f) << 24);
return i;
}
void reteload_free_am_table ( agent thisAgent)

Definition at line 6835 of file rete.cpp.

References free_memory(), MISCELLANEOUS_MEM_USAGE, remove_ref_to_alpha_mem(), agent_struct::reteload_am_table, and agent_struct::reteload_num_ams.

Referenced by load_rete_net().

{
uint64_t i;
for (i=0; i<thisAgent->reteload_num_ams; i++)
remove_ref_to_alpha_mem (thisAgent, *(thisAgent->reteload_am_table+i));
}
void reteload_free_symbol_table ( agent thisAgent)

Definition at line 6745 of file rete.cpp.

References free_memory(), MISCELLANEOUS_MEM_USAGE, agent_struct::reteload_num_syms, agent_struct::reteload_symbol_table, and symbol_remove_ref().

Referenced by load_rete_net().

{
uint64_t i;
for (i=0; i<thisAgent->reteload_num_syms; i++)
symbol_remove_ref (thisAgent, *(thisAgent->reteload_symbol_table+i));
}
void reteload_node_and_children ( agent thisAgent,
rete_node parent,
FILE *  f 
)

Definition at line 7377 of file rete.cpp.

References abort_with_fatal_error(), production_struct::action_list, adjust_sharing_factors_from_here_to_top, agent_struct::all_productions_of_type, rete_node_struct::b, BUFFER_MSG_SIZE, CN_PARTNER_BNODE, production_struct::declared_support, destructively_reverse_list(), production_struct::documentation, FALSE, var_location_struct::field_num, production_struct::filename, production_struct::firing_count, get_number_from_symbol(), insert_at_head_of_dll, production_struct::instantiations, production_struct::interrupt, JUSTIFICATION_PRODUCTION_TYPE, var_location_struct::levels_up, make_memory_block_for_string(), make_new_cn_node(), make_new_mem_node(), make_new_mp_node(), make_new_negative_node(), make_new_positive_node(), make_new_production_node(), MEMORY_BNODE, MP_BNODE, production_struct::name, NEGATIVE_BNODE, NIL, agent_struct::num_productions_of_type, rete_node_struct::rete_node_b_union::p, P_BNODE, production_struct::p_node, node_varnames_struct::parent, p_node_data_struct::parents_nvn, POSITIVE_BNODE, sym_constant_struct::production, PRODUCTION_JUST_ADDED_CALLBACK, agent_struct::production_pool, push(), real_parent_node(), production_struct::reference_count, alpha_mem_struct::reference_count, action_struct::referent, reteload_action_list(), reteload_am_from_index(), reteload_eight_bytes(), reteload_node_varnames(), reteload_one_byte(), reteload_rete_test_list(), reteload_string(), reteload_string_buf, reteload_symbol_from_index(), reteload_two_bytes(), production_struct::rhs_unbound_variables, rhs_value_to_symbol(), production_struct::rl_delta_bar_delta_beta, production_struct::rl_delta_bar_delta_h, production_struct::rl_ecr, production_struct::rl_efr, production_struct::rl_rule, rl_rule_meta(), production_struct::rl_template_conds, production_struct::rl_template_instantiations, production_struct::rl_update_count, rl_valid_rule(), symbol_union::sc, soar_invoke_callbacks(), symbol_add_ref(), TEMPLATE_PRODUCTION_TYPE, production_struct::trace_firings, production_struct::type, UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, UNHASHED_NEGATIVE_BNODE, UNHASHED_POSITIVE_BNODE, update_max_rhs_unbound_variables(), and update_node_with_matches_from_above().

Referenced by load_rete_net().

{
byte type, left_unlinked_flag;
rete_node *New, *ncc_top;
uint64_t count;
alpha_mem *am;
production *prod;
Symbol *sym;
list *ubv_list;
var_location left_hash_loc;
rete_test *other_tests;
type = reteload_one_byte(f);
/*
Initializing the left_hash_loc structure to flag values.
It gets passed into some of the various make_new_??? functions
below but is never used (hopefully) for UNHASHED node types.
*/
left_hash_loc.field_num = static_cast<byte>(-1);
left_hash_loc.levels_up = static_cast<rete_node_level>(-1);
switch (type) {
left_hash_loc.field_num = reteload_one_byte(f);
left_hash_loc.levels_up = static_cast<rete_node_level>(reteload_two_bytes(f));
/* ... and fall through to the next case below ... */
New = make_new_mem_node (thisAgent, parent, type, left_hash_loc);
break;
case MP_BNODE:
left_hash_loc.field_num = reteload_one_byte(f);
left_hash_loc.levels_up = static_cast<rete_node_level>(reteload_two_bytes(f));
/* ... and fall through to the next case below ... */
am = reteload_am_from_index(thisAgent,f);
other_tests = reteload_rete_test_list(thisAgent,f);
left_unlinked_flag = reteload_one_byte(f);
New = make_new_mp_node (thisAgent, parent, type, left_hash_loc, am, other_tests,
left_unlinked_flag != 0);
break;
am = reteload_am_from_index(thisAgent,f);
other_tests = reteload_rete_test_list(thisAgent,f);
left_unlinked_flag = reteload_one_byte(f);
New = make_new_positive_node (thisAgent, parent, type, am, other_tests,
left_unlinked_flag != 0);
break;
left_hash_loc.field_num = reteload_one_byte(f);
left_hash_loc.levels_up = static_cast<rete_node_level>(reteload_two_bytes(f));
/* ... and fall through to the next case below ... */
am = reteload_am_from_index(thisAgent,f);
other_tests = reteload_rete_test_list(thisAgent,f);
New = make_new_negative_node (thisAgent, parent, type, left_hash_loc, am,other_tests);
break;
ncc_top = parent;
while (count--) ncc_top = real_parent_node (ncc_top);
New = make_new_cn_node (thisAgent, ncc_top, parent);
break;
case P_BNODE:
allocate_with_pool (thisAgent, &thisAgent->production_pool, &prod);
prod->reference_count = 1;
prod->firing_count = 0;
prod->filename = NIL;
prod->p_node = NIL;
prod->interrupt = FALSE;
sym = reteload_symbol_from_index (thisAgent,f);
prod->name = sym;
sym->sc.production = prod;
} else {
prod->documentation = NIL;
}
prod->type = reteload_one_byte (f);
prod->action_list = reteload_action_list (thisAgent,f);
count = reteload_eight_bytes (f);
ubv_list = NIL;
while (count--) {
sym = reteload_symbol_from_index(thisAgent,f);
push(thisAgent, sym, ubv_list);
}
prod, next, prev);
thisAgent->num_productions_of_type[prod->type]++;
// Soar-RL stuff
prod->rl_update_count = 0.0;
prod->rl_delta_bar_delta_h = 0.0;
prod->rl_update_count = 0;
prod->rl_rule = false;
prod->rl_ecr = 0.0;
prod->rl_efr = 0.0;
{
prod->rl_rule = rl_valid_rule( prod );
if ( prod->rl_rule )
{
if ( prod->documentation )
{
rl_rule_meta( thisAgent, prod );
}
}
}
New = make_new_production_node (thisAgent, parent, prod);
New->b.p.parents_nvn = reteload_node_varnames (thisAgent, parent,f);
} else {
New->b.p.parents_nvn = NIL;
}
/* --- call new node's add_left routine with all the parent's tokens --- */
/* --- invoke callback on the production --- */
soar_invoke_callbacks (thisAgent, PRODUCTION_JUST_ADDED_CALLBACK, static_cast<soar_call_data>(prod));
break;
default:
{ char msg[BUFFER_MSG_SIZE];
SNPRINTF (msg, BUFFER_MSG_SIZE,"Internal error: fastload found node type %d\n", type);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
New = NIL; /* unreachable, but without it gcc -Wall warns here */
}
} /* end of switch statement */
/* --- read in the children of the node --- */
while (count--) reteload_node_and_children (thisAgent, New,f);
}
node_varnames* reteload_node_varnames ( agent thisAgent,
rete_node node,
FILE *  f 
)
uint8_t reteload_one_byte ( FILE *  f)
rete_test* reteload_rete_test ( agent thisAgent,
FILE *  f 
)

Definition at line 7166 of file rete.cpp.

References rete_test_struct::rete_test_data_union::constant_referent, rete_test_struct::data, destructively_reverse_list(), rete_test_struct::rete_test_data_union::disjunction_list, DISJUNCTION_RETE_TEST, var_location_struct::field_num, var_location_struct::levels_up, NIL, push(), agent_struct::rete_test_pool, reteload_one_byte(), reteload_symbol_from_index(), reteload_two_bytes(), rete_test_struct::right_field_num, symbol_add_ref(), test_is_constant_relational_test(), test_is_variable_relational_test(), rete_test_struct::type, and rete_test_struct::rete_test_data_union::variable_referent.

Referenced by reteload_rete_test_list().

{
rete_test *rt;
Symbol *sym;
uint64_t count;
list *temp;
allocate_with_pool (thisAgent, &thisAgent->rete_test_pool, &rt);
} else if (rt->type==DISJUNCTION_RETE_TEST) {
count = reteload_two_bytes(f);
temp = NIL;
while (count--) {
sym = reteload_symbol_from_index(thisAgent,f);
push(thisAgent, sym, temp);
}
}
return rt;
}
rete_test* reteload_rete_test_list ( agent thisAgent,
FILE *  f 
)

Definition at line 7205 of file rete.cpp.

References rete_test_struct::next, NIL, reteload_rete_test(), and reteload_two_bytes().

Referenced by reteload_node_and_children().

{
rete_test *rt, *prev_rt, *first;
uint64_t count;
prev_rt = NIL;
first = NIL; /* unneeded, but without it gcc -Wall warns here */
count = reteload_two_bytes(f);
while (count--) {
rt = reteload_rete_test(thisAgent,f);
if (prev_rt) prev_rt->next = rt; else first = rt;
prev_rt = rt;
}
if (prev_rt) prev_rt->next = NIL; else first = NIL;
return first;
}
action* reteload_rhs_action ( agent thisAgent,
FILE *  f 
)
rhs_value reteload_rhs_value ( agent thisAgent,
FILE *  f 
)

Definition at line 6983 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, destructively_reverse_list(), funcall_list_to_rhs_value(), lookup_rhs_function(), NIL, print_with_symbols(), push(), reteload_eight_bytes(), reteload_one_byte(), reteload_symbol_from_index(), reteload_two_bytes(), reteloc_to_rhs_value(), symbol_add_ref(), symbol_to_rhs_value(), symbol_to_string(), TRUE, unboundvar_to_rhs_value(), and update_max_rhs_unbound_variables().

Referenced by reteload_rhs_action().

{
rhs_value rv, temp;
uint64_t i, count;
Symbol *sym;
byte type, field_num;
int levels_up;
list *funcall_list;
type = reteload_one_byte(f);
switch (type) {
case 0:
sym = reteload_symbol_from_index(thisAgent,f);
rv = symbol_to_rhs_value (sym);
break;
case 1:
funcall_list = NIL;
sym = reteload_symbol_from_index(thisAgent,f);
/* NLD: 4/30/2011
* I'm fairly certain function calls do not need an added ref.
*
* I traced through production parsing and the RHS function name is not kept around there. Instead, it "finds" the symbol
* (as opposed to "make", which adds a ref) and uses that to hash to the existing RHS function structure (which keeps a
* ref on the symbol name). The initial symbol ref comes from init_built_in_rhs_functions (+1 ref) and then is removed
* later via remove_built_in_rhs_functions (-1 ref).
*
* The parallel in rete-net loading is the symbol table that is loaded in via reteload_all_symbols (+1 ref) and then freed
* in reteload_free_symbol_table (-1 ref).
*/
// symbol_add_ref (sym);
rf = lookup_rhs_function (thisAgent, sym);
if (!rf) {
char msg[BUFFER_MSG_SIZE];
print_with_symbols (thisAgent, "Error: can't load this file because it uses an undefined RHS function %y\n", sym);
SNPRINTF (msg, BUFFER_MSG_SIZE, "Error: can't load this file because it uses an undefined RHS function %s\n", symbol_to_string(thisAgent, sym,TRUE,NIL, 0));
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
push(thisAgent, rf, funcall_list);
count = reteload_eight_bytes(f);
while (count--) {
temp = reteload_rhs_value(thisAgent,f);
push(thisAgent, temp, funcall_list);
}
funcall_list = destructively_reverse_list (funcall_list);
rv = funcall_list_to_rhs_value (funcall_list);
break;
case 2:
field_num = reteload_one_byte(f);
levels_up = reteload_two_bytes(f);
rv = reteloc_to_rhs_value (field_num, static_cast<rete_node_level>(levels_up));
break;
case 3:
break;
default:
{ char msg[BUFFER_MSG_SIZE];
strncpy (msg, "Internal error (file corrupted?): bad rhs_value type\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
rv = NIL; /* unreachable, but without it gcc -Wall warns */
}
return rv;
}
void reteload_string ( FILE *  f)

Definition at line 6624 of file rete.cpp.

References reteload_one_byte(), and reteload_string_buf.

Referenced by load_rete_net(), reteload_all_symbols(), and reteload_node_and_children().

{
int i, ch;
i = 0;
do {
reteload_string_buf[i++] = static_cast<char>(ch);
} while (ch);
}
Symbol* reteload_symbol_from_index ( agent thisAgent,
FILE *  f 
)

Definition at line 6730 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, NIL, reteload_eight_bytes(), agent_struct::reteload_num_syms, and agent_struct::reteload_symbol_table.

Referenced by reteload_alpha_memories(), reteload_node_and_children(), reteload_rete_test(), reteload_rhs_value(), and reteload_varnames().

{
uint64_t index;
if (index==0) return NIL;
index--;
if (index >= thisAgent->reteload_num_syms) {
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "Internal error (file corrupted?): symbol count too small\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
return *(thisAgent->reteload_symbol_table+index);
}
uint16_t reteload_two_bytes ( FILE *  f)

Definition at line 6544 of file rete.cpp.

References reteload_one_byte().

Referenced by reteload_node_and_children(), reteload_rete_test(), reteload_rete_test_list(), and reteload_rhs_value().

{
uint16_t i;
i += (reteload_one_byte(f) << 8);
return i;
}
varnames* reteload_varnames ( agent thisAgent,
FILE *  f 
)

Definition at line 6878 of file rete.cpp.

References destructively_reverse_list(), NIL, one_var_to_varnames(), push(), reteload_eight_bytes(), reteload_one_byte(), reteload_symbol_from_index(), symbol_add_ref(), and var_list_to_varnames().

Referenced by reteload_node_varnames().

{
list *c;
uint64_t i, count;
Symbol *sym;
if (i==0) return NIL;
if (i==1) {
sym = reteload_symbol_from_index (thisAgent,f);
return one_var_to_varnames (sym);
} else {
count = reteload_eight_bytes (f);
c = NIL;
while (count--) {
sym = reteload_symbol_from_index (thisAgent,f);
push(thisAgent, sym, c);
}
}
}
void retesave_action_list ( action first_a,
FILE *  f 
)

Definition at line 7107 of file rete.cpp.

References action_struct::next, NIL, retesave_eight_bytes(), and retesave_rhs_action().

Referenced by retesave_rete_node_and_children().

{
uint64_t i;
for (i=0, a=first_a; a!=NIL; i++, a=a->next);
for (a=first_a; a!=NIL; a=a->next) retesave_rhs_action (a,f);
}
Bool retesave_alpha_mem_and_assign_index ( agent thisAgent,
void *  item,
void *  userdata 
)

Definition at line 6778 of file rete.cpp.

References alpha_mem_struct::acceptable, alpha_mem_struct::attr, agent_struct::current_retesave_amindex, FALSE, alpha_mem_struct::id, alpha_mem_struct::retesave_amindex, retesave_eight_bytes(), retesave_one_byte(), and alpha_mem_struct::value.

Referenced by retesave_alpha_memories().

{
alpha_mem *am;
FILE* f = reinterpret_cast<FILE*>(userdata);
am = static_cast<alpha_mem_struct *>(item);
retesave_eight_bytes (am->id ? am->id->common.a.retesave_symindex : 0,f);
retesave_eight_bytes (am->attr ? am->attr->common.a.retesave_symindex : 0,f);
retesave_eight_bytes (am->value ? am->value->common.a.retesave_symindex : 0,f);
retesave_one_byte (static_cast<byte>(am->acceptable ? 1 : 0),f);
return FALSE;
}
void retesave_alpha_memories ( agent thisAgent,
FILE *  f 
)

Definition at line 6792 of file rete.cpp.

References agent_struct::alpha_hash_tables, hash_table_struct::count, agent_struct::current_retesave_amindex, do_for_all_items_in_hash_table(), retesave_alpha_mem_and_assign_index(), and retesave_eight_bytes().

Referenced by save_rete_net().

{
uint64_t i, num_ams;
thisAgent->current_retesave_amindex = 0;
num_ams = 0;
for (i=0; i<16; i++) num_ams += thisAgent->alpha_hash_tables[i]->count;
retesave_eight_bytes (num_ams,f);
for (i=0; i<16; i++)
}
void retesave_children_of_node ( agent thisAgent,
rete_node node,
FILE *  f 
)

Definition at line 7270 of file rete.cpp.

References CN_BNODE, rete_node_struct::first_child, rete_node_struct::next_sibling, rete_node_struct::node_type, retesave_eight_bytes(), and retesave_rete_node_and_children().

Referenced by retesave_rete_node_and_children(), and save_rete_net().

{
uint64_t i; rete_node *child;
/* --- Count number of non-CN-node children. --- */
for (i=0, child=node->first_child; child; child=child->next_sibling)
if (child->node_type != CN_BNODE) i++;
/* --- Write out records for all the node's children except CN's. --- */
for (child=node->first_child; child; child=child->next_sibling)
if (child->node_type != CN_BNODE)
retesave_rete_node_and_children (thisAgent, child, f);
}
void retesave_eight_bytes ( uint64_t  w,
FILE *  f 
)

Definition at line 6567 of file rete.cpp.

References rete_net_64, retesave_four_bytes(), and retesave_one_byte().

Referenced by retesave_action_list(), retesave_alpha_mem_and_assign_index(), retesave_alpha_memories(), retesave_children_of_node(), retesave_rete_node_and_children(), retesave_rete_test(), retesave_rhs_value(), retesave_symbol_table(), and retesave_varnames().

{
if (!rete_net_64) {
retesave_four_bytes(static_cast<uint32_t>(w), f);
return;
}
retesave_one_byte (static_cast<uint8_t>(w & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 8) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 16) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 24) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 32) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 40) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 48) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 56) & 0xFF), f);
}
void retesave_four_bytes ( uint32_t  w,
FILE *  f 
)

Definition at line 6551 of file rete.cpp.

References retesave_one_byte().

Referenced by retesave_eight_bytes().

{
retesave_one_byte (static_cast<uint8_t>(w & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 8) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 16) & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 24) & 0xFF), f);
}
void retesave_node_varnames ( node_varnames nvn,
rete_node node,
FILE *  f 
)
void retesave_one_byte ( uint8_t  b,
FILE *   
)
void retesave_rete_node_and_children ( agent thisAgent,
rete_node node,
FILE *  f 
)

Definition at line 7284 of file rete.cpp.

References rete_node_struct::a, abort_with_fatal_error(), production_struct::action_list, posneg_node_data_struct::alpha_mem_, rete_node_struct::b, BUFFER_MSG_SIZE, rete_node_struct::rete_node_b_union::cn, CN_BNODE, CN_PARTNER_BNODE, production_struct::declared_support, production_struct::documentation, cons_struct::first, non_pos_node_data_struct::is_left_unlinked, rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, MEMORY_BNODE, MP_BNODE, production_struct::name, NEGATIVE_BNODE, NIL, node_is_left_unlinked(), rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::rete_node_b_union::p, P_BNODE, rete_node_struct::parent, p_node_data_struct::parents_nvn, cn_node_data_struct::partner, POSITIVE_BNODE, rete_node_struct::rete_node_b_union::posneg, p_node_data_struct::prod, real_parent_node(), cons_struct::rest, retesave_action_list(), alpha_mem_struct::retesave_amindex, retesave_children_of_node(), retesave_eight_bytes(), retesave_node_varnames(), retesave_one_byte(), retesave_rete_test_list(), retesave_string(), retesave_two_bytes(), production_struct::rhs_unbound_variables, production_struct::type, UNHASHED_MEMORY_BNODE, UNHASHED_MP_BNODE, UNHASHED_NEGATIVE_BNODE, and UNHASHED_POSITIVE_BNODE.

Referenced by retesave_children_of_node().

{
uint64_t i;
production *prod;
cons *c;
rete_node *temp;
if (node->node_type == CN_BNODE) return; /* ignore CN nodes */
switch (node->node_type) {
/* ... and fall through to the next case below ... */
break;
case MP_BNODE:
/* ... and fall through to the next case below ... */
retesave_one_byte (static_cast<byte>(node->a.np.is_left_unlinked ? 1 : 0),f);
break;
retesave_one_byte (static_cast<byte>(node_is_left_unlinked(node) ? 1 : 0),f);
break;
/* ... and fall through to the next case below ... */
break;
i=0;
temp = real_parent_node (node);
while (temp != node->b.cn.partner->parent) {
temp = real_parent_node (temp);
i++;
}
break;
case P_BNODE:
prod = node->b.p.prod;
retesave_eight_bytes (prod->name->common.a.retesave_symindex,f);
if (prod->documentation) {
} else {
}
for (i=0, c=prod->rhs_unbound_variables; c!=NIL; i++, c=c->rest);
for (c=prod->rhs_unbound_variables; c!=NIL; c=c->rest)
retesave_eight_bytes (static_cast<Symbol *>(c->first)->common.a.retesave_symindex,f);
if (node->b.p.parents_nvn) {
} else {
}
break;
default:
{char msg[BUFFER_MSG_SIZE];
SNPRINTF (msg, BUFFER_MSG_SIZE,
"Internal error: fastsave found node type %d\n", node->node_type);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
} /* end of switch statement */
/* --- For cn_p nodes, write out the CN node's children instead --- */
if (node->node_type == CN_PARTNER_BNODE) node = node->b.cn.partner;
/* --- Write out records for all the node's children. --- */
retesave_children_of_node (thisAgent, node,f);
}
void retesave_rete_test ( rete_test rt,
FILE *  f 
)
void retesave_rete_test_list ( rete_test first_rt,
FILE *  f 
)

Definition at line 7195 of file rete.cpp.

References rete_test_struct::next, NIL, retesave_rete_test(), and retesave_two_bytes().

Referenced by retesave_rete_node_and_children().

{
uint64_t i;
rete_test *rt;
for (i=0, rt=first_rt; rt!=NIL; i++, rt=rt->next);
retesave_two_bytes (static_cast<uint16_t>(i),f);
for (rt=first_rt; rt!=NIL; rt=rt->next)
}
void retesave_rhs_action ( action a,
FILE *  f 
)
void retesave_rhs_value ( rhs_value  rv,
FILE *  f 
)
void retesave_string ( const char *  s,
FILE *  f 
)

Definition at line 6616 of file rete.cpp.

References retesave_one_byte().

Referenced by retesave_rete_node_and_children(), retesave_symbol_and_assign_index(), and save_rete_net().

{
while (*s) {
s++;
}
}
Bool retesave_symbol_and_assign_index ( agent thisAgent,
void *  item,
void *  userdata 
)

Definition at line 6661 of file rete.cpp.

References agent_struct::current_retesave_symindex, FALSE, NIL, retesave_string(), and symbol_to_string().

Referenced by retesave_symbol_table().

{
Symbol *sym;
FILE* f = reinterpret_cast<FILE*>(userdata);
sym = static_cast<symbol_union *>(item);
sym->common.a.retesave_symindex = thisAgent->current_retesave_symindex;
retesave_string (symbol_to_string (thisAgent, sym, FALSE, NIL, 0), f);
return FALSE;
}
void retesave_symbol_table ( agent thisAgent,
FILE *  f 
)
void retesave_two_bytes ( uint16_t  w,
FILE *  f 
)

Definition at line 6539 of file rete.cpp.

References retesave_one_byte().

Referenced by retesave_rete_node_and_children(), retesave_rete_test(), retesave_rete_test_list(), and retesave_rhs_value().

{
retesave_one_byte (static_cast<uint8_t>(w & 0xFF), f);
retesave_one_byte (static_cast<uint8_t>((w >> 8) & 0xFF), f);
}
void retesave_varnames ( varnames names,
FILE *  f 
)

Definition at line 6858 of file rete.cpp.

References NIL, cons_struct::rest, retesave_eight_bytes(), retesave_one_byte(), varnames_is_one_var(), varnames_to_one_var(), and varnames_to_var_list().

Referenced by retesave_node_varnames().

{
list *c;
uint64_t i;
Symbol *sym;
if (! names) {
} else if (varnames_is_one_var(names)) {
sym = varnames_to_one_var (names);
retesave_eight_bytes (sym->common.a.retesave_symindex,f);
} else {
for (i=0, c=varnames_to_var_list(names); c!=NIL; i++, c=c->rest);
for (c=varnames_to_var_list(names); c!=NIL; c=c->rest)
retesave_eight_bytes (static_cast<Symbol *>(c->first)->common.a.retesave_symindex,f);
}
}
void right_addition_routines ( agent thisAgent,
rete_node node,
wme w 
)
right_mem* right_ht_bucket ( agent thisAgent,
uint32_t  hv 
)
inline

Definition at line 672 of file rete.cpp.

References agent_struct::right_ht, and RIGHT_HT_MASK.

Referenced by mp_node_left_addition(), negative_node_left_addition(), and positive_node_left_addition().

{
return * (reinterpret_cast<right_mem **>(thisAgent->right_ht) + (hv & RIGHT_HT_MASK));
}
void right_node_activation ( rete_node node,
Bool   
)
inline
Bool same_rhs ( action rhs1,
action rhs2,
bool  rl_chunk_stop 
)

Definition at line 3545 of file rete.cpp.

References action_struct::attr, FALSE, FLOAT_CONSTANT_SYMBOL_TYPE, FUNCALL_ACTION, action_struct::id, INT_CONSTANT_SYMBOL_TYPE, action_struct::next, preference_is_binary(), action_struct::preference_type, action_struct::referent, rhs_value_is_symbol(), rhs_value_to_symbol(), TRUE, action_struct::type, and action_struct::value.

Referenced by add_production_to_rete().

{
action *a1, *a2;
/* --- Scan through the two RHS's; make sure there's no function calls,
and make sure the actions are all the same. --- */
/* --- Warning: this relies on the representation of rhs_value's:
two of the same funcall will not be equal (==), but two of the
same symbol, reteloc, or unboundvar will be equal (==). --- */
a1 = rhs1;
a2 = rhs2;
while (a1 && a2) {
if (a1->type == FUNCALL_ACTION) return FALSE;
if (a2->type == FUNCALL_ACTION) return FALSE;
if (a1->preference_type != a2->preference_type) return FALSE;
if (a1->id != a2->id) return FALSE;
if (a1->attr != a2->attr) return FALSE;
if (a1->value != a2->value) return FALSE;
if (a1->referent != a2->referent)
{
bool stop=true;
if (rl_chunk_stop)
{
{
if (((a1r->common.symbol_type==INT_CONSTANT_SYMBOL_TYPE) || (a1r->common.symbol_type==FLOAT_CONSTANT_SYMBOL_TYPE)) &&
((a2r->common.symbol_type==INT_CONSTANT_SYMBOL_TYPE) || (a2r->common.symbol_type==FLOAT_CONSTANT_SYMBOL_TYPE)))
{
if (((a1==rhs1) && (!a1->next)) && ((a2==rhs2) && (!a2->next)))
{
stop=false;
}
}
}
}
if (stop) return FALSE;
}
a1 = a1->next;
a2 = a2->next;
}
/* --- If we reached the end of one RHS but not the other, then
they must be different --- */
if (a1 != a2) return FALSE;
/* --- If we got this far, the RHS's must be identical. --- */
return TRUE;
}
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;
}
Bool single_rete_tests_are_identical ( agent thisAgent,
rete_test rt1,
rete_test rt2 
)

Definition at line 3146 of file rete.cpp.

References abort_with_fatal_error(), BUFFER_MSG_SIZE, rete_test_struct::rete_test_data_union::constant_referent, rete_test_struct::data, rete_test_struct::rete_test_data_union::disjunction_list, DISJUNCTION_RETE_TEST, FALSE, cons_struct::first, ID_IS_GOAL_RETE_TEST, ID_IS_IMPASSE_RETE_TEST, NIL, cons_struct::rest, rete_test_struct::right_field_num, test_is_constant_relational_test(), test_is_variable_relational_test(), TRUE, rete_test_struct::type, var_locations_equal(), and rete_test_struct::rete_test_data_union::variable_referent.

Referenced by rete_test_lists_are_identical().

{
cons *c1, *c2;
if (rt1->type != rt2->type) return FALSE;
if (rt1->right_field_num != rt2->right_field_num) return FALSE;
}
if (rt1->type==ID_IS_GOAL_RETE_TEST) return TRUE;
if (rt1->type==ID_IS_IMPASSE_RETE_TEST) return TRUE;
if (rt1->type == DISJUNCTION_RETE_TEST) {
while ((c1!=NIL)&&(c2!=NIL)) {
if (c1->first != c2->first) return FALSE;
c1 = c1->rest;
c2 = c2->rest;
}
if (c1==c2) return TRUE;
return FALSE;
}
{ char msg[BUFFER_MSG_SIZE];
strncpy(msg,"Internal error: bad rete test type in single_rete_tests_are_identical\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
return FALSE; /* unreachable, but without it, gcc -Wall warns here */
}
rete_node* split_mp_node ( agent thisAgent,
rete_node mp_node 
)

Definition at line 2082 of file rete.cpp.

References rete_node_struct::a, rete_node_struct::b, rete_node_struct::first_child, beta_memory_node_data_struct::first_linked_child, init_new_rete_node_with_type(), rete_node_struct::left_hash_loc_field_num, rete_node_struct::left_hash_loc_levels_up, rete_node_struct::rete_node_b_union::mem, MEMORY_BNODE, MP_BNODE, mp_bnode_is_left_unlinked(), token_struct::next_of_node, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, rete_node_struct::parent, POSITIVE_BNODE, rete_node_struct::rete_node_b_union::posneg, relink_to_left_mem, remove_node_from_parents_list_of_children(), agent_struct::rete_node_pool, set_sharing_factor, non_pos_node_data_struct::tokens, UNHASHED_MEMORY_BNODE, UNHASHED_POSITIVE_BNODE, unlink_from_left_mem, and update_stats_for_destroying_node().

Referenced by make_node_for_positive_cond().

{
rete_node mp_copy;
rete_node *pos_node, *mem_node, *parent;
byte mem_node_type, node_type;
token *t;
/* --- determine appropriate node types for new M and P nodes --- */
if (mp_node->node_type==MP_BNODE) {
node_type = POSITIVE_BNODE;
mem_node_type = MEMORY_BNODE;
} else {
mem_node_type = UNHASHED_MEMORY_BNODE;
}
/* --- save a copy of the MP data, then kill the MP node --- */
mp_copy = *mp_node;
parent = mp_node->parent;
update_stats_for_destroying_node (thisAgent, mp_node); /* clean up rete stats stuff */
/* --- the old MP node will get transmogrified into the new Pos node --- */
pos_node = mp_node;
/* --- create the new M node, transfer the MP node's tokens to it --- */
allocate_with_pool (thisAgent, &thisAgent->rete_node_pool, &mem_node);
init_new_rete_node_with_type (thisAgent, mem_node, mem_node_type);
set_sharing_factor (mem_node, mp_copy.sharing_factor);
mem_node->parent = parent;
mem_node->next_sibling = parent->first_child;
parent->first_child = mem_node;
mem_node->first_child = pos_node;
mem_node->b.mem.first_linked_child = NIL;
mem_node->node_id = mp_copy.node_id;
mem_node->a.np.tokens = mp_node->a.np.tokens;
for (t=mp_node->a.np.tokens; t!=NIL; t=t->next_of_node) t->node = mem_node;
/* --- transmogrify the old MP node into the new Pos node --- */
init_new_rete_node_with_type (thisAgent, pos_node, node_type);
pos_node->parent = mem_node;
pos_node->first_child = mp_copy.first_child;
pos_node->next_sibling = NIL;
pos_node->b.posneg = mp_copy.b.posneg;
relink_to_left_mem (pos_node); /* for now, but might undo this below */
set_sharing_factor (pos_node, mp_copy.sharing_factor);
/* --- set join node's unlinking status according to mp_copy's --- */
return mem_node;
}
hash_table* table_for_tests ( agent thisAgent,
Symbol id,
Symbol attr,
Symbol value,
Bool  acceptable 
)
inline

Definition at line 1395 of file rete.cpp.

References agent_struct::alpha_hash_tables.

Referenced by find_alpha_mem(), find_or_make_alpha_mem(), and remove_ref_to_alpha_mem().

{
return thisAgent->alpha_hash_tables [ (id ? 1 : 0) + (attr ? 2 : 0) +
(value ? 4 : 0) +
(acceptable ? 8 : 0) ];
}
Bool test_is_constant_relational_test ( byte  x)
inline
Bool test_is_not_equal_test ( byte  x)
inline
Bool test_is_variable_relational_test ( byte  x)
inline
void unhashed_beta_memory_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)
void unhashed_mp_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 5177 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, posneg_node_data_struct::alpha_mem_, rete_node_struct::b, FALSE, rete_node_struct::first_child, token_struct::token_a_union::ht, insert_token_into_left_ht(), left_addition_routines(), left_node_activation(), make_mp_bnode_left_unlinked(), match_left_and_right(), mp_bnode_is_left_unlinked(), new_left_token(), rete_test_struct::next, right_mem_struct::next_in_am, rete_node_struct::next_sibling, NIL, rete_node_struct::node_id, node_is_right_unlinked(), rete_node_struct::node_type, posneg_node_data_struct::other_tests, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, relink_to_right_mem(), alpha_mem_struct::right_mems, token_added, agent_struct::token_pool, TRUE, uint32_t(), and right_mem_struct::w.

Referenced by init_left_and_right_addition_routines().

{
rete_node *child;
token *New;
right_mem *rm;
rete_test *rt;
Bool failed_a_test;
hv = node->node_id;
/* --- build new left token, add it to the hash table --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
insert_token_into_left_ht (thisAgent, New, hv);
New->a.ht.referent = NIL;
if (mp_bnode_is_left_unlinked(node)) return;
if (node->b.posneg.alpha_mem_->right_mems==NIL) {
return;
}
}
/* --- look through right memory for matches --- */
for (rm=node->b.posneg.alpha_mem_->right_mems; rm!=NIL;
rm=rm->next_in_am) {
/* --- does rm->w match new? --- */
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, New, rm->w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,rm->w);
}
}
void unhashed_mp_node_right_addition ( agent thisAgent,
rete_node node,
wme w 
)

Definition at line 5347 of file rete.cpp.

References token_struct::a, rete_node_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, FALSE, rete_node_struct::first_child, token_struct::token_a_union::ht, left_addition_routines(), left_ht_bucket(), make_mp_bnode_left_linked(), match_left_and_right(), mp_bnode_is_left_unlinked(), rete_test_struct::next, token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::rete_node_b_union::posneg, right_node_activation(), non_pos_node_data_struct::tokens, TRUE, uint32_t(), and unlink_from_right_mem.

Referenced by init_left_and_right_addition_routines().

{
token *tok;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
if (! node->a.np.tokens) {
return;
}
}
hv = node->node_id;
for (tok=left_ht_bucket(thisAgent, hv); tok!=NIL; tok=tok->a.ht.next_in_bucket) {
if (tok->node != node) continue;
/* --- does tok match w? --- */
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, tok, w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,tok,w);
}
}
void unhashed_negative_node_left_addition ( agent thisAgent,
rete_node node,
token tok,
wme w 
)

Definition at line 5465 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, posneg_node_data_struct::alpha_mem_, rete_node_struct::b, FALSE, token_struct::first_child, rete_node_struct::first_child, token_struct::token_a_union::ht, insert_at_head_of_dll, insert_token_into_left_ht(), left_addition_routines(), left_node_activation(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, match_left_and_right(), token_struct::token_a_union::neg, token_struct::negrm_tokens, new_left_token(), rete_test_struct::next, right_mem_struct::next_in_am, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, node_is_right_unlinked(), rete_node_struct::node_type, posneg_node_data_struct::other_tests, token_struct::parent, rete_node_struct::rete_node_b_union::posneg, token_struct::token_a_union::token_in_hash_table_data_struct::referent, relink_to_right_mem(), alpha_mem_struct::right_mems, token_added, agent_struct::token_pool, wme_struct::tokens, TRUE, uint32_t(), token_struct::w, and right_mem_struct::w.

Referenced by init_left_and_right_addition_routines().

{
rete_test *rt;
Bool failed_a_test;
right_mem *rm;
rete_node *child;
token *New;
hv = node->node_id;
/* --- build new token, add it to the hash table --- */
token_added(node);
allocate_with_pool (thisAgent, &thisAgent->token_pool, &New);
new_left_token (New, node, tok, w);
insert_token_into_left_ht (thisAgent, New, hv);
New->a.ht.referent = NIL;
New->negrm_tokens = NIL;
/* --- look through right memory for matches --- */
for (rm=node->b.posneg.alpha_mem_->right_mems; rm!=NIL; rm=rm->next_in_am) {
/* --- does rm->w match new? --- */
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, New, rm->w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
{ token *t;
allocate_with_pool (thisAgent, &thisAgent->token_pool, &t);
t->node = node;
t->parent = NIL;
t->w = rm->w;
t->a.neg.left_token = New;
}
}
/* --- if no matches were found, call each child node --- */
if (! New->negrm_tokens) {
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,NIL);
}
}
void unhashed_negative_node_right_addition ( agent thisAgent,
rete_node node,
wme w 
)

Definition at line 5561 of file rete.cpp.

References token_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, FALSE, token_struct::first_child, token_struct::token_a_union::ht, insert_at_head_of_dll, left_ht_bucket(), token_struct::token_a_union::token_from_right_memory_of_negative_or_cn_node_struct::left_token, match_left_and_right(), token_struct::token_a_union::neg, token_struct::negrm_tokens, rete_test_struct::next, token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, NIL, token_struct::node, rete_node_struct::node_id, posneg_node_data_struct::other_tests, token_struct::parent, rete_node_struct::rete_node_b_union::posneg, remove_token_and_subtree(), right_node_activation(), agent_struct::token_pool, wme_struct::tokens, TRUE, uint32_t(), and token_struct::w.

Referenced by init_left_and_right_addition_routines().

{
token *tok;
rete_test *rt;
Bool failed_a_test;
hv = node->node_id;
for (tok=left_ht_bucket(thisAgent, hv); tok!=NIL; tok=tok->a.ht.next_in_bucket) {
if (tok->node != node) continue;
/* --- does tok match w? --- */
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, tok, w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found: build new negrm token, remove descendent tokens --- */
{ token *t;
allocate_with_pool (thisAgent, &thisAgent->token_pool, &t);
t->node = node;
t->parent = NIL;
t->w = w;
t->a.neg.left_token = tok;
}
while (tok->first_child) remove_token_and_subtree (thisAgent, tok->first_child);
}
}
void unhashed_positive_node_left_addition ( agent thisAgent,
rete_node node,
token New 
)

Definition at line 5068 of file rete.cpp.

References activation_entry_sanity_check, activation_exit_sanity_check, posneg_node_data_struct::alpha_mem_, rete_node_struct::b, FALSE, rete_node_struct::first_child, left_addition_routines(), left_node_activation(), match_left_and_right(), rete_test_struct::next, right_mem_struct::next_in_am, rete_node_struct::next_sibling, NIL, node_is_right_unlinked(), rete_node_struct::node_type, posneg_node_data_struct::other_tests, rete_node_struct::rete_node_b_union::posneg, relink_to_right_mem(), alpha_mem_struct::right_mems, TRUE, unlink_from_left_mem, and right_mem_struct::w.

Referenced by unhashed_beta_memory_node_left_addition().

{
right_mem *rm;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
if (node->b.posneg.alpha_mem_->right_mems==NIL) {
return;
}
}
/* --- look through right memory for matches --- */
for (rm=node->b.posneg.alpha_mem_->right_mems; rm!=NIL;
rm=rm->next_in_am) {
/* --- does rm->w match new? --- */
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, New, rm->w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,New,rm->w);
}
}
void unhashed_positive_node_right_addition ( agent thisAgent,
rete_node node,
wme w 
)

Definition at line 5268 of file rete.cpp.

References token_struct::a, rete_node_struct::a, activation_entry_sanity_check, activation_exit_sanity_check, rete_node_struct::b, FALSE, rete_node_struct::first_child, token_struct::token_a_union::ht, left_addition_routines(), left_ht_bucket(), match_left_and_right(), rete_test_struct::next, token_struct::token_a_union::token_in_hash_table_data_struct::next_in_bucket, rete_node_struct::next_sibling, NIL, token_struct::node, rete_node_struct::node_id, node_is_left_unlinked(), rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, posneg_node_data_struct::other_tests, rete_node_struct::parent, rete_node_struct::rete_node_b_union::posneg, relink_to_left_mem, right_node_activation(), non_pos_node_data_struct::tokens, TRUE, uint32_t(), and unlink_from_right_mem.

Referenced by init_left_and_right_addition_routines().

{
token *tok;
rete_test *rt;
Bool failed_a_test;
rete_node *child;
if (node_is_left_unlinked(node)) {
if (! node->parent->a.np.tokens) {
return;
}
}
hv = node->parent->node_id;
for (tok=left_ht_bucket(thisAgent, hv); tok!=NIL; tok=tok->a.ht.next_in_bucket) {
if (tok->node != node->parent) continue;
/* --- does tok match w? --- */
failed_a_test = FALSE;
for (rt=node->b.posneg.other_tests; rt!=NIL; rt=rt->next)
if (! match_left_and_right (thisAgent, rt, tok, w)) {
failed_a_test = TRUE;
break;
}
if (failed_a_test) continue;
/* --- match found, so call each child node --- */
for (child=node->first_child; child!=NIL; child=child->next_sibling)
(*(left_addition_routines[child->node_type]))(thisAgent,child,tok,w);
}
}
void update_max_rhs_unbound_variables ( agent thisAgent,
uint64_t  num_for_new_production 
)
void update_node_with_matches_from_above ( agent thisAgent,
rete_node child 
)

Definition at line 1931 of file rete.cpp.

References rete_node_struct::a, abort_with_fatal_error(), posneg_node_data_struct::alpha_mem_, rete_node_struct::b, bnode_is_bottom_of_split_mp(), bnode_is_positive(), BUFFER_MSG_SIZE, DUMMY_TOP_BNODE, agent_struct::dummy_top_token, rete_node_struct::first_child, left_addition_routines(), token_struct::negrm_tokens, right_mem_struct::next_in_am, token_struct::next_of_node, rete_node_struct::next_sibling, NIL, node_is_right_unlinked(), rete_node_struct::node_type, rete_node_struct::rete_node_a_union::np, rete_node_struct::parent, rete_node_struct::rete_node_b_union::posneg, right_addition_routines(), alpha_mem_struct::right_mems, non_pos_node_data_struct::tokens, and right_mem_struct::w.

Referenced by add_production_to_rete(), get_all_left_tokens_emerging_from_node(), make_new_cn_node(), make_new_mem_node(), make_new_negative_node(), and reteload_node_and_children().

{
rete_node *saved_parents_first_child, *saved_childs_next_sibling;
right_mem *rm;
token *tok;
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "\nrete.c: Internal error: update_node_with_matches_from_above called on split node", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error (thisAgent, msg);
}
parent = child->parent;
/* --- if parent is dummy top node, tell child about dummy top token --- */
if (parent->node_type==DUMMY_TOP_BNODE) {
(*(left_addition_routines[child->node_type]))(thisAgent,child,thisAgent->dummy_top_token,NIL);
return;
}
/* --- if parent is positive: first do surgery on parent's child list,
to replace the list with "child"; then call parent's add_right
routine with each wme in the parent's alpha mem; then do surgery
to restore previous child list of parent. --- */
if (bnode_is_positive(parent->node_type)) {
/* --- If the node is right unlinked, then don't activate it. This is
important because some interpreter routines rely on the node
being right linked whenever it gets right activated. */
if (node_is_right_unlinked (parent)) return;
saved_parents_first_child = parent->first_child;
saved_childs_next_sibling = child->next_sibling;
parent->first_child = child;
child->next_sibling = NIL;
/* to avoid double-counting these right adds */
rete_node* node_to_ignore_for_activation_stats = parent;
for (rm=parent->b.posneg.alpha_mem_->right_mems; rm!=NIL; rm=rm->next_in_am)
(*(right_addition_routines[parent->node_type]))(thisAgent,parent,rm->w);
node_to_ignore_for_activation_stats = NIL;
parent->first_child = saved_parents_first_child;
child->next_sibling = saved_childs_next_sibling;
return;
}
/* --- if parent is negative or cn: easy, just look at the list of tokens
on the parent node. --- */
for (tok=parent->a.np.tokens; tok!=NIL; tok=tok->next_of_node)
if (! tok->negrm_tokens)
(*(left_addition_routines[child->node_type])) (thisAgent,child,tok,NIL);
}
void update_stats_for_destroying_node ( agent thisAgent,
rete_node node 
)
inline
Symbol* var_bound_in_reconstructed_conds ( agent thisAgent,
condition cond,
byte  where_field_num,
rete_node_level  where_levels_up 
)

Definition at line 4027 of file rete.cpp.

References abort_with_fatal_error(), three_field_tests_struct::attr_test, BUFFER_MSG_SIZE, complex_test_from_test(), complex_test_struct::test_info_union::conjunct_list, CONJUNCTIVE_TEST, complex_test_struct::data, condition_struct::data, cons_struct::first, three_field_tests_struct::id_test, NIL, condition_struct::prev, referent_of_equality_test(), cons_struct::rest, test_is_blank_or_equality_test(), test_is_blank_test(), condition_struct::condition_main_data_union::tests, complex_test_struct::type, and three_field_tests_struct::value_test.

Referenced by add_hash_info_to_id_test(), add_rete_test_list_to_tests(), collect_nots(), and copy_rhs_value_and_substitute_varnames().

{
test t;
cons *c;
while (where_levels_up) { where_levels_up--; cond = cond->prev; }
if (where_field_num==0) t = cond->data.tests.id_test;
else if (where_field_num==1) t = cond->data.tests.attr_test;
else t = cond->data.tests.value_test;
if (test_is_blank_test(t)) goto abort_var_bound_in_reconstructed_conds;
if (ct->type==CONJUNCTIVE_TEST) {
for (c=ct->data.conjunct_list; c!=NIL; c=c->rest)
if ( (! test_is_blank_test (static_cast<test>(c->first))) &&
(test_is_blank_or_equality_test (static_cast<test>(c->first))) )
return referent_of_equality_test (static_cast<test>(c->first));
}
abort_var_bound_in_reconstructed_conds:
{ char msg[BUFFER_MSG_SIZE];
strncpy (msg, "Internal error in var_bound_in_reconstructed_conds\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
return 0; /* unreachable, but without it, gcc -Wall warns here */
}
bool var_is_bound ( Symbol v)
inline
varnames* var_list_to_varnames ( cons x)
inline

Definition at line 2660 of file rete.cpp.

Referenced by add_var_to_varnames(), and reteload_varnames().

{ return reinterpret_cast<varnames *>(reinterpret_cast<char *>(x) + 1); }
Bool var_locations_equal ( var_location  v1,
var_location  v2 
)
inline

Definition at line 269 of file rete.cpp.

Referenced by single_rete_tests_are_identical().

{
return ( ((v1).levels_up==(v2).levels_up) && ((v1).field_num==(v2).field_num) );
}
Bool variable_equal_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)
Bool variable_greater_or_equal_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)
Bool variable_greater_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)
Bool variable_less_or_equal_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)
Bool variable_less_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)
Bool variable_not_equal_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)
Bool variable_same_type_rete_test_routine ( agent ,
rete_test rt,
token left,
wme w 
)

Definition at line 4910 of file rete.cpp.

References rete_test_struct::data, field_from_wme(), var_location_struct::field_num, var_location_struct::levels_up, token_struct::parent, rete_test_struct::right_field_num, rete_test_struct::rete_test_data_union::variable_referent, and token_struct::w.

Referenced by init_rete().

{
Symbol *s1, *s2;
int i;
while (i!=0) {
left = left->parent;
i--;
}
w = left->w;
}
return (s1->common.symbol_type == s2->common.symbol_type);
}
void* varloc_to_dummy ( rete_node_level  depth,
byte  field_num 
)
inline

Definition at line 2485 of file rete.cpp.

Referenced by push_var_binding().

{
return reinterpret_cast<void *>((depth << 2) + field_num);
}
Bool varnames_is_one_var ( varnames x)
inline
uint64_t varnames_is_var_list ( varnames x)
inline

Definition at line 2661 of file rete.cpp.

Referenced by varnames_is_one_var().

{ return reinterpret_cast<uint64_t>(x) & 1; }
Symbol* varnames_to_one_var ( varnames x)
inline

Definition at line 2663 of file rete.cpp.

Referenced by add_var_to_varnames(), add_varnames_to_test(), deallocate_varnames(), and retesave_varnames().

{ return reinterpret_cast<Symbol *>(x); }
list* varnames_to_var_list ( varnames x)
inline

Definition at line 2664 of file rete.cpp.

Referenced by add_var_to_varnames(), add_varnames_to_test(), deallocate_varnames(), and retesave_varnames().

{ return reinterpret_cast<list *>(static_cast<char *>(x) - 1); }
Bool wme_matches_alpha_mem ( wme w,
alpha_mem am 
)
inline

Definition at line 1359 of file rete.cpp.

References wme_struct::acceptable, alpha_mem_struct::acceptable, wme_struct::attr, alpha_mem_struct::attr, wme_struct::id, alpha_mem_struct::id, NIL, wme_struct::value, and alpha_mem_struct::value.

Referenced by add_wme_to_aht(), and find_or_make_alpha_mem().

{
return ((am->id==NIL) || (am->id==w->id)) &&
((am->attr==NIL) || (am->attr==w->attr)) &&
((am->value==NIL) || (am->value==w->value)) &&
}
int64_t xml_aux ( agent thisAgent,
rete_node node,
rete_node cutoff,
condition cond,
wme_trace_type  wtt,
int  indent 
)

Definition at line 8876 of file rete.cpp.

References posneg_node_data_struct::alpha_mem_, rete_node_struct::b, ncc_info_struct::bottom, rete_node_struct::rete_node_b_union::cn, CONJUNCTIVE_NEGATION_CONDITION, condition_struct::data, deallocate_token_list(), FULL_WME_TRACE, get_all_left_tokens_emerging_from_node(), condition_struct::condition_main_data_union::ncc, right_mem_struct::next_in_am, token_struct::next_of_node, NIL, NONE_WME_TRACE, cn_node_data_struct::partner, rete_node_struct::rete_node_b_union::posneg, condition_struct::prev, real_parent_node(), alpha_mem_struct::right_mems, wme_struct::timetag, TIMETAG_WME_TRACE, condition_struct::type, right_mem_struct::w, xml_att_val(), xml_begin_tag(), xml_condition(), xml_end_tag(), xml_move_current_to_last_child(), xml_move_current_to_parent(), xml_object(), and xml_whole_token().

Referenced by xml_partial_match_information().

{ /* number of spaces indent */
token *tokens, *t, *parent_tokens;
right_mem *rm;
int64_t matches_one_level_up;
int64_t matches_at_this_level;
//#define MATCH_COUNT_STRING_BUFFER_SIZE 20
//char match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE];
/* --- find the number of matches for this condition --- */
tokens = get_all_left_tokens_emerging_from_node (thisAgent, node);
matches_at_this_level = 0;
for (t=tokens; t!=NIL; t=t->next_of_node) matches_at_this_level++;
deallocate_token_list (thisAgent, tokens);
/* --- if we're at the cutoff node, we're done --- */
if (node==cutoff) return matches_at_this_level;
/* --- do stuff higher up --- */
parent = real_parent_node(node);
matches_one_level_up = xml_aux (thisAgent, parent, cutoff,
cond->prev, wtt, indent);
/* --- Form string for current match count: If an earlier cond had no
matches, just leave it blank; if this is the first 0, use ">>>>" --- */
if (! matches_one_level_up) {
//xml_att_val(thisAgent, kMatchCount, 0) ;
//strncpy (match_count_string, " ", MATCH_COUNT_STRING_BUFFER_SIZE);
//match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE - 1] = 0; /* ensure null termination */
} else if (! matches_at_this_level) {
//xml_att_val(thisAgent, kMatchCount, 0) ;
//strncpy (match_count_string, ">>>>", MATCH_COUNT_STRING_BUFFER_SIZE);
//match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE - 1] = 0; /* ensure null termination */
} else {
//xml_att_val(thisAgent, kMatchCount, matches_at_this_level) ;
//SNPRINTF (match_count_string, MATCH_COUNT_STRING_BUFFER_SIZE, "%4ld", matches_at_this_level);
//match_count_string[MATCH_COUNT_STRING_BUFFER_SIZE - 1] = 0; /* ensure null termination */
}
/* --- print extra indentation spaces --- */
//print_spaces (thisAgent, indent);
/* --- recursively print match counts for the NCC subconditions --- */
xml_begin_tag(thisAgent, kTagConjunctive_Negation_Condition) ;
//print (thisAgent, " -{\n");
xml_aux (thisAgent, real_parent_node(node->b.cn.partner),
parent,
cond->data.ncc.bottom,
wtt,
indent+5);
//print_spaces (thisAgent, indent);
//print (thisAgent, "%s }\n", match_count_string);
xml_end_tag(thisAgent, kTagConjunctive_Negation_Condition) ;
} else {
//print (thisAgent, "%s", match_count_string);
xml_condition (thisAgent, cond);
// DJP: This is a trick to let us insert more attributes into xml_condition().
// DJP: Moved this test from earlier down to here as no longer building match_count_string
if (!matches_one_level_up)
xml_att_val(thisAgent, kMatchCount, 0) ;
else
xml_att_val(thisAgent, kMatchCount, matches_at_this_level) ;
//print (thisAgent, "\n");
/* --- if this is the first match-failure (0 matches), print info on
matches for left and right --- */
if (matches_one_level_up && (!matches_at_this_level)) {
if (wtt!=NONE_WME_TRACE) {
//print_spaces (thisAgent, indent);
xml_begin_tag(thisAgent, kTagLeftMatches) ;
//print (thisAgent, "*** Matches For Left ***\n");
parent_tokens = get_all_left_tokens_emerging_from_node (thisAgent, parent);
for (t=parent_tokens; t!=NIL; t=t->next_of_node) {
//print_spaces (thisAgent, indent);
xml_begin_tag(thisAgent, kTagToken) ;
xml_whole_token (thisAgent, t, wtt);
xml_end_tag(thisAgent, kTagToken) ;
//print (thisAgent, "\n");
}
deallocate_token_list (thisAgent, parent_tokens);
xml_end_tag(thisAgent, kTagLeftMatches) ;
//print_spaces (thisAgent, indent);
//print (thisAgent, "*** Matches for Right ***\n");
xml_begin_tag(thisAgent, kTagRightMatches) ;
//print_spaces (thisAgent, indent);
for (rm=node->b.posneg.alpha_mem_->right_mems; rm!=NIL;
rm=rm->next_in_am) {
//if (wtt==TIMETAG_WME_TRACE) print (thisAgent, "%lu", rm->w->timetag);
//else if (wtt==FULL_WME_TRACE) print_wme (thisAgent, rm->w);
//print (thisAgent, " ");
if (wtt==TIMETAG_WME_TRACE) xml_att_val(thisAgent, kWME_TimeTag, rm->w->timetag);
else if (wtt==FULL_WME_TRACE) xml_object (thisAgent, rm->w);
}
xml_end_tag(thisAgent, kTagRightMatches) ;
//print (thisAgent, "\n");
}
} /* end of if (matches_one_level_up ...) */
}
/* --- return result --- */
return matches_at_this_level;
}
void xml_condition ( agent thisAgent,
condition cond 
)

Definition at line 8552 of file rete.cpp.

References condition_struct::next, NIL, condition_struct::prev, TRUE, and xml_condition_list().

Referenced by xml_aux().

{
condition *old_next, *old_prev;
old_next = cond->next;
old_prev = cond->prev;
cond->next = NIL;
cond->prev = NIL;
xml_condition_list (thisAgent, cond, 0, TRUE);
cond->next = old_next;
cond->prev = old_prev;
}
void xml_condition_list ( agent thisAgent,
condition conds,
int  indent,
Bool  internal 
)

Definition at line 8391 of file rete.cpp.

References three_field_tests_struct::attr_test, COLUMNS_PER_LINE, CONJUNCTIVE_NEGATION_CONDITION, copy_of_equality_test_found_in_test(), copy_test_removing_goal_impasse_tests(), condition_struct::data, deallocate_test(), agent_struct::dl_cons_pool, extract_dl_list_elements(), FALSE, three_field_tests_struct::id_test, agent_struct::id_test_to_match, dl_cons_struct::item, condition_struct::condition_main_data_union::ncc, NEGATIVE_CONDITION, dl_cons_struct::next, condition_struct::next, match_set_trace::next, NIL, dl_cons_struct::prev, agent_struct::printer_output_column, remove_from_dll, condition_struct::test_for_acceptable_preference, test_is_blank_test(), test_to_string(), condition_struct::condition_main_data_union::tests, ncc_info_struct::top, TRUE, condition_struct::type, three_field_tests_struct::value_test, xml_att_val(), xml_begin_tag(), XML_CONDITION_LIST_TEMP_SIZE, xml_end_tag(), and xml_pick_conds_with_matching_id_test().

Referenced by xml_condition().

{
dl_list *conds_not_yet_printed, *tail_of_conds_not_yet_printed;
dl_list *conds_for_this_id;
dl_cons *dc;
Bool removed_goal_test, removed_impasse_test;
test id_test;
if (!conds) return;
/* --- build dl_list of all the actions --- */
conds_not_yet_printed = NIL;
tail_of_conds_not_yet_printed = NIL;
for (c=conds; c!=NIL; c=c->next)
{
allocate_with_pool (thisAgent, &thisAgent->dl_cons_pool, &dc);
dc->item = c;
if (conds_not_yet_printed)
{
tail_of_conds_not_yet_printed->next = dc;
}
else
{
conds_not_yet_printed = dc;
}
dc->prev = tail_of_conds_not_yet_printed;
tail_of_conds_not_yet_printed = dc;
}
tail_of_conds_not_yet_printed->next = NIL;
/* --- main loop: find all conds for first id, print them together --- */
Bool did_one_line_already = FALSE;
while (conds_not_yet_printed)
{
if (did_one_line_already)
{
//print (thisAgent, "\n");
//print_spaces (thisAgent, indent);
}
else
{
did_one_line_already = TRUE;
}
dc = conds_not_yet_printed;
remove_from_dll (conds_not_yet_printed, dc, next, prev);
c = static_cast<condition_struct *>(dc->item);
{
free_with_pool (&thisAgent->dl_cons_pool, dc);
//print_string (thisAgent, "-{");
xml_begin_tag(thisAgent, kTagConjunctive_Negation_Condition);
xml_condition_list (thisAgent, c->data.ncc.top, indent+2, internal);
xml_end_tag(thisAgent, kTagConjunctive_Negation_Condition);
//print_string (thisAgent, "}");
continue;
}
/* --- normal pos/neg conditions --- */
removed_goal_test = removed_impasse_test = FALSE;
&removed_goal_test,
&removed_impasse_test);
thisAgent->id_test_to_match = copy_of_equality_test_found_in_test (thisAgent, id_test);
/* --- collect all cond's whose id test matches this one --- */
conds_for_this_id = dc;
dc->prev = NIL;
if (internal)
{
dc->next = NIL;
}
else
{
dc->next = extract_dl_list_elements (thisAgent, &conds_not_yet_printed,
}
// DJP: Moved this loop out so we get a condition tag per condition on this id
// rather than an id with a series of conditions.
while (conds_for_this_id)
{
/* --- print the collected cond's all together --- */
//print_string (thisAgent, " (");
xml_begin_tag(thisAgent, kTagCondition);
if (removed_goal_test)
{
//print_string (thisAgent, "state ");
xml_att_val(thisAgent, kConditionTest, kConditionTestState);
}
if (removed_impasse_test)
{
//print_string (thisAgent, "impasse ");
xml_att_val(thisAgent, kConditionTest, kConditionTestImpasse);
}
//print_string (thisAgent, test_to_string (thisAgent, id_test, NULL, 0));
//xml_test(thisAgent, kConditionId, id_test) ;
xml_att_val(thisAgent, kConditionId, test_to_string(thisAgent, id_test, NULL, 0)) ;
deallocate_test (thisAgent, thisAgent->id_test_to_match);
deallocate_test (thisAgent, id_test);
//growable_string gs = make_blank_growable_string(thisAgent);
dc = conds_for_this_id;
conds_for_this_id = conds_for_this_id->next;
c = static_cast<condition_struct *>(dc->item);
free_with_pool (&thisAgent->dl_cons_pool, dc);
{ /* --- build and print attr/value test for condition c --- */
ch = temp;
//strncpy (ch, " ", XML_CONDITION_LIST_TEMP_SIZE - (ch - temp));
{
strncat (ch, "-", XML_CONDITION_LIST_TEMP_SIZE - (ch - temp));
}
//strncat (ch, "^", XML_CONDITION_LIST_TEMP_SIZE - (ch - temp));
while (*ch) ch++;
test_to_string (thisAgent, c->data.tests.attr_test, ch, XML_CONDITION_LIST_TEMP_SIZE - (ch - temp));
while (*ch) ch++;
*ch = 0 ; // Terminate
xml_att_val(thisAgent, kAttribute, temp) ;
// Reset the ch pointer
ch = temp ;
{
*(ch++) = ' ';
test_to_string (thisAgent, c->data.tests.value_test, ch, XML_CONDITION_LIST_TEMP_SIZE - (ch - temp));
while (*ch) ch++;
{
strncpy (ch, " +", XML_CONDITION_LIST_TEMP_SIZE - (ch - temp)); while (*ch) ch++;
}
}
*ch = 0;
if (thisAgent->printer_output_column + (ch - temp) >= COLUMNS_PER_LINE)
{
//print_string (thisAgent, "\n");
//print_spaces (thisAgent, indent+6);
}
//print_string (thisAgent, temp);
//add_to_growable_string(thisAgent, &gs, temp);
xml_att_val(thisAgent, kValue, temp);
}
//free_growable_string(thisAgent, gs);
}
//print_string (thisAgent, ")");
xml_end_tag(thisAgent, kTagCondition);
} /* end of while (conds_not_yet_printed) */
}
void xml_instantiation_with_wmes ( agent thisAgent,
instantiation inst,
wme_trace_type  wtt,
int  action 
)

Definition at line 8564 of file rete.cpp.

References condition_struct::bt, FULL_WME_TRACE, production_struct::name, condition_struct::next, NIL, NONE_WME_TRACE, POSITIVE_CONDITION, instantiation_struct::prod, wme_struct::timetag, TIMETAG_WME_TRACE, instantiation_struct::top_of_instantiated_conditions, condition_struct::type, bt_info_struct::wme_, xml_att_val(), xml_begin_tag(), xml_end_tag(), and xml_object().

Referenced by xml_match_set().

{
int PRINTING = -1;
int FIRING = 0;
int RETRACTING = 1;
condition *cond;
if (action == PRINTING) {
xml_begin_tag(thisAgent, kTagProduction);
} else if (action == FIRING) {
xml_begin_tag(thisAgent, kTagProduction_Firing);
xml_begin_tag(thisAgent, kTagProduction);
} else if (action == RETRACTING) {
xml_begin_tag(thisAgent, kTagProduction_Retracting);
xml_begin_tag(thisAgent, kTagProduction);
}
if (inst->prod) {
//print_with_symbols (thisAgent, "%y", inst->prod->name);
xml_att_val(thisAgent, kProduction_Name, inst->prod->name);
} else {
//print (thisAgent, "[dummy production]");
xml_att_val(thisAgent, kProduction_Name, "[dummy_production]");
}
//print (thisAgent, "\n");
if (wtt==NONE_WME_TRACE) {
if (action == PRINTING) {
xml_end_tag(thisAgent, kTagProduction);
} else if (action == FIRING) {
xml_end_tag(thisAgent, kTagProduction);
xml_end_tag(thisAgent, kTagProduction_Firing);
} else if (action == RETRACTING) {
xml_end_tag(thisAgent, kTagProduction);
xml_end_tag(thisAgent, kTagProduction_Retracting);
}
return;
}
for (cond=inst->top_of_instantiated_conditions; cond!=NIL; cond=cond->next)
if (cond->type==POSITIVE_CONDITION) {
switch (wtt) {
//print (thisAgent, " %lu", cond->bt.wme_->timetag);
xml_begin_tag(thisAgent, kTagWME);
xml_att_val(thisAgent, kWME_TimeTag, cond->bt.wme_->timetag);
xml_end_tag(thisAgent, kTagWME);
break;
if (action != RETRACTING) {
//print (thisAgent, " ");
xml_object (thisAgent, cond->bt.wme_);
} else {
// Not all conds available when retracting, depending on DO_TOP_LEVEL_REF_CTS
#ifdef DO_TOP_LEVEL_REF_CTS
//print (thisAgent, " ");
xml_object (thisAgent, cond->bt.wme_);
#else
// Wmes that matched the LHS of a retraction may already be free'd; just print tt.
//print (thisAgent, " %lu", cond->bt.wme_->timetag);
xml_begin_tag(thisAgent, kTagWME);
xml_att_val(thisAgent, kWME_TimeTag, cond->bt.wme_->timetag);
xml_end_tag(thisAgent, kTagWME);
#endif
}
break;
}
}
if (action == PRINTING) {
xml_end_tag(thisAgent, kTagProduction);
} else if (action == FIRING) {
xml_end_tag(thisAgent, kTagProduction);
xml_end_tag(thisAgent, kTagProduction_Firing);
} else if (action == RETRACTING) {
xml_end_tag(thisAgent, kTagProduction);
xml_end_tag(thisAgent, kTagProduction_Retracting);
}
}
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) ;
}
Bool xml_pick_conds_with_matching_id_test ( dl_cons dc,
agent thisAgent 
)
void xml_whole_token ( agent thisAgent,
token t,
wme_trace_type  wtt 
)

Definition at line 8260 of file rete.cpp.

References agent_struct::dummy_top_token, FULL_WME_TRACE, token_struct::parent, wme_struct::timetag, TIMETAG_WME_TRACE, token_struct::w, xml_att_val(), and xml_object().

Referenced by xml_aux(), xml_match_set(), and xml_partial_match_information().

{
if (t==thisAgent->dummy_top_token) return;
xml_whole_token (thisAgent, t->parent, wtt);
if (t->w) {
if (wtt==TIMETAG_WME_TRACE) xml_att_val(thisAgent, kWME_TimeTag, t->w->timetag);
else if (wtt==FULL_WME_TRACE) xml_object (thisAgent, t->w);
//if (wtt!=NONE_WME_TRACE) print (thisAgent, " ");
}
}
uint32_t xor_op ( uint32_t  i,
uint32_t  a,
uint32_t  v 
)
inline

Definition at line 1550 of file rete.cpp.

Referenced by add_wme_to_rete().

{
return ((i) ^ (a) ^ (v));
}

Variable Documentation

const char* bnode_type_names[256]
Initial value:
{
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","",""
}

Definition at line 356 of file rete.cpp.

Referenced by get_node_count_statistic(), and init_bnode_type_names().

byte relational_test_type_to_test_type[256]
Initial value:
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
}

Definition at line 2913 of file rete.cpp.

Referenced by add_rete_test_list_to_tests(), and init_test_type_conversion_tables().

FILE* rete_fs_file

Definition at line 6519 of file rete.cpp.

Referenced by load_rete_net(), retesave_one_byte(), and save_rete_net().

Bool rete_net_64
char reteload_string_buf[4 *(1000+5)]
byte test_type_to_relational_test_type[256]
Initial value:
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
}

Definition at line 2890 of file rete.cpp.

Referenced by add_rete_tests_for_test(), and init_test_type_conversion_tables().