Beispiel #1
0
        /// <summary>
        /// �ݹ齨��FPTree
        /// </summary>
        /// <param name="_listItemNameList"></param>
        /// <param name="_treeNode"></param>
        private void CreateTree(List<ItemInfo> _listItemNameList, TreeNodeItem _treeNode, Hashtable _hashFrequentItemLinkTable)
        {
            if (_listItemNameList.Count == 0) return;

            bool _isExists = false;
            TreeNodeItem _currentNode = null;
            foreach (TreeNodeItem _subTreeNode in _treeNode.Nodes)
            {
                if (_subTreeNode.ItemName == _listItemNameList[0].ItemName)
                {
                    _subTreeNode.Count += 1;
                    _isExists = true;
                    _currentNode = _subTreeNode;
                    break;
                }
            }
            if (!_isExists)
            {
                _currentNode = new TreeNodeItem(_listItemNameList[0].ItemName, 1);
                FrequentLinkItem _frequentLinkItem = (FrequentLinkItem)_hashFrequentItemLinkTable[_currentNode.ItemName];
                //TreeNodeItem _nextNode = _frequentItemList[_itemIndex].NextNode;
                if (_frequentLinkItem.LinkNode == null)
                    _frequentLinkItem.LinkNode = _currentNode;
                else
                    GetNextNode(_frequentLinkItem.LinkNode).NextNode = _currentNode;

                _treeNode.Nodes.Add(_currentNode);
            }
            _listItemNameList.RemoveAt(0);
            if (_currentNode != null)
                CreateTree(_listItemNameList, _currentNode, _hashFrequentItemLinkTable);
        }
