📄 partialsupporttree.java
字号:
// Step through P-tree table itemSet for (index=0;index < pTreeItemSet.length;index++) { // Check that index is within Ttree array if (pTreeItemSet[index] >= tTreeLength) break; // If valid node, i.e. index is within Ttree array therfore // node subsets are supported elsewhere, update if (linkRef[pTreeItemSet[index]] != null) { linkRef[pTreeItemSet[index]].support = linkRef[pTreeItemSet[index]].support + support; numUpdates++; } } } // At wrong level else { // Step through search itemSet int scLength = pTreeNodeLabel.length; for (index=0;index < scLength;index++) { //for (index=0;index < scLength;index++) { // Check that index is within Ttree array if (pTreeNodeLabel[index] >= tTreeLength) break; // If there is a node with a child reference follow that // reference if (linkRef[pTreeNodeLabel[index]] != null) { if (linkRef[pTreeNodeLabel[index]].childRef != null) addSupportToTtreeLevelN(linkRef[pTreeNodeLabel[index]].childRef, level-1,pTreeItemSet,pTreeItemSet,support); } } } } /*----------------------------------------------------------------------- */ /* */ /* PUBLIC OUTPUT METHODS */ /* */ /*----------------------------------------------------------------------- */ /* Fout types of output: 1) Output P-tree 2) Output P-tree Statistics 3) Output P-tree Table 4) Output P-tree Table statistics */ /* ---------------- */ /* 1. OUTPUT P TREE */ /* ---------------- */ /** Commences process to output P-tree. */ public void outputPtree() { System.out.println(); outputPtree1(startPtreeRef); } /** Continues process to output P-tree. @param linkPtreeRef the reference to the start of the P-tree. */ public void outputPtree1(PtreeNodeTop[] linkPtreeRef) { String newNode; int counter = 1; // Start by processing top level for (int index=0;index<linkPtreeRef.length;index++) { if (linkPtreeRef[index] != null) { outputPtree2(index,linkPtreeRef[index],counter); counter++; } } } /** Outputs top-level node of P-tree. @param index the current index in the top-level (array) of tghe P-tree. @param linkRef the reference to the P-tree top level node in question. @param counter the node counter (not necesserily the same as the index if some nodes are absent). */ private void outputPtree2(int index, PtreeNodeTop linkRef, int counter) { String newNode = Integer.toString(counter); // Outputnode number and support System.out.print("(" + newNode + ")"); short[] itemSet = new short[1]; itemSet[0] = (short) index; outputItemSet(itemSet); System.out.println("support = " + linkRef.support); // Continue outputPtree3(linkRef.childRef,newNode,1); } /** Outputs remainder of P-tree (not the top level). @param linkRef the reference to the current location in the P-tree. @param node the identifier for the current node (for output purposes only). @param counter the node counter (used to generate a new node identifier). */ private void outputPtree3(PtreeNode linkRef, String node, int counter) { String newNode; if (linkRef != null) { // Outputnode number if (node == "start") newNode = Integer.toString(counter); else { newNode = node.concat("."); newNode = newNode.concat(Integer.toString(counter)); } System.out.print("(" + newNode + ")"); outputItemSet(linkRef.itemSet); System.out.println("support = " + linkRef.support); // Continue outputPtree3(linkRef.childRef,newNode,1); counter++; outputPtree3(linkRef.siblingRef,node,counter); } } /* ---------------------- */ /* 2. OUTPUT P TREE STATS */ /* ---------------------- */ /** Commences the process of outputting P-tree statistics (for diagnostic purposes): (a) Storage, (b) Number of nodes on P-tree, (c) number of partial support increments (updates) and (d) generation time. */ public void outputPtreeStats() { System.out.println("P-TREE STATISTICS\n-----------------"); System.out.println(calculateStorage(startPtreeRef) + " (Bytes) storage"); System.out.println(calculateNumNodes(startPtreeRef) + " nodess"); System.out.println(numberOfNodeUpdates + " support value increments"); } /* OUTPUT P TREE STORAGE: */ /** Outputs P-tree storgae requirements in Bytes. */ public void outputPtreeStorage() { int storage; storage = calculateStorage(startPtreeRef); System.out.println("P-tree storage = " + storage + " (Bytes)"); } /** Commences process to calculate P-tree storage requirements. @param linkPtreeRef the reference to the current portion of the P-tree. @return total required storage in bytes. */ private int calculateStorage(PtreeNodeTop[] linkPtreeRef) { int storage = 4; // For start reference // Start by processing top level for (int index=1;index<linkPtreeRef.length;index++) { if (linkPtreeRef[index] != null) storage = calculateStorage(storage, linkPtreeRef[index]); storage = storage+4; } // Return return(storage); } /** Commences process to calculates storage requirements for a branch of the P-tree eminating from the top level. @param storage the required storage sofar. @param linkref the reference to the start of the branch. @return total required storage in bytes for branch of P-tree. */ private int calculateStorage(int storage, PtreeNodeTop linkRef) { storage = storage+8; // For top level node // Continue return(calculateStorage(storage,linkRef.childRef)); } /** Calculates recursivly the storage requirements for a sub-branch of the P-tree. @param storage the required storage sofar. @param linkref the reference to current location in the P-tree branch. @return total required storage in bytes for sub-branch of P-tree. */ private int calculateStorage(int storage, PtreeNode linkRef) { if (linkRef != null) { // 4 each foe childRef, siblingRef and support count storage = storage+12+(linkRef.itemSet.length*2); // Continue storage = calculateStorage(storage,linkRef.childRef); storage = calculateStorage(storage,linkRef.siblingRef); } // Return return(storage); } /* OUTPUT NUMBER OF P TREE NODES: */ /** Outputs total number of P-tree nodes (and the number of support value increments). */ public void outputNumNodes() { int num = 0; num = calculateNumNodes(startPtreeRef); System.out.println("Number of P-tree nodes = " + num); System.out.println("Number of P-tree support value increments = " + numberOfNodeUpdates); } /** Commence process of determining total number of nodes in P-tree. @param linkPtreeRef the reference to the start of the P-tree. @return total number of nodes. */ private int calculateNumNodes(PtreeNodeTop[] linkPtreeRef) { int num = 0; // For start reference // Start by processing top level for (int index=1;index<linkPtreeRef.length;index++) { if (linkPtreeRef[index] != null) num = 1 + calculateNumNodes(num, linkPtreeRef[index].childRef); } // Return return(num); } /** Commence process of determining total number of nodes in (sub-) branch of P-tree. @param linkPtreeRef the reference to the current location in the P-tree. @param the node count so far @return total number of nodes. */ private int calculateNumNodes(int num, PtreeNode linkRef) { if (linkRef != null) { num++; // Continue num = calculateNumNodes(num,linkRef.childRef); num = calculateNumNodes(num,linkRef.siblingRef); } // Return return(num); } /* ---------------------- */ /* 3. OUTPUT P-TREE TABLE */ /* ---------------------- */ /** Outputs P-tree table. */ public void outputPtreeTable() { int index1,index2; System.out.println("P-ree Nodes of cardinality [N]: "); for (index1=1;index1<pTreeNodesOfCardinalityN.length;index1++) System.out.println("[" + index1 + "] " + pTreeNodesOfCardinalityN[index1]); System.out.println("Marker values on completion of P-tree table " + "generation: "); for (index1=1;index1<pTreeTableMarker.length;index1++) System.out.println("[" + index1 + "] " + pTreeTableMarker[index1]); // Step through Ptree table for(index1=1;index1<startPtreeTable.length;index1++) { System.out.println("LEVEL = " + index1); if (startPtreeTable[index1] == null) System.out.print("null"); else { for(index2=0;index2<pTreeTableMarker[index1];index2++) { System.out.print("Node label = "); outputItemSet(startPtreeTable[index1][index2]. pTreeNodeLabel); System.out.print(" Itemset = "); outputItemSet(startPtreeTable[index1][index2]. pTreeItemSet); System.out.println(" sup = " + startPtreeTable[index1][index2].support); } } System.out.println(); } } /* ---------------------------- */ /* 4. OUTPUT P-TREE TABLE STATS */ /* ---------------------------- */ /** Outputs storage requirements for P-tree table. */ public void outputPtreeTableStats() { int index1,index2; int storage=0, nodeCounter, nodeTotal=0; // For each level in the P-tree table for(index1=1;index1<startPtreeTable.length;index1++) { nodeCounter=0; // If null we still need a pointer so 4 bytes if (startPtreeTable[index1] == null) storage = storage+4; // Else step through records at this level else { for(index2=0;index2<pTreeTableMarker[index1];index2++) { nodeCounter++; // 4 for support and 2 for each item in search itemSet storage = storage + 4 + (startPtreeTable[index1][index2]. pTreeNodeLabel.length*2); // 2 for each item in pTree itemSet storage = storage + (startPtreeTable[index1][index2]. pTreeItemSet.length*2); } } nodeTotal = nodeTotal+nodeCounter; } System.out.println("P-tree Table Storage = " + storage + " (" + nodeTotal + " nodes)"); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -