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

📄 crstrtgy.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   unsigned long long timetag;   ACTIVATION *lastAct, *actPtr;   /*============================================*/   /* Set up initial information for the search. */   /*============================================*/   timetag = newActivation->timetag;   randomID = newActivation->randomID;   if (theGroup->prev == NULL)     { lastAct = NULL; }   else     { lastAct = theGroup->prev->last; }   /*=========================================================*/   /* Find the insertion point in the agenda. The activation  */   /* is placed before activations of lower salience and      */   /* after activations of higher salience. Among activations */   /* of equal salience, the placement of the activation is   */   /* determined through the generation of a random number.   */   /*=========================================================*/   actPtr = theGroup->first;   while (actPtr != NULL)     {      if (randomID > actPtr->randomID)        {         lastAct = actPtr;         if (actPtr == theGroup->last)           { break; }         else            { actPtr = actPtr->next; }        }      else if (randomID < actPtr->randomID)       { break; }      else if (timetag > actPtr->timetag)        {         lastAct = actPtr;         if (actPtr == theGroup->last)           { break; }         else            { actPtr = actPtr->next; }        }      else       { break; }     }        /*========================================*/   /* Update the salience group information. */   /*========================================*/      if ((lastAct == NULL) ||        ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))     { theGroup->first = newActivation; }        if ((theGroup->last == NULL) || (theGroup->last == lastAct))     { theGroup->last = newActivation; }   /*===========================================*/   /* Return the insertion point in the agenda. */   /*===========================================*/   return(lastAct);  }/*********************************************************//* SortPartialMatch: Creates an array of sorted timetags *//*    in ascending order from a partial match.           *//*********************************************************/static unsigned long long *SortPartialMatch(  void *theEnv,  struct partialMatch *binds)  {   unsigned long long *nbinds;   unsigned long long temp;   int flag;   unsigned j, k;   /*====================================================*/   /* Copy the array. Use 0 to represent the timetags of */   /* negated patterns. Patterns matching fact/instances */   /* should have timetags greater than 0.               */   /*====================================================*/   nbinds = (unsigned long long *) get_mem(theEnv,sizeof(long long) * binds->bcount);         for (j = 0; j < binds->bcount; j++)     {      if ((binds->binds[j].gm.theMatch != NULL) &&          (binds->binds[j].gm.theMatch->matchingItem != NULL))        { nbinds[j] = binds->binds[j].gm.theMatch->matchingItem->timeTag; }      else        { nbinds[j] = 0; }     }   /*=================*/   /* Sort the array. */   /*=================*/   for (flag = TRUE, k = binds->bcount - 1;        flag == TRUE;        k--)     {      flag = FALSE;      for (j = 0 ; j < k ; j++)        {         if (nbinds[j] < nbinds[j + 1])           {            temp = nbinds[j];            nbinds[j] = nbinds[j+1];            nbinds[j+1] = temp;            flag = TRUE;           }        }     }   /*===================*/   /* Return the array. */   /*===================*/   return(nbinds);  }/**************************************************************************//* ComparePartialMatches: Compares two activations using the lex conflict *//*   resolution strategy to determine which activation should be placed   *//*   first on the agenda. This lexicographic comparison function is used  *//*   for both the lex and mea strategies.                                 *//**************************************************************************/static int ComparePartialMatches(  void *theEnv,  ACTIVATION *actPtr,  ACTIVATION *newActivation)  {   int cCount, oCount, mCount, i;   unsigned long long *basis1, *basis2;   /*=================================================*/   /* If the activation already on the agenda doesn't */   /* have a set of sorted timetags, then create one. */   /*=================================================*/   basis1 = SortPartialMatch(theEnv,newActivation->basis);   basis2 = SortPartialMatch(theEnv,actPtr->basis);      /*==============================================================*/   /* Determine the number of timetags in each of the activations. */   /* The number of timetags to be compared is the lessor of these */   /* two numbers.                                                 */   /*==============================================================*/   cCount = newActivation->basis->bcount;   oCount = actPtr->basis->bcount;    if (oCount > cCount) mCount = cCount;   else mCount = oCount;   /*===========================================================*/   /* Compare the sorted timetags one by one until there are no */   /* more timetags to compare or the timetags being compared   */   /* are not equal. If the timetags aren't equal, then the     */   /* activation containing the larger timetag is placed before */   /* the activation containing the smaller timetag.            */   /*===========================================================*/   for (i = 0 ; i < mCount ; i++)     {      if (basis1[i] < basis2[i])        {          rtn_mem(theEnv,sizeof(long long) * cCount,basis1);         rtn_mem(theEnv,sizeof(long long) * oCount,basis2);         return(LESS_THAN);         }      else if (basis1[i] > basis2[i])        {          rtn_mem(theEnv,sizeof(long long) * cCount,basis1);         rtn_mem(theEnv,sizeof(long long) * oCount,basis2);         return(GREATER_THAN);         }     }     rtn_mem(theEnv,sizeof(long long) * cCount,basis1);   rtn_mem(theEnv,sizeof(long long) * oCount,basis2);   /*==========================================================*/   /* If the sorted timetags are identical up to the number of */   /* timetags contained in the smaller partial match, then    */   /* the activation containing more timetags should be        */   /* placed before the activation containing fewer timetags.  */   /*==========================================================*/   if (cCount < oCount) return(LESS_THAN);   else if (cCount > oCount) return(GREATER_THAN);   /*=========================================================*/   /* If the sorted partial matches for both activations are  */   /* identical (containing the same number and values of     */   /* timetags), then the activation associated with the rule */   /* having the highest complexity is placed before the      */   /* other partial match.                                    */   /*=========================================================*/   if (newActivation->theRule->complexity < actPtr->theRule->complexity)     { return(LESS_THAN); }   else if (newActivation->theRule->complexity > actPtr->theRule->complexity)     { return(GREATER_THAN); }   /*================================================*/   /* The two partial matches are equal for purposes */   /* of placement on the agenda for the lex and mea */   /* conflict resolution strategies.                */   /*================================================*/   return(EQUAL);  }/************************************//* EnvSetStrategy: C access routine *//*   for the set-strategy command.  *//************************************/globle int EnvSetStrategy(  void *theEnv,  int value)  {   int oldStrategy;      oldStrategy = AgendaData(theEnv)->Strategy;   AgendaData(theEnv)->Strategy = value;   if (oldStrategy != AgendaData(theEnv)->Strategy) EnvReorderAgenda(theEnv,NULL);   return(oldStrategy);  }/************************************//* EnvGetStrategy: C access routine *//*   for the get-strategy command.  *//************************************/globle int EnvGetStrategy(  void *theEnv)  {   return(AgendaData(theEnv)->Strategy);  }/********************************************//* GetStrategyCommand: H/L access routine   *//*   for the get-strategy command.          *//********************************************/globle void *GetStrategyCommand(  void *theEnv)  {   EnvArgCountCheck(theEnv,"get-strategy",EXACTLY,0);   return((SYMBOL_HN *) EnvAddSymbol(theEnv,GetStrategyName(EnvGetStrategy(theEnv))));  }/********************************************//* SetStrategyCommand: H/L access routine   *//*   for the set-strategy command.          *//********************************************/globle void *SetStrategyCommand(  void *theEnv)  {   DATA_OBJECT argPtr;   char *argument;   int oldStrategy;      oldStrategy = AgendaData(theEnv)->Strategy;   /*=====================================================*/   /* Check for the correct number and type of arguments. */   /*=====================================================*/   if (EnvArgCountCheck(theEnv,"set-strategy",EXACTLY,1) == -1)     { return((SYMBOL_HN *) EnvAddSymbol(theEnv,GetStrategyName(EnvGetStrategy(theEnv)))); }   if (EnvArgTypeCheck(theEnv,"set-strategy",1,SYMBOL,&argPtr) == FALSE)     { return((SYMBOL_HN *) EnvAddSymbol(theEnv,GetStrategyName(EnvGetStrategy(theEnv)))); }   argument = DOToString(argPtr);   /*=============================================*/   /* Set the strategy to the specified strategy. */   /*=============================================*/   if (strcmp(argument,"depth") == 0)     { EnvSetStrategy(theEnv,DEPTH_STRATEGY); }   else if (strcmp(argument,"breadth") == 0)     { EnvSetStrategy(theEnv,BREADTH_STRATEGY); }   else if (strcmp(argument,"lex") == 0)     { EnvSetStrategy(theEnv,LEX_STRATEGY); }   else if (strcmp(argument,"mea") == 0)     { EnvSetStrategy(theEnv,MEA_STRATEGY); }   else if (strcmp(argument,"complexity") == 0)     { EnvSetStrategy(theEnv,COMPLEXITY_STRATEGY); }   else if (strcmp(argument,"simplicity") == 0)     { EnvSetStrategy(theEnv,SIMPLICITY_STRATEGY); }   else if (strcmp(argument,"random") == 0)     { EnvSetStrategy(theEnv,RANDOM_STRATEGY); }   else     {      ExpectedTypeError1(theEnv,"set-strategy",1,      "symbol with value depth, breadth, lex, mea, complexity, simplicity, or random");      return((SYMBOL_HN *) EnvAddSymbol(theEnv,GetStrategyName(EnvGetStrategy(theEnv))));     }   /*=======================================*/   /* Return the old value of the strategy. */   /*=======================================*/   return((SYMBOL_HN *) EnvAddSymbol(theEnv,GetStrategyName(oldStrategy)));  }/**********************************************************//* GetStrategyName: Given the integer value corresponding *//*   to a specified strategy, return a character string   *//*   of the strategy's name.                              *//**********************************************************/static char *GetStrategyName(  int strategy)  {   char *sname;   switch (strategy)     {      case DEPTH_STRATEGY:        sname = "depth";        break;      case BREADTH_STRATEGY:        sname = "breadth";        break;      case LEX_STRATEGY:        sname = "lex";        break;      case MEA_STRATEGY:        sname = "mea";        break;      case COMPLEXITY_STRATEGY:        sname = "complexity";        break;      case SIMPLICITY_STRATEGY:        sname = "simplicity";        break;      case RANDOM_STRATEGY:        sname = "random";        break;      default:        sname = "unknown";        break;     }   return(sname);  }#endif /* DEFRULE_CONSTRUCT */

⌨️ 快捷键说明

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