Ejemplo n.º 1
0
void retract_instantiation (instantiation *inst) {
  preference *pref, *next;
  bool retracted_a_preference;
  bool trace_it;

  /* --- invoke callback function --- */
#ifndef NO_CALLBACKS
  soar_invoke_callbacks(soar_agent, 
			RETRACTION_CALLBACK,
			(soar_call_data) inst);
#endif
  
  retracted_a_preference = FALSE;
  
  trace_it = trace_firings_of_inst (inst);

  /* --- retract any preferences that are in TM and aren't o-supported --- */
  pref = inst->preferences_generated;
  while (pref!=NIL) {
    next = pref->inst_next;
    if (pref->in_tm && (! pref->o_supported)) {

      if (trace_it) {
        if (!retracted_a_preference) {
	  if (get_printer_output_column()!=1) print ("\n");  /* AGR 617/634 */
          print ("Retracting ");
          print_instantiation_with_wmes
            (inst, (wme_trace_type)current_agent(sysparams)[TRACE_FIRINGS_WME_TRACE_TYPE_SYSPARAM]);
          if (current_agent(sysparams)[TRACE_FIRINGS_PREFERENCES_SYSPARAM]) print (" -->");
        }
        if (current_agent(sysparams)[TRACE_FIRINGS_PREFERENCES_SYSPARAM]) {
          print (" ");
          print_preference (pref);
        }
      }

      remove_preference_from_tm (pref);
      retracted_a_preference = TRUE;
    }
    pref = next;
  }

  /* --- remove inst from list of instantiations of this production --- */
  remove_from_dll (inst->prod->instantiations, inst, next, prev);

  /* --- if retracting a justification, excise it --- */
  /*
   * if the reference_count on the production is 1 (or less) then the
   * only thing supporting this justification is the instantiation, hence
   * it has already been excised, and doing it again is wrong.
   */
  if (inst->prod->type==JUSTIFICATION_PRODUCTION_TYPE &&
      inst->prod->reference_count > 1)
    excise_production (inst->prod, FALSE);
  
  /* --- mark as no longer in MS, and possibly deallocate  --- */
  inst->in_ms = FALSE;
  possibly_deallocate_instantiation (inst);
}
Ejemplo n.º 2
0
/* IMPORTANT: Any changes made to deallocate_preference should also be made to corresponding code in deallocate_instantiation */
void deallocate_preference(agent* thisAgent, preference* pref, bool dont_cache)
{
    /*  Remove from temporary memory and match goal if necessary */
    if (pref->in_tm) remove_preference_from_tm(thisAgent, pref);
    if (pref->on_goal_list) remove_from_dll(pref->inst->match_goal->id->preferences_from_goal, pref, all_of_goal_next, all_of_goal_prev);

    if (pref->inst)
    {
        if (!dont_cache) cache_preference_if_necessary(thisAgent, pref);
        remove_from_dll(pref->inst->preferences_generated, pref, inst_next, inst_prev);
        possibly_deallocate_instantiation(thisAgent, pref->inst);
    }

    /* Clean up contents and deallocate */
    deallocate_preference_contents(thisAgent, pref, dont_cache);

}