static LinkedList<Transaction<int>> transactions; //项集的集合 #endregion Fields #region Methods /// <summary> /// Apriori算法 /// </summary> static void Apriori() { //初始化,生成含有一个项的频繁项集 AprioriInitialize(); int depth = 1; Console.WriteLine(depth.ToString() + "层结束"); Candidates<int> lastCandi = frequentItemsets.Last(); while(lastCandi.ItemSets.Count>0) { Candidates<int> tmpCandi = new Candidates<int>(); depth++; //根据上一次的频繁项集合并生成新的候选集 foreach (var tmp in lastCandi.GenerateNewCandidates()) tmpCandi.AddCandidate(tmp, 0); if (tmpCandi.ItemSets.Count == 0) break; //判断当前候选集中的项集的所有子集是否都在上一层的频繁项集中 tmpCandi.Pruning(lastCandi.ItemSets); //计算support counting留下大于minsup的项集 Candidates<int> newCandi = DoSupportCounting(tmpCandi,depth); frequentItemsets.AddLast(newCandi); lastCandi = newCandi; Console.WriteLine(depth.ToString() + "层结束"); } Console.WriteLine("按回车结束程序..."); }