/******************************************************************************* Name: PrintChangedAgenda Description: Update the agenda window Arguments: None Returns: *******************************************************************************/ int PrintChangedAgenda() { void *theEnv = GetCurrentEnvironment(); void *rule_ptr; char buffer[MAX_CHAR_IN_BUF]; char *name, labelBuffer[MAX_CHAR_IN_BUF]; Window AgendaWin; Display *theDisplay; struct defmodule* theModule = (struct defmodule *) EnvGetCurrentModule(theEnv); /*======================================================*/ /* Change the name of the window to the current module. */ /*======================================================*/ AgendaWin = XtWindow(agenda); theDisplay = XtDisplay(agenda); if (theModule != NULL) { name = EnvGetDefmoduleName(theEnv,theModule); strcpy(labelBuffer,"Agenda Window("); strcat(labelBuffer,name); strcat(labelBuffer,")"); } else { strcpy(labelBuffer,"Agenda Window"); } XStoreName(theDisplay,AgendaWin,labelBuffer); /*============================*/ /* Wipe out the old contents. */ /*============================*/ XtSetArg(TheArgs[0], XtNstring, ""); XtSetValues(agenda_text, TheArgs, 1); XawAsciiSourceFreeString(XawTextGetSource(agenda_text)); /*============================*/ /* Print the new agenda list. */ /*============================*/ rule_ptr = EnvGetNextActivation(theEnv,NULL); while (rule_ptr != NULL) { EnvGetActivationPPForm(theEnv,buffer,MAX_CHAR_IN_BUF - 1,rule_ptr); EnvPrintRouter(theEnv,"xagenda",buffer); EnvPrintRouter(theEnv,"xagenda", "\n"); rule_ptr = EnvGetNextActivation(theEnv,rule_ptr); } return 0; }
static int CountActivations( void *theEnv) { int count = 0; void *Ptr = NULL; while ((Ptr = EnvGetNextActivation(theEnv,Ptr)) != NULL) { count++; } return count; }
globle void EnvRefreshAgenda( void *theEnv, void *vTheModule) { struct activation *theActivation; struct defmodule *theModule = (struct defmodule *) vTheModule; intBool oldValue; int allModules = FALSE; /*==========================*/ /* Save the current module. */ /*==========================*/ SaveCurrentModule(theEnv); /*=============================================*/ /* If the module specified is a NULL pointer, */ /* then every module has its agenda refreshed. */ /*=============================================*/ if (theModule == NULL) { allModules = TRUE; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); } /*=======================================================*/ /* Remember the current setting for salience evaluation. */ /* To perform the refresh, the when activated setting is */ /* used to recompute the salience values. */ /*=======================================================*/ oldValue = EnvGetSalienceEvaluation(theEnv); EnvSetSalienceEvaluation(theEnv,WHEN_ACTIVATED); /*========================*/ /* Refresh the agenda(s). */ /*========================*/ for (; theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*=========================================*/ /* Change the current module to the module */ /* of the agenda being refreshed. */ /*=========================================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*================================================================*/ /* Recompute the salience values for the current module's agenda. */ /*================================================================*/ for (theActivation = (struct activation *) EnvGetNextActivation(theEnv,NULL); theActivation != NULL; theActivation = (struct activation *) EnvGetNextActivation(theEnv,theActivation)) { theActivation->salience = EvaluateSalience(theEnv,theActivation->theRule); } /*======================================================*/ /* Reorder the agenda based on the new salience values. */ /*======================================================*/ EnvReorderAgenda(theEnv,theModule); /*===============================================*/ /* Return if only one agenda is being refreshed. */ /*===============================================*/ if (! allModules) { EnvSetSalienceEvaluation(theEnv,oldValue); RestoreCurrentModule(theEnv); return; } } /*==========================================*/ /* Restore the salience evaluation setting. */ /*==========================================*/ EnvSetSalienceEvaluation(theEnv,oldValue); /*=============================*/ /* Restore the current module. */ /*=============================*/ RestoreCurrentModule(theEnv); }
globle intBool EnvMatchesCount( void *theEnv, void *theRule) { struct defrule *rulePtr, *tmpPtr; struct betaMemory *theMemory, **theStorage; struct partialMatch *listOfMatches; struct alphaMemoryHash *listOfHashNodes, **theAlphaStorage; struct joinNode *theJoin, *lastJoin; int i, depth; ACTIVATION *agendaPtr; long count; /*=================================================*/ /* Loop through each of the disjuncts for the rule */ /*=================================================*/ for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr; rulePtr != NULL; rulePtr = rulePtr->disjunct) { /*======================================*/ /* Determine the last join in the rule. */ /*======================================*/ lastJoin = rulePtr->lastJoin; /*===================================*/ /* Determine the number of patterns. */ /*===================================*/ depth = GetPatternNumberFromJoin(lastJoin); /*=========================================*/ /* Store the alpha memory partial matches. */ /*=========================================*/ theAlphaStorage = (struct alphaMemoryHash **) genalloc(theEnv,(unsigned) (depth * sizeof(struct alphaMemoryHash *))); theJoin = lastJoin; i = depth - 1; while (theJoin != NULL) { if (theJoin->joinFromTheRight) { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; } else { theAlphaStorage[i] = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->firstHash; i--; theJoin = theJoin->lastLevel; } } /*========================================*/ /* List the alpha memory partial matches. */ /*========================================*/ for (i = 0; i < depth; i++) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *))); return(TRUE); } EnvPrintRouter(theEnv,WDISPLAY,"Matches for Pattern "); PrintLongInteger(theEnv,WDISPLAY,(long int) i + 1); EnvPrintRouter(theEnv,WDISPLAY,": "); count = 0; for (listOfHashNodes = theAlphaStorage[i]; listOfHashNodes != NULL; listOfHashNodes = listOfHashNodes->nextHash) { listOfMatches = listOfHashNodes->alphaMemory; while (listOfMatches != NULL) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *))); return(TRUE); } count++; listOfMatches = listOfMatches->nextInMemory; } } PrintLongInteger(theEnv,WDISPLAY,count); EnvPrintRouter(theEnv,WDISPLAY,"\n"); } genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *))); /*========================================*/ /* Store the beta memory partial matches. */ /*========================================*/ depth = lastJoin->depth; theStorage = (struct betaMemory **) genalloc(theEnv,(unsigned) (depth * sizeof(struct betaMemory *))); theJoin = lastJoin; for (i = depth - 1; i >= 0; i--) { /* theStorage[i] = GetBetaMemory(theEnv,theJoin); */ theStorage[i] = theJoin->leftMemory; theJoin = theJoin->lastLevel; } /*=======================================*/ /* List the beta memory partial matches. */ /*=======================================*/ for (i = 1; i < depth; i++) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *))); return(TRUE); } /* count = 0; */ EnvPrintRouter(theEnv,WDISPLAY,"Partial matches for CEs 1 - "); PrintLongInteger(theEnv,WDISPLAY,(long int) i + 1); EnvPrintRouter(theEnv,WDISPLAY,": "); theMemory = theStorage[i]; /* for (b = 0; b < theMemory->size; b++) { listOfMatches = theMemory->beta[b]; while (listOfMatches != NULL) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *))); return(TRUE); } count++; listOfMatches = listOfMatches->nextInMemory; } } */ count = theMemory->count; PrintLongInteger(theEnv,WDISPLAY,count); EnvPrintRouter(theEnv,WDISPLAY,"\n"); } genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *))); } /*===================*/ /* List activations. */ /*===================*/ rulePtr = tmpPtr; EnvPrintRouter(theEnv,WDISPLAY,"Activations: "); count = 0; for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL); agendaPtr != NULL; agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr)) { if (GetHaltExecution(theEnv) == TRUE) return(TRUE); if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name) { count++; } } PrintLongInteger(theEnv,WDISPLAY,count); EnvPrintRouter(theEnv,WDISPLAY,"\n"); return(TRUE); }
globle intBool EnvMatches( void *theEnv, void *theRule) { struct defrule *rulePtr, *tmpPtr; struct joinNode *lastJoin; ACTIVATION *agendaPtr; int flag; /*=================================================*/ /* Loop through each of the disjuncts for the rule */ /*=================================================*/ for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr; rulePtr != NULL; rulePtr = rulePtr->disjunct) { /*======================================*/ /* Determine the last join in the rule. */ /*======================================*/ lastJoin = rulePtr->lastJoin; /*========================================*/ /* List the alpha memory partial matches. */ /*========================================*/ ListAlphaMatches(theEnv,lastJoin->lastLevel,0); /*=======================================*/ /* List the beta memory partial matches. */ /*=======================================*/ ListBetaMatches(theEnv,lastJoin,1); } /*===================*/ /* List activations. */ /*===================*/ rulePtr = tmpPtr; EnvPrintRouter(theEnv,WDISPLAY,"Activations\n"); flag = 1; for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL); agendaPtr != NULL; agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr)) { if (GetHaltExecution(theEnv) == TRUE) return(TRUE); if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name) { flag = 0; PrintPartialMatch(theEnv,WDISPLAY,GetActivationBasis(agendaPtr)); EnvPrintRouter(theEnv,WDISPLAY,"\n"); } } if (flag) EnvPrintRouter(theEnv,WDISPLAY," None\n"); return(TRUE); }
/******************************************************************************* Name: UpdateWindowsMenu Description: Sets manager menu items to sensitive or unsensitive Arguments: None Returns: None *******************************************************************************/ static void UpdateWindowsMenu() { void *theEnv = GetCurrentEnvironment(); /* ==================================================== */ /* Refresh the manager window if nessessary */ /* ==================================================== */ if(list_change || list1_change ) RefreshMngrList(); /* =================================================================== */ /* Set the sensitive state to defrule manager item in the browse menu */ /* =================================================================== */ if(EnvGetNextDefrule(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defrule_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defrule_manager, TheArgs, 1); } /* ===================================-================================ */ /* Set the sensitive state to deffacts manager item in the browse menu */ /* ==================================================================== */ if(EnvGetNextDeffacts(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(deffact_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(deffact_manager, TheArgs, 1); } /* ======================================================================= */ /* Set the sensitive state to deftemplate manager item in the browse menu */ /* ======================================================================= */ if(EnvGetNextDeftemplate(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(deftemplate_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(deftemplate_manager, TheArgs, 1); } /* ======================================================================= */ /* Set the sensitive state to deffunction manager item in the browse menu */ /* ======================================================================= */ if(EnvGetNextDeffunction(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(deffunction_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(deffunction_manager, TheArgs, 1); } /* ===================================================================== */ /* Set the sensitive state to defglobal manager item in the browse menu */ /* ===================================================================== */ if(EnvGetNextDefglobal(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defglobal_manager,TheArgs,1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defglobal_manager,TheArgs,1); } /* ====================================================================== */ /* Set the sensitive state to defgeneric manager item in the browse menu */ /* ====================================================================== */ if(EnvGetNextDefgeneric(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defgeneric_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defgeneric_manager, TheArgs, 1); } /* ======================================================================== */ /* Set the sensitive state to definstances manager item in the browse menu */ /* ======================================================================== */ if(EnvGetNextDefinstances(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(definstances_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(definstances_manager, TheArgs, 1); } /* ==================================================================== */ /* Set the sensitive state to defclass manager item in the browse menu */ /* ==================================================================== */ if(EnvGetNextDefclass(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defclass_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defclass_manager, TheArgs, 1); } /* =================================================================== */ /* Set the sensitive state to agenda manager item in the browse menu */ /* =================================================================== */ if(EnvGetNextActivation(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(agenda_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(agenda_manager, TheArgs, 1); } }
globle BOOLEAN EnvMatches_PY( void *theEnv, char *logicalName, void *theRule) { struct defrule *rulePtr, *tmpPtr; struct partialMatch *listOfMatches, **theStorage; struct joinNode *theJoin, *lastJoin; int i, depth; ACTIVATION *agendaPtr; int flag; int matchesDisplayed; /*=================================================*/ /* Loop through each of the disjuncts for the rule */ /*=================================================*/ for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr; rulePtr != NULL; rulePtr = rulePtr->disjunct) { /*======================================*/ /* Determine the last join in the rule. */ /*======================================*/ lastJoin = rulePtr->lastJoin; /*===================================*/ /* Determine the number of patterns. */ /*===================================*/ depth = GetPatternNumberFromJoin(lastJoin); /*=========================================*/ /* Store the alpha memory partial matches. */ /*=========================================*/ theStorage = (struct partialMatch **) genalloc(theEnv,(unsigned) (depth * sizeof(struct partialMatch))); theJoin = lastJoin; i = depth - 1; while (theJoin != NULL) { if (theJoin->joinFromTheRight) { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; } else { theStorage[i] = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->alphaMemory; i--; theJoin = theJoin->lastLevel; } } /*========================================*/ /* List the alpha memory partial matches. */ /*========================================*/ for (i = 0; i < depth; i++) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch))); return(TRUE); } EnvPrintRouter(theEnv,logicalName,"Matches for Pattern "); PrintLongInteger(theEnv,logicalName,(long int) i + 1); EnvPrintRouter(theEnv,logicalName,"\n"); listOfMatches = theStorage[i]; if (listOfMatches == NULL) EnvPrintRouter(theEnv,logicalName," None\n"); while (listOfMatches != NULL) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch))); return(TRUE); } PrintPartialMatch(theEnv,logicalName,listOfMatches); EnvPrintRouter(theEnv,logicalName,"\n"); listOfMatches = listOfMatches->next; } } genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch))); /*========================================*/ /* Store the beta memory partial matches. */ /*========================================*/ depth = lastJoin->depth; theStorage = (struct partialMatch **) genalloc(theEnv,(unsigned) (depth * sizeof(struct partialMatch))); theJoin = lastJoin; for (i = depth - 1; i >= 0; i--) { theStorage[i] = theJoin->beta; theJoin = theJoin->lastLevel; } /*=======================================*/ /* List the beta memory partial matches. */ /*=======================================*/ for (i = 1; i < depth; i++) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch))); return(TRUE); } matchesDisplayed = 0; EnvPrintRouter(theEnv,logicalName,"Partial matches for CEs 1 - "); PrintLongInteger(theEnv,logicalName,(long int) i + 1); EnvPrintRouter(theEnv,logicalName,"\n"); listOfMatches = theStorage[i]; while (listOfMatches != NULL) { if (GetHaltExecution(theEnv) == TRUE) { genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch))); return(TRUE); } if (listOfMatches->counterf == FALSE) { matchesDisplayed++; PrintPartialMatch(theEnv,logicalName,listOfMatches); EnvPrintRouter(theEnv,logicalName,"\n"); } listOfMatches = listOfMatches->next; } if (matchesDisplayed == 0) { EnvPrintRouter(theEnv,logicalName," None\n"); } } genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct partialMatch))); } /*===================*/ /* List activations. */ /*===================*/ rulePtr = tmpPtr; EnvPrintRouter(theEnv,logicalName,"Activations\n"); flag = 1; for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL); agendaPtr != NULL; agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr)) { if (GetHaltExecution(theEnv) == TRUE) return(TRUE); if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name) { flag = 0; PrintPartialMatch(theEnv,logicalName,GetActivationBasis(agendaPtr)); EnvPrintRouter(theEnv,logicalName,"\n"); } } if (flag) EnvPrintRouter(theEnv,logicalName," None\n"); return(TRUE); }