public DelacorteGrid FillToCreateNewGrid(IEnumerable <int> permutation) { var output = new DelacorteGrid((int[, ])Array.Clone()); output.FillWith(permutation); return(output); }
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); }
public ExhaustiveSearch(DelacorteGrid startingGrid, int n, int upperTarget, int lowerTarget) { gridsGenerated = new GridGenerator(n).GenerateAllGridsGivenPartialGrid(startingGrid); bestGrid = null; worstGrid = null; BestScore = upperTarget; WorstScore = lowerTarget; }
public ExhaustiveSearch(int n, int upperTarget, int lowerTarget) { gridsGenerated = new GridGenerator(n).GenerateAllGridsFromScratch(); bestGrid = null; worstGrid = null; BestScore = upperTarget; WorstScore = lowerTarget; }
public IEnumerable <DelacorteGrid> GenerateAllGridsGivenPartialGrid(DelacorteGrid startingGrid) { List <int> remainingValuesToBeFilled = startingGrid.IdentifyUnusedValues(); foreach (var permutation in SimpleNumberPermuter.GeneratePermutationsOfList(remainingValuesToBeFilled)) { yield return(startingGrid.FillToCreateNewGrid(permutation)); } }
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(); }
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); }
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); }
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); }
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); } }
public DelacorteGridEvaluator(DelacorteGrid grid) { xMax = grid.X; yMax = grid.Y; array = grid.Array; }
private static void AssessConceptualBoundsOfLowScore() { var grid = new DelacorteGrid(4, 4, Enumerable.Repeat(1, 16)); new DelacorteGridEvaluator(grid).BreakDown(); }