public WavePropagator(
            PatternModel model,
            ITopology topology,
            WavePropagatorOptions options)
        {
            this.patternCount = model.PatternCount;
            this.frequencies  = model.Frequencies;

            this.indexCount        = topology.IndexCount;
            this.backtrack         = options.BacktrackPolicy != null;
            this.backtrackPolicy   = options.BacktrackPolicy;
            this.maxBacktrackDepth = options.MaxBacktrackDepth;
            this.constraints       = options.Constraints ?? new IWaveConstraint[0];
            this.topology          = topology;
            this.randomDouble      = options.RandomDouble ?? new Random().NextDouble;
            directionsCount        = topology.DirectionsCount;
            this.indexPicker       = options.IndexPicker ?? new EntropyTracker();
            this.patternPicker     = options.PatternPicker ?? new WeightedRandomPatternPicker();

            switch (options.ModelConstraintAlgorithm)
            {
            case ModelConstraintAlgorithm.OneStep:
                patternModelConstraint = new OneStepPatternModelConstraint(this, model);
                break;

            case ModelConstraintAlgorithm.Default:
            case ModelConstraintAlgorithm.Ac4:
                patternModelConstraint = new Ac4PatternModelConstraint(this, model);
                break;

            case ModelConstraintAlgorithm.Ac3:
                patternModelConstraint = new Ac3PatternModelConstraint(this, model);
                break;

            default:
                throw new Exception();
            }

            if (options.Clear)
            {
                Clear();
            }
        }
        private Tuple <IIndexPicker, IPatternPicker> MakePickers(TilePropagatorOptions options)
        {
            var pathConstraint         = options.Constraints?.OfType <EdgedPathConstraint>().FirstOrDefault();
            var connectedConstraint    = options.Constraints?.OfType <ConnectedConstraint>().FirstOrDefault();
            var connectedPickHeuristic = connectedConstraint != null && connectedConstraint.UsePickHeuristic;

            if (connectedPickHeuristic)
            {
                // Lists pickers that implement IFilteredIndexPicker
                if (options.IndexPickerType != IndexPickerType.Default &&
                    options.IndexPickerType != IndexPickerType.MinEntropy &&
                    options.IndexPickerType != IndexPickerType.Ordered)
                {
                    throw new Exception($"Connected Pick Heuristic is incompatible with the selected IndexPikcerType {options.IndexPickerType}");
                }
                if (options.IndexPickerType == IndexPickerType.Default)
                {
                    options.IndexPickerType = IndexPickerType.MinEntropy;
                }
            }

            // Use the appropriate random picker
            // Generally this is HeapEntropyTracker, but it doesn't support some features
            // so there's a few slower implementations for that
            IIndexPicker   indexPicker   = null;
            IPatternPicker patternPicker = null;

            switch (options.IndexPickerType)
            {
            case IndexPickerType.Ordered:
            {
                if (options.IndexOrder != null)
                {
                    indexPicker = new OrderedIndexPicker(options.IndexOrder);
                }
                else
                {
                    indexPicker = new SimpleOrderedIndexPicker();
                }
                break;
            }

            case IndexPickerType.ArrayPriorityMinEntropy:
            {
                if (options.WeightSetByIndex == null || options.WeightSets == null)
                {
                    throw new ArgumentNullException($"Expected WeightSetByIndex and WeightSets to be set");
                }
                if (options.TilePickerType != TilePickerType.ArrayPriority && options.TilePickerType != TilePickerType.Default)
                {
                    throw new Exception($"ArrayPriorityMinEntropy only works with Default tile picker");
                }

                var weightSetCollection = new WeightSetCollection(options.WeightSetByIndex, options.WeightSets, tileModelMapping);
                var entropyTracker      = new ArrayPriorityEntropyTracker(weightSetCollection);

                indexPicker   = entropyTracker;
                patternPicker = entropyTracker;
                break;
            }

            case IndexPickerType.MinEntropy:
            {
                indexPicker = new EntropyTracker();
                break;
            }

            case IndexPickerType.Default:
            case IndexPickerType.HeapMinEntropy:
            {
                indexPicker = new HeapEntropyTracker();
                break;
            }

            case IndexPickerType.Dirty:
            {
                // Create clean patterns
                if (tileModelMapping.TileCoordToPatternCoordIndexAndOffset != null)
                {
                    throw new NotSupportedException();
                }
                if (options.CleanTiles == null)
                {
                    throw new ArgumentNullException($"{nameof(options.CleanTiles)} is null");
                }
                var cleanPatterns = options.CleanTiles.Map(t => tileModelMapping.TilesToPatternsByOffset[0][t].First());

                indexPicker = new DirtyIndexPicker(new SimpleOrderedIndexPicker(), cleanPatterns);
                break;
            }

            default:
                throw new Exception($"Unknown IndexPickerType {options.IndexPickerType}");
            }

            if (patternPicker == null)
            {
                switch (options.TilePickerType)
                {
                case TilePickerType.Default:
                case TilePickerType.Weighted:
                    patternPicker = new WeightedRandomPatternPicker();
                    break;

                case TilePickerType.Ordered:
                    patternPicker = new SimpleOrderedPatternPicker();
                    break;

                case TilePickerType.ArrayPriority:
                    if (options.WeightSetByIndex == null || options.WeightSets == null)
                    {
                        throw new ArgumentNullException($"Expected WeightSetByIndex and WeightSets to be set");
                    }
                    var weightSetCollection = new WeightSetCollection(options.WeightSetByIndex, options.WeightSets, tileModelMapping);
                    patternPicker = new ArrayPriorityPatternPicker(weightSetCollection);
                    break;

                default:
                    throw new Exception($"Unknown TilePickerType {options.TilePickerType}");
                }
            }

            if (connectedPickHeuristic)
            {
                indexPicker = connectedConstraint.GetHeuristic(
                    (IFilteredIndexPicker)indexPicker,
                    this);
            }

            if (options.MemoizeIndices)
            {
                indexPicker = new MemoizeIndexPicker(indexPicker);
            }

            return(Tuple.Create(indexPicker, patternPicker));
        }