sudoku_main.cpp
Go to the documentation of this file.
73 * We have to define 9x9x9 variables. Let x_{ijk} where i = 1...9, j = 1...9 and k = 1..9 be those binary variables.
74 * x_{ijk} is the the binary variable representing the number k (1 or 2 or ... 9) in the ith row and jth column
76 std::vector<std::vector<std::vector< SCIP_VAR* >>> xvars(9, std::vector<std::vector< SCIP_VAR* >>(9, std::vector< SCIP_VAR* >(9)));
103 /* for each column j and each number k we must have that only one entry of column j is k; since x_{ijk} is 1
104 * if and only if the i-th entry of the j-th column is k, we can model this requirement with the following linear
117 /* we first create an empty equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
139 /* for each row i and each number k we must have that only one entry of row i is k; we can model
153 /* we first create an empty equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
176 * a subgrid is formed by the entries (i,j) such that i is in {p, p + 1, p + 2} and j is in {q, q + 1, q + 2} for
193 /* we first create an empty an equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
221 /* so far we have required that for each column, row, and subgrid only one occurence of {1, ..., 9} appears.
222 * However, we have not yet imposed that they must appear in different positions. So, for example, a solution
225 * Thus, by requiring that each entry (i,j) has a number assigned to it we obtain a correct model.
240 /* we first create an empty an equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
264 /* we use SCIPfixVar to fix the binary variables corresponding to the given value in the puzzle to 1.
265 * see https://www.scipopt.org/doc-7.0.1/html/group__PublicVariableMethods.php#ga7965b16efcb2f8cdf7e289198c5cbe16
272 /* The unsolved puzzle where there are blanks are represented by -1 in the puzzle datastructure */
288 /* in c++, we can set the SCIP parameters by <tt> sSCIPsetIntParam(SCIP* scip, "parameter", param_value) ) </tt> */
292 /* Some wrongly generated sudoku puzzles can be infeasible. So we use the solnstatus to display different types of
299 /* SCIP_STATUS_OPTIMAL status indicates that an optimal solution was found, hence we can print the final puzzle */
311 /* As we are using 0 based indices, to display the final puzzle, we should increment values by 1. */
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
Definition: cons_linear.c:18207
SCIP_RETCODE SCIPcreateConsBasicLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs)
Definition: cons_linear.c:18055
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
Definition: scip_prob.c:1242
SCIP_RETCODE SCIPcreateProbBasic(SCIP *scip, const char *name)
Definition: scip_prob.c:180
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:487
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1174
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1217
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8276
SCIP_RETCODE SCIPcreateVarBasic(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype)
Definition: scip_var.c:194
Definition: objbenders.h:44
void printSudoku(const std::vector< std::vector< int > > &sudokupuzzle)
Definition: sudoku_utils.h:88
std::vector< std::vector< int > > getSudokuPuzzle(std::string &filepath)
Definition: sudoku_utils.h:43
SCIP callable library.
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
Definition: scipdefplugins.c:37
default SCIP plugins
Definition: struct_cons.h:47
Definition: struct_sol.h:74
Definition: struct_var.h:208
Definition: struct_scip.h:70
A set of utilities that are used to read the puzzle and display the puzzle.