📄 crstrtgy.c
字号:
if (actPtr->salience > salience) { lastAct = actPtr; actPtr = actPtr->next; } else if (actPtr->salience < salience) { return(lastAct); } else if (randomID > actPtr->randomID) { lastAct = actPtr; actPtr = actPtr->next; } else if (randomID < actPtr->randomID) { return(lastAct); } else if (timetag > actPtr->timetag) { lastAct = actPtr; actPtr = actPtr->next; } else { return(lastAct); } } /*===========================================*/ /* Return the insertion point in the agenda. */ /*===========================================*/ return(lastAct); }/******************************************************************//* SortPartialMatch: Copies a partial match and then sorts the *//* fact-indices in the copied partial match in ascending order. *//******************************************************************/static struct partialMatch *SortPartialMatch(binds) struct partialMatch *binds; { struct partialMatch *nbinds; struct alphaMatch *temp; int flag, j, k; /*=================*/ /* Copy the array. */ /*=================*/ nbinds = CopyPartialMatch(binds,0,0); /*=================*/ /* Sort the array. */ /*=================*/ for (flag = CLIPS_TRUE, k = binds->bcount - 1; flag == CLIPS_TRUE; k--) { flag = CLIPS_FALSE; for (j = 0 ; j < k ; j++) { if ((nbinds->binds[j].gm.theMatch->matchingItem != NULL) && (nbinds->binds[j + 1].gm.theMatch->matchingItem != NULL)) { if (nbinds->binds[j].gm.theMatch->matchingItem->timeTag < nbinds->binds[j + 1].gm.theMatch->matchingItem->timeTag) { temp = nbinds->binds[j].gm.theMatch; nbinds->binds[j].gm.theMatch = nbinds->binds[j+1].gm.theMatch; nbinds->binds[j+1].gm.theMatch = temp; flag = CLIPS_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(actPtr,newActivation) ACTIVATION *actPtr, *newActivation; { int cCount, oCount, mCount, i; /*=================================================*/ /* If the activation already on the agenda doesn't */ /* have a set of sorted timetags, then create one. */ /*=================================================*/ if (actPtr->sortedBasis == NULL) { actPtr->sortedBasis = SortPartialMatch(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->sortedBasis->bcount; oCount = actPtr->sortedBasis->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 ((actPtr->sortedBasis->binds[i].gm.theMatch->matchingItem != NULL) && (newActivation->sortedBasis->binds[i].gm.theMatch->matchingItem != NULL)) { if (newActivation->sortedBasis->binds[i].gm.theMatch->matchingItem->timeTag < actPtr->sortedBasis->binds[i].gm.theMatch->matchingItem->timeTag) { return(LESS_THAN); } else if (newActivation->sortedBasis->binds[i].gm.theMatch->matchingItem->timeTag > actPtr->sortedBasis->binds[i].gm.theMatch->matchingItem->timeTag) { return(GREATER_THAN); } } else if (newActivation->sortedBasis->binds[i].gm.theMatch->matchingItem != NULL) { return(GREATER_THAN); } else if (actPtr->sortedBasis->binds[i].gm.theMatch->matchingItem != NULL) { return(LESS_THAN); } } /*==========================================================*/ /* 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); }/*************************************//* SetStrategy: C access routine for *//* the set-strategy command. *//*************************************/globle int SetStrategy(value) int value; { int oldStrategy; oldStrategy = Strategy; Strategy = value; if (oldStrategy != Strategy) ReorderAgenda(NULL); return(oldStrategy); }/*************************************//* GetStrategy: C access routine for *//* the get-strategy command. *//*************************************/globle int GetStrategy() { return(Strategy); }/********************************************//* GetStrategyCommand: CLIPS access routine *//* for the get-strategy command. *//********************************************/globle SYMBOL_HN *GetStrategyCommand() { ArgCountCheck("get-strategy",EXACTLY,0); return((SYMBOL_HN *) AddSymbol(GetStrategyName(GetStrategy()))); }/********************************************//* SetStrategyCommand: CLIPS access routine *//* for the set-strategy command. *//********************************************/globle SYMBOL_HN *SetStrategyCommand() { DATA_OBJECT argPtr; char *argument; int oldStrategy = Strategy; /*=====================================================*/ /* Check for the correct number and type of arguments. */ /*=====================================================*/ if (ArgCountCheck("set-strategy",EXACTLY,1) == -1) { return((SYMBOL_HN *) AddSymbol(GetStrategyName(GetStrategy()))); } if (ArgTypeCheck("set-strategy",1,SYMBOL,&argPtr) == CLIPS_FALSE) { return((SYMBOL_HN *) AddSymbol(GetStrategyName(GetStrategy()))); } argument = DOToString(argPtr); /*=============================================*/ /* Set the strategy to the specified strategy. */ /*=============================================*/ if (strcmp(argument,"depth") == 0) { SetStrategy(DEPTH_STRATEGY); } else if (strcmp(argument,"breadth") == 0) { SetStrategy(BREADTH_STRATEGY); } else if (strcmp(argument,"lex") == 0) { SetStrategy(LEX_STRATEGY); } else if (strcmp(argument,"mea") == 0) { SetStrategy(MEA_STRATEGY); } else if (strcmp(argument,"complexity") == 0) { SetStrategy(COMPLEXITY_STRATEGY); } else if (strcmp(argument,"simplicity") == 0) { SetStrategy(SIMPLICITY_STRATEGY); } else if (strcmp(argument,"random") == 0) { SetStrategy(RANDOM_STRATEGY); } else { ExpectedTypeError1("set-strategy",1, "symbol with value depth, breadth, lex, mea, complexity, simplicity, or random"); return((SYMBOL_HN *) AddSymbol(GetStrategyName(GetStrategy()))); } /*=======================================*/ /* Return the old value of the strategy. */ /*=======================================*/ return((SYMBOL_HN *) AddSymbol(GetStrategyName(oldStrategy))); } /**********************************************************//* GetStrategyName: Given the integer value corresponding *//* to a specified strategy, return a character string *//* of the strategy's name. *//**********************************************************/static char *GetStrategyName(strategy) 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 /* CONFLICT_RESOLUTION_STRATEGIES */ #endif /* DEFRULE_CONSTRUCT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -