📄 objrtmch.c
字号:
listOfJoins = listOfJoins->rightMatchNode; } } alphaPtr = alphaPtr->nxtInGroup; } } /****************************************************** NAME : EvaluateObjectPatternTest DESCRIPTION : Evaluates the pattern network test expression for a node INPUTS : 1) The actual index of the slot value field currently being examined 2) The multifield marker (if any) for the pattern node being exmained 3) The pattern network test expression 4) The pattern node being examined RETURNS : CLIPS_TRUE if the node passes the test, CLIPS_FALSE otherwise SIDE EFFECTS : Evaluation of the test EvaluationError and HaltExecution are always set to CLIPS_FALSE NOTES : Assumes networkTest != NULL ******************************************************/static BOOLEAN EvaluateObjectPatternTest(objectSlotField,selfSlotMarker,networkTest,patternNode) int objectSlotField; struct multifieldMarker *selfSlotMarker; EXPRESSION *networkTest; OBJECT_PATTERN_NODE *patternNode; { DATA_OBJECT vresult; int rv; if (networkTest->type == OBJ_PN_CONSTANT) { struct expr *oldArgument; oldArgument = CurrentExpression; CurrentExpression = networkTest; rv = ObjectCmpConstantFunction(networkTest->value,&vresult); CurrentExpression = oldArgument; if (rv) { if (((struct ObjectCmpPNConstant *) ValueToBitMap(networkTest->value))->pass) patternNode->blocked = CLIPS_TRUE; return(CLIPS_TRUE); } return(CLIPS_FALSE); } /* ========================================================= Evaluate or expressions expressed in the format: (or <expression 1> <expression 2> ... <expression n>) Returns true (1.0) if any of the expression are true, otherwise returns false (0.0). ========================================================= */ if (networkTest->value == PTR_OR) { networkTest = networkTest->argList; while (networkTest != NULL) { if (EvaluateObjectPatternTest(objectSlotField,selfSlotMarker,networkTest,patternNode)) { /* ============================================ A node can be blocked ONLY if there were one positive constant test on that node ============================================ */ patternNode->blocked = CLIPS_FALSE; return(CLIPS_TRUE); } patternNode->blocked = CLIPS_FALSE; networkTest = networkTest->nextArg; } return(CLIPS_FALSE); } /* ========================================================== Evaluate and expressions expressed in the format: (and <expression 1> <expression 2> ... <expression n>) Returns false (0.0) if any of the expression are false, otherwise returns true (1.0). ========================================================== */ else if (networkTest->value == PTR_AND) { networkTest = networkTest->argList; while (networkTest != NULL) { if (EvaluateObjectPatternTest(objectSlotField,selfSlotMarker,networkTest,patternNode) == CLIPS_FALSE) { patternNode->blocked = CLIPS_FALSE; return(CLIPS_FALSE); } patternNode->blocked = CLIPS_FALSE; networkTest = networkTest->nextArg; } return(CLIPS_TRUE); } /* ======================================================= Evaluate all other expressions using EvaluateExpression ======================================================= */ else { HaltExecution = CLIPS_FALSE; if (EvaluateExpression(networkTest,&vresult)) { ObjectPatternNetErrorMessage(patternNode); EvaluationError = CLIPS_FALSE; HaltExecution = CLIPS_FALSE; return(CLIPS_FALSE); } if ((vresult.value != CLIPSFalseSymbol) || (vresult.type != SYMBOL)) return(CLIPS_TRUE); } return(CLIPS_FALSE); }/*************************************************** NAME : ObjectAssertAction DESCRIPTION : Filters an instance through the object pattern network INPUTS : The instance RETURNS : Nothing useful SIDE EFFECTS : Instance matched NOTES : None ***************************************************/static VOID ObjectAssertAction(ins) INSTANCE_TYPE *ins; { ins->header.timeTag = UseEntityTimeTag; CurrentPatternObject = ins; CurrentPatternObjectSlot = NULL; MarkObjectPatternNetwork(NULL); ObjectPatternMatch(0,ObjectNetworkPointer(),NULL); ins->reteSynchronized = CLIPS_TRUE; }/********************************************************************** NAME : ObjectModifyAction DESCRIPTION : Removes an instance from patterns (and attached joins) applicable to specified slot(s), and then filters same instance through object pattern network (only against patterns which explicitly match on named slot(s)) INPUTS : 1) The instance 2) The bitmap of slot ids RETURNS : Nothing useful SIDE EFFECTS : Instance retracted/asserted NOTES : None **********************************************************************/static VOID ObjectModifyAction(ins,slotNameIDs) INSTANCE_TYPE *ins; SLOT_BITMAP *slotNameIDs; { ins->header.timeTag = UseEntityTimeTag; ObjectRetractAction(ins,slotNameIDs); CurrentPatternObject = ins; CurrentPatternObjectSlot = NULL; MarkObjectPatternNetwork(slotNameIDs); ObjectPatternMatch(0,ObjectNetworkPointer(),NULL); ins->reteSynchronized = CLIPS_TRUE; }/**************************************************** NAME : ObjectRetractAction DESCRIPTION : Retracts the instance from the applicable patterns for the object (if the slotNameID != -1, then the instance is only retracted from the alpha memories of the patterns which actually match on that slot) INPUTS : 1) The instance 2) The slot bitmap for a modify (NULL if the instance is actually being removed) RETURNS : Nothing useful SIDE EFFECTS : Retractions performed NOTES : None ****************************************************/static VOID ObjectRetractAction(ins,slotNameIDs) INSTANCE_TYPE *ins; SLOT_BITMAP *slotNameIDs; { struct patternMatch *prvMatch,*tmpMatch, *deleteMatch,*lastDeleteMatch; OBJECT_ALPHA_NODE *alphaPtr;#if LOGICAL_DEPENDENCIES VOID *saveDependents;#endif if (slotNameIDs == NULL) { if (ins->partialMatchList != NULL) { tmpMatch = (struct patternMatch *) ins->partialMatchList; while (tmpMatch != NULL) { ins->busy--; tmpMatch = tmpMatch->next; } NetworkRetract((struct patternMatch *) ins->partialMatchList); ins->partialMatchList = NULL; } } else { deleteMatch = NULL; lastDeleteMatch = NULL; prvMatch = NULL; tmpMatch = (struct patternMatch *) ins->partialMatchList; while (tmpMatch != NULL) { alphaPtr = (OBJECT_ALPHA_NODE *) tmpMatch->matchingPattern; if (alphaPtr->slotbmp != NULL) { if (CompareSlotBitMaps(slotNameIDs, (SLOT_BITMAP *) ValueToBitMap(alphaPtr->slotbmp))) { ins->busy--; if (prvMatch == NULL) ins->partialMatchList = (VOID *) tmpMatch->next; else prvMatch->next = tmpMatch->next; if (!deleteMatch) deleteMatch = tmpMatch; else lastDeleteMatch->next = tmpMatch; lastDeleteMatch = tmpMatch; tmpMatch = tmpMatch->next; lastDeleteMatch->next = NULL; } else { prvMatch = tmpMatch; tmpMatch = tmpMatch->next; } } else { prvMatch = tmpMatch; tmpMatch = tmpMatch->next; } } /* ============================================= We need to preserve any logical dependencies of this object and reattach them after doing the retract. Otherwise, the Rete network will believe the object is gone and remove the links from the partial matches upon which this object is logically dependent. ============================================= */ if (deleteMatch != NULL) {#if LOGICAL_DEPENDENCIES saveDependents = ins->header.dependents; ins->header.dependents = NULL; NetworkRetract(deleteMatch); ins->header.dependents = saveDependents;#else NetworkRetract(deleteMatch);#endif } } ins->reteSynchronized = CLIPS_TRUE; } /***************************************************** NAME : ObjectPatternNetErrorMessage DESCRIPTION : Prints out a locational error message when an evaluation error occurs during object pattern-matching INPUTS : The pattern node RETURNS : Nothing useful SIDE EFFECTS : Error message displayed NOTES : None *****************************************************/static VOID ObjectPatternNetErrorMessage(patternPtr) OBJECT_PATTERN_NODE *patternPtr; { PrintErrorID("OBJRTMCH",1,CLIPS_TRUE); PrintCLIPS(WERROR,"This error occurred in the object pattern network\n"); PrintCLIPS(WERROR," Currently active instance: ["); PrintCLIPS(WERROR,ValueToString(CurrentPatternObject->name)); PrintCLIPS(WERROR,"]\n"); PrintCLIPS(WERROR," Problem resides in slot "); PrintCLIPS(WERROR,ValueToString(FindIDSlotName(patternPtr->slotNameID))); PrintCLIPS(WERROR," field #"); PrintLongInteger(WERROR,(long) patternPtr->whichField); PrintCLIPS(WERROR,"\n"); TraceErrorToObjectPattern(CLIPS_TRUE,patternPtr); PrintCLIPS(WERROR,"\n"); }/********************************************************* NAME : TraceErrorToObjectPattern DESCRIPTION : Used by ObjectPatternNetErrorMessage() to print the rule(s) which contain an object pattern. INPUTS : 1) A flag indicating if this is the node in which the error actually occurred or not 2) The pattern node RETURNS : Nothing useful SIDE EFFECTS : Error message displayed NOTES : None *********************************************************/static VOID TraceErrorToObjectPattern(errorNode,patternPtr) int errorNode; OBJECT_PATTERN_NODE *patternPtr; { struct joinNode *joinPtr; while (patternPtr != NULL) { if (patternPtr->alphaNode != NULL) { joinPtr = patternPtr->alphaNode->header.entryJoin; while (joinPtr != NULL) { PrintCLIPS(WERROR," Of pattern #"); PrintLongInteger(WERROR,(long) joinPtr->depth); PrintCLIPS(WERROR," in rule(s):\n"); TraceErrorToRule(joinPtr," "); joinPtr = joinPtr->rightMatchNode; } } TraceErrorToObjectPattern(CLIPS_FALSE,patternPtr->nextLevel); if (errorNode) break; patternPtr = patternPtr->rightNode; } }#endif /*************************************************** NAME : DESCRIPTION : INPUTS : RETURNS : SIDE EFFECTS : NOTES : ***************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -