1 #include <portability.h>
52 #include "soar_TraceNames.h"
69 using namespace soar_TraceNames;
71 #ifdef USE_MEM_POOL_ALLOCATORS
72 typedef std::list< Symbol*, soar_module::soar_memory_pool_allocator< Symbol* > >
symbol_list;
87 print(thisAgent,
"\n Candidate %d", cand);
135 #define NOTHING_DECIDER_FLAG 0
136 #define CANDIDATE_DECIDER_FLAG 1
137 #define CONFLICTED_DECIDER_FLAG 2
138 #define FORMER_CANDIDATE_DECIDER_FLAG 3
139 #define BEST_DECIDER_FLAG 4
140 #define WORST_DECIDER_FLAG 5
141 #define UNARY_INDIFFERENT_DECIDER_FLAG 6
142 #define ALREADY_EXISTING_WME_DECIDER_FLAG 7
143 #define UNARY_PARALLEL_DECIDER_FLAG 8
147 #define UNARY_INDIFFERENT_CONSTANT_DECIDER_FLAG 9
165 allocate_with_pool (thisAgent, &thisAgent->
dl_cons_pool, &dc);
197 w->
value->common.a.decider_wme = w;
219 w = p->
value->common.a.decider_wme;
227 p->
value->common.a.decider_wme = w;
233 w = p->
value->common.a.decider_wme;
241 p->
value->common.a.decider_wme = w;
343 #define promote_if_needed(thisAgent, sym) \
344 { if ((sym)->common.symbol_type==IDENTIFIER_SYMBOL_TYPE) \
345 promote_id_and_tc(thisAgent, sym,new_level); }
353 if (id->
id.
level <= new_level)
return;
357 id->
id.level = new_level;
359 id->id.could_be_a_link_from_below =
TRUE;
364 strncpy (msg,
"decide.c: Internal error: tried to promote a goal or impasse id\n",
BUFFER_MSG_SIZE);
470 allocate_with_pool (thisAgent, &thisAgent->
dl_cons_pool, &dc);
484 allocate_with_pool (thisAgent, &thisAgent->
dl_cons_pool, &dc);
511 id->id.input_wmes =
NIL;
570 #ifdef USE_MEM_POOL_ALLOCATORS
575 ids_to_walk.push_back( root );
577 while ( !ids_to_walk.empty() )
579 id = ids_to_walk.back();
580 ids_to_walk.pop_back();
602 allocate_with_pool (thisAgent, &thisAgent->
dl_cons_pool, &dc);
614 ids_to_walk.push_back( w->
value );
624 ids_to_walk.push_back( pref->
value );
631 ids_to_walk.push_back( pref->
referent );
648 ids_to_walk.push_back( w->
value );
676 #ifdef USE_MEM_POOL_ALLOCATORS
681 ids_to_walk.push_back( root );
683 while ( !ids_to_walk.empty() )
685 id = ids_to_walk.back();
686 ids_to_walk.pop_back();
696 dc =
id->id.unknown_level;
700 id->id.unknown_level =
NIL;
702 id->id.promotion_level = thisAgent->
walk_level;
710 ids_to_walk.push_back( w->
value );
720 ids_to_walk.push_back( pref->
value );
726 ids_to_walk.push_back( pref->
referent );
744 ids_to_walk.push_back( w->
value );
777 id->id.unknown_level =
NIL;
818 id->id.unknown_level =
NIL;
836 #ifndef NO_TIMING_STUFF
837 #ifdef DETAILED_TIMING_STATS
838 soar_process_timer local_timer;
848 #ifndef NO_TIMING_STUFF
849 #ifdef DETAILED_TIMING_STATS
855 #ifndef NO_TIMING_STUFF
856 #ifdef DETAILED_TIMING_STATS
858 thisAgent->timers_ownership_cpu_time[thisAgent->
current_phase].update(local_timer);
912 *result_candidates = candidates;
918 value = candidates->
value;
923 if ( !consistency && candidates &&
rl_enabled( thisAgent ) )
936 Bool match_found, not_all_indifferent, not_all_parallel;
943 *result_candidates =
NIL;
957 *result_candidates = force_result;
999 *result_candidates = candidates;
1005 *result_candidates = candidates;
1007 if ( !consistency &&
rl_enabled( thisAgent ) && candidates )
1019 #define NEW_PREFERENCES_SCHEME 1 // bug 234
1020 #if(NEW_PREFERENCES_SCHEME == 1)
1061 if (j->common.decider_flag && k->common.decider_flag)
1074 if (j->common.decider_flag && k->common.decider_flag)
1106 *result_candidates = candidates;
1128 #else // !NEW_PREFERENCES_SCHEME
1171 if (j->common.decider_flag && k->common.decider_flag) {
1195 if (j->common.decider_flag && k->common.decider_flag) {
1228 *result_candidates = candidates;
1246 #endif // !NEW_PREFERENCES_SCHEME
1287 *result_candidates = candidates;
1289 if ( !consistency &&
rl_enabled( thisAgent ) && candidates )
1317 not_all_indifferent =
FALSE;
1327 if (p==cand)
continue;
1328 match_found =
FALSE;
1337 not_all_indifferent =
TRUE;
1341 if (not_all_indifferent)
break;
1344 if ( !not_all_indifferent )
1349 (*result_candidates)->next_candidate =
NIL;
1352 *result_candidates = candidates;
1359 *result_candidates = candidates;
1368 not_all_parallel =
FALSE;
1375 if (p==cand)
continue;
1376 match_found =
FALSE;
1385 not_all_parallel =
TRUE;
1389 if (not_all_parallel)
break;
1392 *result_candidates = candidates;
1394 if (! not_all_parallel) {
1490 switch (impasse_type) {
1531 static_cast<soar_call_data>(s) );
1539 static_cast<soar_call_data>(s) );
1545 id->id.impasse_wmes =
NIL;
1593 "decide.c: Internal error: couldn't find acceptable pref wme\n",
BUFFER_MSG_SIZE);
1605 all_of_goal_next, all_of_goal_prev);
1623 allocate_with_pool (thisAgent, &thisAgent->
condition_pool, &cond);
1634 #ifdef DO_TOP_LEVEL_REF_CTS
1664 enum item_types { regular, numeric };
1669 unsigned int item_count;
1671 Symbol* loop_count_sym = NULL;
1672 Symbol* count_sym = NULL;
1674 for (
int it=regular; it<=numeric; it++ )
1676 if ( it == regular )
1689 if ( w->
attr == loop_sym )
1697 if ( ( it == numeric ) && items )
1710 w =
id->
id.impasse_wmes;
1714 if ( w->
attr == loop_sym )
1719 w->
value->common.a.decider_wme = w;
1731 else if ( w->
attr == loop_count_sym )
1757 cand->
value->common.a.decider_wme->preference = bt_pref;
1765 if ( item_count > 0 )
1767 count_sym =
make_int_constant( thisAgent, static_cast< int64_t >( item_count ) );
1813 w->
value->common.a.decider_wme = w;
1842 cand->
value->common.a.decider_wme->preference = cand;
1877 #ifndef NO_TIMING_STUFF
1878 #ifdef DETAILED_TIMING_STATS
1879 thisAgent->timers_gds.start();
1944 abort_with_fatal_error(thisAgent,
"**** Wanted to create a GDS for a WME level different from the instantiation level.....Big problems....exiting....****\n\n");
1965 #ifdef DEBUG_GDS_HIGH
1967 print(thisAgent,
" Goal level of preference: %d\n",
1973 #ifdef DEBUG_GDS_HIGH
1980 #ifdef DEBUG_GDS_HIGH
1981 print_with_symbols(thisAgent,
" %y is simply the instantiation that led to a chunk.\n Not adding it the current instantiations.\n", pref->
inst->
prod->
name);
1987 #ifdef DEBUG_GDS_HIGH
1994 #ifdef DEBUG_GDS_HIGH
2001 #ifdef DEBUG_GDS_HIGH
2002 print(thisAgent,
"\n CALLING ELABORATE GDS....\n");
2009 #ifdef DEBUG_GDS_HIGH
2010 print(thisAgent,
" FINISHED ELABORATING GDS.\n\n");
2016 #ifndef NO_TIMING_STUFF
2017 #ifdef DETAILED_TIMING_STATS
2018 thisAgent->timers_gds.stop();
2019 thisAgent->timers_gds_cpu_time[thisAgent->
current_phase].update(thisAgent->timers_gds);
2117 if (!s->
wmes)
return;
2147 static_cast<soar_call_data>(goal) );
2166 #ifdef DO_TOP_LEVEL_REF_CTS
2170 all_of_goal_next, all_of_goal_prev);
2186 all_of_goal_next, all_of_goal_prev);
2308 attr_of_impasse, impasse_type,
2323 print(thisAgent,
"Soar appears to be in an infinite loop. \nContinuing to subgoal may cause Soar to \nexceed the program stack of your system.\n");
2325 xml_generate_warning(thisAgent,
"Soar appears to be in an infinite loop. \nContinuing to subgoal may cause Soar to \nexceed the program stack of your system.\n");
2341 id->id.lower_goal =
NIL;
2344 id->id.isa_goal =
TRUE;
2346 id->id.allow_bottom_up_chunks =
TRUE;
2349 id->id.rl_info->previous_q = 0;
2350 id->id.rl_info->reward = 0;
2351 id->id.rl_info->gap_age = 0;
2352 id->id.rl_info->hrl_age = 0;
2354 #ifdef USE_MEM_POOL_ALLOCATORS
2357 id->id.rl_info->eligibility_traces =
new (
id->id.rl_info->eligibility_traces )
rl_et_map();
2360 #ifdef USE_MEM_POOL_ALLOCATORS
2363 id->id.rl_info->prev_op_rl_rules =
new (
id->id.rl_info->prev_op_rl_rules )
rl_rule_list();
2367 id->id.epmem_info->last_ol_time = 0;
2368 id->id.epmem_info->last_cmd_time = 0;
2369 id->id.epmem_info->last_cmd_count = 0;
2372 #ifdef USE_MEM_POOL_ALLOCATORS
2375 id->id.epmem_info->epmem_wmes =
new (
id->id.epmem_info->epmem_wmes )
epmem_wme_stack();
2379 id->id.smem_info->last_cmd_time[0] = 0;
2380 id->id.smem_info->last_cmd_time[1] = 0;
2381 id->id.smem_info->last_cmd_count[0] = 0;
2382 id->id.smem_info->last_cmd_count[1] = 0;
2384 #ifdef USE_MEM_POOL_ALLOCATORS
2387 id->id.smem_info->smem_wmes =
new (
id->id.smem_info->smem_wmes )
smem_wme_stack();
2393 static_cast<soar_call_data>(
id) );
2422 strncpy (msg,
"decide.c: Internal error: bad type of existing impasse.\n",
BUFFER_MSG_SIZE);
2426 strncpy (msg,
"decide.c: Internal error: couldn't find type of existing impasse.\n",
BUFFER_MSG_SIZE);
2439 strncpy (msg,
"decide.c: Internal error: couldn't find attribute of existing impasse.\n",
BUFFER_MSG_SIZE);
2458 Symbol *attribute_of_impasse;
2484 switch ( impasse_type )
2507 std::string temp =
"";
2538 strncpy (msg,
"decide.c: Internal error: more than one winner for context slot\n",
BUFFER_MSG_SIZE);
2554 attribute_of_impasse = s->
attr;
2564 attribute_of_impasse = s->
attr;
2742 xml_att_val(thisAgent, kPhase_Name, kSubphaseName_ChangingWorkingMemory);
2745 print (thisAgent,
"\t--- Change Working Memory (PE) ---\n",0);
2746 xml_att_val(thisAgent, kPhase_FiringType, kPhaseFiringType_PE);
2749 print (thisAgent,
"\t--- Change Working Memory (IE) ---\n",0);
2750 xml_att_val(thisAgent, kPhase_FiringType, kPhaseFiringType_IE);
2871 curr_pi = curr_pi->
next) {
2872 if (curr_pi->
inst == inst) {
2886 new_pi->
inst = inst;
2905 wme_to_add->
gds = gds;
2912 memset(msgbuf, 0, 256);
2930 wme *wme_matching_this_cond;
2940 inst = curr_pi->
inst;
2944 print(thisAgent,
" ");
2957 wme_matching_this_cond = cond->
bt.
wme_;
2958 wme_goal_level = cond->
bt.
level;
2959 pref_for_this_wme = wme_matching_this_cond->
preference;
2962 print(thisAgent,
"\n wme_matching_this_cond at goal_level = %d : ",
2964 print_wme(thisAgent, wme_matching_this_cond);
2966 if (pref_for_this_wme) {
2967 print(thisAgent,
" pref_for_this_wme : ");
2977 if ((pref_for_this_wme ==
NIL) ||
2978 (wme_goal_level < inst->match_goal_level))
2982 if (pref_for_this_wme ==
NIL)
2984 print(thisAgent,
" this wme has no preferences (it's an arch-created wme)\n");
2986 else if (wme_goal_level < inst->match_goal_level)
2988 print(thisAgent,
" this wme is in the supergoal\n");
2993 if (wme_matching_this_cond->
gds !=
NIL)
2997 if (wme_matching_this_cond->
gds->
goal ==
NIL)
3002 wme_matching_this_cond,
wme,
3003 gds_next, gds_prev);
3011 free_with_pool( &( thisAgent->
gds_pool ), wme_matching_this_cond->
gds );
3014 print(thisAgent,
"\n REMOVING GDS FROM MEMORY.");
3026 print(thisAgent,
"\n .....GDS' goal is NIL so switching from old to new GDS list....\n");
3042 print(thisAgent,
"\n\n\n HELLO! HELLO! The inst->match_goal_level is 1");
3045 wme_matching_this_cond,
wme,
3046 gds_next, gds_prev);
3049 free_with_pool( &( thisAgent->
gds_pool ), wme_matching_this_cond->
gds );
3052 print(thisAgent,
"\n REMOVING GDS FROM MEMORY.");
3063 print(thisAgent,
"\n ....switching from old to new GDS list....\n");
3082 print(thisAgent,
"\nDEBUG DEBUG : The new header should never have a prev value.\n");
3084 print_with_symbols(thisAgent,
"\n ......WME did not have defined GDS. Now adding to goal [%y].\n", wme_matching_this_cond->
gds->
goal);
3090 print(thisAgent,
" Added WME to GDS for goal = %d",
3103 print(thisAgent,
" this wme is local and o-supported\n");
3115 print(thisAgent,
" don't back up through top state\n");
3125 print(thisAgent,
" this wme is local and i-supported\n");
3133 print(thisAgent,
"here's the wme with no slot:\t");
3141 wme *fake_inst_wme_cond;
3144 if (fake_inst_wme_cond->
gds !=
NIL)
3154 fake_inst_wme_cond,
wme,
3155 gds_next, gds_prev);
3163 free_with_pool( &( thisAgent->
gds_pool ), fake_inst_wme_cond->
gds );
3166 print(thisAgent,
"\n REMOVING GDS FROM MEMORY.");
3177 print(thisAgent,
"\n .....GDS' goal is NIL so switching from old to new GDS list....\n");
3191 print(thisAgent,
"\n\n\n\n\n HELLO! HELLO! The inst->match_goal_level is 1");
3194 fake_inst_wme_cond,
wme,
3195 gds_next, gds_prev);
3199 free_with_pool( &( thisAgent->
gds_pool ), fake_inst_wme_cond->
gds );
3202 print(thisAgent,
"\n REMOVING GDS FROM MEMORY.");
3214 print(thisAgent,
"\n .....switching from old to new GDS list....\n");
3234 print(thisAgent,
"\nDEBUG DEBUG : The new header should never have a prev value.\n");
3236 print_with_symbols(thisAgent,
"\n ......WME did not have defined GDS. Now adding to goal [%y].\n", fake_inst_wme_cond->
gds->
goal);
3240 print(thisAgent,
" Added WME to GDS for goal = %d", fake_inst_wme_cond->
gds->
goal->
id.
level);
3242 fake_inst_wme_cond->
gds->
goal);
3250 pref; pref=pref->
next)
3254 print(thisAgent,
" looking at pref for the wme: ");
3266 if (pref->
value == wme_matching_this_cond->
value) {
3310 print(thisAgent,
" the inst producing this pref was already explored; skipping it\n");
3318 print(thisAgent,
" this inst is for a pref with a differnt value than the condition WME; skippint it\n");
3345 temp_pi = curr_pi->
next;
3355 print(thisAgent,
"\n RECURSING using these parents:\n");
3358 curr_pi = curr_pi->
next) {
3391 memset(msgbuf, 0, 256);
3396 xml_att_val(thisAgent, soar_TraceNames::kTypeString, msgbuf);
3398 xml_end_tag(thisAgent, soar_TraceNames::kTagVerbose);
3402 #ifndef NO_TIMING_STUFF
3403 #ifdef DETAILED_TIMING_STATS
3404 thisAgent->timers_gds.start();
3446 if (s->isa_context_slot && !s->changed)
3447 s->changed =
reinterpret_cast<dl_cons*
>(1);
3467 #ifndef NO_TIMING_STUFF
3468 #ifdef DETAILED_TIMING_STATS
3469 thisAgent->timers_gds.stop();
3470 thisAgent->timers_gds_cpu_time[thisAgent->
current_phase].update(thisAgent->timers_gds);
3483 curr_pi = curr_pi->
next)
3492 allocate_with_pool( thisAgent, &( thisAgent->
gds_pool ), &gds );