📄 incrrset.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 05/17/06 */
/* */
/* INCREMENTAL RESET MODULE */
/*******************************************************/
/*************************************************************/
/* Purpose: Provides functionality for the incremental */
/* reset of the pattern and join networks when a new */
/* rule is added. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* */
/* Revision History: */
/* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
/* */
/* 6.24: Removed INCREMENTAL_RESET compilation flag. */
/* */
/* Renamed BOOLEAN macro type to intBool. */
/* */
/*************************************************************/
#define _INCRRSET_SOURCE_
#include "setup.h"
#include <stdio.h>
#define _STDIO_INCLUDED_
#if DEFRULE_CONSTRUCT
#include "agenda.h"
#include "argacces.h"
#include "constant.h"
#include "drive.h"
#include "engine.h"
#include "envrnmnt.h"
#include "evaluatn.h"
#include "pattern.h"
#include "router.h"
#include "incrrset.h"
/***************************************/
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
/***************************************/
#if (! RUN_TIME) && (! BLOAD_ONLY)
static void MarkNetworkForIncrementalReset(void *,struct defrule *,int);
static void CheckForPrimableJoins(void *,struct defrule *);
static void PrimeJoin(void *,struct joinNode *);
static void MarkPatternForIncrementalReset(void *,int,struct patternNodeHeader *,int);
#endif
/**************************************************************/
/* IncrementalReset: Incrementally resets the specified rule. */
/**************************************************************/
globle void IncrementalReset(
void *theEnv,
struct defrule *tempRule)
{
#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)
#pragma unused(theEnv,tempRule)
#endif
#if (! RUN_TIME) && (! BLOAD_ONLY)
struct defrule *tempPtr;
struct patternParser *theParser;
/*================================================*/
/* If incremental reset is disabled, then return. */
/*================================================*/
if (! EnvGetIncrementalReset(theEnv)) return;
/*=====================================================*/
/* Mark the pattern and join network data structures */
/* associated with the rule being incrementally reset. */
/*=====================================================*/
MarkNetworkForIncrementalReset(theEnv,tempRule,TRUE);
/*==========================*/
/* Begin incremental reset. */
/*==========================*/
EngineData(theEnv)->IncrementalResetInProgress = TRUE;
/*============================================================*/
/* If the new rule shares patterns or joins with other rules, */
/* then it is necessary to update its join network based on */
/* existing partial matches it shares with other rules. */
/*============================================================*/
for (tempPtr = tempRule;
tempPtr != NULL;
tempPtr = tempPtr->disjunct)
{ CheckForPrimableJoins(theEnv,tempPtr); }
/*===============================================*/
/* Filter existing data entities through the new */
/* portions of the pattern and join networks. */
/*===============================================*/
for (theParser = PatternData(theEnv)->ListOfPatternParsers;
theParser != NULL;
theParser = theParser->next)
{
if (theParser->incrementalResetFunction != NULL)
{ (*theParser->incrementalResetFunction)(theEnv); }
}
/*========================*/
/* End incremental reset. */
/*========================*/
EngineData(theEnv)->IncrementalResetInProgress = FALSE;
/*====================================================*/
/* Remove the marks in the pattern and join networks. */
/*====================================================*/
MarkNetworkForIncrementalReset(theEnv,tempRule,FALSE);
#endif
}
#if (! RUN_TIME) && (! BLOAD_ONLY)
/**********************************************************************/
/* MarkNetworkForIncrementalReset: Coordinates marking the initialize */
/* flags in the pattern and join networks both before and after an */
/* incremental reset. */
/**********************************************************************/
static void MarkNetworkForIncrementalReset(
void *theEnv,
struct defrule *tempRule,
int value)
{
struct joinNode *joinPtr;
struct patternNodeHeader *patternPtr;
/*============================================*/
/* Loop through each of the rule's disjuncts. */
/*============================================*/
for (;
tempRule != NULL;
tempRule = tempRule->disjunct)
{
/*============================================*/
/* Loop through each of the disjunct's joins. */
/*============================================*/
for (joinPtr = tempRule->lastJoin;
joinPtr != NULL;
joinPtr = GetPreviousJoin(joinPtr))
{
/*================*/
/* Mark the join. */
/*================*/
joinPtr->marked = FALSE; /* GDR 6.05 */
if ((joinPtr->initialize) && (joinPtr->joinFromTheRight == FALSE))
{
joinPtr->initialize = value;
patternPtr = (struct patternNodeHeader *) GetPatternForJoin(joinPtr);
MarkPatternForIncrementalReset(theEnv,(int) joinPtr->rhsType,patternPtr,value);
}
}
}
}
/*******************************************************************************/
/* CheckForPrimableJoins: Updates the joins of a rule for an incremental reset */
/* if portions of that rule are shared with other rules that have already */
/* been incrementally reset. A join for a new rule will be updated if it is */
/* marked for initialization and either its parent join or its associated */
/* entry pattern node has not been marked for initialization. The function */
/* PrimeJoin is used to update joins which meet these criteria. */
/*******************************************************************************/
static void CheckForPrimableJoins(
void *theEnv,
struct defrule *tempRule)
{
struct joinNode *joinPtr;
struct partialMatch *theList;
/*========================================*/
/* Loop through each of the rule's joins. */
/*========================================*/
for (joinPtr = tempRule->lastJoin;
joinPtr != NULL;
joinPtr = GetPreviousJoin(joinPtr))
{
/*===============================*/
/* Update the join if necessary. */
/*===============================*/
if ((joinPtr->initialize) && (! joinPtr->marked)) /* GDR 6.05 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -