Beispiel #1
0
        public static ItemsetCollection FindSubsets(Itemset itemset, int n)
        {
            ItemsetCollection subsets = new ItemsetCollection();

            int subsetCount = (int)Math.Pow(2, itemset.Count);

            for (int i = 0; i < subsetCount; i++)
            {
                if (n == 0 || GetOnCount(i, itemset.Count) == n)
                {
                    string binary = DecimalToBinary(i, itemset.Count);

                    Itemset subset = new Itemset();
                    for (int charIndex = 0; charIndex < binary.Length; charIndex++)
                    {
                        if (binary[charIndex] == '1')
                        {
                            subset.Add(itemset[charIndex]);
                        }
                    }
                    subsets.Add(subset);
                }
            }

            return(subsets);
        }
Beispiel #2
0
        public ItemsetCollection setData()
        {
            _items = new Itemset();
            _items.Add("Game");
            _items.Add("Water");
            _items.Add("Monster");
            _items.Add("Candy");
            _items.Add("Shoes");
            _items.Add("Controller");
            _items.Add("PizzaRolls");
            _items.Add("Console");

            _db = new ItemsetCollection();
            _db.Add(new Itemset()
            {
                _items[0], _items[2], _items[3], _items[5]
            });
            _db.Add(new Itemset()
            {
                _items[1], _items[4]
            });
            _db.Add(new Itemset()
            {
                _items[0], _items[2], _items[6]
            });
            _db.Add(new Itemset()
            {
                _items[1], _items[3], _items[4], _items[7]
            });
            _db.Add(new Itemset()
            {
                _items[0], _items[1], _items[6]
            });

            return(_db);
        }