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

📄 agenda.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
/* SalienceNonIntegerError: Error message that is printed when *//*   a rule's salience does not evaluate to an integer.        *//***************************************************************/globle VOID SalienceNonIntegerError()  {   PrintErrorID("AGENDA",1,CLIPS_TRUE);   PrintCLIPS(WERROR,"Salience value must be an integer value.\n");  }         #if DYNAMIC_SALIENCE/**********************************************//* RefreshAgendaCommand: CLIPS access routine *//*   for the refresh-agenda command.          *//**********************************************/globle VOID RefreshAgendaCommand()  {   int numArgs, error;   struct defmodule *theModule;      /*==============================================*/   /* This function can have at most one argument. */   /*==============================================*/      if ((numArgs = ArgCountCheck("refresh-agenda",NO_MORE_THAN,1)) == -1) return;   /*===============================================================*/   /* If a module name is specified, then the agenda of that module */   /* is refreshed. Otherwise, the agenda of the current module is  */   /* refreshed.                                                    */   /*===============================================================*/      if (numArgs == 1)     {      theModule = GetModuleName("refresh-agenda",1,&error);      if (error) return;     }   else     { theModule = ((struct defmodule *) GetCurrentModule()); }   /*===============================================*/   /* Refresh the agenda of the appropriate module. */   /*===============================================*/      RefreshAgenda(theModule);  }/***************************************//* RefreshAgenda: C access routine for *//*   the refresh-agenda command.       *//***************************************/globle VOID RefreshAgenda(vTheModule)  VOID *vTheModule;  {   struct activation *theActivation;   struct defmodule *theModule = (struct defmodule *) vTheModule;   BOOLEAN oldValue;   int allModules = CLIPS_FALSE;      /*==========================*/   /* Save the current module. */   /*==========================*/      SaveCurrentModule();      /*=============================================*/   /* If the module specified is a NULL pointer,  */   /* then every module has its agenda refreshed. */   /*=============================================*/      if (theModule == NULL)     {      allModules = CLIPS_TRUE;      theModule = (struct defmodule *) GetNextDefmodule(NULL);     }        /*=======================================================*/   /* Remember the current setting for salience evaluation. */   /* To perform the refresh, the when activated setting is */   /* used to recompute the salience values.                */   /*=======================================================*/      oldValue = GetSalienceEvaluation();   SetSalienceEvaluation(WHEN_ACTIVATED);         /*========================*/   /* Refresh the agenda(s). */   /*========================*/   for (;        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {       /*=========================================*/      /* Change the current module to the module */      /* of the agenda being refreshed.          */      /*=========================================*/            SetCurrentModule((VOID *) theModule);            /*================================================================*/      /* Recompute the salience values for the current module's agenda. */      /*================================================================*/            for (theActivation = (struct activation *) GetNextActivation(NULL);           theActivation != NULL;           theActivation = (struct activation *) GetNextActivation(theActivation))        { theActivation->salience = EvaluateSalience(theActivation->theRule); }      /*======================================================*/      /* Reorder the agenda based on the new salience values. */      /*======================================================*/            ReorderAgenda(theModule);            /*===============================================*/      /* Return if only one agenda is being refreshed. */      /*===============================================*/            if (! allModules)         {         SetSalienceEvaluation(oldValue);         RestoreCurrentModule();         return;        }     }   /*==========================================*/   /* Restore the salience evaluation setting. */   /*==========================================*/      SetSalienceEvaluation(oldValue);      /*=============================*/   /* Restore the current module. */   /*=============================*/      RestoreCurrentModule();  } /************************************************************//* SetSalienceEvaluationCommand: CLIPS command for setting  *//*   the salience evaluation behavior.                      *//*   Syntax: (set-salience-evaluation-behavior <symbol>)    *//************************************************************/globle SYMBOL_HN *SetSalienceEvaluationCommand()  {   DATA_OBJECT argPtr;   char *argument, *oldValue;      /*==================================================*/   /* Get the current setting for salience evaluation. */   /*==================================================*/   oldValue = SalienceEvaluationName(GetSalienceEvaluation());      /*=========================================*/   /* This function expects a single argument */   /* which must be a symbol.                 */   /*=========================================*/      if (ArgCountCheck("set-salience-evaluation",EXACTLY,1) == -1)     { return((SYMBOL_HN *) AddSymbol(oldValue)); }   if (ArgTypeCheck("set-salience-evaluation",1,SYMBOL,&argPtr) == CLIPS_FALSE)     { return((SYMBOL_HN *) AddSymbol(oldValue)); }   /*=============================================================*/   /* The allowed symbols to pass as an argument to this function */   /* are when-defined, when-activated, and every-cycle.          */   /*=============================================================*/      argument = DOToString(argPtr);   if (strcmp(argument,"when-defined") == 0)     { SetSalienceEvaluation(WHEN_DEFINED); }   else if (strcmp(argument,"when-activated") == 0)     { SetSalienceEvaluation(WHEN_ACTIVATED); }   else if (strcmp(argument,"every-cycle") == 0)     { SetSalienceEvaluation(EVERY_CYCLE); }   else     {      ExpectedTypeError1("set-salience-evaluation",1,      "symbol with value when-defined, when-activated, or every-cycle");      return((SYMBOL_HN *) AddSymbol(oldValue));     }   /*=================================================*/   /* Return the old setting for salience evaluation. */   /*=================================================*/      return((SYMBOL_HN *) AddSymbol(oldValue));  }  /************************************************************//* GetSalienceEvaluationCommand: CLIPS command for getting  *//*   the salience evaluation behavior.                      *//*   Syntax: (get-salience-evaluation-behavior)             *//************************************************************/globle SYMBOL_HN *GetSalienceEvaluationCommand()  {   ArgCountCheck("get-salience-evaluation",EXACTLY,0);   return((SYMBOL_HN *) AddSymbol(SalienceEvaluationName(GetSalienceEvaluation())));  }/*****************************************************************//* SalienceEvaluationName: Given the integer value corresponding *//*   to a specified salience evaluation behavior, returns a      *//*   character string of the behavior's name.                    *//*****************************************************************/static char *SalienceEvaluationName(strategy)  int strategy;  {   char *sname;   switch (strategy)     {      case WHEN_DEFINED:        sname = "when-defined";        break;      case WHEN_ACTIVATED:        sname = "when-activated";        break;      case EVERY_CYCLE:        sname = "every-cycle";        break;      default:        sname = "unknown";        break;     }   return(sname);  }  /***************************************************************//* GetSalienceEvaluation: Returns the value of current type of *//*  salience evaluation (e.g., when defined, when activated,   *//*  or every cycle).                                           *//***************************************************************/globle BOOLEAN GetSalienceEvaluation()  { return(SalienceEvaluation); }/*************************************************************//* SetSalienceEvaluation: Sets the value of the current type *//*   of salience evaluation.                                 *//*************************************************************/globle BOOLEAN SetSalienceEvaluation(value)  int value;  {   int ov;   ov = SalienceEvaluation;   SalienceEvaluation = value;   return(ov);  } /*****************************************************************//* EvaluateSalience: Returns the salience value of the specified *//*   defrule. If salience evaluation is currently set to         *//*   when-defined, then the current value of the rule's salience *//*   is returned. Otherwise the salience expression associated   *//*   with the rule is reevaluated, the value is stored as the    *//*   rule's current salience, and it is then returned.           *//*****************************************************************/static int EvaluateSalience(vPtr) VOID *vPtr; {  struct defrule *rPtr = (struct defrule *) vPtr;  DATA_OBJECT salienceValue;  int salience;  /*==================================================*/  /* If saliences are only being evaluated when rules */  /* are defined, then just return the last salience  */  /* value evaluated for the rule.                    */  /*==================================================*/    if (GetSalienceEvaluation() == WHEN_DEFINED)    { return(rPtr->salience); }    /*=================================================================*/  /* If the rule's salience value was defined as an integer constant */  /* (i.e., not an expression or global variable which could change  */  /* on reevaluation), then just return the salience value computed  */  /* for the rule when it was defined.                               */  /*=================================================================*/    if (rPtr->dynamicSalience == NULL) return(rPtr->salience);  /*====================================================*/  /* Reevaluate the rule's salience. If an error occurs */  /* during evaluation, print an error message.         */  /*====================================================*/    SetEvaluationError(CLIPS_FALSE);  if (EvaluateExpression(rPtr->dynamicSalience,&salienceValue))    {     SalienceInformationError(ValueToString(rPtr->header.name));     return(rPtr->salience);    }  /*========================================*/  /* The salience value must be an integer. */  /*========================================*/  if (salienceValue.type != INTEGER)    {     SalienceNonIntegerError();     SalienceInformationError(ValueToString(rPtr->header.name));     SetEvaluationError(CLIPS_TRUE);     return(rPtr->salience);    }      /*==========================================*/  /* The salience value must fall between the */  /* minimum and maximum allowed values.      */  /*==========================================*/  salience = (int) ValueToLong(salienceValue.value);  if ((salience > MAX_SALIENCE) || (salience < MIN_SALIENCE))    {     SalienceRangeError();     SetEvaluationError(CLIPS_TRUE);     SalienceInformationError(ValueToString(((struct defrule *) rPtr)->header.name));     return(rPtr->salience);    }      /*===================================*/  /* Store the new salience value with */  /* the rule and return this value.   */  /*===================================*/    rPtr->salience = salience;  return(rPtr->salience); } #endif /* DYNAMIC_SALIENCE */ #if DEBUGGING_FUNCTIONS/***********************************************//* AgendaCommand: Prints out the agenda of the *//*   rules that are ready to fire.             *//*   Syntax: (agenda)                          *//***********************************************/globle VOID AgendaCommand()  {   int numArgs, error;   struct defmodule *theModule;      /*==============================================*/   /* This function can have at most one argument. */   /*==============================================*/      if ((numArgs = ArgCountCheck("agenda",NO_MORE_THAN,1)) == -1) return;   /*===============================================================*/   /* If a module name is specified, then the agenda of that module */   /* is displayed. Otherwise, the agenda of the current module is  */   /* displayed.                                                    */   /*===============================================================*/      if (numArgs == 1)     {      theModule = GetModuleName("agenda",1,&error);      if (error) return;     }   else     { theModule = ((struct defmodule *) GetCurrentModule()); }        /*===============================================*/   /* Display the agenda of the appropriate module. */   /*===============================================*/      Agenda(WDISPLAY,theModule);  }  #endif /* DEBUGGING_FUNCTIONS */#endif /* DEFRULE_CONSTRUCT */

⌨️ 快捷键说明

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