public static ISolver GetSolver() { // FIXME: Allow control over which solver is used // FIXME: Relative paths are fragile! // Look in the directory of the symbooglix binaries for solver var pathToSolver = "../../../Symbooglix/bin/{0}/z3".Replace('/', Path.DirectorySeparatorChar); // Depending on the build type choose which directory we search for the Solver #if DEBUG pathToSolver = String.Format(pathToSolver, "Debug"); #else pathToSolver = String.Format(pathToSolver, "Release"); #endif if (!File.Exists(pathToSolver)) { pathToSolver += ".exe"; } if (!File.Exists(pathToSolver)) { Assert.Fail("Could not find solver at \"{0}\"", pathToSolver); } var solver = new SimpleSolver(new Z3SMTLIBSolver(/*useNamedAttributes=*/ true, pathToSolver, /*persistentProcess=*/ true, true)); solver.SetTimeout(10); return(solver); }
protected override ISolverBundle Solver(SlotClusterFixed <ConstrainedSlot, CylinderBrain> cluster) { typedSolver = new SimpleSolver <ConstrainedSlot, ConstrainedSlotInfos, CylinderBrain>(); typedSolver.slotCluster = cluster; solver = typedSolver; return(solver); }
/// <summary> /// Solve the board /// </summary> /// <param name="boardData">the board to solve</param> /// <returns>true if a solution can be found</returns> public bool Solve(int[,] boardData) { if (SimpleSolver.IsConsistent(boardData)) { this.SolveInternal(boardData); return(this.solutionCount > 0); } return(false); }
public void TestInitialize() { if (Rc == null) { Rc = new Cube(); } if (Solver == null) { Solver = new SimpleSolver(Rc); } }
public async Task SolveTest(string path, int solutionsCount) { var absPath = Path.Combine(TestContext.CurrentContext.TestDirectory, path); var sudoku = await SudokuAdapter.ReadFromFileAsync(absPath); var solver = new SimpleSolver(); var actualSolutionsCount = solver.CountSolutions(sudoku); Assert.AreEqual(solutionsCount, actualSolutionsCount); }
public async Task TestTopNSolutions(string path, int solutionsLimit, Enums.TopType type, int expectedDifficulty) { var absPath = Path.Combine(TestContext.CurrentContext.TestDirectory, path); var sudoku = await SudokuAdapter.ReadFromFileAsync(absPath); var solver = new SimpleSolver(); var solutions = solver.GetTopNSolutions(sudoku, solutionsLimit, type); Assert.AreEqual(solutionsLimit, solutions.Count); Assert.AreEqual(expectedDifficulty, solutions.First().DifficultyPoints); }
public IActionResult Index(Dictionary <string, string> grid) { var model = new HomeViewModel { Grid = grid }; var solver = new SimpleSolver(determineBoardSize(grid)); var board = convertBoard(grid); if (solver.Solve(board)) { model.Grid = convertBoard(solver.GetFirstSolution()); } return(View(model)); }
public void CanSolveBoards() { int i = 0; foreach (var board in GetBoards()) { i++; var result = SimpleSolver.Solve(board); Assert.True(result.Solved); } //var result = Solver.Solve(GetBoards()[0]); //Assert.True(result.IsSolved); }
public SudokuGrid CreateGrid(Difficulty difficulty) { ISudokuSolver solver = new SimpleSolver(seed: _seed, asGenerator: true); var grid = new SudokuGrid(); PreAddToGrid(ref grid); var(success, solvedGrid) = solver.Solve(grid); // Minimize risk of getting a similar looking puzzle RandomizeLayout(ref solvedGrid); // Remove elements to match the difficulty RemoveElements(ref solvedGrid, difficulty); SetEnabledStates(ref solvedGrid); return(solvedGrid); }
private async void SolveButton_Click(object sender, EventArgs e) { var solvedSudoku = await Task.Run(() => { var solver = new SimpleSolver(); return(solver.SolveSudoku(_model.CurrentSudoku)); }); if (solvedSudoku == null) { MessageBox.Show(@"This Sudoku does not have any solution"); } else { _model.CurrentSudoku = solvedSudoku; UpdateLabelsUi(); } }
public static Executor GetExecutor(Program p, IStateScheduler scheduler = null, ISolver solver = null, bool useConstantFolding = false) { if (scheduler == null) { scheduler = new DFSStateScheduler(); } if (solver == null) { solver = new SimpleSolver(new DummySolver()); } IExprBuilder builder = new SimpleExprBuilder(/*immutable=*/ true); if (useConstantFolding) { builder = new ConstantFoldingExprBuilder(new ConstantCachingExprBuilder(builder)); } Executor e = new Executor(p, scheduler, solver, builder, new SimpleSymbolicPool()); return(e); }
private int RemoveElementsRandomly(ref SudokuGrid grid, int toRemove) { if (toRemove == 0) { return(toRemove); } // Remove cells at random while attempting to keep a single unique solution: // Remove a cell at random, and attempt to solve the puzzle using remaining numbers, // If not possible the removal is a success. If possible, reset the value and move on. var values = Enumerable.Range(0, 80).ToList(); values.Shuffle(_seed); var solver = new SimpleSolver(); foreach (var cell in values) { var x = cell % 9; var y = cell / 9; if (grid.Grid[x, y].Value == 0) { continue; } var originalValue = grid.Grid[x, y].Value; var complementNumbers = Enumerable.Range(1, 9).Except(new List <int>(grid.Grid[x, y].Value)); var ambiguous = false; foreach (var number in complementNumbers) { var validValuesForCell = grid.ValidValues(x, y); if (validValuesForCell.Contains(number)) { // No need to check if it is not possible to place the number continue; } grid.Grid[x, y].Value = number; var tempGrid = grid.DeepClone(); var(success, _) = solver.Solve(tempGrid); if (success) { //Console.WriteLine($"Failed check for ({x},{y}) for value {number}. Original: {originalValue}"); grid.Grid[x, y].Value = originalValue; ambiguous = true; break; } } if (ambiguous == false) { Console.WriteLine($"Success check for ({x},{y}). Original: {originalValue}"); grid.Grid[x, y].Value = 0; toRemove--; if (toRemove == 0) { return(toRemove); } } } return(toRemove); }