/** * ���ýڵ���� * * @param clusteringFeature ��ǰ�ڵ� * @param level ��ǰ���ֵ */ private void setTreeLevel(ClusteringFeature clusteringFeature, int level) { LeafNode leafNode = null; NonLeafNode nonLeafNode = null; if (clusteringFeature instanceof LeafNode) { leafNode = (LeafNode) clusteringFeature; } else if (clusteringFeature instanceof NonLeafNode) { nonLeafNode = (NonLeafNode) clusteringFeature; } if (nonLeafNode != null) { nonLeafNode.setLevel(level); level++; // �����ӽڵ� if (nonLeafNode.getNonLeafChilds() != null) { for (NonLeafNode n1 : nonLeafNode.getNonLeafChilds()) { setTreeLevel(n1, level); } } else { for (LeafNode n2 : nonLeafNode.getLeafChilds()) { setTreeLevel(n2, level); } } } else { leafNode.setLevel(level); level++; // �����Ӿ۴� for (Cluster c : leafNode.getClusterChilds()) { c.setLevel(level); } } }
/** * ��ʾCF���������� * * @param rootNode CF����ڵ� */ private void showCFTree(ClusteringFeature rootNode) { // �ո���������� int blankNum = 5; // ��ǰ����� int currentLevel = 1; LinkedList<ClusteringFeature> nodeQueue = new LinkedList<>(); ClusteringFeature cf; LeafNode leafNode; NonLeafNode nonLeafNode; ArrayList<Cluster> clusterList = new ArrayList<>(); String typeName; nodeQueue.add(rootNode); while (nodeQueue.size() > 0) { cf = nodeQueue.poll(); if (cf instanceof LeafNode) { leafNode = (LeafNode) cf; typeName = LEAFNODE; if (leafNode.getClusterChilds() != null) { for (Cluster c : leafNode.getClusterChilds()) { nodeQueue.add(c); } } } else if (cf instanceof NonLeafNode) { nonLeafNode = (NonLeafNode) cf; typeName = NON_LEAFNODE; if (nonLeafNode.getNonLeafChilds() != null) { for (NonLeafNode n1 : nonLeafNode.getNonLeafChilds()) { nodeQueue.add(n1); } } else { for (LeafNode n2 : nonLeafNode.getLeafChilds()) { nodeQueue.add(n2); } } } else { clusterList.add((Cluster) cf); typeName = CLUSTER; } if (currentLevel != cf.getLevel()) { currentLevel = cf.getLevel(); System.out.println(); System.out.println("|"); System.out.println("|"); } else if (currentLevel == cf.getLevel() && currentLevel != 1) { for (int i = 0; i < blankNum; i++) { System.out.print("-"); } } System.out.print(typeName); System.out.print("N:" + cf.getN() + ", LS:"); System.out.print("["); for (double d : cf.getLS()) { System.out.print(MessageFormat.format("{0}, ", d)); } System.out.print("]"); } System.out.println(); System.out.println("*******���շֺõľ۴�****"); // ��ʾ�Ѿ��ֺ���ľ۴ص� for (int i = 0; i < clusterList.size(); i++) { System.out.println("Cluster" + (i + 1) + "��"); for (double[] point : clusterList.get(i).getData()) { System.out.print("["); for (double d : point) { System.out.print(MessageFormat.format("{0}, ", d)); } System.out.println("]"); } } }