sudoku_main.cpp
Go to the documentation of this file.
64 * We have to define 9x9x9 variables. Let x_{ijk} where i = 1...9, j = 1...9 and k = 1..9 be those binary variables.
65 * x_{ijk} is the the binary variable representing the number k (1 or 2 or ... 9) in the ith row and jth column
67 std::vector<std::vector<std::vector< SCIP_VAR* >>> xvars(9, std::vector<std::vector< SCIP_VAR* >>(9, std::vector< SCIP_VAR* >(9)));
94 /* 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
95 * if and only if the i-th entry of the j-th column is k, we can model this requirement with the following linear
108 /* we first create an empty equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
130 /* for each row i and each number k we must have that only one entry of row i is k; we can model
144 /* we first create an empty equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
167 * 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
184 /* we first create an empty an equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
212 /* so far we have required that for each column, row, and subgrid only one occurence of {1, ..., 9} appears.
213 * However, we have not yet imposed that they must appear in different positions. So, for example, a solution
216 * Thus, by requiring that each entry (i,j) has a number assigned to it we obtain a correct model.
231 /* we first create an empty an equality constraint (i.e. the lhs and rhs are equal to 1) and then add the
255 /* we use SCIPfixVar to fix the binary variables corresponding to the given value in the puzzle to 1.
256 * see https://www.scipopt.org/doc-7.0.1/html/group__PublicVariableMethods.php#ga7965b16efcb2f8cdf7e289198c5cbe16
263 /* The unsolved puzzle where there are blanks are represented by -1 in the puzzle datastructure */
279 /* in c++, we can set the SCIP parameters by <tt> sSCIPsetIntParam(SCIP* scip, "parameter", param_value) ) </tt> */
283 /* Some wrongly generated sudoku puzzles can be infeasible. So we use the solnstatus to display different types of
290 /* SCIP_STATUS_OPTIMAL status indicates that an optimal solution was found, hence we can print the final puzzle */
302 /* As we are using 0 based indices, to display the final puzzle, we should increment values by 1. */
Definition: struct_scip.h:59
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
Definition: scip_prob.c:1240
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1353
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
Definition: cons_linear.c:18089
Definition: struct_var.h:198
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:185
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:17937
Definition: type_var.h:53
Definition: struct_sol.h:64
Definition: struct_cons.h:37
std::vector< std::vector< int > > getSudokuPuzzle(std::string &filepath)
Definition: sudoku_utils.h:34
Definition: type_stat.h:52
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
Definition: scipdefplugins.c:28
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8257
Definition: type_prob.h:39
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1110
Definition: objbenders.h:33
A set of utilities that are used to read the puzzle and display the puzzle.
default SCIP plugins
void printSudoku(const std::vector< std::vector< int >> &sudokupuzzle)
Definition: sudoku_utils.h:79
Definition: type_stat.h:53
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:503
SCIP_RETCODE SCIPcreateProbBasic(SCIP *scip, const char *name)
Definition: scip_prob.c:170
SCIP callable library.