public CombinationGenerator(int masterSetSize, int selectionSize)
        {
            if (selectionSize > masterSetSize)
                throw new CombinationGeneratorException(MasterSetSizeMustBeLarger);
            else if (masterSetSize < 1)
                throw new CombinationGeneratorException(MasterSetSizeMustBeGreaterThanZero);
            else if (selectionSize < 1)
                throw new CombinationGeneratorException(SelectionSizeMustBeGreaterThanZero);

            MasterSetSize = masterSetSize;
            SelectionCount = selectionSize;

            // generate the collection of travelers with values in the range [1, MasterSetSize]
            ITroupe currentTroupe = null;
            ITroupe previousTroupe = null;

            for (var i = SelectionCount; i > 0; i--)
            {
                if (i == SelectionCount)
                    currentTroupe = new SingletonTroupe(new Traveler(i, MasterSetSize));
                else
                    currentTroupe = new Troupe(new Traveler(i, MasterSetSize), previousTroupe, (SelectionCount-i)+1);

                previousTroupe = currentTroupe;
            }

            _masterTroupe = currentTroupe;
        }
示例#2
0
 public Troupe(ITraveler leftMostTraveler, ITroupe childTroupe, int travelerCount)
 {
     _leftMostTraveler = leftMostTraveler;
     _childTroupe = childTroupe;
     _travelerCount = travelerCount;
 }