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

📄 agenda.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
   SaveCurrentModule(theEnv);   /*=============================================*/   /* If the module specified is a NULL pointer,  */   /* then every module has its agenda refreshed. */   /*=============================================*/   if (theModule == NULL)     {      allModules = TRUE;      theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);     }   /*=======================================================*/   /* Remember the current setting for salience evaluation. */   /* To perform the refresh, the when activated setting is */   /* used to recompute the salience values.                */   /*=======================================================*/   oldValue = EnvGetSalienceEvaluation(theEnv);   EnvSetSalienceEvaluation(theEnv,WHEN_ACTIVATED);   /*========================*/   /* Refresh the agenda(s). */   /*========================*/   for (;        theModule != NULL;        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))     {      /*=========================================*/      /* Change the current module to the module */      /* of the agenda being refreshed.          */      /*=========================================*/      EnvSetCurrentModule(theEnv,(void *) theModule);      /*================================================================*/      /* Recompute the salience values for the current module's agenda. */      /*================================================================*/      for (theActivation = (struct activation *) EnvGetNextActivation(theEnv,NULL);           theActivation != NULL;           theActivation = (struct activation *) EnvGetNextActivation(theEnv,theActivation))        { theActivation->salience = EvaluateSalience(theEnv,theActivation->theRule); }      /*======================================================*/      /* Reorder the agenda based on the new salience values. */      /*======================================================*/      EnvReorderAgenda(theEnv,theModule);      /*===============================================*/      /* Return if only one agenda is being refreshed. */      /*===============================================*/      if (! allModules)        {         EnvSetSalienceEvaluation(theEnv,oldValue);         RestoreCurrentModule(theEnv);         return;        }     }   /*==========================================*/   /* Restore the salience evaluation setting. */   /*==========================================*/   EnvSetSalienceEvaluation(theEnv,oldValue);   /*=============================*/   /* Restore the current module. */   /*=============================*/   RestoreCurrentModule(theEnv);  }/*********************************************************//* SetSalienceEvaluationCommand: H/L Command for setting *//*   the salience evaluation behavior.                   *//*   Syntax: (set-salience-evaluation-behavior <symbol>) *//*********************************************************/globle void *SetSalienceEvaluationCommand(  void *theEnv)  {   DATA_OBJECT argPtr;   char *argument, *oldValue;   /*==================================================*/   /* Get the current setting for salience evaluation. */   /*==================================================*/   oldValue = SalienceEvaluationName(EnvGetSalienceEvaluation(theEnv));   /*=========================================*/   /* This function expects a single argument */   /* which must be a symbol.                 */   /*=========================================*/   if (EnvArgCountCheck(theEnv,"set-salience-evaluation",EXACTLY,1) == -1)     { return((SYMBOL_HN *) EnvAddSymbol(theEnv,oldValue)); }   if (EnvArgTypeCheck(theEnv,"set-salience-evaluation",1,SYMBOL,&argPtr) == FALSE)     { return((SYMBOL_HN *) EnvAddSymbol(theEnv,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)     { EnvSetSalienceEvaluation(theEnv,WHEN_DEFINED); }   else if (strcmp(argument,"when-activated") == 0)     { EnvSetSalienceEvaluation(theEnv,WHEN_ACTIVATED); }   else if (strcmp(argument,"every-cycle") == 0)     { EnvSetSalienceEvaluation(theEnv,EVERY_CYCLE); }   else     {      ExpectedTypeError1(theEnv,"set-salience-evaluation",1,      "symbol with value when-defined, when-activated, or every-cycle");      return((SYMBOL_HN *) EnvAddSymbol(theEnv,oldValue));     }   /*=================================================*/   /* Return the old setting for salience evaluation. */   /*=================================================*/   return((SYMBOL_HN *) EnvAddSymbol(theEnv,oldValue));  }/*********************************************************//* GetSalienceEvaluationCommand: H/L Command for getting *//*   the salience evaluation behavior.                   *//*   Syntax: (get-salience-evaluation-behavior)          *//*********************************************************/globle void *GetSalienceEvaluationCommand(  void *theEnv)  {   EnvArgCountCheck(theEnv,"get-salience-evaluation",EXACTLY,0);   return((SYMBOL_HN *) EnvAddSymbol(theEnv,SalienceEvaluationName(EnvGetSalienceEvaluation(theEnv))));  }/*****************************************************************//* SalienceEvaluationName: Given the integer value corresponding *//*   to a specified salience evaluation behavior, returns a      *//*   character string of the behavior's name.                    *//*****************************************************************/static char *SalienceEvaluationName(  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);  }/****************************************************************//* EnvGetSalienceEvaluation: Returns the value of current type  *//*  of salience evaluation (e.g., when defined, when activated, *//*  or every cycle).                                            *//****************************************************************/globle intBool EnvGetSalienceEvaluation(  void *theEnv)  {      return(AgendaData(theEnv)->SalienceEvaluation);   }/***********************************************//* EnvSetSalienceEvaluation: Sets the value of *//*   the current type of salience evaluation.  *//***********************************************/globle intBool EnvSetSalienceEvaluation(  void *theEnv,  int value)  {   int ov;   ov = AgendaData(theEnv)->SalienceEvaluation;   AgendaData(theEnv)->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(  void *theEnv,  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 (EnvGetSalienceEvaluation(theEnv) == 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(theEnv,FALSE);  if (EvaluateExpression(theEnv,rPtr->dynamicSalience,&salienceValue))    {     SalienceInformationError(theEnv,"defrule",ValueToString(rPtr->header.name));     return(rPtr->salience);    }  /*========================================*/  /* The salience value must be an integer. */  /*========================================*/  if (salienceValue.type != INTEGER)    {     SalienceNonIntegerError(theEnv);     SalienceInformationError(theEnv,"defrule",ValueToString(rPtr->header.name));     SetEvaluationError(theEnv,TRUE);     return(rPtr->salience);    }  /*==========================================*/  /* The salience value must fall between the */  /* minimum and maximum allowed values.      */  /*==========================================*/  salience = (int) ValueToLong(salienceValue.value);  if ((salience > MAX_DEFRULE_SALIENCE) || (salience < MIN_DEFRULE_SALIENCE))    {     SalienceRangeError(theEnv,MIN_DEFRULE_SALIENCE,MAX_DEFRULE_SALIENCE);     SetEvaluationError(theEnv,TRUE);     SalienceInformationError(theEnv,"defrule",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); }#if DEBUGGING_FUNCTIONS/***********************************************//* AgendaCommand: Prints out the agenda of the *//*   rules that are ready to fire.             *//*   Syntax: (agenda)                          *//***********************************************/globle void AgendaCommand(  void *theEnv)  {   int numArgs, error;   struct defmodule *theModule;   /*==============================================*/   /* This function can have at most one argument. */   /*==============================================*/   if ((numArgs = EnvArgCountCheck(theEnv,"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(theEnv,"agenda",1,&error);      if (error) return;     }   else     { theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv)); }   /*===============================================*/   /* Display the agenda of the appropriate module. */   /*===============================================*/   EnvAgenda(theEnv,WDISPLAY,theModule);  }#endif /* DEBUGGING_FUNCTIONS */#endif /* DEFRULE_CONSTRUCT */

⌨️ 快捷键说明

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