1 #include <portability.h>
106 #include "soar_TraceNames.h"
120 #define discard_chunk_varnames TRUE
147 #ifdef TOKEN_SHARING_STATS
148 #ifndef SHARING_FACTORS
149 #define SHARING_FACTORS
154 #ifdef NULL_ACTIVATION_STATS
155 #ifndef DO_ACTIVATION_STATS_ON_REMOVALS
156 #define DO_ACTIVATION_STATS_ON_REMOVALS
162 using namespace soar_TraceNames;
217 #define CONSTANT_RELATIONAL_RETE_TEST 0x00
218 #define VARIABLE_RELATIONAL_RETE_TEST 0x10
219 #define DISJUNCTION_RETE_TEST 0x20
220 #define ID_IS_GOAL_RETE_TEST 0x30
221 #define ID_IS_IMPASSE_RETE_TEST 0x31
237 #define RELATIONAL_EQUAL_RETE_TEST 0x00
238 #define RELATIONAL_NOT_EQUAL_RETE_TEST 0x01
239 #define RELATIONAL_LESS_RETE_TEST 0x02
240 #define RELATIONAL_GREATER_RETE_TEST 0x03
241 #define RELATIONAL_LESS_OR_EQUAL_RETE_TEST 0x04
242 #define RELATIONAL_GREATER_OR_EQUAL_RETE_TEST 0x05
243 #define RELATIONAL_SAME_TYPE_RETE_TEST 0x06
271 return ( ((v1).levels_up==(v2).levels_up) && ((v1).field_num==(v2).field_num) );
294 return ( (&((_wme)->
id))[(field_num)] );
319 #define UNHASHED_MEMORY_BNODE 0x02
320 #define MEMORY_BNODE 0x03
321 #define UNHASHED_MP_BNODE 0x06
322 #define MP_BNODE 0x07
323 #define UNHASHED_POSITIVE_BNODE 0x14
324 #define POSITIVE_BNODE 0x15
325 #define UNHASHED_NEGATIVE_BNODE 0x08
326 #define NEGATIVE_BNODE 0x09
327 #define DUMMY_TOP_BNODE 0x40
328 #define DUMMY_MATCHES_BNODE 0x41
329 #define CN_BNODE 0x42
330 #define CN_PARTNER_BNODE 0x43
358 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
359 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
360 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
361 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
362 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
363 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
364 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
365 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
366 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
367 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
368 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
369 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
370 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
371 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
372 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
373 "",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
416 unsigned is_left_unlinked:1;
431 #ifdef SHARING_FACTORS
432 uint64_t sharing_factor;
506 rtrm_ancestor = (node)->b.posneg.nearest_ancestor_with_same_am;
512 (node)->b.posneg.next_from_alpha_mem = rtrm_ancestor;
519 rtrm_prev = (node)->b.posneg.alpha_mem_->last_beta_node;
521 (node)->b.posneg.prev_from_alpha_mem = rtrm_prev;
531 #define unlink_from_right_mem(node) { \
532 if ((node)->b.posneg.next_from_alpha_mem == NIL) \
533 (node)->b.posneg.alpha_mem_->last_beta_node = \
534 (node)->b.posneg.prev_from_alpha_mem; \
535 remove_from_dll ((node)->b.posneg.alpha_mem_->beta_nodes, (node), \
536 b.posneg.next_from_alpha_mem, \
537 b.posneg.prev_from_alpha_mem); \
538 mark_node_as_right_unlinked (node); }
566 #define relink_to_left_mem(node) { \
567 insert_at_head_of_dll ((node)->parent->b.mem.first_linked_child, (node), \
568 a.pos.next_from_beta_mem, \
569 a.pos.prev_from_beta_mem); }
574 #define unlink_from_left_mem(node) { \
575 remove_from_dll ((node)->parent->b.mem.first_linked_child, (node), \
576 a.pos.next_from_beta_mem, \
577 a.pos.prev_from_beta_mem); \
578 mark_node_as_left_unlinked(node); }
591 (node)->a.np.is_left_unlinked = 1;
596 (node)->a.np.is_left_unlinked = 0;
601 return ((node)->a.np.is_left_unlinked);
622 token * parent_tok,
wme * parent_wme)
624 (New)->node = (current_node);
626 next_of_node, prev_of_node);
627 (New)->first_child =
NIL;
628 (New)->parent = (parent_tok);
630 next_sibling, prev_sibling);
631 (New)->w = (parent_wme);
633 next_from_wme, prev_from_wme);
648 #define LOG2_LEFT_HT_SIZE 14
649 #define LOG2_RIGHT_HT_SIZE 14
651 #define LEFT_HT_SIZE (1 << LOG2_LEFT_HT_SIZE)
652 #define RIGHT_HT_SIZE (1 << LOG2_RIGHT_HT_SIZE)
654 #define LEFT_HT_MASK (LEFT_HT_SIZE - 1)
655 #define RIGHT_HT_MASK (RIGHT_HT_SIZE - 1)
687 a.ht.next_in_bucket, a.ht.prev_in_bucket);
696 a.ht.next_in_bucket, a.ht.prev_in_bucket);
707 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
708 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
709 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
710 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
711 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
712 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
713 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
714 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
715 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
716 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
717 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
718 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
719 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
720 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
721 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
722 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
726 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
727 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
728 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
729 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
730 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
731 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
732 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
733 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
734 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
735 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
736 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
737 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
738 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
739 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
740 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
741 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
757 #define activation_entry_sanity_check() {}
758 #define activation_exit_sanity_check() {}
769 #ifdef NULL_ACTIVATION_STATS
773 if (node==node_to_ignore_for_activation_stats)
return;
777 thisAgent->num_right_activations++;
779 thisAgent->num_null_right_activations++;
783 thisAgent->num_right_activations++;
784 if (! node->
a.
np.
tokens) thisAgent->num_null_right_activations++;
793 thisAgent->num_left_activations++;
795 thisAgent->num_null_left_activations++;
800 thisAgent->num_left_activations++;
802 thisAgent->num_null_left_activations++;
808 print (
"\nActivations: %lu right (%lu null), %lu left (%lu null)\n",
809 thisAgent->num_right_activations,
810 thisAgent->num_null_right_activations,
811 thisAgent->num_left_activations,
812 thisAgent->num_null_left_activations);
819 #define null_activation_stats_for_right_activation(node) {}
820 #define null_activation_stats_for_left_activation(node) {}
821 #define print_null_activation_stats() {}
842 #ifdef SHARING_FACTORS
847 (node)->sharing_factor = 0;
858 ssf_237 = (sf) - ((node)->sharing_factor);
859 (node)->sharing_factor = (sf);
860 thisAgent->rete_node_counts_if_no_sharing[(node)->node_type]+=ssf_237;
866 thisAgent->rete_node_counts_if_no_sharing[node->
node_type] += delta;
867 node->sharing_factor += delta;
877 #define init_sharing_stats_for_new_node(node) {}
878 #define set_sharing_factor(node,sf) {}
879 #define adjust_sharing_factors_from_here_to_top(node,delta) {}
889 #ifdef TOKEN_SHARING_STATS
895 inline uint64_t real_sharing_factor(
rete_node * node)
897 return ((node)->sharing_factor ? (node)->sharing_factor : 1);
905 thisAgent->token_additions++;
906 thisAgent->token_additions_without_sharing += real_sharing_factor(node);
911 #define token_added(node) {}
943 (node)->node_type = (type);
1003 wme *lowest_goal_wme;
1007 #ifdef DEBUG_WATERFALL
1012 lowest_goal_wme =
NIL;
1013 lowest_level_so_far = -1;
1017 lowest_goal_wme = msc->
w;
1023 if (tok->
w !=
NIL) {
1027 if (lowest_goal_wme ==
NIL)
1028 lowest_goal_wme = tok->
w;
1032 lowest_goal_wme = tok->
w;
1039 if (lowest_goal_wme) {
1040 #ifdef DEBUG_WATERFALL
1043 return lowest_goal_wme->
id;
1047 SNPRINTF(msg,
BUFFER_MSG_SIZE,
"\nError: Did not find goal for ms_change assertion: %s\n",
1057 #ifdef DEBUG_WATERFALL
1063 #ifdef DEBUG_WATERFALL
1070 #ifdef DEBUG_WATERFALL
1071 print(
" is NIL (nil goal retraction)");
1083 print(thisAgent,
"\nAssertion exists but has no p_node");
1091 print(thisAgent,
"\nRetraction exists but has no p_node");
1163 msc, next_in_level, prev_in_level);
1172 msc, next_in_level, prev_in_level);
1204 next_of_node, prev_of_node);
1235 assert (msc !=
NIL);
1239 msc, next_of_node, prev_of_node);
1245 msc, next_in_level, prev_in_level);
1250 msc, next_in_level, prev_in_level);
1272 msc, next_in_level, prev_in_level);
1275 next_of_node, prev_of_node);
1300 next_in_level, prev_in_level);
1309 next_of_node, prev_of_node);
1361 return ((am->
id==
NIL) || (am->
id==w->
id)) &&
1376 ( ( (i ? i->common.hash_id : 0) ^
1377 (a ? a->common.hash_id : 0) ^
1378 (v ? v->common.hash_id : 0) ) &
1401 (acceptable ? 8 : 0) ];
1422 hv = am->
am_id ^ w->
id->common.hash_id;
1441 hv = am->
am_id ^ w->
id->common.hash_id;
1461 for (am = reinterpret_cast<alpha_mem *>(*(ht->
buckets+hash_value)); am!=
NIL;
1463 if ((am->
id==
id) && (am->
attr==attr) &&
1504 more_general_am =
NIL;
1507 if (!more_general_am && value)
1509 if (more_general_am) {
1552 return ((i) ^ (a) ^ (v));
1568 hi = w->
id->common.hash_id;
1569 ha = w->
attr->common.hash_id;
1570 hv = w->
value->common.hash_id;
1618 std::pair< smem_pooled_symbol_set::iterator, bool > insert_result = thisAgent->
smem_changed_ids->insert( w->
id );
1619 if ( insert_result.second )
1628 bool was_encoded =
false;
1654 epmem_wme_set::iterator rc_it = my_refs->find( w );
1655 if ( rc_it != my_refs->end() )
1657 my_refs->erase( rc_it );
1660 bool recurse =
true;
1661 for ( rc_it=my_refs->begin(); ( recurse && rc_it!=my_refs->end() ); rc_it++ )
1663 if ( ( !(*rc_it) ) || ( (*rc_it)->id->id.level == my_agent->
top_state->
id.
level ) )
1708 id->id.epmem_valid =
NIL;
1756 std::pair< smem_pooled_symbol_set::iterator, bool > insert_result = thisAgent->
smem_changed_ids->insert( w->
id );
1757 if ( insert_result.second )
1774 #ifdef DO_ACTIVATION_STATS_ON_REMOVALS
1810 a.neg.next_negrm, a.neg.prev_negrm);
1811 free_with_pool (&thisAgent->
token_pool, tok);
1887 allocate_with_pool (thisAgent, &thisAgent->
token_pool,
1914 if (prev_sibling == node) {
1934 rete_node *saved_parents_first_child, *saved_childs_next_sibling;
1940 strncpy (msg,
"\nrete.c: Internal error: update_node_with_matches_from_above called on split node",
BUFFER_MSG_SIZE);
1967 rete_node* node_to_ignore_for_activation_stats = parent;
1970 node_to_ignore_for_activation_stats =
NIL;
1971 parent->first_child = saved_parents_first_child;
2012 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &node);
2042 Bool prefer_left_unlinking) {
2046 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &node);
2048 node->
parent = parent_mem;
2066 if (prefer_left_unlinking && (! parent_mem->
a.
np.
tokens) &&
2084 rete_node *pos_node, *mem_node, *parent;
2085 byte mem_node_type, node_type;
2099 parent = mp_node->
parent;
2107 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &mem_node);
2111 mem_node->
parent = parent;
2125 pos_node->
parent = mem_node;
2152 parent = mem_node->
parent;
2157 strncpy (msg,
"\nrete.c: Internal error: tried to merge_into_mp_node, but <>1 child\n",
BUFFER_MSG_SIZE);
2170 pos_copy = *pos_node;
2187 mp_node->
parent = parent;
2214 byte mem_node_type, pos_node_type;
2225 prefer_left_unlinking);
2241 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &node);
2276 rete_node *node, *partner, *ncc_subconditions_top_node;
2279 ncc_subconditions_top_node =
NIL;
2280 for (node=bottom_of_subconditions; node!=parent; node=node->
parent) {
2281 ncc_subconditions_top_node = node;
2284 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &node);
2286 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &partner);
2302 partner->
parent = bottom_of_subconditions;
2333 allocate_with_pool (thisAgent, &thisAgent->
rete_node_pool, &p_node);
2335 new_prod->
p_node = p_node;
2340 p_node->
b.
p.
prod = new_prod;
2394 strncpy (msg,
"Internal error: deallocate_rete_node() called on p-node.\n",
BUFFER_MSG_SIZE);
2487 return reinterpret_cast<void *
>((depth << 2) + field_num);
2493 return static_cast<rete_node_level>(
reinterpret_cast<uintptr_t
>(d) >> 2);
2499 return static_cast<byte>(
reinterpret_cast<uintptr_t
>(d) & 3);
2521 c_xy312 =
static_cast<Symbol *
>(v)->var.rete_binding_locations;
2573 push(thisAgent, referent, *varlist);
2581 depth, field_num, dense, varlist);
2685 if (old_varnames ==
NIL)
2707 if (vn ==
NIL)
return;
2722 while (node!=cutoff) {
2784 New->
parent = parent_nvn;
2815 for (cond=cond_list; cond!=
NIL; cond=cond->
next) {
2817 switch (cond->
type) {
2831 New->
parent = parent_nvn;
2892 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2893 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2894 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2895 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2896 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2897 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2898 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2899 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2900 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2901 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2902 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2903 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2904 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2905 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2906 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2907 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
2915 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2916 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2917 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2918 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2919 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2920 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2921 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2922 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2923 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2924 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2925 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2926 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2927 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2928 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2929 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2930 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
2935 #define EQUAL_TEST_TYPE 254
2936 #define ERROR_TEST_TYPE 255
2941 static bool bInit =
FALSE;
2988 Symbol **alpha_constant) {
2990 where.var_location_struct::field_num = 0;
2991 where.var_location_struct::levels_up = 0;
3004 (*alpha_constant==
NIL)) {
3005 *alpha_constant = referent;
3011 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3026 SNPRINTF (msg,
BUFFER_MSG_SIZE,
"Error: Rete build found test of unbound var: %s\n",
3034 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3055 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3070 SNPRINTF (msg,
BUFFER_MSG_SIZE,
"Error: Rete build found test of unbound var: %s\n",
3075 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3085 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3097 current_depth, field_num, rt, alpha_constant);
3102 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3110 allocate_with_pool (thisAgent, &thisAgent->
rete_test_pool, &new_rt);
3119 SNPRINTF (msg,
BUFFER_MSG_SIZE,
"Error: found bad test type %d while building rete\n",
3167 while ((c1!=
NIL)&&(c2!=
NIL)) {
3172 if (c1==c2)
return TRUE;
3176 strncpy(msg,
"Internal error: bad rete test type in single_rete_tests_are_identical\n",
BUFFER_MSG_SIZE);
3184 while (rt1 && rt2) {
3190 if (rt1==rt2)
return TRUE;
3210 for (current = *rt; current!=
NIL; prev=current, current=current->
next)
3214 if (!current)
return FALSE;
3217 if (prev) prev->
next = current->
next;
else *rt = current->
next;
3220 *dest_hash_loc = current->data.variable_referent;
3221 current->next =
NIL;
3240 byte pos_node_type, mem_node_type, mp_node_type;
3241 Symbol *alpha_id, *alpha_attr, *alpha_value;
3245 Bool hash_this_node;
3247 left_hash_loc.var_location_struct::field_num = 0;
3248 left_hash_loc.var_location_struct::levels_up = 0;
3249 list *vars_bound_here;
3251 alpha_id = alpha_attr = alpha_value =
NIL;
3253 vars_bound_here =
NIL;
3257 FALSE, &vars_bound_here);
3259 FALSE, &vars_bound_here);
3261 FALSE, &vars_bound_here);
3288 if (hash_this_node) {
3301 if ((mem_node->
node_type==mem_node_type) &&
3302 ((!hash_this_node) ||
3328 if ((mp_node->
node_type==mp_node_type) &&
3329 ((!hash_this_node) ||
3368 Symbol *alpha_id, *alpha_attr, *alpha_value;
3372 Bool hash_this_node;
3374 left_hash_loc.var_location_struct::field_num = 0;
3375 left_hash_loc.var_location_struct::levels_up = 0;
3376 list *vars_bound_here;
3378 alpha_id = alpha_attr = alpha_value =
NIL;
3380 vars_bound_here =
NIL;
3384 FALSE, &vars_bound_here);
3386 FALSE, &vars_bound_here);
3388 FALSE, &vars_bound_here);
3413 ((!hash_this_node) ||
3454 list **dest_vars_bound) {
3455 rete_node *node, *new_node, *child, *subconditions_bottom_node;
3461 current_depth = depth_of_first_cond;
3464 for (cond=cond_list; cond!=
NIL; cond=cond->
next) {
3465 switch (cond->
type) {
3485 node, &subconditions_bottom_node,
NIL,
NIL);
3507 if (dest_bottom_node) *dest_bottom_node = node;
3508 if (dest_bottom_depth) *dest_bottom_depth = current_depth-1;
3509 if (dest_vars_bound) {
3510 *dest_vars_bound = vars_bound;
3578 if (((a1==rhs1) && (!a1->
next)) && ((a2==rhs2) && (!a2->
next)))
3585 if (stop)
return FALSE;
3593 if (a1 != a2)
return FALSE;
3618 list * & rhs_unbound_vars_for_new_prod,
3619 uint64_t & num_rhs_unbound_vars_for_new_prod,
3625 var_loc.var_location_struct::levels_up = 0;
3626 var_loc.var_location_struct::field_num = 0;
3633 if (
find_var_location (sym, static_cast<rete_node_level>(bottom_depth+1), &var_loc)) {
3639 if (sym->
var.
tc_num != rhs_unbound_vars_tc) {
3641 push(thisAgent, sym, rhs_unbound_vars_for_new_prod);
3643 index = num_rhs_unbound_vars_for_new_prod++;
3657 bottom_depth, rhs_unbound_vars_for_new_prod,
3658 num_rhs_unbound_vars_for_new_prod,
3659 rhs_unbound_vars_tc);
3716 byte production_addition_result;
3720 &bottom_node, &bottom_depth, &vars_bound);
3724 list* rhs_unbound_vars_for_new_prod =
NIL;
3725 uint64_t num_rhs_unbound_vars_for_new_prod = 0;
3729 rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
3732 rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
3734 rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
3737 rhs_unbound_vars_for_new_prod, num_rhs_unbound_vars_for_new_prod, rhs_unbound_vars_tc);
3752 if (warn_on_duplicates)
3754 std::stringstream output;
3755 output <<
"\nIgnoring "
3757 <<
" because it is a duplicate of "
3811 if (refracted_inst) {
3815 allocate_with_pool (thisAgent, &thisAgent->
ms_change_pool, &msc);
3816 msc->
inst = refracted_inst;
3833 #ifdef DEBUG_WATERFALL
3839 msc, next_in_level, prev_in_level);
3842 #ifdef BUG_139_WORKAROUND
3848 next_of_node, prev_of_node);
3855 if (! refracted_inst) {
3867 next_in_level, prev_in_level);
3870 msc, next_in_level, prev_in_level);
3900 return production_addition_result;
4008 prefix[0] = first_letter;
4029 byte where_field_num,
4035 while (where_levels_up) { where_levels_up--; cond = cond->
prev; }
4052 abort_var_bound_in_reconstructed_conds:
4054 strncpy (msg,
"Internal error in var_bound_in_reconstructed_conds\n",
BUFFER_MSG_SIZE);
4079 for ( ; rt!=
NIL; rt=rt->
next) {
4105 new_ct->
type = test_type;
4140 new_ct->
type = test_type;
4145 strncpy (msg,
"Error: bad test_type in add_rete_test_to_test\n",
BUFFER_MSG_SIZE);
4184 for ( ; rt!=
NIL; rt=rt->
next) {
4196 allocate_with_pool (thisAgent, &thisAgent->
not_pool, &new_not);
4197 new_not->
next = nots_found_in_production;
4198 nots_found_in_production = new_not;
4199 new_not->
s1 = right_sym;
4201 new_not->
s2 = referent;
4212 allocate_with_pool (thisAgent, &thisAgent->
not_pool, &new_not);
4213 new_not->
next = nots_found_in_production;
4214 nots_found_in_production = new_not;
4215 new_not->
s1 = right_sym;
4217 new_not->
s2 = referent;
4237 if (vn ==
NIL)
return;
4301 allocate_with_pool (thisAgent, &thisAgent->
condition_pool, &cond);
4303 cond->
prev = conds_for_cutoff_and_up;
4305 *dest_top_cond = cond;
4312 conds_for_cutoff_and_up,
4313 dest_top_cond, &(cond->
prev),
4314 nots_found_in_production);
4318 *dest_bottom_cond = cond;
4330 nots_found_in_production);
4347 nots_found_in_production);
4412 char first_letter) {
4413 cons *c, *new_c, *prev_new_c;
4432 prefix[0] = first_letter;
4455 prev_new_c = new_fl;
4459 static_cast<char *>(c->
first),
4460 cond, first_letter);
4461 prev_new_c->
rest = new_c;
4475 action *old, *New, *prev, *first;
4482 allocate_with_pool (thisAgent, &thisAgent->
action_pool, &New);
4483 if (prev) prev->
next = New;
else first = New;
4500 cond, first_letter);
4504 if (prev) prev->
next =
NIL;
else first =
NIL;
4548 dest_top_cond, dest_bottom_cond,
4549 nots_found_in_production);
4550 if (tok) *dest_nots = nots_found_in_production;
4551 nots_found_in_production =
NIL;
4560 *(cell++) = static_cast<symbol_union *>(c->
first);
4581 if (field_num==0)
return w->
id;
4582 if (field_num==1)
return w->
attr;
4598 #define ertr error_rete_test_routine
4599 Bool ( (*(rete_test_routines[256]))
4602 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4603 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4604 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4605 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4606 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4607 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4608 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4609 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4610 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4611 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4612 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4613 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4614 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4615 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4616 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
4617 ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr,
ertr, ertr
4626 return ( (*(rete_test_routines[(_rete_test)->type])) \
4627 (thisAgent,(_rete_test),(left),(w)) );
4653 #define numcmp(x,y) (((x) < (y)) ? -1 : (((x) > (y)) ? 1 : 0))
4659 switch (s1->common.symbol_type) {
4661 switch (s2->common.symbol_type) {
4670 switch (s2->common.symbol_type) {
4679 switch (s2->common.symbol_type) {
4689 switch (s2->common.symbol_type) {
4709 strncpy (msg,
"Internal error: bad rete test type, hit error_rete_test_routine\n",
BUFFER_MSG_SIZE);
4790 return static_cast<Bool>(s1->common.symbol_type == s2->common.symbol_type);
4926 return (s1->common.symbol_type == s2->common.symbol_type);
4943 SNPRINTF (msg,
BUFFER_MSG_SIZE,
"Rete net error: tried to left-activate node of type %d\n",
4951 SNPRINTF (msg,
BUFFER_MSG_SIZE,
"Rete net error: tried to right-activate node of type %d\n",
4975 for (t=tok, levels_up -= 2; levels_up!=0; levels_up--) t=t->
parent;
4980 hv = node->
node_id ^ referent->common.hash_id;
4984 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5011 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5049 right_hv = am->
am_id ^ hash_referent->common.hash_id;
5051 if (rm->
am != am)
continue;
5053 if (hash_referent != rm->
w->
id)
continue;
5054 failed_a_test =
FALSE;
5057 failed_a_test =
TRUE;
5060 if (failed_a_test)
continue;
5090 failed_a_test =
FALSE;
5093 failed_a_test =
TRUE;
5096 if (failed_a_test)
continue;
5126 for (t=tok, levels_up -= 2; levels_up!=0; levels_up--) t=t->
parent;
5131 hv = node->
node_id ^ referent->common.hash_id;
5135 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5157 right_hv = am->
am_id ^ referent->common.hash_id;
5159 if (rm->
am != am)
continue;
5161 if (referent != rm->
w->
id)
continue;
5162 failed_a_test =
FALSE;
5165 failed_a_test =
TRUE;
5168 if (failed_a_test)
continue;
5193 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5213 failed_a_test =
FALSE;
5216 failed_a_test =
TRUE;
5219 if (failed_a_test)
continue;
5254 failed_a_test =
FALSE;
5257 failed_a_test =
TRUE;
5260 if (failed_a_test)
continue;
5292 failed_a_test =
FALSE;
5295 failed_a_test =
TRUE;
5298 if (failed_a_test)
continue;
5327 hv = node->
node_id ^ referent->common.hash_id;
5330 if (tok->
node != node)
continue;
5333 failed_a_test =
FALSE;
5336 failed_a_test =
TRUE;
5339 if (failed_a_test)
continue;
5369 if (tok->
node != node)
continue;
5371 failed_a_test =
FALSE;
5374 failed_a_test =
TRUE;
5377 if (failed_a_test)
continue;
5415 for (t=tok, levels_up -= 2; levels_up!=0; levels_up--) t=t->
parent;
5420 hv = node->
node_id ^ referent->common.hash_id;
5424 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5432 right_hv = am->
am_id ^ referent->common.hash_id;
5434 if (rm->
am != am)
continue;
5436 if (referent != rm->
w->
id)
continue;
5437 failed_a_test =
FALSE;
5440 failed_a_test =
TRUE;
5443 if (failed_a_test)
continue;
5445 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &t);
5453 a.neg.next_negrm, a.neg.prev_negrm);
5483 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5492 failed_a_test =
FALSE;
5495 failed_a_test =
TRUE;
5498 if (failed_a_test)
continue;
5500 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &t);
5508 a.neg.next_negrm, a.neg.prev_negrm);
5531 hv = node->
node_id ^ referent->common.hash_id;
5534 if (tok->
node != node)
continue;
5537 failed_a_test =
FALSE;
5540 failed_a_test =
TRUE;
5543 if (failed_a_test)
continue;
5546 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &t);
5554 a.neg.next_negrm, a.neg.prev_negrm);
5573 if (tok->
node != node)
continue;
5575 failed_a_test =
FALSE;
5578 failed_a_test =
TRUE;
5581 if (failed_a_test)
continue;
5584 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &t);
5592 a.neg.next_negrm, a.neg.prev_negrm);
5616 hv = node->
node_id ^ cast_and_possibly_truncate<uint32_t>(tok) ^ cast_and_possibly_truncate<uint32_t>(w);
5622 if ((t->
node==node)&&(t->
parent==tok)&&(t->
w==w))
return;
5626 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5642 token *left, *negrm_tok;
5651 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &negrm_tok);
5656 while (temp != partner->
parent) {
5663 hv = partner->
node_id ^ cast_and_possibly_truncate<uint32_t>(tok) ^ cast_and_possibly_truncate<uint32_t>(w);
5665 if ((left->
node==partner)&&(left->
parent==tok)&&(left->
w==w))
break;
5670 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &left);
5679 a.neg.next_negrm, a.neg.prev_negrm);
5721 token *current_token, *New;
5730 token *OPERAND_curr_tok, *temp_tok;
5733 Bool operator_proposal,op_elab;
5734 char action_attr[50];
5737 wme *lowest_goal_wme;
5746 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
5750 match_found =
FALSE;
5754 current_token = tok;
5756 current_node = node->
parent;
5759 if (current_wme != cond->
bt.
wme_) {
5760 match_found=
FALSE;
break;
5763 current_wme = current_token->
w;
5764 current_token = current_token->
parent;
5767 if (match_found)
break;
5770 #ifdef BUG_139_WORKAROUND
5788 next_of_node, prev_of_node);
5793 next_in_level, prev_in_level);
5805 msc, next_in_level, prev_in_level);
5811 #ifdef DEBUG_RETE_PNODES
5820 #ifdef DEBUG_RETE_PNODES
5825 allocate_with_pool (thisAgent, &thisAgent->
ms_change_pool, &msc);
5862 #ifdef DEBUG_WATERFALL
5882 operator_proposal =
FALSE;
5888 "operator") ==
NIL) &&
5890 operator_proposal =
TRUE;
5897 if (operator_proposal ==
FALSE) {
5903 for (OPERAND_curr_tok = node->
a.
np.
tokens;
5904 OPERAND_curr_tok !=
NIL;
5933 lowest_goal_wme =
NIL;
5935 for (pass = 0; pass != 2; pass++) {
5937 temp_tok = OPERAND_curr_tok;
5938 while (temp_tok !=
NIL) {
5939 while (temp_tok->
w ==
NIL) {
5940 temp_tok = temp_tok->
parent;
5941 if (temp_tok ==
NIL)
break;
5943 if (temp_tok ==
NIL)
break;
5944 if (temp_tok->
w ==
NIL)
break;
5948 if (lowest_goal_wme ==
NIL)
5949 lowest_goal_wme = temp_tok->
w;
5953 lowest_goal_wme = temp_tok->
w;
5995 temp_tok = temp_tok->
parent;
6001 }
else if (op_elab ==
TRUE) {
6006 print_with_symbols(thisAgent,
"\nWARNING: operator elaborations mixed with operator applications\nget o_support in prod %y",
6011 add_to_growable_string(thisAgent, &gs,
"WARNING: operator elaborations mixed with operator applications\nget o_support in prod ");
6020 print_with_symbols(thisAgent,
"\nWARNING: operator elaborations mixed with operator applications\nget i_support in prod %y",
6025 add_to_growable_string(thisAgent, &gs,
"WARNING: operator elaborations mixed with operator applications\nget i_support in prod ");
6058 msc, next_in_level, prev_in_level);
6068 SNPRINTF(buf, 254,
"RETE: putting [%s] into ms_o_assertions",
symbol_to_string(thisAgent, node->
b.
p.
prod->
name,
true, 0, 0));
6079 msc, next_in_level, prev_in_level);
6088 SNPRINTF(buf, 254,
"RETE: putting [%s] into ms_i_assertions",
symbol_to_string(thisAgent, node->
b.
p.
prod->
name,
true, 0, 0));
6114 next_of_node, prev_of_node);
6141 if ((msc->
tok==tok) && (msc->
w==w)) {
6150 print(thisAgent,
"RETRACTION (1) reset interrupt to READY -- (Interrupt, Stop) to (%d, %d)\n", node->
b.
p.
prod->
interrupt, thisAgent->
stop_soar);
6161 next_in_level, prev_in_level);
6168 next_in_level, prev_in_level);
6174 #ifdef DEBUG_RETE_PNODES
6189 #ifdef DEBUG_RETE_PNODES
6196 allocate_with_pool (thisAgent, &thisAgent->
ms_change_pool, &msc);
6206 next_of_node, prev_of_node);
6214 #ifdef DEBUG_WATERFALL
6215 print(
"\n Level of retraction is: %d", msc->
level);
6245 next_in_level, prev_in_level);
6249 msc, next_in_level, prev_in_level);
6252 #ifdef DEBUG_WATERFALL
6254 print(
" is active at level %d\n", msc->
level);
6257 print(
"\n Retractions list:\n");
6260 assertion=assertion->
next) {
6267 print(
"\nCurrent NIL Goal list:\n");
6275 if (assertion->
goal)
print(
"This assertion has non-NIL goal pointer.\n");
6296 #ifdef BUG_139_WORKAROUND
6298 #ifdef BUG_139_WORKAROUND_WARNING
6299 print(thisAgent,
"\nWarning: can't find an existing inst to retract (BUG 139 WORKAROUND)\n");
6300 xml_generate_warning(thisAgent,
"Warning: can't find an existing inst to retract (BUG 139 WORKAROUND)");
6308 "Internal error: can't find existing instantiation to retract\n",
BUFFER_MSG_SIZE);
6325 token *tok, *next_value_for_tok, *left, *t, *next_t;
6341 next_sibling,prev_sibling);
6343 next_from_wme, prev_from_wme);
6356 }
else if (node_type==
P_BNODE) {
6377 #ifdef DO_ACTIVATION_STATS_ON_REMOVALS
6396 static_cast<uint32_t>(reinterpret_cast<uint64_t>(tok->
parent)) ^
6397 static_cast<uint32_t>(reinterpret_cast<uint64_t>(tok->
w)));
6401 next_from_wme, prev_from_wme);
6403 next_of_node, prev_of_node);
6405 next_sibling, prev_sibling);
6413 a.neg.next_negrm, a.neg.prev_negrm);
6423 "Internal error: bad node type %d in remove_token_and_subtree\n",
6429 free_with_pool (&thisAgent->
token_pool, tok);
6430 if (tok==root)
break;
6431 tok = next_value_for_tok;
6536 return static_cast<uint8_t
>(fgetc (f));
6663 FILE* f =
reinterpret_cast<FILE*
>(userdata);
6691 uint64_t num_sym_constants, num_variables;
6692 uint64_t num_int_constants, num_float_constants;
6693 Symbol **current_place_in_symtab;
6701 thisAgent->
reteload_num_syms = num_sym_constants + num_variables + num_int_constants
6702 + num_float_constants;
6710 for (i=0; i<num_sym_constants; i++) {
6714 for (i=0; i<num_variables; i++) {
6718 for (i=0; i<num_int_constants; i++) {
6720 *(current_place_in_symtab++) =
6723 for (i=0; i<num_float_constants; i++) {
6725 *(current_place_in_symtab++) =
6734 if (index==0)
return NIL;
6738 strncpy (msg,
"Internal error (file corrupted?): symbol count too small\n",
BUFFER_MSG_SIZE);
6780 FILE* f =
reinterpret_cast<FILE*
>(userdata);
6793 uint64_t i, num_ams;
6799 for (i=0; i<16; i++)
6806 Symbol *id, *attr, *value;
6828 "Internal error (file corrupted?): alpha mem count too small\n",
BUFFER_MSG_SIZE);
6884 if (i==0)
return NIL;
6895 push(thisAgent, sym, c);
6928 while (temp!=node->
parent) {
6930 nvn_for_ncc = nvn_for_ncc->
parent;
6932 nvn->
parent = nvn_for_ncc;
6969 for (i=0; c!=
NIL; i++, c=c->
rest);
6987 byte type, field_num;
7019 print_with_symbols (thisAgent,
"Error: can't load this file because it uses an undefined RHS function %y\n", sym);
7024 push(thisAgent, rf, funcall_list);
7028 push(thisAgent, temp, funcall_list);
7045 strncpy (msg,
"Internal error (file corrupted?): bad rhs_value type\n",
BUFFER_MSG_SIZE);
7088 allocate_with_pool (thisAgent, &thisAgent->
action_pool, &a);
7111 for (i=0, a=first_a; a!=
NIL; i++, a=a->
next);
7117 action *a, *prev_a, *first_a;
7125 if (prev_a) prev_a->
next = a;
else first_a = a;
7128 if (prev_a) prev_a->
next =
NIL;
else first_a =
NIL;
7188 push(thisAgent, sym, temp);
7199 for (i=0, rt=first_rt; rt!=
NIL; i++, rt=rt->
next);
7201 for (rt=first_rt; rt!=
NIL; rt=rt->next)
7214 if (prev_rt) prev_rt->
next = rt;
else first = rt;
7217 if (prev_rt) prev_rt->
next =
NIL;
else first =
NIL;
7365 "Internal error: fastsave found node type %d\n", node->
node_type);
7378 byte type, left_unlinked_flag;
7416 New =
make_new_mp_node (thisAgent, parent, type, left_hash_loc, am, other_tests,
7417 left_unlinked_flag != 0);
7427 left_unlinked_flag != 0);
7478 push(thisAgent, sym, ubv_list);
7528 SNPRINTF (msg,
BUFFER_MSG_SIZE,
"Internal error: fastload found node type %d\n", type);
7552 print (thisAgent,
"Internal error: save_rete_net() with justifications present.\n");
7558 uint8_t version = use_rete_net_64 ? 4 : 3;
7569 int format_version_num;
7581 print (thisAgent,
"Internal error: load_rete_net() called with nonempty WM.\n");
7586 print (thisAgent,
"Internal error: load_rete_net() called with nonempty PM.\n");
7596 print (thisAgent,
"This file isn't a Soar fastsave file.\n");
7600 switch(format_version_num)
7611 print (thisAgent,
"This file is in a format (version %d) I don't understand.\n", format_version_num);
7669 if (! prod->
p_node)
return 0;
7678 else node = node->
parent;
7702 static bool bnode_initialzied =
false;
7707 if(!bnode_initialzied)
7723 bnode_initialzied =
true;
7744 for (i=0; i<256; i++) {
7772 char * node_type_name,
7781 if (!strcmp(
"total", node_type_name))
7783 if (!strcmp(
"actual", column_name))
7785 for (tot=0, i=0; i<256; i++) tot+=thisAgent->
actual[i];
7788 else if (!strcmp(
"if-no-merging", column_name))
7790 for (tot=0, i=0; i<256; i++) tot+=thisAgent->
if_no_merging[i];
7793 #ifdef SHARING_FACTORS
7794 else if (!strcmp(
"if-no-sharing", column_name))
7796 for (tot=0, i=0; i<256; i++) tot+=thisAgent->
if_no_sharing[i];
7807 for (i=0; i<256; i++)
7810 if (!strcmp(
"actual", column_name))
7812 *result = thisAgent->
actual[i];
7814 else if (!strcmp(
"if-no-merging", column_name))
7818 #ifdef SHARING_FACTORS
7819 else if (!strcmp(
"if-no-sharing", column_name))
7863 allocate_with_pool (thisAgent, &thisAgent->
token_pool, &New);
7878 dummy_matches_node.
parent = node;
7934 token *tokens, *t, *parent_tokens;
7936 int64_t matches_one_level_up;
7937 int64_t matches_at_this_level;
7938 #define MATCH_COUNT_STRING_BUFFER_SIZE 20
7944 matches_at_this_level = 0;
7949 if (node==cutoff)
return matches_at_this_level;
7953 matches_one_level_up =
ppmi_aux (thisAgent, parent, cutoff,
7954 cond->
prev, wtt, indent);
7958 if (! matches_one_level_up) {
7961 }
else if (! matches_at_this_level) {
7974 print (thisAgent,
" -{\n");
7981 print (thisAgent,
"%s }\n", match_count_string);
7983 print (thisAgent,
"%s", match_count_string);
7985 print (thisAgent,
"\n");
7988 if (matches_one_level_up && (!matches_at_this_level)) {
7991 print (thisAgent,
"*** Matches For Left ***\n");
7996 print (thisAgent,
"\n");
8000 print (thisAgent,
"*** Matches for Right ***\n");
8006 print (thisAgent,
" ");
8008 print (thisAgent,
"\n");
8014 return matches_at_this_level;
8027 print (thisAgent,
"\n%d complete matches.\n", n);
8029 print (thisAgent,
"*** Complete Matches ***\n");
8033 print (thisAgent,
"\n");
8057 for(tmp = trace; tmp; tmp=tmp->
next) {
8058 if(tmp->
sym == sym)
return tmp;
8066 for(tmp = trace; tmp; tmp=tmp->
next) {
8067 if((tmp->
sym == sym) && (goal == tmp->
goal))
return tmp;
8083 print (thisAgent,
"O Assertions:\n");
8093 temp_token.
w = msc->
w;
8095 print (thisAgent,
"\n");
8108 tmp->next = ms_trace;
8120 tmp = ms_trace; ms_trace = tmp->
next;
8130 print(thisAgent,
"(%d)\n", tmp->count);
8132 print(thisAgent,
"\n");
8139 print (thisAgent,
"I Assertions:\n");
8149 temp_token.
w = msc->
w;
8151 print (thisAgent,
"\n");
8165 tmp->next = ms_trace;
8177 tmp = ms_trace; ms_trace = tmp->
next;
8187 print(thisAgent,
"(%d)\n", tmp->count);
8189 print(thisAgent,
"\n");
8198 print (thisAgent,
"Retractions:\n");
8201 print (thisAgent,
" ");
8203 print (thisAgent,
"\n");
8216 tmp->next = ms_trace;
8228 tmp = ms_trace; ms_trace = tmp->
next;
8239 print(thisAgent,
" [NIL] ");
8242 print(thisAgent,
"(%d)\n", tmp->count);
8244 print(thisAgent,
"\n");
8280 void xml_test (
agent* thisAgent,
char const* pTag,
test t) {
8282 size_t dest_size = 0 ;
8311 strncpy (ch,
"<> ", dest_size - (ch - dest));
8312 ch[dest_size - (ch - dest) - 1] = 0;
8318 strncpy (ch,
"< ", dest_size - (ch - dest));
8319 ch[dest_size - (ch - dest) - 1] = 0;
8324 strncpy (ch,
"> ", dest_size - (ch - dest));
8325 ch[dest_size - (ch - dest) - 1] = 0;
8330 strncpy (ch,
"<= ", dest_size - (ch - dest));
8331 ch[dest_size - (ch - dest) - 1] = 0;
8336 strncpy (ch,
">= ", dest_size - (ch - dest));
8337 ch[dest_size - (ch - dest) - 1] = 0;
8342 strncpy (ch,
"<=> ", dest_size - (ch - dest));
8343 ch[dest_size - (ch - dest) - 1] = 0;
8349 xml_att_val(thisAgent, pTag,
"BUGBUG--Adding disjunction in XML--not done yet") ;
8350 strncpy (ch,
"<< ", dest_size - (ch - dest));
8351 ch[dest_size - (ch - dest) - 1] = 0;
8358 strncpy (ch,
">>", dest_size - (ch - dest));
8359 ch[dest_size - (ch - dest) - 1] = 0;
8363 xml_att_val(thisAgent, pTag,
"BUGBUG--Adding conjunction in XML--not done yet") ;
8364 strncpy (ch,
"{ ", dest_size - (ch - dest));
8365 ch[dest_size - (ch - dest) - 1] = 0;
8368 xml_test (thisAgent, pTag, static_cast<char *>(c->
first)) ;
8372 strncpy (ch,
"}", dest_size - (ch - dest));
8373 ch[dest_size - (ch - dest) - 1] = 0;
8376 strncpy (dest,
"[GOAL ID TEST]", dest_size - (ch - dest));
8377 ch[dest_size - (ch - dest) - 1] = 0;
8380 strncpy (dest,
"[IMPASSE ID TEST]", dest_size - (ch - dest));
8381 ch[dest_size - (ch - dest) - 1] = 0;
8390 #define XML_CONDITION_LIST_TEMP_SIZE 10000
8392 int indent,
Bool internal) {
8393 dl_list *conds_not_yet_printed, *tail_of_conds_not_yet_printed;
8397 Bool removed_goal_test, removed_impasse_test;
8403 conds_not_yet_printed =
NIL;
8404 tail_of_conds_not_yet_printed =
NIL;
8406 for (c=conds; c!=
NIL; c=c->
next)
8408 allocate_with_pool (thisAgent, &thisAgent->
dl_cons_pool, &dc);
8410 if (conds_not_yet_printed)
8412 tail_of_conds_not_yet_printed->
next = dc;
8416 conds_not_yet_printed = dc;
8418 dc->
prev = tail_of_conds_not_yet_printed;
8419 tail_of_conds_not_yet_printed = dc;
8421 tail_of_conds_not_yet_printed->
next =
NIL;
8425 while (conds_not_yet_printed)
8427 if (did_one_line_already)
8434 did_one_line_already =
TRUE;
8437 dc = conds_not_yet_printed;
8444 xml_begin_tag(thisAgent, kTagConjunctive_Negation_Condition);
8446 xml_end_tag(thisAgent, kTagConjunctive_Negation_Condition);
8452 removed_goal_test = removed_impasse_test =
FALSE;
8455 &removed_impasse_test);
8459 conds_for_this_id = dc;
8473 while (conds_for_this_id)
8479 if (removed_goal_test)
8482 xml_att_val(thisAgent, kConditionTest, kConditionTestState);
8486 if (removed_impasse_test)
8489 xml_att_val(thisAgent, kConditionTest, kConditionTestImpasse);
8499 dc = conds_for_this_id;
8500 conds_for_this_id = conds_for_this_id->
next;
8555 old_next = cond->
next;
8556 old_prev = cond->
prev;
8560 cond->
next = old_next;
8561 cond->
prev = old_prev;
8573 if (action == PRINTING) {
8575 }
else if (action == FIRING) {
8578 }
else if (action == RETRACTING) {
8588 xml_att_val(thisAgent, kProduction_Name,
"[dummy_production]");
8595 if (action == PRINTING) {
8597 }
else if (action == FIRING) {
8600 }
else if (action == RETRACTING) {
8602 xml_end_tag(thisAgent, kTagProduction_Retracting);
8619 if (action != RETRACTING) {
8624 #ifdef DO_TOP_LEVEL_REF_CTS
8642 if (action == PRINTING) {
8644 }
else if (action == FIRING) {
8647 }
else if (action == RETRACTING) {
8649 xml_end_tag(thisAgent, kTagProduction_Retracting);
8685 temp_token.
w = msc->
w;
8701 tmp->next = ms_trace;
8714 tmp = ms_trace; ms_trace = tmp->
next;
8754 temp_token.
w = msc->
w;
8771 tmp->next = ms_trace;
8783 tmp = ms_trace; ms_trace = tmp->
next;
8830 tmp->next = ms_trace;
8842 tmp = ms_trace; ms_trace = tmp->
next;
8882 token *tokens, *t, *parent_tokens;
8884 int64_t matches_one_level_up;
8885 int64_t matches_at_this_level;
8892 matches_at_this_level = 0;
8897 if (node==cutoff)
return matches_at_this_level;
8901 matches_one_level_up =
xml_aux (thisAgent, parent, cutoff,
8902 cond->
prev, wtt, indent);
8906 if (! matches_one_level_up) {
8910 }
else if (! matches_at_this_level) {
8925 xml_begin_tag(thisAgent, kTagConjunctive_Negation_Condition) ;
8934 xml_end_tag(thisAgent, kTagConjunctive_Negation_Condition) ;
8942 if (!matches_one_level_up)
8945 xml_att_val(thisAgent, kMatchCount, matches_at_this_level) ;
8951 if (matches_one_level_up && (!matches_at_this_level)) {
8985 return matches_at_this_level;
9001 print (thisAgent,
"*** Complete Matches ***\n");
9023 static bool is_initialized =
false;
9044 is_initialized =
true;
9090 for (i=0; i<16; i++)