Exemple #1
0
 public static StageBits2 Mutate(this StageBits2 stageBits, IRando randy, double mutationRate)
 {
     return(new StageBits2(
                order: stageBits.Order,
                masks: stageBits.Masks.Mutate(randy, mutationRate),
                bits: stageBits.Bits.Mutate(randy, mutationRate)
                ));
 }
Exemple #2
0
        public static SbScratchPad ToSbScratchPad2(this StageBits2 stageBits)
        {
            var overlaps = stageBits.Order.SquareArrayCoords()
                           .Select(t =>
                                   new SbSpItem(row: t.Item1,
                                                col: t.Item2,
                                                overlap: stageBits.Overlap(row: t.Item1, col: t.Item2)));

            var scratchPad = new SbScratchPad(
                overlaps: overlaps,
                order: stageBits.Order);

            return(scratchPad);
        }
Exemple #3
0
        public static IPermutation ToPermutation(this StageBits2 stageBits)
        {
            var permArray    = 0u.CountUp(stageBits.Order).ToArray();
            var sbScratchPad = stageBits.ToSbScratchPad2();

            //System.Diagnostics.Debug.WriteLine(sbScratchPad.PrintOverlaps());
            //System.Diagnostics.Debug.WriteLine(sbScratchPad.PrintUsed());

            while (!sbScratchPad.IsSpent())
            {
                var dSbSp = sbScratchPad.BestOnDiag();
                dSbSp.IsUsed = true;
                var bSpSp = sbScratchPad.BestOnCol(dSbSp.Col);
                permArray[bSpSp.Col] = bSpSp.Row;
                permArray[bSpSp.Row] = bSpSp.Col;
                sbScratchPad.Mark(bSpSp, stageBits.Order);

                //  System.Diagnostics.Debug.WriteLine(sbScratchPad.PrintUsed());
            }

            return(PermutationEx.MakePermutation(permArray));
        }
Exemple #4
0
 public static ISorterStage ToSorterStage(this StageBits2 stageBits, uint stageNumber)
 {
     return(stageBits.ToPermutation().ToSorterStage(stageNumber));
 }