Beispiel #2
0
 /// <summary>
 /// ������һ�����
 /// </summary>
 /// <param name="_preNode"></param>
 /// <returns></returns>
 private TreeNodeItem GetNextNode(TreeNodeItem _currentNode)
 {
     if (_currentNode.NextNode == null) return _currentNode;
     else
         return GetNextNode(_currentNode.NextNode);
 }
 public FrequentLinkItem(int _index, TreeNodeItem _linkNode)
 {
     this._index = _index;
     this._linkNode = _linkNode;
 }
 public TreeNodeItem(TreeNodeItem _treeNodeItem)
     : this()
 {
     this._itemName = _treeNodeItem.ItemName;
     this._count = _treeNodeItem.Count;
 }
 /// <summary>
 /// ��������
 /// ʹItemName���,Count���,Parent���
 /// </summary>
 /// <returns></returns>
 public TreeNodeItem CloneNode()
 {
     TreeNodeItem _newNode = new TreeNodeItem();
     _newNode.ItemName = this.ItemName;
     _newNode.Count = this.Count;
     _newNode.Parent = this.Parent;
     return _newNode;
 }
        /// <summary>
        /// ��Ƶ��һ�����,�Ӻ�ǰ����
        /// ��������FPTree
        /// </summary>
        /// <param name="_frequentItemList"></param>
        public void FPGrowth(FPTree _fpTree, List<TreeNodeItem> _itemSet)
        {
            if (_fpTree.SinglePath)
            {
                //�����������,��_itemSetList����
                List<ItemSet> _itemSetList = new List<ItemSet>();
                CombineNodes(_fpTree, _itemSetList);
                //����ģʽ �¡Ȧ�,_itemSetList�Ǧµļ���
                AddPattern(_itemSet, _itemSetList);

                _itemSet.Clear();
            }
            else
            {
                for (int i = _fpTree.FrequentItemCount - 1; i > -1; i--)
                {
                    //ͷ���е�ÿ��a(i)
                    TreeNodeItem _treeNodeItem = _fpTree.GetLinkNode(i);
                    //����ģʽ�� = a(i)�Ȧ�
                    List<TreeNodeItem> _itemSetConbine = new List<TreeNodeItem>();
                    if (_treeNodeItem != null)
                    {
                        if (_itemSet == null)
                            _itemSet = new List<TreeNodeItem>();
                        TreeNodeItem[] _arrTreeNodeItem = new TreeNodeItem[_itemSet.Count];
                        _itemSet.CopyTo(_arrTreeNodeItem);
                        _itemSetConbine.AddRange(_arrTreeNodeItem);
                        _itemSetConbine.Insert(0,_treeNodeItem);
                    }
                    //��������FPTree(1)
                    FPTree _conditionFPTree = new FPTree();
                    _conditionFPTree.MinSupCount = _fpTree.MinSupCount;
                    List<List<TreeNodeItem>> _listStrList = new List<List<TreeNodeItem>>();
                    Hashtable _hashTable = new Hashtable();

                    bool _doLoop = (_treeNodeItem != null);
                    while (_doLoop)
                    {
                        //��������ģʽ��,֧�ֶȼ�����С�������List
                        List<TreeNodeItem> _treeNodeItemList = new List<TreeNodeItem>();
                        GetParentPath(_treeNodeItem.CloneNode(), _treeNodeItemList, _hashTable, _conditionFPTree);

                        //���ģʽ�Ѿ��������Ҳ���Ƶ��һ�
                        if (_treeNodeItemList.Count == 0 && _itemSetConbine.Count >1)
                            //����ģʽ
                            AddPattern(_itemSetConbine,_fpTree);

                        //��������FPTree(2)
                        if(_treeNodeItemList.Count>0)
                        _listStrList.Add(_treeNodeItemList);

                        //�������ģʽ��
                        if (_treeNodeItem.NextNode != null)
                            _treeNodeItem = _treeNodeItem.NextNode;
                        else
                            _doLoop = false;
                    }
                    //��������FPTree(3)
                    if(_listStrList.Count >0)
                    _conditionFPTree.InitializeConditionFPTree(_listStrList);

                    //������Ƿ�Ϊ��
                    if (_conditionFPTree.TopNode.Nodes.Count > 0)
                        FPGrowth(_conditionFPTree, _itemSetConbine);
                    else
                        _itemSetConbine = _itemSet;
                }
            }
        }
        /// <summary>
        /// ����һ�������ӽڵ�ĸ����
        /// ���ø����ļ���ΪҶ�ӽ�����
        /// ������
        /// </summary>
        /// <param name="_treeNodeItem"></param>
        /// <param name="_treeNodeItemList"></param>
        public void GetParentPath(TreeNodeItem _treeNodeItem, List<TreeNodeItem> _treeNodeItemList, Hashtable _hashTable,FPTree _fpTree)
        {
            while (_treeNodeItem.Parent != null && _treeNodeItem.Parent.ItemName != null)
            {
                //����ģʽ�����еĽڵ��֧�ֶȼ�����ΪҶ�Ӽ���
                TreeNodeItem _newTreeNodeItem = _treeNodeItem.Parent.CloneNode();
                _newTreeNodeItem.Count = _treeNodeItem.Count;

                _treeNodeItemList.Insert(0, _newTreeNodeItem);
                //����Ƶ��һ�
                if (_hashTable.ContainsKey(_newTreeNodeItem.ItemName))
                    _hashTable[_newTreeNodeItem.ItemName] = Convert.ToInt32(_hashTable[_newTreeNodeItem.ItemName]) +
                        _newTreeNodeItem.Count;
                else
                    _hashTable.Add(_newTreeNodeItem.ItemName, _newTreeNodeItem.Count);
                //Ƶ��
                if (Convert.ToInt32(_hashTable[_newTreeNodeItem.ItemName]) > _fpTree.MinSupCount - 1)
                {
                    _fpTree.BuildFrequentItemList(_newTreeNodeItem.ItemName,
                        Convert.ToInt32(_hashTable[_newTreeNodeItem.ItemName]));
                }
                _treeNodeItem = _newTreeNodeItem;
            }
        }