globle void TraceErrorToRule( struct joinNode *joinPtr, char *indentSpaces) { MarkRuleNetwork(0); TraceErrorToRuleDriver(joinPtr,indentSpaces); }
static void BsaveExpressions( FILE *fp) { struct defrule *theDefrule, *theDisjunct; struct defmodule *theModule; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { /*======================================================*/ /* Set the current module to the module being examined. */ /*======================================================*/ SetCurrentModule((void *) theModule); /*==================================================*/ /* Loop through each defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) GetNextDefrule(NULL); theDefrule != NULL; theDefrule = (struct defrule *) GetNextDefrule(theDefrule)) { /*===========================================*/ /* Save the dynamic salience of the defrule. */ /*===========================================*/ #if DYNAMIC_SALIENCE BsaveExpression(theDefrule->dynamicSalience,fp); #endif #if CERTAINTY_FACTORS BsaveExpression(theDefrule->dynamicCF,fp); #endif /*===================================*/ /* Loop through each disjunct of the */ /* defrule and save its RHS actions. */ /*===================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { BsaveExpression(theDisjunct->actions,fp); } } } /*==============================*/ /* Set the marked flag for each */ /* join in the join network. */ /*==============================*/ MarkRuleNetwork(1); }
globle void TagRuleNetwork( long int *moduleCount, long int *ruleCount, long int *joinCount) { struct defmodule *modulePtr; struct defrule *rulePtr; struct joinNode *joinPtr; *moduleCount = 0; *ruleCount = 0; *joinCount = 0; MarkRuleNetwork(0); /*===========================*/ /* Loop through each module. */ /*===========================*/ for (modulePtr = (struct defmodule *) GetNextDefmodule(NULL); modulePtr != NULL; modulePtr = (struct defmodule *) GetNextDefmodule(modulePtr)) { (*moduleCount)++; SetCurrentModule((void *) modulePtr); /*=========================*/ /* Loop through each rule. */ /*=========================*/ rulePtr = (struct defrule *) GetNextDefrule(NULL); while (rulePtr != NULL) { rulePtr->header.bsaveID = *ruleCount; (*ruleCount)++; /*=========================*/ /* Loop through each join. */ /*=========================*/ for (joinPtr = rulePtr->lastJoin; joinPtr != NULL; joinPtr = GetPreviousJoin(joinPtr)) { if (joinPtr->marked == 0) { joinPtr->marked = 1; joinPtr->bsaveID = *joinCount; (*joinCount)++; } } if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct; else rulePtr = (struct defrule *) GetNextDefrule(rulePtr); } } }
static void BsaveExpressions( void *theEnv, FILE *fp) { struct defrule *theDefrule, *theDisjunct; struct defmodule *theModule; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*======================================================*/ /* Set the current module to the module being examined. */ /*======================================================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*==================================================*/ /* Loop through each defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); theDefrule != NULL; theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule)) { /*===========================================*/ /* Save the dynamic salience of the defrule. */ /*===========================================*/ BsaveExpression(theEnv,theDefrule->dynamicSalience,fp); /*===================================*/ /* Loop through each disjunct of the */ /* defrule and save its RHS actions. */ /*===================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { BsaveExpression(theEnv,theDisjunct->actions,fp); } } } /*==============================*/ /* Set the marked flag for each */ /* join in the join network. */ /*==============================*/ MarkRuleNetwork(theEnv,1); }
static void BsaveBinaryItem( FILE *fp) { unsigned long int space; struct defrule *theDefrule; #if FUZZY_DEFTEMPLATES struct defrule *theDisjunct; #endif struct defmodule *theModule; struct defruleModule *theModuleItem; struct bsaveDefruleModule tempDefruleModule; #if CERTAINTY_FACTORS long int disjunctExpressionCountCF = 0L; #endif /*===============================================*/ /* Write out the space required by the defrules. */ /*===============================================*/ space = (NumberOfDefrules * sizeof(struct bsaveDefrule)) + (NumberOfJoins * sizeof(struct bsaveJoinNode)) + #if FUZZY_DEFTEMPLATES (NumberOfPatternFuzzyValues * sizeof(struct fzSlotLocator)) + #endif (NumberOfDefruleModules * sizeof(struct bsaveDefruleModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*===============================================*/ /* Write out each defrule module data structure. */ /*===============================================*/ NumberOfDefrules = 0; #if FUZZY_DEFTEMPLATES NumberOfPatternFuzzyValues = 0; #endif for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); theModuleItem = (struct defruleModule *) GetModuleItem(NULL,FindModuleItem("defrule")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefruleModule.header, &theModuleItem->header); GenWrite(&tempDefruleModule,(unsigned long) sizeof(struct bsaveDefruleModule),fp); } /*========================================*/ /* Write out each defrule data structure. */ /*========================================*/ for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); for (theDefrule = (struct defrule *) GetNextDefrule(NULL); theDefrule != NULL; theDefrule = (struct defrule *) GetNextDefrule(theDefrule)) { BsaveDisjuncts(fp,theDefrule); } } #if FUZZY_DEFTEMPLATES /*====================================*/ /* Write out the PatternFuzzyValues . */ /*====================================*/ theModule = (struct defmodule *) GetNextDefmodule(NULL); while (theModule != NULL) { SetCurrentModule((VOID *) theModule); theDefrule = (struct defrule *) GetNextDefrule(NULL); while (theDefrule != NULL) { theDisjunct = theDefrule; while (theDisjunct != NULL) { int i; struct bsaveFzSlotLocator tempFZSlotLocator; for (i=0; i<theDisjunct->numberOfFuzzySlots; i++) { FUZZY_VALUE_HN *fvhnPtr; struct fzSlotLocator *fvSLPtr; fvSLPtr = theDisjunct->pattern_fv_arrayPtr + i; fvhnPtr = fvSLPtr->fvhnPtr; tempFZSlotLocator.patternNum = fvSLPtr->patternNum; tempFZSlotLocator.slotNum = fvSLPtr->slotNum; tempFZSlotLocator.fvhnPtr = fvhnPtr->bucket; GenWrite(&tempFZSlotLocator,(unsigned long) sizeof(struct bsaveFzSlotLocator),fp); } theDisjunct = theDisjunct->disjunct; } theDefrule = (struct defrule *) GetNextDefrule(theDefrule); } theModule = (struct defmodule *) GetNextDefmodule(theModule); } #endif /*=============================*/ /* Write out the Rete Network. */ /*=============================*/ MarkRuleNetwork(1); BsaveJoins(fp); /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defrules, defrule modules, and joins in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ if (Bloaded()) { RestoreBloadCount(&NumberOfDefruleModules); RestoreBloadCount(&NumberOfDefrules); RestoreBloadCount(&NumberOfJoins); #if FUZZY_DEFTEMPLATES RestoreBloadCount(&NumberOfPatternFuzzyValues); #endif } }
static void BsaveFind() { struct defrule *theDefrule, *theDisjunct; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ if (Bloaded()) { SaveBloadCount(NumberOfDefruleModules); SaveBloadCount(NumberOfDefrules); SaveBloadCount(NumberOfJoins); #if FUZZY_DEFTEMPLATES SaveBloadCount(NumberOfPatternFuzzyValues); #endif } /*====================================================*/ /* Set the binary save ID for defrule data structures */ /* and count the number of each type. */ /*====================================================*/ TagRuleNetwork(&NumberOfDefruleModules,&NumberOfDefrules,&NumberOfJoins); #if FUZZY_DEFTEMPLATES NumberOfPatternFuzzyValues = 0; #endif /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { /*============================*/ /* Set the current module to */ /* the module being examined. */ /*============================*/ SetCurrentModule((void *) theModule); /*==================================================*/ /* Loop through each defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) GetNextDefrule(NULL); theDefrule != NULL; theDefrule = (struct defrule *) GetNextDefrule(theDefrule)) { /*================================================*/ /* Initialize the construct header for the binary */ /* save. The binary save ID has already been set. */ /*================================================*/ MarkConstructHeaderNeededItems(&theDefrule->header,theDefrule->header.bsaveID); /*===========================================*/ /* Count and mark data structures associated */ /* with dynamic salience. */ /*===========================================*/ #if DYNAMIC_SALIENCE ExpressionCount += ExpressionSize(theDefrule->dynamicSalience); MarkNeededItems(theDefrule->dynamicSalience); #endif #if CERTAINTY_FACTORS ExpressionCount += ExpressionSize(theDefrule->dynamicCF); MarkNeededItems(theDefrule->dynamicCF); #endif /*==========================================*/ /* Loop through each disjunct of the rule */ /* counting and marking the data structures */ /* associated with RHS actions. */ /*==========================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { ExpressionCount += ExpressionSize(theDisjunct->actions); MarkNeededItems(theDisjunct->actions); #if FUZZY_DEFTEMPLATES /* count the number of PatternFuzzyValues store with each rule and mark all of the FuzzyValues pointed to as needed */ if (theDisjunct->numberOfFuzzySlots > 0) { int i; FUZZY_VALUE_HN *fvhnPtr; struct fzSlotLocator *fvSLPtr; NumberOfPatternFuzzyValues += theDisjunct->numberOfFuzzySlots; for (i= 0; i<theDisjunct->numberOfFuzzySlots; i++) { fvSLPtr = theDisjunct->pattern_fv_arrayPtr + i; fvhnPtr = fvSLPtr->fvhnPtr; if (fvhnPtr != NULL) { fvhnPtr->neededFuzzyValue = TRUE; } } } #endif } } } /*===============================*/ /* Reset the bsave tags assigned */ /* to defrule data structures. */ /*===============================*/ MarkRuleNetwork(1); }
static void BsaveBinaryItem( void *theEnv, FILE *fp) { unsigned long int space; struct defrule *theDefrule; struct defmodule *theModule; struct defruleModule *theModuleItem; struct bsaveDefruleModule tempDefruleModule; /*===============================================*/ /* Write out the space required by the defrules. */ /*===============================================*/ space = (DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct bsaveDefrule)) + (DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct bsaveJoinNode)) + (DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct bsaveDefruleModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*===============================================*/ /* Write out each defrule module data structure. */ /*===============================================*/ DefruleBinaryData(theEnv)->NumberOfDefrules = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); theModuleItem = (struct defruleModule *) GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"defrule")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefruleModule.header, &theModuleItem->header); GenWrite(&tempDefruleModule,(unsigned long) sizeof(struct bsaveDefruleModule),fp); } /*========================================*/ /* Write out each defrule data structure. */ /*========================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); theDefrule != NULL; theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule)) { BsaveDisjuncts(theEnv,fp,theDefrule); } } /*=============================*/ /* Write out the Rete Network. */ /*=============================*/ MarkRuleNetwork(theEnv,1); BsaveJoins(theEnv,fp); /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defrules, defrule modules, and joins in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules); RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefrules); RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfJoins); }
static void BsaveFind( void *theEnv) { struct defrule *theDefrule, *theDisjunct; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfDefruleModules); SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfDefrules); SaveBloadCount(theEnv,DefruleBinaryData(theEnv)->NumberOfJoins); /*====================================================*/ /* Set the binary save ID for defrule data structures */ /* and count the number of each type. */ /*====================================================*/ TagRuleNetwork(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules, &DefruleBinaryData(theEnv)->NumberOfDefrules, &DefruleBinaryData(theEnv)->NumberOfJoins); /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*============================*/ /* Set the current module to */ /* the module being examined. */ /*============================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*==================================================*/ /* Loop through each defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); theDefrule != NULL; theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule)) { /*================================================*/ /* Initialize the construct header for the binary */ /* save. The binary save ID has already been set. */ /*================================================*/ MarkConstructHeaderNeededItems(&theDefrule->header,theDefrule->header.bsaveID); /*===========================================*/ /* Count and mark data structures associated */ /* with dynamic salience. */ /*===========================================*/ ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDefrule->dynamicSalience); MarkNeededItems(theEnv,theDefrule->dynamicSalience); /*==========================================*/ /* Loop through each disjunct of the rule */ /* counting and marking the data structures */ /* associated with RHS actions. */ /*==========================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDisjunct->actions); MarkNeededItems(theEnv,theDisjunct->actions); } } } /*===============================*/ /* Reset the bsave tags assigned */ /* to defrule data structures. */ /*===============================*/ MarkRuleNetwork(theEnv,1); }