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

Function main

contribs/qecode/examples/NimFibo.cpp:33–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31///////////////////////////////////////////////////////////////////////////////////////////
32
33int main() {
34 for (int N = 10; N<=22;N++) // Initial number of matches
35 {
36 clock_t start, finish;
37 start=clock();
38
39 int* scopeSize = new int[N+2];
40 bool* qtScope = new bool[N+2];
41 for (int i=0;i<N+2;i++) {
42 qtScope[i] = ( i%2 != 0);
43 scopeSize[i] = 2;
44 }
45 Qcop p(N+2,qtScope,scopeSize);
46
47 p.QIntVar(0,1,N-1);
48 p.QIntVar(1,0,N);
49 rel(*(p.space()),p.var(0) == p.var(1));
50 IntVarArgs b(2); b[0] = p.var(0) ; b[1] = p.var(1);
51 branch(*(p.space()),b,INT_VAR_SIZE_MIN(),INT_VAL_MIN());
52 p.nextScope();
53
54 for (int i=1;i<N+2;i++) {
55 p.QIntVar(2*i , 1, N-1);
56 p.QIntVar(2*i + 1, 0, N);
57 rel(*(p.space()), p.var(2*i) <= 2*p.var(2*(i-1)));
58 rel(*(p.space()), p.var(2*i + 1) == p.var(2*i) + p.var(2*i - 1));
59 IntVarArgs bb(2*i + 2);
60 for (int plop = 0;plop < (2*i + 2);plop++)
61 bb[plop] = p.var(plop);
62 branch(*(p.space()),bb,INT_VAR_SIZE_MIN(),INT_VAL_MIN());
63 p.nextScope();
64 }
65
66 p.makeStructure();
67 QCOP_solver s(&p);
68
69 unsigned long int nodes=0;
70
71 Strategy outcome = s.solve(nodes);
72 finish=clock();
73 cout << "For " << N << " matches : "<<endl;
74 cout << " outcome: " << ( outcome.isFalse() ? "FALSE" : "TRUE") << endl;
75 cout << " nodes visited: " << nodes << endl;
76 cout << "Time taken: " << (finish-start) << " microseconds."<<endl;
77 }
78 return 0;
79}

Callers

nothing calls this directly

Calls 10

INT_VAR_SIZE_MINFunction · 0.85
INT_VAL_MINFunction · 0.85
relFunction · 0.50
branchFunction · 0.50
QIntVarMethod · 0.45
spaceMethod · 0.45
varMethod · 0.45
nextScopeMethod · 0.45
makeStructureMethod · 0.45
solveMethod · 0.45

Tested by

no test coverage detected