MCPcopy Create free account
hub / github.com/Gecode/gecode / main

Function main

examples/queen-armies.cpp:273–319  ·  view source on GitHub ↗

\brief Main-function * \relates QueenArmies */

Source from the content-addressed store, hash-verified

271 * \relates QueenArmies
272 */
273int
274main(int argc, char* argv[]) {
275 SizeOptions opt("QueenArmies");
276 opt.size(6);
277 opt.branching(QueenArmies::BRANCH_SPECIFIC);
278 opt.branching(QueenArmies::BRANCH_NAIVE, "naive");
279 opt.branching(QueenArmies::BRANCH_SPECIFIC, "specific");
280 opt.solutions(0);
281 opt.parse(argc,argv);
282
283 // Set up the A-sets
284 // A[i] will contain the values attacked by a queen at position i
285 int n = opt.size();
286 A = new IntSet[n*n];
287 int *p = new int[std::max(n*n, 25)];
288 int pn = 0;
289 for (int i = n; i--; ) {
290 for (int j = n; j--; ) {
291 int dir[][2] = {
292 { 0, 1},
293 { 1, 1},
294 { 1, 0},
295 { 0, -1},
296 {-1, -1},
297 {-1, 0},
298 { 1, -1},
299 {-1, 1}
300 };
301 p[pn++] = pos(i, j, n);
302 for (int k = 8; k--; ) {
303 for (int l = 0; l < n
304 && 0 <= (i+l*dir[k][0]) && (i+l*dir[k][0]) < n
305 && 0 <= (j+l*dir[k][1]) && (j+l*dir[k][1]) < n; ++l) {
306 p[pn++] = pos(i+l*dir[k][0], j+l*dir[k][1], n);
307 }
308 }
309
310 A[pos(i, j, n)] = IntSet(p, pn);
311
312 pn = 0;
313 }
314 }
315 delete [] p;
316
317 IntMaximizeScript::run<QueenArmies,BAB,SizeOptions>(opt);
318 return 0;
319}
320
321// STATISTICS: example-any

Callers

nothing calls this directly

Calls 7

IntSetClass · 0.85
branchingMethod · 0.80
posFunction · 0.70
maxFunction · 0.50
sizeMethod · 0.45
solutionsMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected