📄 objrtmch.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* OBJECT PATTERN MATCHER MODULE */ /*******************************************************//**************************************************************//* Purpose: RETE Network Interface for Objects *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//**************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if INSTANCE_PATTERN_MATCHING#include "classfun.h"#include "clipsmem.h"#include "drive.h"#include "multifld.h"#if LOGICAL_DEPENDENCIES#include "lgcldpnd.h"#endif#if INCREMENTAL_RESET && (! RUN_TIME) && (! BLOAD_ONLY)#include "incrrset.h"#endif#include "reteutil.h"#include "ruledlt.h"#include "reorder.h"#include "retract.h"#include "router.h"#include "objrtfnx.h"#define _OBJRTMCH_SOURCE_#include "objrtmch.h"#include "insmngr.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** *//* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */typedef struct objectMatchAction { int type; INSTANCE_TYPE *ins; SLOT_BITMAP *slotNameIDs; struct objectMatchAction *nxt; } OBJECT_MATCH_ACTION;/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILERstatic VOID ResetObjectMatchTimeTags(void);static VOID QueueObjectMatchAction(int,INSTANCE_TYPE *,int);static SLOT_BITMAP *QueueModifySlotMap(SLOT_BITMAP *,int);static VOID ReturnObjectMatchAction(OBJECT_MATCH_ACTION *);static VOID ProcessObjectMatchQueue(void);static VOID MarkObjectPatternNetwork(SLOT_BITMAP *);static BOOLEAN CompareSlotBitMaps(SLOT_BITMAP *,SLOT_BITMAP *);static VOID ObjectPatternMatch(int,OBJECT_PATTERN_NODE *,struct multifieldMarker *);static VOID ProcessPatternNode(int,OBJECT_PATTERN_NODE *,struct multifieldMarker *);static VOID CreateObjectAlphaMatch(OBJECT_ALPHA_NODE *);static BOOLEAN EvaluateObjectPatternTest(int,struct multifieldMarker *,EXPRESSION *, OBJECT_PATTERN_NODE *);static VOID ObjectAssertAction(INSTANCE_TYPE *);static VOID ObjectModifyAction(INSTANCE_TYPE *,SLOT_BITMAP *);static VOID ObjectRetractAction(INSTANCE_TYPE *,SLOT_BITMAP *);static VOID ObjectPatternNetErrorMessage(OBJECT_PATTERN_NODE *);static VOID TraceErrorToObjectPattern(int,OBJECT_PATTERN_NODE *);#elsestatic VOID ResetObjectMatchTimeTags();static VOID QueueObjectMatchAction();static SLOT_BITMAP *QueueModifySlotMap();static VOID ReturnObjectMatchAction();static VOID ProcessObjectMatchQueue();static VOID MarkObjectPatternNetwork();static BOOLEAN CompareSlotBitMaps();static VOID ObjectPatternMatch();static VOID ProcessPatternNode();static VOID CreateObjectAlphaMatch();static BOOLEAN EvaluateObjectPatternTest();static VOID ObjectAssertAction();static VOID ObjectModifyAction();static VOID ObjectRetractAction();static VOID ObjectPatternNetErrorMessage();static VOID TraceErrorToObjectPattern();#endif/* ========================================= ***************************************** EXTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** *//* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static OBJECT_MATCH_ACTION *ObjectMatchActionQueue = NULL;static OBJECT_PATTERN_NODE *ObjectPatternNetworkPointer = NULL;static OBJECT_ALPHA_NODE *ObjectPatternNetworkTerminalPointer = NULL;static BOOLEAN DelayObjectPatternMatching = CLIPS_FALSE;static unsigned long CurrentObjectMatchTimeTag = 0L;static long UseEntityTimeTag = 0L;/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*************************************************************************** NAME : ObjectMatchDelay DESCRIPTION : CLIPS interface for SetDelayObjectPatternMatching INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : DelayObjectPatternMatching set and Rete network updates delayed until pattern-matching is completed NOTES : CLIPS Syntax: (object-pattern-match-delay <action>*) ***************************************************************************/globle VOID ObjectMatchDelay(result) DATA_OBJECT *result; { register int ov; ov = SetDelayObjectPatternMatching(CLIPS_TRUE); EvaluateExpression(GetFirstArgument(),result); if (EvaluationError) { SetHaltExecution(CLIPS_FALSE); SetEvaluationError(CLIPS_FALSE); SetDelayObjectPatternMatching(ov); SetEvaluationError(CLIPS_TRUE); } else SetDelayObjectPatternMatching(ov); } /*************************************************** NAME : SetDelayObjectPatternMatching DESCRIPTION : Sets the flag determining if Rete network activity is to be delayed for objects or not INPUTS : The value of the flag RETURNS : The old value of the flag SIDE EFFECTS : DelayObjectPatternMatching set NOTES : When the delay is set to CLIPS_FALSE, all pending Rete network updates are performed ***************************************************/globle BOOLEAN SetDelayObjectPatternMatching(value) int value; { BOOLEAN oldval; oldval = DelayObjectPatternMatching; if (value) DelayObjectPatternMatching = CLIPS_TRUE; else { DelayObjectPatternMatching = CLIPS_FALSE; ObjectNetworkAction(0,NULL,-1); } return(oldval); } /*************************************************** NAME : GetDelayObjectPatternMatching DESCRIPTION : Gets the flag determining if Rete network activity is to be delayed for objects or not INPUTS : None RETURNS : The flag SIDE EFFECTS : None NOTES : None ***************************************************/globle BOOLEAN GetDelayObjectPatternMatching() { return(DelayObjectPatternMatching); }/******************************************************** NAME : ObjectNetworkPointer DESCRIPTION : Returns the first object network pattern node INPUTS : None RETURNS : The top of the object pattern network SIDE EFFECTS : None NOTES : None ********************************************************/globle OBJECT_PATTERN_NODE *ObjectNetworkPointer() { return(ObjectPatternNetworkPointer); }/******************************************************** NAME : ObjectNetworkTerminalPointer DESCRIPTION : Returns the first terminal pattern node INPUTS : None RETURNS : The last node of a pattern SIDE EFFECTS : None NOTES : None ********************************************************/globle OBJECT_ALPHA_NODE *ObjectNetworkTerminalPointer() { return(ObjectPatternNetworkTerminalPointer); }/*************************************************** NAME : SetObjectNetworkPointer DESCRIPTION : Sets the object pattern network to the given network INPUTS : Top of the new pattern network RETURNS : Nothing useful SIDE EFFECTS : ObjectPatternNetworkPointer set NOTES : None ***************************************************/globle VOID SetObjectNetworkPointer(value) OBJECT_PATTERN_NODE *value; { ObjectPatternNetworkPointer = value; }/******************************************************* NAME : SetObjectNetworkTerminalPointer DESCRIPTION : Sets the global list of terminal pattern nodes (the ones containing the bitmaps) to the given node INPUTS : The last node of a pattern RETURNS : Nothing useful SIDE EFFECTS : ObjectPatternNetworkTerminalPointer set NOTES : None *******************************************************/globle VOID SetObjectNetworkTerminalPointer(value) OBJECT_ALPHA_NODE *value; { ObjectPatternNetworkTerminalPointer = value; }/************************************************************************ NAME : ObjectNetworkAction DESCRIPTION : Main driver for pattern-matching on objects If the pattern-matching is current delayed or another object is currently being pattern-matched, the requested match action is queued for later processing. Otherwise, the match action is performed and the Rete network is updated. INPUTS : 1) The match action type OBJECT_ASSERT (1) OBJECT_RETRACT (2) OBJECT_MODIFY (3) 2) The instance to be matched (can be NULL if only want pending actions to be performed) 3) The name id of the slot being updated (can be -1) If this argument is -1, it is assumed that any pattern which could match this instance must be checked. Otherwise, only the patterns which explicitly match on the named slot will be checked. RETURNS : Nothing useful SIDE EFFECTS : Action queued or Rete network updated NOTES : None ************************************************************************/globle VOID ObjectNetworkAction(type,ins,slotNameID) int type; INSTANCE_TYPE *ins; int slotNameID; { SLOT_BITMAP *tmpMap; if (JoinOperationInProgress) return; JoinOperationInProgress = CLIPS_TRUE; /* ================================================ For purposes of conflict resolution, all objects which have had pattern-matching delayed will have the same relative timestamp, i.e., the inference engine thinks they all just appeared simultaneously When delay is off, however, each object gets the new and current timestamp as expected. ================================================ */ UseEntityTimeTag = CurrentEntityTimeTag++; /* ================================================== If pattern-matching is delayed (by use of the set-object-pattern-match-delay function), then the instance should be marked for later processing (when the delay is turned off). ================================================== */ if (ins != NULL) { /* 6.05 Bug Fix */ ins->reteSynchronized = CLIPS_FALSE; if (DelayObjectPatternMatching == CLIPS_FALSE) switch (type) { case OBJECT_ASSERT : ObjectAssertAction(ins); break; case OBJECT_RETRACT : ObjectRetractAction(ins,NULL); break; default : tmpMap = QueueModifySlotMap(NULL,slotNameID); ObjectModifyAction(ins,tmpMap); rm((VOID *) tmpMap,SlotBitMapSize(tmpMap)); } else QueueObjectMatchAction(type,ins,slotNameID); } /* ======================================== Process all pending actions in the queue All updates will use the same timestamp ======================================== */ ProcessObjectMatchQueue();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -