Exemple #1
0
void deallocate_instantiation (instantiation *inst) {
  condition *cond;

  /* mvp 5-17-94 */
  list *c, *c_old;
  preference *pref;
  goal_stack_level level;
  
  level = inst->match_goal_level;
 
#ifdef DEBUG_INSTANTIATIONS
  if (inst->prod)
    print_with_symbols ("\nDeallocate instantiation of %y",inst->prod->name);
#endif

  for (cond=inst->top_of_instantiated_conditions; cond!=NIL; cond=cond->next)
    if (cond->type==POSITIVE_CONDITION) {

      /* mvp 6-22-94, modified 94.01.17 by AGR with lotsa help from GAP */
     if (cond->bt.prohibits) {
       c_old = c = cond->bt.prohibits;
       cond->bt.prohibits = NIL;
       for (; c!=NIL; c=c->rest) {
 		   pref = (preference *) c->first;
           #ifdef DO_TOP_LEVEL_REF_CTS
		   preference_remove_ref (pref);
           #else
	       if (level > TOP_GOAL_LEVEL)  preference_remove_ref (pref);
           #endif
       }
       free_list (c_old);
     }
     /* mvp done */
     #ifdef DO_TOP_LEVEL_REF_CTS
       wme_remove_ref (cond->bt.wme);
       if (cond->bt.trace) preference_remove_ref (cond->bt.trace);
     #else
	   if (level > TOP_GOAL_LEVEL) {
		   wme_remove_ref (cond->bt.wme);
           if (cond->bt.trace) preference_remove_ref (cond->bt.trace);
	   }
     #endif
   }

  deallocate_condition_list (inst->top_of_instantiated_conditions);
  deallocate_list_of_nots (inst->nots);
  if (inst->prod) production_remove_ref (inst->prod);
  free_with_pool (&current_agent(instantiation_pool), inst);
}
Exemple #2
0
void clear_preference_list(agent* thisAgent, cons* &pPrefList)
{
    cons *c;
    preference* lPref;

    if (pPrefList)
    {
        lPref = NIL;
        for (c = pPrefList; c != NIL; c = c->rest)
        {
            lPref = static_cast<preference*>(c->first);
            preference_remove_ref(thisAgent, lPref, true);
        }
        free_list(thisAgent, pPrefList);
        pPrefList = NULL;
    }
}
Exemple #3
0
void remove_preference_from_tm(agent* thisAgent, preference* pref)
{
    slot* s;

    s = pref->slot;

    /*  remove preference from the list for the slot */
    remove_from_dll(s->all_preferences, pref, all_of_slot_next, all_of_slot_prev);
    remove_from_dll(s->preferences[pref->type], pref, next, prev);

    /*  other miscellaneous stuff */
    pref->in_tm = false;
    pref->slot = NIL;      /* BUG shouldn't we use pref->slot in place of pref->in_tm? */
    mark_slot_as_changed(thisAgent, s);

    /*  if acceptable/require pref for context slot, we may need to remove
       a wme later */
    if ((s->isa_context_slot) &&
            ((pref->type == ACCEPTABLE_PREFERENCE_TYPE) ||
             (pref->type == REQUIRE_PREFERENCE_TYPE)))
    {
        mark_context_slot_as_acceptable_preference_changed(thisAgent, s);
    }

    /*  update identifier levels */
    if (pref->value->symbol_type == IDENTIFIER_SYMBOL_TYPE)
    {
        post_link_removal(thisAgent, pref->id, pref->value);
    }
    if (preference_is_binary(pref->type))
        if (pref->referent->symbol_type == IDENTIFIER_SYMBOL_TYPE)
        {
            post_link_removal(thisAgent, pref->id, pref->referent);
        }
    if (thisAgent->trace_settings[TRACE_FIRINGS_PREFERENCES_SYSPARAM])
    {
        thisAgent->outputManager->printa_sf(thisAgent,  "%e- ");
        print_preference(thisAgent, pref, false);
        thisAgent->outputManager->printa_sf(thisAgent,  " (%y)\n", pref->inst->prod_name);
    }
    /*  deallocate it and clones if possible */
    preference_remove_ref(thisAgent, pref);
}
Exemple #4
0
/* MMA 8-2012: Clear out and deallocate the CDPS. */
void clear_CDPS(agent* thisAgent, slot* s)
{

    list* cond_current, *cond_old;
    preference* pref;
    
    /* The CDPS should never exist on a top-level slot, so we do
     * not need to worry about checking for DO_TOP_LEVEL_REF_CTS. */
    
    cond_old = cond_current = s->CDPS;
    s->CDPS = NIL;
    for (; cond_current != NIL; cond_current = cond_current->rest)
    {
        pref = static_cast<preference*>(cond_current->first);
        preference_remove_ref(thisAgent, pref);
    }
    free_list(thisAgent, cond_old);
    
}
Exemple #5
0
void process_o_rejects_and_deallocate_them(agent* thisAgent, preference* o_rejects, preference_list& bufdeallo)
{
    preference* pref, *next_pref, *p, *next_p;
    slot* s;

    for (pref = o_rejects; pref != NIL; pref = pref->next)
    {
        preference_add_ref(pref);  /* prevents it from being deallocated if it's
                                   a clone of some other pref we're about to
                                   remove */
    }

    pref = o_rejects;
    while (pref)
    {
        next_pref = pref->next;
        s = find_slot(pref->id, pref->attr);
        if (s)
        {
            /*  remove all pref's in the slot that have the same value */
            p = s->all_preferences;
            while (p)
            {
                next_p = p->all_of_slot_next;
                if (p->value == pref->value)
                {
                    // Buffer deallocation by adding a reference here and putting it
                    // on a list. These are deallocated after the inner elaboration
                    // loop completes.
                    preference_add_ref(p);
                    bufdeallo.push_back(p);
                    remove_preference_from_tm(thisAgent, p);
                }
                p = next_p;
            }
        }
        preference_remove_ref(thisAgent, pref);
        pref = next_pref;
    }
}
Exemple #6
0
void assert_new_preferences (void) {
  instantiation *inst, *next_inst;
  preference *pref, *next_pref;
  preference *o_rejects;

  o_rejects = NIL;  


  /* REW: begin 09.15.96 */
  if ((current_agent(operand2_mode) == TRUE) &&
      (current_agent(soar_verbose_flag) == TRUE))
     printf("\n   in assert_new_preferences:");
  /* REW: end   09.15.96 */


  for (inst=current_agent(newly_created_instantiations);
       inst!=NIL;
       inst=next_inst) {
    next_inst = inst->next;
    if (inst->in_ms)
      insert_at_head_of_dll (inst->prod->instantiations, inst, next, prev);


    /* REW: begin 09.15.96 */
    if (current_agent(operand2_mode) == TRUE) {
       if (current_agent(soar_verbose_flag) == TRUE)
	  print_with_symbols("\n      asserting instantiation: %y\n",
			     inst->prod->name);
    }
    /* REW: end   09.15.96 */


    for (pref=inst->preferences_generated; pref!=NIL; pref=next_pref) {
      next_pref = pref->inst_next;
      if ((pref->type==REJECT_PREFERENCE_TYPE)&&(pref->o_supported)) {
        /* --- o-reject: just put it in the buffer for later --- */
        pref->next = o_rejects;
        o_rejects = pref;


	/* REW: begin 09.15.96 */
	/* No knowledge retrieval necessary in Operand2 */
	/* REW: end   09.15.96 */

      } else if (inst->in_ms || pref->o_supported) {
        /* --- normal case --- */
        add_preference_to_tm (pref);


	/* REW: begin 09.15.96 */
	/* No knowledge retrieval necessary in Operand2 */
	/* REW: end   09.15.96 */


      } else {
        /* --- inst. is refracted chunk, and pref. is not o-supported:
           remove the preference --- */
        /* --- first splice it out of the clones list--otherwise we might
           accidentally deallocate some clone that happens to have refcount==0
           just because it hasn't been asserted yet --- */
        if (pref->next_clone) pref->next_clone->prev_clone = pref->prev_clone;
        if (pref->prev_clone) pref->prev_clone->next_clone = pref->next_clone;
        pref->next_clone = pref->prev_clone = NIL;
        /* --- now add then remove ref--this should result in deallocation */
        preference_add_ref (pref);
        preference_remove_ref (pref);
      }
    }
  }

  if (o_rejects) process_o_rejects_and_deallocate_them (o_rejects);
}