Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
agent.cpp
Go to the documentation of this file.
1 #include <portability.h>
2 
3 /*************************************************************************
4  * PLEASE SEE THE FILE "license.txt" (INCLUDED WITH THIS SOFTWARE PACKAGE)
5  * FOR LICENSE AND COPYRIGHT INFORMATION.
6  *************************************************************************/
7 
8 /*************************************************************************
9  *
10  * file: agent.cpp
11  *
12  * =======================================================================
13  * Initialization for the agent structure. Also the cleanup routine
14  * when an agent is destroyed. These routines are usually replaced
15  * by the same-named routines in the Tcl interface file soarAgent.c
16  * The versions in this file are used only when not linking in Tcl.
17  * HOWEVER, this code should be maintained, and the agent structure
18  * must be kept up to date.
19  * =======================================================================
20  */
21 
22 #include <stdlib.h>
23 #include <map>
24 
25 #include "agent.h"
26 #include "kernel.h"
27 #include "mem.h"
28 #include "lexer.h"
29 #include "symtab.h"
30 #include "gdatastructs.h"
31 #include "rhsfun.h"
32 #include "instantiations.h"
33 #include "production.h"
34 #include "gsysparam.h"
35 #include "init_soar.h"
36 #include "decide.h"
37 #include "print.h"
38 #include "recmem.h"
39 #include "backtrace.h"
40 #include "chunk.h"
41 #include "explain.h"
42 #include "rete.h"
43 #include "trace.h"
44 #include "callback.h"
45 #include "io_soar.h"
46 #include "xml.h"
47 #include "utilities.h"
48 #include "soar_module.h"
49 #include "exploration.h"
50 #include "reinforcement_learning.h"
51 #include "decision_manipulation.h"
52 #include "wma.h"
53 #include "episodic_memory.h"
54 #include "semantic_memory.h"
55 
56 
57 /* ================================================================== */
58 
59 //char * soar_version_string;
60 
61 /* ===================================================================
62 
63  Initialization Function
64 
65 =================================================================== */
66 
67 void init_soar_agent(agent* thisAgent) {
68 
69  /* JC ADDED: initialize the rhs function linked list */
70  thisAgent->rhs_functions = NIL;
71 
72  /* --- initialize everything --- */
73  init_symbol_tables(thisAgent);
74  create_predefined_symbols(thisAgent);
75  init_production_utilities(thisAgent);
76  init_built_in_rhs_functions (thisAgent);
77  init_rete (thisAgent);
78  init_lexer (thisAgent);
79  init_firer (thisAgent);
80  init_decider (thisAgent);
81  init_soar_io (thisAgent);
82  init_chunker (thisAgent);
83  init_tracing (thisAgent);
84  init_explain(thisAgent); /* AGR 564 */
85  select_init(thisAgent);
86  predict_init(thisAgent);
87 
88  init_memory_pool( thisAgent, &( thisAgent->gds_pool ), sizeof( goal_dependency_set ), "gds" );
89 
90  init_memory_pool( thisAgent, &( thisAgent->rl_info_pool ), sizeof( rl_data ), "rl_id_data" );
91  init_memory_pool( thisAgent, &( thisAgent->rl_et_pool ), sizeof( rl_et_map ), "rl_et" );
92  init_memory_pool( thisAgent, &( thisAgent->rl_rule_pool ), sizeof( rl_rule_list ), "rl_rules" );
93 
94  init_memory_pool( thisAgent, &( thisAgent->wma_decay_element_pool ), sizeof( wma_decay_element ), "wma_decay" );
95  init_memory_pool( thisAgent, &( thisAgent->wma_decay_set_pool ), sizeof( wma_decay_set ), "wma_decay_set" );
96  init_memory_pool( thisAgent, &( thisAgent->wma_wme_oset_pool ), sizeof( wma_pooled_wme_set ), "wma_oset" );
97  init_memory_pool( thisAgent, &( thisAgent->wma_slot_refs_pool ), sizeof( wma_sym_reference_map ), "wma_slot_ref" );
98 
99  init_memory_pool( thisAgent, &( thisAgent->epmem_wmes_pool ), sizeof( epmem_wme_stack ), "epmem_wmes" );
100  init_memory_pool( thisAgent, &( thisAgent->epmem_info_pool ), sizeof( epmem_data ), "epmem_id_data" );
101  init_memory_pool( thisAgent, &( thisAgent->smem_wmes_pool ), sizeof( smem_wme_stack ), "smem_wmes" );
102  init_memory_pool( thisAgent, &( thisAgent->smem_info_pool ), sizeof( smem_data ), "smem_id_data" );
103 
104  init_memory_pool( thisAgent, &( thisAgent->epmem_literal_pool ), sizeof( epmem_literal), "epmem_literals" );
105  init_memory_pool( thisAgent, &( thisAgent->epmem_pedge_pool ), sizeof( epmem_pedge ), "epmem_pedges" );
106  init_memory_pool( thisAgent, &( thisAgent->epmem_uedge_pool ), sizeof( epmem_uedge ), "epmem_uedges" );
107  init_memory_pool( thisAgent, &( thisAgent->epmem_interval_pool ), sizeof( epmem_interval ), "epmem_intervals" );
108 
109  thisAgent->epmem_params->exclusions->set_value( "epmem" );
110  thisAgent->epmem_params->exclusions->set_value( "smem" );
111 
112  thisAgent->smem_params->base_incremental_threshes->set_string( "10" );
113 
114 #ifdef REAL_TIME_BEHAVIOR
115  /* RMJ */
116  init_real_time(thisAgent);
117 #endif
118 
119 
120  /* --- add default object trace formats --- */
122  "%id %ifdef[(%v[name])]");
123  add_trace_format (thisAgent, FALSE, FOR_STATES_TF, NIL,
124  "%id %ifdef[(%v[attribute] %v[impasse])]");
125  { Symbol *evaluate_object_sym;
126  evaluate_object_sym = make_sym_constant (thisAgent, "evaluate-object");
127  add_trace_format (thisAgent, FALSE, FOR_OPERATORS_TF, evaluate_object_sym,
128  "%id (evaluate-object %o[object])");
129  symbol_remove_ref (thisAgent, evaluate_object_sym);
130  }
131  /* --- add default stack trace formats --- */
132  add_trace_format (thisAgent, TRUE, FOR_STATES_TF, NIL,
133  "%right[6,%dc]: %rsd[ ]==>S: %cs");
135  "%right[6,%dc]: %rsd[ ] O: %co");
136 
137  reset_statistics (thisAgent);
138 
139  /* RDF: For gSKI */
140  init_agent_memory(thisAgent);
141  /* END */
142 
143 }
144 
145 agent * create_soar_agent (char * agent_name) { /* loop index */
146  char cur_path[MAXPATHLEN]; /* AGR 536 */
147 
148  //agent* newAgent = static_cast<agent *>(malloc(sizeof(agent)));
149  agent* newAgent = new agent();
150 
151  newAgent->current_tc_number = 0;
152 
153  newAgent->name = savestring(agent_name);
154 
155  /* mvp 5-17-94 */
156  newAgent->variables_set = NIL;
157 
158 //#ifdef _WINDOWS
159 // newAgent->current_line[0] = 0;
160 // newAgent->current_line_index = 0;
161 //#endif /* _WINDOWS */
162 
163  newAgent->all_wmes_in_rete = NIL;
164  newAgent->alpha_mem_id_counter = 0;
165  newAgent->alternate_input_string = NIL;
166  newAgent->alternate_input_suffix = NIL;
167  newAgent->alternate_input_exit = FALSE;/* Soar-Bugs #54 */
168  newAgent->backtrace_number = 0;
169  newAgent->beta_node_id_counter = 0;
170  newAgent->bottom_goal = NIL;
171  newAgent->changed_slots = NIL;
172  newAgent->chunk_count = 1;
173  newAgent->chunk_free_problem_spaces = NIL;
174  newAgent->chunky_problem_spaces = NIL; /* AGR MVL1 */
175  strcpy(newAgent->chunk_name_prefix,"chunk"); /* ajc (5/14/02) */
177  newAgent->current_file = NIL;
178  newAgent->current_phase = INPUT_PHASE;
179  newAgent->applyPhase = FALSE;
180  newAgent->current_symbol_hash_id = 0;
181  newAgent->current_variable_gensym_number = 0;
182  newAgent->current_wme_timetag = 1;
183  newAgent->default_wme_depth = 1; /* AGR 646 */
184  newAgent->disconnected_ids = NIL;
185  newAgent->existing_output_links = NIL;
186  newAgent->output_link_changed = FALSE; /* KJC 11/9/98 */
187  /* newAgent->explain_flag = FALSE; */
188  newAgent->go_number = 1;
189  newAgent->go_type = GO_DECISION;
190  newAgent->grounds_tc = 0;
192  newAgent->ids_with_unknown_level = NIL;
193  newAgent->input_period = 0; /* AGR REW1 */
194  newAgent->input_cycle_flag = TRUE; /* AGR REW1 */
195  newAgent->justification_count = 1;
196  newAgent->lex_alias = NIL; /* AGR 568 */
198  newAgent->locals_tc = 0;
199  newAgent->max_chunks_reached = FALSE; /* MVP 6-24-94 */
200  newAgent->mcs_counter = 1;
201  newAgent->memory_pools_in_use = NIL;
202  newAgent->ms_assertions = NIL;
203  newAgent->ms_retractions = NIL;
204  newAgent->num_existing_wmes = 0;
205  newAgent->num_wmes_in_rete = 0;
206  newAgent->potentials_tc = 0;
207  newAgent->prev_top_state = NIL;
208  newAgent->print_prompt_flag = TRUE;
209  newAgent->printer_output_column = 1;
210  newAgent->production_being_fired = NIL;
211  newAgent->productions_being_traced = NIL;
212  newAgent->promoted_ids = NIL;
213  newAgent->reason_for_stopping = "Startup";
214  newAgent->slots_for_possible_removal = NIL;
215  newAgent->stop_soar = TRUE;
216  newAgent->system_halted = FALSE;
217  newAgent->token_additions = 0;
218  newAgent->top_dir_stack = NIL; /* AGR 568 */
219  newAgent->top_goal = NIL;
220  newAgent->top_state = NIL;
221  newAgent->wmes_to_add = NIL;
222  newAgent->wmes_to_remove = NIL;
223  newAgent->wme_filter_list = NIL; /* Added this to avoid
224  access violation
225  -AJC (5/13/02) */
226  newAgent->multi_attributes = NIL;
227 
228  /* REW: begin 09.15.96 */
229 
230  newAgent->did_PE = FALSE;
231  newAgent->soar_verbose_flag = FALSE;
232  newAgent->FIRING_TYPE = IE_PRODS;
233  newAgent->ms_o_assertions = NIL;
234  newAgent->ms_i_assertions = NIL;
235 
236  /* REW: end 09.15.96 */
237 
238  newAgent->postponed_assertions = NIL;
239 
240  /* REW: begin 08.20.97 */
241  newAgent->active_goal = NIL;
242  newAgent->active_level = 0;
243  newAgent->previous_active_level = 0;
244 
245  /* Initialize Waterfall-specific lists */
246  newAgent->nil_goal_retractions = NIL;
247  /* REW: end 08.20.97 */
248 
249  /* REW: begin 10.24.97 */
250  newAgent->waitsnc = FALSE;
251  newAgent->waitsnc_detect = FALSE;
252  /* REW: end 10.24.97 */
253 
254  /* Initializing rete stuff */
255  for (int i=0; i < 256; i++) {
256  newAgent->actual[i]=0;
257  newAgent->if_no_merging[i]=0;
258  newAgent->if_no_sharing[i]=0;
259  }
260 
261  /* Initializing lexeme */
262  newAgent->lexeme.type = NULL_LEXEME;
263  newAgent->lexeme.string[0] = 0;
264  newAgent->lexeme.length = 0;
265  newAgent->lexeme.int_val = 0;
266  newAgent->lexeme.float_val = 0.0;
267  newAgent->lexeme.id_letter = 'A';
268  newAgent->lexeme.id_number = 0;
269 
270  reset_max_stats(newAgent);
271 
272  newAgent->real_time_tracker = 0;
273  newAgent->attention_lapse_tracker = 0;
274 
275  if(!getcwd(cur_path, MAXPATHLEN))
276  print(newAgent, "Unable to set current directory while initializing agent.\n");
277  newAgent->top_dir_stack = static_cast<dir_stack_struct *>(malloc(sizeof(dir_stack_struct))); /* AGR 568 */
278  newAgent->top_dir_stack->directory = static_cast<char *>(malloc(MAXPATHLEN*sizeof(char))); /* AGR 568 */
279  newAgent->top_dir_stack->next = NIL; /* AGR 568 */
280  strcpy(newAgent->top_dir_stack->directory, cur_path); /* AGR 568 */
281 
282  /* changed all references of 'i', a var belonging to a previous for loop, to 'productionTypeCounter' to be unique
283  stokesd Sept 10 2004*/
284  for (int productionTypeCounter=0; productionTypeCounter<NUM_PRODUCTION_TYPES; productionTypeCounter++) {
285  newAgent->all_productions_of_type[productionTypeCounter] = NIL;
286  newAgent->num_productions_of_type[productionTypeCounter] = 0;
287  }
288 
289  newAgent->o_support_calculation_type = 4; /* KJC 7/00 */ // changed from 3 to 4 by voigtjr (/* bugzilla bug 339 */)
291 
292  /* JC ADDED: Make sure that the RHS functions get initialized correctly */
293  newAgent->rhs_functions = NIL;
294 
295  // JRV: Allocates data for XML generation
296  xml_create( newAgent );
297 
298  soar_init_callbacks( newAgent );
299 
300  //
301  // This call is needed to set up callbacks.
302  init_memory_utilities(newAgent);
303 
304  //
305  // This was moved here so that system parameters could
306  // be set before the agent was initialized.
307  init_sysparams (newAgent);
308 
309  /* Initializing all the timer structures */
310  // Timers must be initialized after sysparams
311 #ifndef NO_TIMING_STUFF
312  newAgent->timers_cpu.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED]));
313  newAgent->timers_kernel.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED]));
314  newAgent->timers_phase.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED]));
315 #ifdef DETAILED_TIMING_STATS
316  newAgent->timers_gds.set_enabled(&(newAgent->sysparams[TIMERS_ENABLED]));
317 #endif
318  reset_timers(newAgent);
319 #endif
320 
321  // dynamic memory pools (should come before consumers of dynamic pools)
322  newAgent->dyn_memory_pools = new std::map< size_t, memory_pool* >();
323 
324  // dynamic counters
325  newAgent->dyn_counters = new std::map< std::string, uint64_t >();
326 
327  // exploration initialization
330 
331  // rl initialization
332  newAgent->rl_params = new rl_param_container( newAgent );
333  newAgent->rl_stats = new rl_stat_container( newAgent );
334  newAgent->rl_prods = new rl_production_memory();
335 
337 
338  // select initialization
339  newAgent->select = new select_info;
340  select_init( newAgent );
341 
342 
343  // predict initialization
344  newAgent->prediction = new std::string();
345  predict_init( newAgent );
346 
347 
348  // wma initialization
349  newAgent->wma_params = new wma_param_container( newAgent );
350  newAgent->wma_stats = new wma_stat_container( newAgent );
351  newAgent->wma_timers = new wma_timer_container( newAgent );
352 
353 #ifdef USE_MEM_POOL_ALLOCATORS
354  newAgent->wma_forget_pq = new wma_forget_p_queue( std::less< wma_d_cycle >(), soar_module::soar_memory_pool_allocator< std::pair< wma_d_cycle, wma_decay_set* > >( newAgent ) );
355  newAgent->wma_touched_elements = new wma_pooled_wme_set( std::less< wme* >(), soar_module::soar_memory_pool_allocator< wme* >( newAgent ) );
356  newAgent->wma_touched_sets = new wma_decay_cycle_set( std::less< wma_d_cycle >(), soar_module::soar_memory_pool_allocator< wma_d_cycle >( newAgent ) );
357 #else
358  newAgent->wma_forget_pq = new wma_forget_p_queue();
359  newAgent->wma_touched_elements = new wma_pooled_wme_set();
360  newAgent->wma_touched_sets = new wma_decay_cycle_set();
361 #endif
362  newAgent->wma_initialized = false;
363  newAgent->wma_tc_counter = 2;
364 
365 
366  // epmem initialization
367  newAgent->epmem_params = new epmem_param_container( newAgent );
368  newAgent->epmem_stats = new epmem_stat_container( newAgent );
369  newAgent->epmem_timers = new epmem_timer_container( newAgent );
370 
371  newAgent->epmem_db = new soar_module::sqlite_database();
372  newAgent->epmem_stmts_common = NULL;
373  newAgent->epmem_stmts_graph = NULL;
374 
375  newAgent->epmem_node_mins = new std::vector<epmem_time_id>();
376  newAgent->epmem_node_maxes = new std::vector<bool>();
377 
378  newAgent->epmem_edge_mins = new std::vector<epmem_time_id>();
379  newAgent->epmem_edge_maxes = new std::vector<bool>();
380  newAgent->epmem_id_repository = new epmem_parent_id_pool();
381  newAgent->epmem_id_replacement = new epmem_return_id_pool();
382  newAgent->epmem_id_ref_counts = new epmem_id_ref_counter();
383 
384 #ifdef USE_MEM_POOL_ALLOCATORS
385  newAgent->epmem_node_removals = new epmem_id_removal_map( std::less< epmem_node_id >(), soar_module::soar_memory_pool_allocator< std::pair< epmem_node_id, bool > >( newAgent ) );
386  newAgent->epmem_edge_removals = new epmem_id_removal_map( std::less< epmem_node_id >(), soar_module::soar_memory_pool_allocator< std::pair< epmem_node_id, bool > >( newAgent ) );
387 
388  newAgent->epmem_wme_adds = new epmem_symbol_set( std::less< Symbol* >(), soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) );
389  newAgent->epmem_promotions = new epmem_symbol_set( std::less< Symbol* >(), soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) );
390 
392 #else
393  newAgent->epmem_node_removals = new epmem_id_removal_map();
394  newAgent->epmem_edge_removals = new epmem_id_removal_map();
395 
396  newAgent->epmem_wme_adds = new epmem_symbol_set();
397  newAgent->epmem_promotions = new epmem_symbol_set();
398 
399  newAgent->epmem_id_removes = new epmem_symbol_stack();
400 #endif
401 
402  newAgent->epmem_validation = 0;
403  newAgent->epmem_first_switch = true;
404 
405  // smem initialization
406  newAgent->smem_params = new smem_param_container( newAgent );
407  newAgent->smem_stats = new smem_stat_container( newAgent );
408  newAgent->smem_timers = new smem_timer_container( newAgent );
409 
410  newAgent->smem_db = new soar_module::sqlite_database();
411 
412  newAgent->smem_validation = 0;
413  newAgent->smem_first_switch = true;
414 
415 #ifdef USE_MEM_POOL_ALLOCATORS
416  newAgent->smem_changed_ids = new smem_pooled_symbol_set( std::less< Symbol* >(), soar_module::soar_memory_pool_allocator< Symbol* >( newAgent ) );
417 #else
418  newAgent->smem_changed_ids = new smem_pooled_symbol_set();
419 #endif
420  newAgent->smem_ignore_changes = false;
421 
422  // statistics initialization
423  newAgent->dc_stat_tracking = false;
424  newAgent->stats_db = new soar_module::sqlite_database();
425 
426  newAgent->substate_break_level = 0;
427 
428  return newAgent;
429 }
430 
431 /*
432 ===============================
433 
434 ===============================
435 */
436 void destroy_soar_agent (agent * delete_agent)
437 {
438  //print(delete_agent, "\nDestroying agent %s.\n", delete_agent->name); /* AGR 532 */
439 
440 //#ifdef USE_X_DISPLAY
441 //
442 // /* Destroy X window associated with agent */
443 // destroy_agent_window (delete_agent);
444 //#endif /* USE_X_DISPLAY */
445 
447  // Soar Modules - could potentially rely on hash tables
449 
450  // cleanup exploration
451  for ( int i=0; i<EXPLORATION_PARAMS; i++ )
452  delete delete_agent->exploration_params[ i ];
453 
454  // cleanup Soar-RL
456  delete delete_agent->rl_prods;
457  delete delete_agent->rl_params;
458  delete delete_agent->rl_stats;
459  delete_agent->rl_params = NULL; // apoptosis needs to know this for excise_all_productions below
460 
461  // cleanup select
462  select_init( delete_agent );
463  delete delete_agent->select;
464 
465  // cleanup predict
466  delete delete_agent->prediction;
467 
468  // cleanup wma
469  delete_agent->wma_params->activation->set_value( soar_module::off );
470  delete delete_agent->wma_forget_pq;
471  delete delete_agent->wma_touched_elements;
472  delete delete_agent->wma_touched_sets;
473  delete delete_agent->wma_params;
474  delete delete_agent->wma_stats;
475  delete delete_agent->wma_timers;
476 
477  // cleanup epmem
478  epmem_close( delete_agent );
479  delete delete_agent->epmem_params;
480  delete delete_agent->epmem_stats;
481  delete delete_agent->epmem_timers;
482 
483  delete delete_agent->epmem_node_removals;
484  delete delete_agent->epmem_node_mins;
485  delete delete_agent->epmem_node_maxes;
486  delete delete_agent->epmem_edge_removals;
487  delete delete_agent->epmem_edge_mins;
488  delete delete_agent->epmem_edge_maxes;
489  delete delete_agent->epmem_id_repository;
490  delete delete_agent->epmem_id_replacement;
491  delete delete_agent->epmem_id_ref_counts;
492  delete delete_agent->epmem_id_removes;
493 
494  delete delete_agent->epmem_wme_adds;
495  delete delete_agent->epmem_promotions;
496 
497  delete delete_agent->epmem_db;
498 
499 
500  // cleanup smem
501  smem_close( delete_agent );
502  delete delete_agent->smem_changed_ids;
503  delete delete_agent->smem_params;
504  delete delete_agent->smem_stats;
505  delete delete_agent->smem_timers;
506 
507  delete delete_agent->smem_db;
508 
509  // cleanup statistics db
510  stats_close( delete_agent );
511  delete delete_agent->stats_db;
512  delete_agent->stats_db = 0;
513 
516 
517  remove_built_in_rhs_functions(delete_agent);
518 
519  /* Free structures stored in agent structure */
520  free(delete_agent->name);
521  free(delete_agent->top_dir_stack->directory);
522  free(delete_agent->top_dir_stack);
523 
524  /* Freeing the agent's multi attributes structure */
525  multi_attribute* lastmattr = 0;
526  for ( multi_attribute* curmattr = delete_agent->multi_attributes;
527  curmattr != 0;
528  curmattr = curmattr->next ) {
529 
530  symbol_remove_ref(delete_agent, curmattr->symbol);
531 
532  free_memory(delete_agent, lastmattr, MISCELLANEOUS_MEM_USAGE);
533  lastmattr = curmattr;
534  }
535  free_memory(delete_agent, lastmattr, MISCELLANEOUS_MEM_USAGE);
536 
537  /* Freeing all the productions owned by this agent */
538  excise_all_productions(delete_agent, false);
539 
540  /* Releasing all the predefined symbols */
541  release_predefined_symbols(delete_agent);
542 
543  /* Releasing rete stuff RPM 11/06 */
544  free_with_pool(&delete_agent->rete_node_pool, delete_agent->dummy_top_node);
545  free_with_pool(&delete_agent->token_pool, delete_agent->dummy_top_token);
546 
547  /* Cleaning up the various callbacks
548  TODO: Not clear why callbacks need to take the agent pointer essentially twice.
549  */
551 
552  /* RPM 9/06 begin */
553 
554  free_memory(delete_agent, delete_agent->left_ht, HASH_TABLE_MEM_USAGE);
555  free_memory(delete_agent, delete_agent->right_ht, HASH_TABLE_MEM_USAGE);
556  free_memory(delete_agent, delete_agent->rhs_variable_bindings, MISCELLANEOUS_MEM_USAGE);
557 
558  /* Releasing memory allocated in inital call to start_lex_from_file from init_lexer */
559  free_memory_block_for_string(delete_agent, delete_agent->current_file->filename);
560  free_memory (delete_agent, delete_agent->current_file, MISCELLANEOUS_MEM_USAGE);
561 
562  /* Releasing trace formats (needs to happen before tracing hashtables are released) */
563  remove_trace_format (delete_agent, FALSE, FOR_ANYTHING_TF, NIL);
564  remove_trace_format (delete_agent, FALSE, FOR_STATES_TF, NIL);
565  Symbol *evaluate_object_sym = find_sym_constant (delete_agent, "evaluate-object");
566  remove_trace_format (delete_agent, FALSE, FOR_OPERATORS_TF, evaluate_object_sym);
567  remove_trace_format (delete_agent, TRUE, FOR_STATES_TF, NIL);
568  remove_trace_format (delete_agent, TRUE, FOR_OPERATORS_TF, NIL);
569 
570  /* Releasing hashtables allocated in init_tracing */
571  for (int i=0; i<3; i++) {
572  free_hash_table(delete_agent, delete_agent->object_tr_ht[i]);
573  free_hash_table(delete_agent, delete_agent->stack_tr_ht[i]);
574  }
575 
576  /* Releasing memory allocated in init_rete */
577  for (int i=0; i<16; i++) {
578  free_hash_table(delete_agent, delete_agent->alpha_hash_tables[i]);
579  }
580 
581  /* Releasing other hashtables */
582  free_hash_table(delete_agent, delete_agent->variable_hash_table);
583  free_hash_table(delete_agent, delete_agent->identifier_hash_table);
584  free_hash_table(delete_agent, delete_agent->sym_constant_hash_table);
585  free_hash_table(delete_agent, delete_agent->int_constant_hash_table);
586  free_hash_table(delete_agent, delete_agent->float_constant_hash_table);
587 
588  /* Releasing memory pools */
589  memory_pool* cur_pool = delete_agent->memory_pools_in_use;
590  memory_pool* next_pool;
591  while(cur_pool != NIL) {
592  next_pool = cur_pool->next;
593  free_memory_pool(delete_agent, cur_pool);
594  cur_pool = next_pool;
595  }
596 
597  /* RPM 9/06 end */
598 
599  // dynamic memory pools (cleared in the last step)
600  for ( std::map< size_t, memory_pool* >::iterator it=delete_agent->dyn_memory_pools->begin(); it!=delete_agent->dyn_memory_pools->end(); it++ )
601  {
602  delete it->second;
603  }
604  delete delete_agent->dyn_memory_pools;
605 
606  delete delete_agent->dyn_counters;
607 
608  // JRV: Frees data used by XML generation
609  xml_destroy( delete_agent );
610 
611  /* Free soar agent structure */
612  delete delete_agent;
613 }