⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agenda.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /* in which the activation is stored. */   /*====================================*/   theModuleItem = (struct defruleModule *) theActivation->theRule->header.whichModule;      /*========================================================*/   /* If the activation is the top activation on the agenda, */   /* then update the module pointer to agenda.              */   /*========================================================*/      if (theActivation == theModuleItem->agenda)     { theModuleItem->agenda = theActivation->next; }   /*==================================================*/   /* Update the pointers in the preceding activation. */   /*==================================================*/      if (theActivation->prev != NULL)     { theActivation->prev->next = theActivation->next; }        /*==================================================*/   /* Update the pointers in the following activation. */   /*==================================================*/      if (theActivation->next != NULL)      { theActivation->next->prev = theActivation->prev; }        /*=================================================*/   /* Update the pointers in the detached activation. */   /*=================================================*/      theActivation->prev = NULL;   theActivation->next = NULL;      /*=============================*/   /* Mark the agenda as changed. */   /*=============================*/   AgendaChanged = CLIPS_TRUE;      return(CLIPS_TRUE);  }/****************************************************************************//* PrintActivation: Prints an activation in a "pretty" format. Salience,    *//*   rule name, and the partial match which activated the rule are printed. *//****************************************************************************/static VOID PrintActivation(logicalName,vTheActivation)  char *logicalName;  VOID *vTheActivation;  {   struct activation *theActivation = (struct activation *) vTheActivation;   char printSpace[20];   sprintf(printSpace,"%-6d ",theActivation->salience);   PrintCLIPS(logicalName,printSpace);   PrintCLIPS(logicalName,ValueToString(theActivation->theRule->header.name));   PrintCLIPS(logicalName,": ");   PrintPartialMatch(logicalName,theActivation->basis);  }/****************************************************//* Agenda: C access routine for the agenda command. *//****************************************************/globle VOID Agenda(logicalName,vTheModule)  char *logicalName;  VOID *vTheModule;  {   struct defmodule *theModule = (struct defmodule *) vTheModule;   ListItemsDriver(logicalName,theModule,"activation","activations",                   GetNextActivation,NULL,PrintActivation,NULL);  }/*******************************************************************//* RemoveActivation: Returns an activation and its associated data *//*   structures to the Memory Manager. Links to other activations  *//*   and partial matches may also be updated.                      *//*******************************************************************/globle VOID RemoveActivation(vTheActivation,updateAgenda,updateLinks)  VOID *vTheActivation;  int updateAgenda, updateLinks;  {   struct defruleModule *theModuleItem;   struct activation *theActivation = (struct activation *) vTheActivation;      /*====================================*/   /* Determine the module of the agenda */    /* in which the activation is stored. */   /*====================================*/   theModuleItem = (struct defruleModule *) theActivation->theRule->header.whichModule;   /*=================================*/   /* Update the agenda if necessary. */   /*=================================*/   if (updateAgenda == CLIPS_TRUE)     {      /*===============================================*/      /* Update the pointer links between activations. */      /*===============================================*/            if (theActivation->prev == NULL)        {         theModuleItem->agenda = theModuleItem->agenda->next;         if (theModuleItem->agenda != NULL) theModuleItem->agenda->prev = NULL;        }      else        {         theActivation->prev->next = theActivation->next;         if (theActivation->next != NULL)           { theActivation->next->prev = theActivation->prev; }        }      /*===================================*/      /* Indicate removal of activation if */      /* activations are being watched.    */      /*===================================*/#if DEBUGGING_FUNCTIONS      if (theActivation->theRule->watchActivation)        {         PrintCLIPS(WTRACE,"<== Activation ");         PrintActivation(WTRACE,(VOID *) theActivation);         PrintCLIPS(WTRACE,"\n");        }#endif      /*=============================*/      /* Mark the agenda as changed. */      /*=============================*/         AgendaChanged = CLIPS_TRUE;     }   /*============================================*/   /* Update join and agenda links if necessary. */   /*============================================*/   if ((updateLinks == CLIPS_TRUE) && (theActivation->basis != NULL))     { theActivation->basis->binds[theActivation->basis->bcount].gm.theValue = NULL; }   /*================================================*/   /* Return the activation to the free memory pool. */   /*================================================*/   NumberOfActivations--;#if CONFLICT_RESOLUTION_STRATEGIES   if (theActivation->sortedBasis != NULL)     { ReturnPartialMatch(theActivation->sortedBasis); }#endif   rtn_struct(activation,theActivation);  }/**************************************************************//* AgendaClearFunction: Agenda clear routine for use with the *//*   clear command. Resets the current time tag to zero.      *//**************************************************************/static VOID AgendaClearFunction()  {    CurrentTimetag = 0;   }/*************************************************//* RemoveAllActivations: Removes all activations *//*   from the agenda of the current module.      *//*************************************************/globle VOID RemoveAllActivations()  {   struct activation *tempPtr, *theActivation;   theActivation = GetDefruleModuleItem(NULL)->agenda;   while (theActivation != NULL)     {      tempPtr = theActivation->next;      RemoveActivation(theActivation,CLIPS_TRUE,CLIPS_TRUE);      theActivation = tempPtr;     }  }/*****************************************************************//* GetAgendaChanged: Returns the value of the boolean flag which *//*   indicates whether any changes have been made to the agenda. *//*****************************************************************/globle int GetAgendaChanged()  {    return(AgendaChanged);  }/*****************************************************************//* SetAgendaChanged: Sets the value of the boolean flag which    *//*   indicates whether any changes have been made to the agenda. *//*****************************************************************/globle VOID SetAgendaChanged(value)  int value;  {   AgendaChanged = value;  }/*******************************************************//* ReorderAgenda: Completely reorders the agenda based *//*   on the current conflict resolution strategy.      *//*******************************************************/globle VOID ReorderAgenda(vTheModule)  VOID *vTheModule;  {   struct activation *theActivation, *tempPtr;   struct defmodule *theModule = (struct defmodule *) vTheModule;   int allModules = CLIPS_FALSE;   struct defruleModule *theModuleItem;   /*=============================================*/   /* If the module specified is a NULL pointer,  */   /* then every module has its agenda reordered. */   /*=============================================*/      if (theModule == NULL)      {      allModules = CLIPS_TRUE;      theModule = (struct defmodule *) GetNextDefmodule(NULL);     }   /*========================*/   /* Reorder the agenda(s). */   /*========================*/      for (;        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {       /*=================================*/      /* Get the list of activations and */      /* remove them from the agenda.    */      /*=================================*/            theModuleItem = GetDefruleModuleItem(theModule);      theActivation = theModuleItem->agenda;      theModuleItem->agenda = NULL;      /*=========================================*/      /* Reorder the activations by placing them */      /* back on the agenda one by one.          */      /*=========================================*/            while (theActivation != NULL)        {         tempPtr = theActivation->next;         theActivation->next = NULL;         theActivation->prev = NULL;         PlaceActivation(&(theModuleItem->agenda),theActivation);         theActivation = tempPtr;        }            /*===============================================*/      /* Return if only one agenda is being reordered. */      /*===============================================*/            if (! allModules) return;     }  }  /****************************************************//* GetNumberOfActivations: Returns the value of the *//*   total number of activations on all agendas.    *//****************************************************/globle long int GetNumberOfActivations()  { return(NumberOfActivations); }  /********************************************************//* RefreshCommand: CLIPS command for refreshing a rule. *//*   Syntax: (refresh <defrule-name>)                   *//********************************************************/globle VOID RefreshCommand()  {   char *ruleName;   VOID *rulePtr;   /*===========================*/   /* Get the name of the rule. */   /*===========================*/      ruleName = GetConstructName("refresh","rule name");   if (ruleName == NULL) return;   /*===============================*/   /* Determine if the rule exists. */   /*===============================*/      rulePtr = FindDefrule(ruleName);   if (rulePtr == NULL)     {      CantFindItemErrorMessage("defrule",ruleName);      return;     }   /*===================*/   /* Refresh the rule. */   /*===================*/      Refresh(rulePtr);  }/***********************************************************//* Refresh: Refreshes a defrule. Activations of the rule   *//*   that have already been fired are added to the agenda. *//***********************************************************/globle BOOLEAN Refresh(theRule)  VOID *theRule;  {   struct defrule *rulePtr;   struct partialMatch *listOfMatches;   /*====================================*/   /* Refresh each disjunct of the rule. */   /*====================================*/         for (rulePtr = (struct defrule *) theRule;        rulePtr != NULL;        rulePtr = rulePtr->disjunct)     {      /*================================*/      /* Check each partial match that  */      /* satisfies the LHS of the rule. */      /*================================*/            for (listOfMatches = rulePtr->lastJoin->beta;           listOfMatches != NULL;           listOfMatches = listOfMatches->next)        {         /*=======================================================*/         /* If the partial match is associated with an activation */         /* (which it should always be) and it isn't associated   */         /* with a not CE that still has matches, then place a    */         /* new activation on the agenda if this partial match    */         /* doesn't have an activation associated with it.        */         /*=======================================================*/                  if ((listOfMatches->activationf) && (! listOfMatches->counterf))           {            if (listOfMatches->binds[listOfMatches->bcount].gm.theValue == NULL)              { AddActivation(rulePtr,listOfMatches); }           }        }     }   return(CLIPS_TRUE);  }  /************************************************************//* SalienceInformationError: Error message for errors which *//*   occur during the evaluation of a rule's salience.      *//************************************************************/globle VOID SalienceInformationError(ruleName)  char *ruleName;  {   PrintErrorID("AGENDA",3,CLIPS_TRUE);   PrintCLIPS(WERROR,"This error occurred while evaluating the salience");   if (ruleName != NULL)     {      PrintCLIPS(WERROR," for rule ");      PrintCLIPS(WERROR,ruleName);     }   PrintCLIPS(WERROR,".\n");  }/**********************************************************//* SalienceRangeError: Error message that is printed when *//*   a salience value does not fall between the minimum   *//*   and maximum salience values.                         *//**********************************************************/globle VOID SalienceRangeError()  {   PrintErrorID("AGENDA",2,CLIPS_TRUE);   PrintCLIPS(WERROR,"Salience value out of range ");   PrintLongInteger(WERROR,(long int) MIN_SALIENCE);   PrintCLIPS(WERROR," to ");   PrintLongInteger(WERROR,(long int) MAX_SALIENCE);   PrintCLIPS(WERROR,".\n");  }  /***************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -