39int main(
int argc,
char *argv[])
50 std::cerr <<
"call " << argv[0] <<
" <puzzle file> " <<
"\n";
54 std::string puzzlefilepath = argv[1];
56 std::cout <<
"The unsolved Sudoku Puzzle is: " <<
"\n";
76 std::vector<std::vector<std::vector< SCIP_VAR* >>> xvars(9, std::vector<std::vector< SCIP_VAR* >>(9, std::vector< SCIP_VAR* >(9)));
77 std::ostringstream namebuf;
79 for(
i = 0;
i < 9; ++
i )
81 for( j = 0; j < 9; ++j )
83 for( k = 0; k < 9; ++k )
87 namebuf <<
"x[" <<
i <<
"," << j <<
"," << k <<
"]";
91 namebuf.str().c_str(),
108 std::vector< SCIP_CONS* > columnconstraints;
109 for( j = 0; j < 9; ++j )
111 for( k = 0; k < 9; ++k )
115 namebuf <<
"col_" << j <<
"_" << k <<
"]";
123 namebuf.str().c_str(),
129 for(
i = 0;
i < 9; ++
i )
135 columnconstraints.push_back(cons);
143 std::vector< SCIP_CONS* > rowconstraints;
144 for(
i = 0;
i < 9; ++
i )
146 for( k = 0; k < 9; ++k )
151 namebuf <<
"row_" <<
i <<
"_" << k <<
"]";
159 namebuf.str().c_str(),
165 for( j = 0; j < 9; ++j )
171 rowconstraints.push_back(cons);
181 std::vector< SCIP_CONS* > subgridconstraints;
182 for( k = 0; k < 9; ++k )
184 for( p = 0; p < 3; ++p )
186 for( q = 0; q < 3; ++q )
191 namebuf <<
"subgrid_" << k <<
"_" << p <<
"_" << q <<
"]";
199 namebuf.str().c_str(),
207 for( j = 3 * (p + 1) - 3; j < 3 * (p + 1); ++j )
209 for(
i = 3 * (q + 1) - 3;
i < 3 * (q + 1); ++
i )
215 subgridconstraints.push_back(cons);
230 std::vector< SCIP_CONS* > fillgridconstraints;
231 for(
i = 0;
i < 9; ++
i )
233 for( j = 0; j < 9; ++j )
238 namebuf <<
"fillgrid_" <<
i <<
"_" << j <<
"]";
246 namebuf.str().c_str(),
253 for( k = 0; k < 9; ++k )
259 fillgridconstraints.push_back(cons);
268 for(
i = 0;
i < 9; ++
i )
270 for( j = 0; j < 9; ++j )
273 if( puzzle[
i][j] > 0 )
303 for(
i = 0;
i < 9; ++
i )
305 for( j = 0; j < 9; ++j )
307 for( k = 0; k < 9; ++k )
312 puzzle[
i][j] = k + 1;
317 std::cout <<
"The solved puzzle is: "
324 std::cout <<
"Check the Input puzzle"
329 std::cerr <<
"Something went wrong during the optimization." <<
"\n";
334 for(
i = 0;
i < 9; ++
i )
336 for( j = 0; j < 9; ++j )
338 for( k = 0; k < 9; ++k )
349 for(
auto &constr : columnconstraints )
353 columnconstraints.clear();
355 for(
auto &constr : rowconstraints )
359 rowconstraints.clear();
361 for(
auto &constr : subgridconstraints )
365 subgridconstraints.clear();
367 for(
auto &constr : fillgridconstraints )
371 fillgridconstraints.clear();
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
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)
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
SCIP_STATUS SCIPgetStatus(SCIP *scip)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
SCIP_RETCODE SCIPcreateProbBasic(SCIP *scip, const char *name)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
SCIP_RETCODE SCIPcreateVarBasic(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype)
assert(minobj< SCIPgetCutoffbound(scip))
void printSudoku(const std::vector< std::vector< int > > &sudokupuzzle)
std::vector< std::vector< int > > getSudokuPuzzle(std::string &filepath)
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
int main(int argc, char *argv[])
A set of utilities that are used to read the puzzle and display the puzzle.
struct SCIP_Cons SCIP_CONS
enum SCIP_Status SCIP_STATUS