00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #define _RULECOM_SOURCE_
00038
00039 #include <stdio.h>
00040 #define _STDIO_INCLUDED_
00041 #include <string.h>
00042
00043 #include "setup.h"
00044
00045 #if DEFRULE_CONSTRUCT
00046
00047 #include "argacces.h"
00048 #include "constant.h"
00049 #include "constrct.h"
00050 #include "crstrtgy.h"
00051 #include "engine.h"
00052 #include "envrnmnt.h"
00053 #include "evaluatn.h"
00054 #include "extnfunc.h"
00055 #include "incrrset.h"
00056 #include "lgcldpnd.h"
00057 #include "memalloc.h"
00058 #include "pattern.h"
00059 #include "reteutil.h"
00060 #include "router.h"
00061 #include "ruledlt.h"
00062 #include "sysdep.h"
00063 #include "watch.h"
00064
00065 #if BLOAD || BLOAD_AND_BSAVE || BLOAD_ONLY
00066 #include "rulebin.h"
00067 #endif
00068
00069 #include "rulecom.h"
00070
00071
00072
00073
00074
00075 #if DEVELOPER
00076 static void ShowJoins(void *,void *);
00077 #endif
00078 static int ListAlphaMatches(void *,struct joinNode *,int);
00079 static int ListBetaMatches(void *,struct joinNode *,int);
00080 static int ListBetaJoinActivity(void *,struct joinNode *,int,long long *,int);
00081 static void PrintMatchesMemory(void *,struct joinNode *,struct betaMemory *,int,int);
00082
00083
00084
00085
00086 globle void DefruleCommands(
00087 void *theEnv)
00088 {
00089 #if ! RUN_TIME
00090 EnvDefineFunction2(theEnv,"run",'v', PTIEF RunCommand,"RunCommand", "*1i");
00091 EnvDefineFunction2(theEnv,"halt",'v', PTIEF HaltCommand,"HaltCommand","00");
00092 EnvDefineFunction2(theEnv,"focus",'b', PTIEF FocusCommand,"FocusCommand", "1*w");
00093 EnvDefineFunction2(theEnv,"clear-focus-stack",'v',PTIEF ClearFocusStackCommand,
00094 "ClearFocusStackCommand","00");
00095 EnvDefineFunction2(theEnv,"get-focus-stack",'m',PTIEF GetFocusStackFunction,
00096 "GetFocusStackFunction","00");
00097 EnvDefineFunction2(theEnv,"pop-focus",'w',PTIEF PopFocusFunction,
00098 "PopFocusFunction","00");
00099 EnvDefineFunction2(theEnv,"get-focus",'w',PTIEF GetFocusFunction,
00100 "GetFocusFunction","00");
00101 #if DEBUGGING_FUNCTIONS
00102 EnvDefineFunction2(theEnv,"set-break",'v', PTIEF SetBreakCommand,
00103 "SetBreakCommand","11w");
00104 EnvDefineFunction2(theEnv,"remove-break",'v', PTIEF RemoveBreakCommand,
00105 "RemoveBreakCommand", "*1w");
00106 EnvDefineFunction2(theEnv,"show-breaks",'v', PTIEF ShowBreaksCommand,
00107 "ShowBreaksCommand", "01w");
00108 EnvDefineFunction2(theEnv,"matches",'v',PTIEF MatchesCommand,"MatchesCommand","11w");
00109 EnvDefineFunction2(theEnv,"join-activity",'g',PTIEF JoinActivityCommand,"JoinActivityCommand","11w");
00110 EnvDefineFunction2(theEnv,"matches-count",'v',PTIEF MatchesCountCommand,"MatchesCountCommand","11w");
00111 EnvDefineFunction2(theEnv,"list-focus-stack",'v', PTIEF ListFocusStackCommand,
00112 "ListFocusStackCommand", "00");
00113 EnvDefineFunction2(theEnv,"dependencies", 'v', PTIEF DependenciesCommand,
00114 "DependenciesCommand", "11h");
00115 EnvDefineFunction2(theEnv,"dependents", 'v', PTIEF DependentsCommand,
00116 "DependentsCommand", "11h");
00117 EnvDefineFunction2(theEnv,"timetag", 'g', PTIEF TimetagFunction,
00118 "TimetagFunction", "11h");
00119 #endif
00120
00121 EnvDefineFunction2(theEnv,"get-incremental-reset",'b',
00122 GetIncrementalResetCommand,"GetIncrementalResetCommand","00");
00123 EnvDefineFunction2(theEnv,"set-incremental-reset",'b',
00124 SetIncrementalResetCommand,"SetIncrementalResetCommand","11");
00125
00126 EnvDefineFunction2(theEnv,"get-beta-memory-resizing",'b',
00127 GetBetaMemoryResizingCommand,"GetBetaMemoryResizingCommand","00");
00128 EnvDefineFunction2(theEnv,"set-beta-memory-resizing",'b',
00129 SetBetaMemoryResizingCommand,"SetBetaMemoryResizingCommand","11");
00130
00131 EnvDefineFunction2(theEnv,"get-strategy", 'w', PTIEF GetStrategyCommand, "GetStrategyCommand", "00");
00132 EnvDefineFunction2(theEnv,"set-strategy", 'w', PTIEF SetStrategyCommand, "SetStrategyCommand", "11w");
00133
00134 #if DEVELOPER && (! BLOAD_ONLY)
00135 EnvDefineFunction2(theEnv,"rule-complexity",'l', PTIEF RuleComplexityCommand,"RuleComplexityCommand", "11w");
00136 EnvDefineFunction2(theEnv,"show-joins", 'v', PTIEF ShowJoinsCommand, "ShowJoinsCommand", "11w");
00137 EnvDefineFunction2(theEnv,"show-aht", 'v', PTIEF ShowAlphaHashTable, "ShowAlphaHashTable", "00");
00138 #if DEBUGGING_FUNCTIONS
00139 AddWatchItem(theEnv,"rule-analysis",0,&DefruleData(theEnv)->WatchRuleAnalysis,0,NULL,NULL);
00140 #endif
00141 #endif
00142
00143 #else
00144 #if MAC_MCW || WIN_MCW || MAC_XCD
00145 #pragma unused(theEnv)
00146 #endif
00147 #endif
00148 }
00149
00150
00151
00152
00153
00154 globle intBool EnvGetBetaMemoryResizing(
00155 void *theEnv)
00156 {
00157 return(DefruleData(theEnv)->BetaMemoryResizingFlag);
00158 }
00159
00160
00161
00162
00163
00164 globle intBool EnvSetBetaMemoryResizing(
00165 void *theEnv,
00166 int value)
00167 {
00168 int ov;
00169
00170 ov = DefruleData(theEnv)->BetaMemoryResizingFlag;
00171
00172 DefruleData(theEnv)->BetaMemoryResizingFlag = value;
00173
00174 return(ov);
00175 }
00176
00177
00178
00179
00180
00181 globle int SetBetaMemoryResizingCommand(
00182 void *theEnv)
00183 {
00184 int oldValue;
00185 DATA_OBJECT argPtr;
00186
00187 oldValue = EnvGetBetaMemoryResizing(theEnv);
00188
00189
00190
00191
00192
00193 if (EnvArgCountCheck(theEnv,"set-beta-memory-resizing",EXACTLY,1) == -1)
00194 { return(oldValue); }
00195
00196
00197
00198
00199
00200
00201 EnvRtnUnknown(theEnv,1,&argPtr);
00202
00203 if ((argPtr.value == EnvFalseSymbol(theEnv)) && (argPtr.type == SYMBOL))
00204 { EnvSetBetaMemoryResizing(theEnv,FALSE); }
00205 else
00206 { EnvSetBetaMemoryResizing(theEnv,TRUE); }
00207
00208
00209
00210
00211
00212 return(oldValue);
00213 }
00214
00215
00216
00217
00218
00219 globle int GetBetaMemoryResizingCommand(
00220 void *theEnv)
00221 {
00222 int oldValue;
00223
00224 oldValue = EnvGetBetaMemoryResizing(theEnv);
00225
00226 if (EnvArgCountCheck(theEnv,"get-beta-memory-resizing",EXACTLY,0) == -1)
00227 { return(oldValue); }
00228
00229 return(oldValue);
00230 }
00231
00232 #if DEBUGGING_FUNCTIONS
00233
00234
00235
00236
00237
00238 globle void MatchesCommand(
00239 void *theEnv)
00240 {
00241 char *ruleName;
00242 void *rulePtr;
00243
00244 ruleName = GetConstructName(theEnv,"matches","rule name");
00245 if (ruleName == NULL) return;
00246
00247 rulePtr = EnvFindDefrule(theEnv,ruleName);
00248 if (rulePtr == NULL)
00249 {
00250 CantFindItemErrorMessage(theEnv,"defrule",ruleName);
00251 return;
00252 }
00253
00254 EnvMatches(theEnv,rulePtr);
00255 }
00256
00257
00258
00259
00260
00261 globle intBool EnvMatches(
00262 void *theEnv,
00263 void *theRule)
00264 {
00265 struct defrule *rulePtr, *tmpPtr;
00266 struct joinNode *lastJoin;
00267 ACTIVATION *agendaPtr;
00268 int flag;
00269
00270
00271
00272
00273
00274 for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr;
00275 rulePtr != NULL;
00276 rulePtr = rulePtr->disjunct)
00277 {
00278
00279
00280
00281
00282 lastJoin = rulePtr->lastJoin;
00283
00284
00285
00286
00287
00288 ListAlphaMatches(theEnv,lastJoin->lastLevel,0);
00289
00290
00291
00292
00293
00294 ListBetaMatches(theEnv,lastJoin,1);
00295 }
00296
00297
00298
00299
00300
00301 rulePtr = tmpPtr;
00302 EnvPrintRouter(theEnv,WDISPLAY,"Activations\n");
00303 flag = 1;
00304 for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL);
00305 agendaPtr != NULL;
00306 agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr))
00307 {
00308 if (GetHaltExecution(theEnv) == TRUE) return(TRUE);
00309
00310 if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name)
00311 {
00312 flag = 0;
00313 PrintPartialMatch(theEnv,WDISPLAY,GetActivationBasis(agendaPtr));
00314 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00315 }
00316 }
00317
00318 if (flag) EnvPrintRouter(theEnv,WDISPLAY," None\n");
00319
00320 return(TRUE);
00321 }
00322
00323
00324
00325
00326 static int ListAlphaMatches(
00327 void *theEnv,
00328 struct joinNode *theJoin,
00329 int priorPatterns)
00330 {
00331 struct alphaMemoryHash *listOfHashNodes;
00332 struct partialMatch *listOfMatches;
00333 int flag;
00334
00335 if (theJoin == NULL)
00336 { return(priorPatterns); }
00337
00338 if (theJoin->rightSideEntryStructure == NULL)
00339 {
00340 priorPatterns++;
00341
00342 EnvPrintRouter(theEnv,WDISPLAY,"Matches for Pattern ");
00343 PrintLongInteger(theEnv,WDISPLAY,(long int) priorPatterns);
00344 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00345
00346 if (theJoin->rightMemory->beta[0]->children != NULL)
00347 { EnvPrintRouter(theEnv,WDISPLAY,"*\n"); }
00348 else
00349 { EnvPrintRouter(theEnv,WDISPLAY," None\n"); }
00350
00351 return(priorPatterns);
00352 }
00353
00354 if (theJoin->lastLevel != NULL)
00355 { priorPatterns = ListAlphaMatches(theEnv,theJoin->lastLevel,priorPatterns); }
00356
00357 if (theJoin->joinFromTheRight)
00358 { return ListAlphaMatches(theEnv,(struct joinNode *) theJoin->rightSideEntryStructure,priorPatterns); }
00359
00360 listOfHashNodes = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->firstHash;
00361
00362 priorPatterns++;
00363
00364 if (GetHaltExecution(theEnv) == TRUE)
00365 { return(priorPatterns); }
00366
00367 EnvPrintRouter(theEnv,WDISPLAY,"Matches for Pattern ");
00368 PrintLongInteger(theEnv,WDISPLAY,(long int) priorPatterns);
00369 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00370
00371 for (flag = 1;
00372 listOfHashNodes != NULL;
00373 listOfHashNodes = listOfHashNodes->nextHash)
00374 {
00375 listOfMatches = listOfHashNodes->alphaMemory;
00376
00377 while (listOfMatches != NULL)
00378 {
00379 if (GetHaltExecution(theEnv) == TRUE)
00380 { return(priorPatterns); }
00381
00382 flag = 0;
00383 PrintPartialMatch(theEnv,WDISPLAY,listOfMatches);
00384 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00385 listOfMatches = listOfMatches->nextInMemory;
00386 }
00387 }
00388
00389 if (flag) EnvPrintRouter(theEnv,WDISPLAY," None\n");
00390
00391 return(priorPatterns);
00392 }
00393
00394
00395
00396
00397 static int ListBetaMatches(
00398 void *theEnv,
00399 struct joinNode *theJoin,
00400 int blockStart)
00401 {
00402 int patternsFound = 0, startPatterns;
00403
00404 if (GetHaltExecution(theEnv) == TRUE)
00405 { return(0); }
00406
00407 if (theJoin == NULL)
00408 { return(patternsFound); }
00409
00410 if (theJoin->lastLevel != NULL)
00411 { patternsFound += ListBetaMatches(theEnv,theJoin->lastLevel,blockStart); }
00412
00413 if (theJoin->depth > 2)
00414 {
00415 PrintMatchesMemory(theEnv,theJoin,
00416 theJoin->leftMemory,
00417 blockStart,
00418 blockStart + patternsFound - 1);
00419 }
00420
00421 startPatterns = patternsFound;
00422
00423 if (theJoin->joinFromTheRight)
00424 { patternsFound += ListBetaMatches(theEnv,(struct joinNode *) theJoin->rightSideEntryStructure,blockStart+patternsFound); }
00425
00426 if ((theJoin->joinFromTheRight) &&
00427 (((struct joinNode *) (theJoin->rightSideEntryStructure))->depth > 1))
00428 {
00429 PrintMatchesMemory(theEnv,theJoin,
00430 theJoin->rightMemory,
00431 blockStart + startPatterns,
00432 blockStart + patternsFound - 1);
00433 }
00434
00435
00436 if (theJoin->joinFromTheRight)
00437 { return(patternsFound); }
00438 else
00439 { return(patternsFound + 1); }
00440 }
00441
00442
00443
00444
00445 #if WIN_BTC
00446 #pragma argsused
00447 #endif
00448 static void PrintMatchesMemory(
00449 void *theEnv,
00450 struct joinNode *theJoin,
00451 struct betaMemory *theMemory,
00452 int startCE,
00453 int endCE)
00454 {
00455 #if MAC_MCW || WIN_MCW || MAC_XCD
00456 #pragma unused(theJoin)
00457 #endif
00458 struct partialMatch *listOfMatches;
00459 unsigned long b;
00460 int matchesDisplayed;
00461
00462 if (GetHaltExecution(theEnv) == TRUE)
00463 { return; }
00464
00465 matchesDisplayed = 0;
00466 EnvPrintRouter(theEnv,WDISPLAY,"Partial matches for CEs ");
00467 PrintLongInteger(theEnv,WDISPLAY,(long int) startCE);
00468 EnvPrintRouter(theEnv,WDISPLAY," - ");
00469 PrintLongInteger(theEnv,WDISPLAY,(long int) endCE);
00470
00471 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00472
00473 for (b = 0; b < theMemory->size; b++)
00474 {
00475 listOfMatches = theMemory->beta[b];
00476
00477 while (listOfMatches != NULL)
00478 {
00479 if (GetHaltExecution(theEnv) == TRUE)
00480 { return; }
00481
00482 matchesDisplayed++;
00483 PrintPartialMatch(theEnv,WDISPLAY,listOfMatches);
00484 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00485
00486 listOfMatches = listOfMatches->nextInMemory;
00487 }
00488 }
00489
00490 if (matchesDisplayed == 0) { EnvPrintRouter(theEnv,WDISPLAY," None\n"); }
00491 }
00492
00493
00494
00495
00496
00497
00498 globle long long JoinActivityCommand(
00499 void *theEnv)
00500 {
00501 char *ruleName;
00502 void *rulePtr;
00503
00504 ruleName = GetConstructName(theEnv,"join-activity","rule name");
00505 if (ruleName == NULL) return(0);
00506
00507 rulePtr = EnvFindDefrule(theEnv,ruleName);
00508 if (rulePtr == NULL)
00509 {
00510 CantFindItemErrorMessage(theEnv,"defrule",ruleName);
00511 return(0);
00512 }
00513
00514 return EnvJoinActivity(theEnv,rulePtr,0);
00515 }
00516
00517
00518
00519
00520
00521 globle long long EnvJoinActivity(
00522 void *theEnv,
00523 void *theRule,
00524 int verbosity)
00525 {
00526 struct defrule *rulePtr;
00527 struct joinNode *lastJoin;
00528 long long totalActivity = 0;
00529
00530
00531
00532
00533
00534 for (rulePtr = (struct defrule *) theRule;
00535 rulePtr != NULL;
00536 rulePtr = rulePtr->disjunct)
00537 {
00538
00539
00540
00541
00542 lastJoin = rulePtr->lastJoin;
00543
00544
00545
00546
00547
00548 ListBetaJoinActivity(theEnv,lastJoin,1,&totalActivity,verbosity);
00549 }
00550
00551 return(totalActivity);
00552 }
00553
00554
00555
00556
00557 static int ListBetaJoinActivity(
00558 void *theEnv,
00559 struct joinNode *theJoin,
00560 int blockStart,
00561 long long *activity,
00562 int verbosity)
00563 {
00564 int priorLeftPatterns = 0, priorRightPatterns = 0;
00565
00566 if (theJoin == NULL)
00567 { return(priorLeftPatterns + priorRightPatterns); }
00568
00569 if (theJoin->lastLevel != NULL)
00570 { priorLeftPatterns = ListBetaJoinActivity(theEnv,theJoin->lastLevel,blockStart,activity,verbosity); }
00571
00572 if (theJoin->joinFromTheRight)
00573 { priorRightPatterns = ListBetaJoinActivity(theEnv,(struct joinNode *) theJoin->rightSideEntryStructure,blockStart+priorLeftPatterns,activity,verbosity); }
00574
00575 if (theJoin->depth == 1)
00576 {
00577 if (theJoin->joinFromTheRight)
00578 { return(priorLeftPatterns + priorRightPatterns); }
00579 else
00580 { return(priorLeftPatterns + priorRightPatterns + 1); }
00581 }
00582
00583 if ((priorLeftPatterns > 1) || (theJoin->joinFromTheRight))
00584 {
00585
00586
00587 if (priorLeftPatterns > 1)
00588 {
00589
00590
00591
00592
00593
00594 }
00595 else if (theJoin->joinFromTheRight)
00596 {
00597
00598
00599
00600
00601
00602 }
00603
00604 *activity += theJoin->memoryCompares + theJoin->memoryAdds + theJoin->memoryDeletes;
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614 }
00615
00616 if (theJoin->joinFromTheRight)
00617 { return(priorLeftPatterns + priorRightPatterns); }
00618 else
00619 { return(priorLeftPatterns + priorRightPatterns + 1); }
00620 }
00621
00622
00623
00624
00625
00626 globle void MatchesCountCommand(
00627 void *theEnv)
00628 {
00629 char *ruleName;
00630 void *rulePtr;
00631
00632 ruleName = GetConstructName(theEnv,"matches-count","rule name");
00633 if (ruleName == NULL) return;
00634
00635 rulePtr = EnvFindDefrule(theEnv,ruleName);
00636 if (rulePtr == NULL)
00637 {
00638 CantFindItemErrorMessage(theEnv,"defrule",ruleName);
00639 return;
00640 }
00641
00642 EnvMatchesCount(theEnv,rulePtr);
00643 }
00644
00645
00646
00647
00648
00649 globle intBool EnvMatchesCount(
00650 void *theEnv,
00651 void *theRule)
00652 {
00653 struct defrule *rulePtr, *tmpPtr;
00654 struct betaMemory *theMemory, **theStorage;
00655 struct partialMatch *listOfMatches;
00656 struct alphaMemoryHash *listOfHashNodes, **theAlphaStorage;
00657 struct joinNode *theJoin, *lastJoin;
00658 int i, depth;
00659 ACTIVATION *agendaPtr;
00660 long count;
00661
00662
00663
00664
00665
00666 for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr;
00667 rulePtr != NULL;
00668 rulePtr = rulePtr->disjunct)
00669 {
00670
00671
00672
00673
00674 lastJoin = rulePtr->lastJoin;
00675
00676
00677
00678
00679
00680 depth = GetPatternNumberFromJoin(lastJoin);
00681
00682
00683
00684
00685
00686 theAlphaStorage = (struct alphaMemoryHash **)
00687 genalloc(theEnv,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));
00688
00689 theJoin = lastJoin;
00690 i = depth - 1;
00691 while (theJoin != NULL)
00692 {
00693 if (theJoin->joinFromTheRight)
00694 { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; }
00695 else
00696 {
00697 theAlphaStorage[i] = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->firstHash;
00698 i--;
00699 theJoin = theJoin->lastLevel;
00700 }
00701 }
00702
00703
00704
00705
00706
00707 for (i = 0; i < depth; i++)
00708 {
00709 if (GetHaltExecution(theEnv) == TRUE)
00710 {
00711 genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));
00712 return(TRUE);
00713 }
00714
00715 EnvPrintRouter(theEnv,WDISPLAY,"Matches for Pattern ");
00716 PrintLongInteger(theEnv,WDISPLAY,(long int) i + 1);
00717 EnvPrintRouter(theEnv,WDISPLAY,": ");
00718
00719 count = 0;
00720 for (listOfHashNodes = theAlphaStorage[i];
00721 listOfHashNodes != NULL;
00722 listOfHashNodes = listOfHashNodes->nextHash)
00723 {
00724 listOfMatches = listOfHashNodes->alphaMemory;
00725
00726 while (listOfMatches != NULL)
00727 {
00728 if (GetHaltExecution(theEnv) == TRUE)
00729 {
00730 genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));
00731 return(TRUE);
00732 }
00733
00734 count++;
00735 listOfMatches = listOfMatches->nextInMemory;
00736 }
00737 }
00738
00739 PrintLongInteger(theEnv,WDISPLAY,count);
00740 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00741 }
00742
00743 genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));
00744
00745
00746
00747
00748
00749 depth = lastJoin->depth;
00750 theStorage = (struct betaMemory **) genalloc(theEnv,(unsigned) (depth * sizeof(struct betaMemory *)));
00751
00752 theJoin = lastJoin;
00753 for (i = depth - 1; i >= 0; i--)
00754 {
00755
00756 theStorage[i] = theJoin->leftMemory;
00757 theJoin = theJoin->lastLevel;
00758 }
00759
00760
00761
00762
00763
00764 for (i = 1; i < depth; i++)
00765 {
00766 if (GetHaltExecution(theEnv) == TRUE)
00767 {
00768 genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *)));
00769 return(TRUE);
00770 }
00771
00772
00773
00774 EnvPrintRouter(theEnv,WDISPLAY,"Partial matches for CEs 1 - ");
00775 PrintLongInteger(theEnv,WDISPLAY,(long int) i + 1);
00776 EnvPrintRouter(theEnv,WDISPLAY,": ");
00777 theMemory = theStorage[i];
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 count = theMemory->count;
00797 PrintLongInteger(theEnv,WDISPLAY,count);
00798
00799 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00800 }
00801
00802 genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *)));
00803 }
00804
00805
00806
00807
00808
00809 rulePtr = tmpPtr;
00810 EnvPrintRouter(theEnv,WDISPLAY,"Activations: ");
00811 count = 0;
00812 for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL);
00813 agendaPtr != NULL;
00814 agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr))
00815 {
00816 if (GetHaltExecution(theEnv) == TRUE) return(TRUE);
00817
00818 if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name)
00819 { count++; }
00820 }
00821
00822 PrintLongInteger(theEnv,WDISPLAY,count);
00823 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00824
00825 return(TRUE);
00826 }
00827
00828
00829
00830
00831
00832 globle long long TimetagFunction(
00833 void *theEnv)
00834 {
00835 DATA_OBJECT item;
00836 void *ptr;
00837
00838 if (EnvArgCountCheck(theEnv,"timetag",EXACTLY,1) == -1) return(-1LL);
00839
00840 ptr = GetFactOrInstanceArgument(theEnv,1,&item,"timetag");
00841
00842 if (ptr == NULL) return(-1);
00843
00844 return ((struct patternEntity *) ptr)->timeTag;
00845 }
00846
00847 #endif
00848
00849 #if DEVELOPER
00850
00851
00852
00853
00854 globle long RuleComplexityCommand(
00855 void *theEnv)
00856 {
00857 char *ruleName;
00858 struct defrule *rulePtr;
00859
00860 ruleName = GetConstructName(theEnv,"rule-complexity","rule name");
00861 if (ruleName == NULL) return(-1);
00862
00863 rulePtr = (struct defrule *) EnvFindDefrule(theEnv,ruleName);
00864 if (rulePtr == NULL)
00865 {
00866 CantFindItemErrorMessage(theEnv,"defrule",ruleName);
00867 return(-1);
00868 }
00869
00870 return(rulePtr->complexity);
00871 }
00872
00873
00874
00875
00876
00877 globle void ShowJoinsCommand(
00878 void *theEnv)
00879 {
00880 char *ruleName;
00881 void *rulePtr;
00882
00883 ruleName = GetConstructName(theEnv,"show-joins","rule name");
00884 if (ruleName == NULL) return;
00885
00886 rulePtr = EnvFindDefrule(theEnv,ruleName);
00887 if (rulePtr == NULL)
00888 {
00889 CantFindItemErrorMessage(theEnv,"defrule",ruleName);
00890 return;
00891 }
00892
00893 ShowJoins(theEnv,rulePtr);
00894
00895 return;
00896 }
00897
00898
00899
00900
00901
00902 static void ShowJoins(
00903 void *theEnv,
00904 void *theRule)
00905 {
00906 struct defrule *rulePtr;
00907 struct joinNode *theJoin;
00908 struct joinNode *joinList[MAXIMUM_NUMBER_OF_PATTERNS];
00909 int numberOfJoins;
00910 char rhsType;
00911
00912 rulePtr = (struct defrule *) theRule;
00913
00914
00915
00916
00917
00918 while (rulePtr != NULL)
00919 {
00920
00921
00922
00923
00924 numberOfJoins = -1;
00925 theJoin = rulePtr->lastJoin;
00926 while (theJoin != NULL)
00927 {
00928 if (theJoin->joinFromTheRight)
00929 { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; }
00930 else
00931 {
00932 numberOfJoins++;
00933 joinList[numberOfJoins] = theJoin;
00934 theJoin = theJoin->lastLevel;
00935 }
00936 }
00937
00938
00939
00940
00941
00942 while (numberOfJoins >= 0)
00943 {
00944 char buffer[20];
00945
00946 if (joinList[numberOfJoins]->patternIsNegated)
00947 { rhsType = 'n'; }
00948 else if (joinList[numberOfJoins]->patternIsExists)
00949 { rhsType = 'x'; }
00950 else
00951 { rhsType = ' '; }
00952
00953 gensprintf(buffer,"%2d%c%c: ",(int) joinList[numberOfJoins]->depth,
00954 rhsType,
00955 (joinList[numberOfJoins]->logicalJoin) ? 'l' : ' ');
00956 EnvPrintRouter(theEnv,WDISPLAY,buffer);
00957 PrintExpression(theEnv,WDISPLAY,joinList[numberOfJoins]->networkTest);
00958 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00959
00960 if (joinList[numberOfJoins]->leftHash != NULL)
00961 {
00962 EnvPrintRouter(theEnv,WDISPLAY," LH : ");
00963 PrintExpression(theEnv,WDISPLAY,joinList[numberOfJoins]->leftHash);
00964 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00965 }
00966
00967 numberOfJoins--;
00968 };
00969
00970
00971
00972
00973
00974 rulePtr = rulePtr->disjunct;
00975 if (rulePtr != NULL) EnvPrintRouter(theEnv,WDISPLAY,"\n");
00976 }
00977 }
00978
00979
00980
00981
00982
00983 globle void ShowAlphaHashTable(
00984 void *theEnv)
00985 {
00986 int i, count;
00987 long totalCount = 0;
00988 struct alphaMemoryHash *theEntry;
00989 struct partialMatch *theMatch;
00990 char buffer[40];
00991
00992 for (i = 0; i < ALPHA_MEMORY_HASH_SIZE; i++)
00993 {
00994 for (theEntry = DefruleData(theEnv)->AlphaMemoryTable[i], count = 0;
00995 theEntry != NULL;
00996 theEntry = theEntry->next)
00997 { count++; }
00998
00999 if (count != 0)
01000 {
01001 totalCount += count;
01002 gensprintf(buffer,"%4d: %4d ->",i,count);
01003 EnvPrintRouter(theEnv,WDISPLAY,buffer);
01004
01005 for (theEntry = DefruleData(theEnv)->AlphaMemoryTable[i], count = 0;
01006 theEntry != NULL;
01007 theEntry = theEntry->next)
01008 {
01009 for (theMatch = theEntry->alphaMemory;
01010 theMatch != NULL;
01011 theMatch = theMatch->nextInMemory)
01012 { count++; }
01013
01014 gensprintf(buffer," %4d",count);
01015 EnvPrintRouter(theEnv,WDISPLAY,buffer);
01016 if (theEntry->owner->rightHash == NULL)
01017 { EnvPrintRouter(theEnv,WDISPLAY,"*"); }
01018 }
01019
01020 EnvPrintRouter(theEnv,WDISPLAY,"\n");
01021 }
01022 }
01023 gensprintf(buffer,"Total Count: %ld\n",totalCount);
01024 EnvPrintRouter(theEnv,WDISPLAY,buffer);
01025 }
01026
01027 #endif
01028
01029 #endif
01030