예제 #1
0
        public DelacorteGrid FillToCreateNewGrid(IEnumerable <int> permutation)
        {
            var output = new DelacorteGrid((int[, ])Array.Clone());

            output.FillWith(permutation);
            return(output);
        }
예제 #2
0
        private void Run(bool displayGridsMatchingBest)
        {
            Parallel.ForEach(gridsGenerated, grid =>
            {
                var result = new DelacorteGridEvaluator(grid).Evaluate();

                if (result > BestScore || (displayGridsMatchingBest && result == BestScore))
                {
                    BestScore = result;
                    bestGrid  = grid;
                    Console.WriteLine(grid + "   ==  " + result);
                }
                if (result < WorstScore || (displayGridsMatchingBest && result == WorstScore))
                {
                    WorstScore = result;
                    worstGrid  = grid;
                    Console.WriteLine(grid + "   ==  " + result);
                }
            });

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Best:");
            Console.WriteLine(bestGrid + "   ==  " + BestScore);
            Console.WriteLine("Worst:");
            Console.WriteLine(worstGrid + "   ==  " + WorstScore);
        }
예제 #3
0
 public ExhaustiveSearch(DelacorteGrid startingGrid, int n, int upperTarget, int lowerTarget)
 {
     gridsGenerated = new GridGenerator(n).GenerateAllGridsGivenPartialGrid(startingGrid);
     bestGrid       = null;
     worstGrid      = null;
     BestScore      = upperTarget;
     WorstScore     = lowerTarget;
 }
예제 #4
0
 public ExhaustiveSearch(int n, int upperTarget, int lowerTarget)
 {
     gridsGenerated = new GridGenerator(n).GenerateAllGridsFromScratch();
     bestGrid       = null;
     worstGrid      = null;
     BestScore      = upperTarget;
     WorstScore     = lowerTarget;
 }
예제 #5
0
        public IEnumerable <DelacorteGrid> GenerateAllGridsGivenPartialGrid(DelacorteGrid startingGrid)
        {
            List <int> remainingValuesToBeFilled = startingGrid.IdentifyUnusedValues();

            foreach (var permutation in SimpleNumberPermuter.GeneratePermutationsOfList(remainingValuesToBeFilled))
            {
                yield return(startingGrid.FillToCreateNewGrid(permutation));
            }
        }
예제 #6
0
        private static void BreakdownOfTemplate()
        {
            var template = new DelacorteGrid(4, 4, new[]
            {
                8, 0, 0, 12,
                0, 0, 0, 0,
                0, 0, 0, 0,
                4, 6, 0, 16
            });

            new DelacorteGridEvaluator(template).BreakDown();
        }
예제 #7
0
        private static void Solve4x4Min()
        {
            var template = new DelacorteGrid(4, 4, new[]
            {
                16, 6, 0, 0,
                8, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0
            });

            var x = new Stopwatch();

            x.Start();
            new ExhaustiveSearch(template, 4, int.MaxValue, int.MaxValue).RunWithDuplicates();
            x.Stop();
            Console.WriteLine("Completed");
            Console.WriteLine(x.ElapsedMilliseconds);
        }
예제 #8
0
        static void GridFillTimeBenchmark()
        {
            var x = new Stopwatch();

            x.Start();
            for (int i = 0; i < 50; i++)
            {
                DelacorteGrid y = null;
                foreach (var force in new GridGenerator(3).GenerateAllGridsFromScratch())
                {
                    y = force;
                }
                Console.WriteLine(y);
            }
            x.Stop();
            Console.WriteLine("Completed");
            Console.WriteLine(x.ElapsedMilliseconds);
        }
예제 #9
0
        private static void Solve4x4Max(DelacorteGrid template)
        {
            //var template = new DelacorteGrid(4, 4, new[]
            //{
            //    8, 0, 0, 12,
            //    0, 0, 0, 0,
            //    0, 0, 0, 0,
            //    6, 4, 0, 16
            //});

            Console.WriteLine(template);
            var x = new Stopwatch();

            x.Start();
            new ExhaustiveSearch(template, 4, int.MinValue, int.MinValue).RunWithDuplicates();
            x.Stop();
            Console.WriteLine(template);
            Console.WriteLine("Completed");
            Console.WriteLine(x.ElapsedMilliseconds);
        }
예제 #10
0
        private static void OtherScript()
        {
            var template = new DelacorteGrid(4, 4, new[]
            {
                8, 0, 0, 12,
                0, 0, 0, 14,
                7, 0, 0, 0,
                6, 4, 0, 16
            });

            var collection = new GridGenerator(4)
                             .GenerateAllGridsGivenPartialGrid(template)
                             .Select(grid => new DelacorteGridEvaluator(grid).Evaluate());

            Console.WriteLine(collection.Max());
            Console.WriteLine(collection.Min());
            var histogram = collection.GroupBy(i => i).OrderBy(i => i.Key).ToDictionary(group => group.Key, group => group.Count());

            foreach (var entry in histogram)
            {
                Console.WriteLine(entry.Key + "|" + entry.Value);
            }
        }
예제 #11
0
 public DelacorteGridEvaluator(DelacorteGrid grid)
 {
     xMax  = grid.X;
     yMax  = grid.Y;
     array = grid.Array;
 }
예제 #12
0
        private static void AssessConceptualBoundsOfLowScore()
        {
            var grid = new DelacorteGrid(4, 4, Enumerable.Repeat(1, 16));

            new DelacorteGridEvaluator(grid).BreakDown();
        }