(
intargc,
char*argv[])
50std::cerr <<
"call "<< argv[0] <<
" <puzzle file> "<<
"\n";
54std::string puzzlefilepath = argv[1];
56std::cout <<
"The unsolved Sudoku Puzzle is: "<<
"\n";
76std::vector<std::vector<std::vector< SCIP_VAR* >>> xvars(9, std::vector<std::vector< SCIP_VAR* >>(9, std::vector< SCIP_VAR* >(9)));
77std::ostringstream namebuf;
79 for( i = 0; i < 9; ++i )
81 for( j = 0; j < 9; ++j )
83 for( k = 0; k < 9; ++k )
87namebuf <<
"x["<< i <<
","<< j <<
","<< k <<
"]";
91namebuf.str().c_str(),
108std::vector< SCIP_CONS* > columnconstraints;
109 for( j = 0; j < 9; ++j )
111 for( k = 0; k < 9; ++k )
115namebuf <<
"col_"<< j <<
"_"<< k <<
"]";
123namebuf.str().c_str(),
129 for( i = 0; i < 9; ++i )
135columnconstraints.push_back(cons);
143std::vector< SCIP_CONS* > rowconstraints;
144 for( i = 0; i < 9; ++i )
146 for( k = 0; k < 9; ++k )
151namebuf <<
"row_"<< i <<
"_"<< k <<
"]";
159namebuf.str().c_str(),
165 for( j = 0; j < 9; ++j )
171rowconstraints.push_back(cons);
181std::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 )
191namebuf <<
"subgrid_"<< k <<
"_"<< p <<
"_"<< q <<
"]";
199namebuf.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 )
215subgridconstraints.push_back(cons);
230std::vector< SCIP_CONS* > fillgridconstraints;
231 for( i = 0; i < 9; ++i )
233 for( j = 0; j < 9; ++j )
238namebuf <<
"fillgrid_"<< i <<
"_"<< j <<
"]";
246namebuf.str().c_str(),
253 for( k = 0; k < 9; ++k )
259fillgridconstraints.push_back(cons);
268 for( i = 0; i < 9; ++i )
270 for( j = 0; j < 9; ++j )
273 if( puzzle[i][j] > 0 )
280assert(fixed ==
TRUE);
282assert(infeasible ==
FALSE);
303 for( i = 0; i < 9; ++i )
305 for( j = 0; j < 9; ++j )
307 for( k = 0; k < 9; ++k )
312puzzle[i][j] = k + 1;
317std::cout <<
"The solved puzzle is: " 324std::cout <<
"Check the Input puzzle" 329std::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 )
353columnconstraints.clear();
355 for(
auto&constr : rowconstraints )
359rowconstraints.clear();
361 for(
auto&constr : subgridconstraints )
365subgridconstraints.clear();
367 for(
auto&constr : fillgridconstraints )
371fillgridconstraints.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)
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.
enum SCIP_Status SCIP_STATUS
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4