29 : _scip(0), _n(n), _vars(n, vector<
SCIP_VAR *>(n)), _cons()
47 ostringstream namebuf;
48 for(
size_t i = 0;
i < _n; ++
i )
50 for(
size_t j = 0; j < _n; ++j )
54 namebuf <<
"x#" <<
i <<
"#" << j;
57 SCIP_CALL_EXC(
SCIPcreateVar(_scip, &
var, namebuf.str().c_str(), 0.0, 1.0, 1.0,
SCIP_VARTYPE_BINARY,
TRUE,
FALSE,
NULL,
NULL,
NULL,
NULL,
NULL) );
69 for(
size_t i = 0;
i < _n; ++
i )
81 for(
size_t j = 0; j < _n; ++j )
88 _cons.push_back(cons);
92 for(
size_t j = 0; j < _n; ++j )
96 namebuf <<
"col_" << j;
100 for(
size_t i = 0;
i < _n; ++
i )
104 _cons.push_back(cons);
111 for(
size_t j = 0; j < _n; ++j )
115 namebuf <<
"diag_col_down_" << j;
119 for(
size_t i = 0;
i < _n - j; ++
i )
122 _cons.push_back(cons);
126 for(
size_t i = 0;
i < _n; ++
i )
130 namebuf<<
"diag_row_down_"<<
i;
134 for(
size_t j = 0; j < _n -
i; ++j )
137 _cons.push_back(cons);
141 for(
size_t j = 0; j < _n; ++j )
145 namebuf<<
"diag_col_up_"<<j;
149 for(
size_t i = 0;
i < _n - j; ++
i )
152 _cons.push_back(cons);
156 for(
size_t i = 0;
i < _n; ++
i )
160 namebuf<<
"diag_row_up"<<
i;
164 for(
size_t j = 0; j < _n -
i; ++j )
167 _cons.push_back(cons);
177 out <<
"solution for " << _n <<
"-queens:" << endl << endl;
182 out <<
"no solution found" << endl;
186 for(
size_t i = 0;
i < _n; ++
i )
188 for(
size_t j = 0; j < _n; ++j )
192 for(
size_t j = 0; j < _n; ++j )
203 for(
size_t j = 0; j < _n; ++j)
215 for(
size_t i = 0;
i < _n; ++
i )
217 for (
size_t j = 0; j < _n; ++j )
223 for( vector<SCIP_CONS *>::size_type
i = 0;
i < _cons.size(); ++
i )
233 std::cerr <<
"SCIP Error: " << exp.
what() << std::endl;
exception handling class for SCIP
const char * what(void) const
returns the error message
~QueensSolver()
destructor this is the place to release the SCIP_VAR and SCIP_CONS pointers and to free the SCIP poin...
void solve(void)
solves the queens problem using SCIPsolve
QueensSolver(size_t n=8)
constructs the BP model for the n-queens problem
void disp(std::ostream &out=std::cout)
display the solution
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreate(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 SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
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 SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
void SCIPmessagehdlrSetQuiet(SCIP_MESSAGEHDLR *messagehdlr, SCIP_Bool quiet)
public methods for message output
exception handling for SCIP
#define SCIP_CALL_EXC(x)
macro to call scip function with exception handling
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
struct SCIP_Cons SCIP_CONS