public void ApplyVariableHeuristics(VariableHeuristics heur) { varHeur = heur; if (heur == VariableHeuristics.DEFINITION_ORDER) { return; } if (heur == VariableHeuristics.RANDOM) { Random rand = new Random(10); Variables = Variables.OrderBy(v => rand.Next()).ToList(); } if (heur == VariableHeuristics.MIN_REMAINING_VALUES_DYN) { SelectNextVariable = SelectNextVariableMRV; } if (heur == VariableHeuristics.MOST_CONSTRAINED) { RemoveInitiallyBlockedValuesFromDomains(); Variables = Variables.OrderBy(v => v.Domain.Count).ToList(); foreach (SudokuVariable v in Variables) { v.ResetDomain(); } } }
public SudokuSolverAlgorithm(SudokuBook sudokuBook, VariableHeuristics variableHeursitics, ValueHeuristics valueHeuristics) { AllSolutions = new List <Sudoku>(); SudokuBook = sudokuBook; SolvingOrder = new List <VariableConstraint>(); VariableHeuristics = variableHeursitics; ValueHeuristics = valueHeuristics; }
public void ApplyVariableHeuristics(VariableHeuristics heur) { varHeur = heur; if (heur == VariableHeuristics.DEFINITION_ORDER) { return; } if (heur == VariableHeuristics.RANDOM) { Random rand = new Random(100); Variables = Variables.OrderBy(v => rand.Next()).ToList(); } if (heur == VariableHeuristics.MOST_CONSTRAINED) { Variables = Variables.OrderByDescending(v => Constraints[v].Count).ToList(); } if (heur == VariableHeuristics.ROWS_DESCENDING) { Variables = Variables.OrderBy(v => v.Horizontal ? v.SectionNum * 1000 + v.BeginIndex : v.SectionNum + v.BeginIndex * 1000).ToList(); } if (heur == VariableHeuristics.FROM_TOP_LEFT_CORNER) { Variables = Variables.OrderBy(v => v.SectionNum + v.BeginIndex).ToList(); } if (heur == VariableHeuristics.FROM_TOP_LEFT_LEAST_DOMAIN) { Variables = Variables.OrderBy(v => v.Domain.Count).OrderBy(v => v.SectionNum + v.BeginIndex).ToList(); } if (heur == VariableHeuristics.LEAST_DOMAIN) { Variables = Variables.OrderBy(v => v.Domain.Count).ToList(); } if (heur == VariableHeuristics.MIN_REMAINING_VALUES_DYN) { SelectNextVariable = SelectNextVariableMRV; } }
private void AssumeSolvingOrder() { SolvingOrder = VariableHeuristics.Assume(CurrentExample); }