public void TestWave2() { var r = new Random(); var frequencies = new double[] { 2, 1, 1 }; var wave = new Wave(frequencies.Length, 2); var entropyTracker = new HeapEntropyTracker(wave, frequencies, null, r.NextDouble); entropyTracker.Reset(); Assert.IsFalse(wave.RemovePossibility(0, 0)); entropyTracker.DoBan(0, 0); Assert.AreEqual(0, entropyTracker.GetRandomIndex(r.NextDouble)); Assert.IsFalse(wave.RemovePossibility(1, 2)); entropyTracker.DoBan(1, 2); Assert.AreEqual(1, entropyTracker.GetRandomIndex(r.NextDouble)); Assert.IsFalse(wave.RemovePossibility(1, 0)); entropyTracker.DoBan(1, 0); Assert.AreEqual(0, entropyTracker.GetRandomIndex(r.NextDouble)); Assert.IsFalse(wave.RemovePossibility(0, 1)); entropyTracker.DoBan(0, 1); Assert.AreEqual(-1, entropyTracker.GetRandomIndex(r.NextDouble)); Assert.IsTrue(wave.RemovePossibility(0, 2)); entropyTracker.DoBan(0, 2); }
private IPickHeuristic MakePickHeuristic(WavePropagator wavePropagator, TilePropagatorOptions options) { var waveFrequencySets = options.Weights == null ? null : GetFrequencySets(options.Weights, tileModelMapping); var randomDouble = wavePropagator.RandomDouble; var patternTopology = wavePropagator.Topology; var pathConstraint = options.Constraints?.OfType <EdgedPathConstraint>().FirstOrDefault(); var pathPickHeuristic = pathConstraint != null && pathConstraint.UsePickHeuristic; var connectedConstraint = options.Constraints?.OfType <ConnectedConstraint>().FirstOrDefault(); var connectedPickHeuristic = connectedConstraint != null && connectedConstraint.UsePickHeuristic; // 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 IRandomPicker randomPicker; if (options.PickHeuristicType == PickHeuristicType.Ordered) { randomPicker = new OrderedRandomPicker(wavePropagator.Wave, wavePropagator.Frequencies, patternTopology.Mask); } else if (waveFrequencySets != null) { var entropyTracker = new ArrayPriorityEntropyTracker(wavePropagator.Wave, waveFrequencySets, patternTopology.Mask); entropyTracker.Reset(); wavePropagator.AddTracker(entropyTracker); randomPicker = entropyTracker; } else if (pathPickHeuristic || connectedPickHeuristic) { var entropyTracker = new EntropyTracker(wavePropagator.Wave, wavePropagator.Frequencies, patternTopology.Mask); entropyTracker.Reset(); wavePropagator.AddTracker(entropyTracker); randomPicker = entropyTracker; } else { var entropyTracker = new HeapEntropyTracker(wavePropagator.Wave, wavePropagator.Frequencies, patternTopology.Mask, randomDouble); entropyTracker.Reset(); wavePropagator.AddTracker(entropyTracker); randomPicker = entropyTracker; } IPickHeuristic heuristic = new RandomPickerHeuristic(randomPicker, randomDouble); if (pathPickHeuristic) { heuristic = pathConstraint.GetHeuristic( randomPicker, randomDouble, this, tileModelMapping, heuristic); } if (connectedPickHeuristic) { heuristic = connectedConstraint.GetHeuristic( randomPicker, randomDouble, this, tileModelMapping, heuristic); } return(heuristic); }