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

Function main

contribs/qecode/examples/MatrixGame.cpp:46–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44using namespace MiniModel;
45
46int main (int argc, char * const argv[]) {
47
48 int depth = 5; // Size of the matrix is 2^depth. Larger values may take long to solve...
49 int nbDecisionVar = 2*depth;
50 int nbScope = nbDecisionVar+1;
51 bool* qtScopes = new bool[nbScope];
52 for (int i=0;i<nbScope;i++) {
53 qtScopes[i] = ((i%2) != 0);
54// cout << (((i%2) != 0)?"true":"false")<<endl;
55 }
56 int boardSize = (int)pow((double)2,(double)depth);
57
58 std::srand(std::time(NULL));
59
60 IntArgs board(boardSize*boardSize);
61 for (int i=0; i<boardSize; i++)
62 for (int j=0; j<boardSize; j++)
63 board[j*boardSize+i] = (int)( (double)rand() / ((double)RAND_MAX + 1) * 50 ) < 25 ? 0:1;
64
65 IntArgs access(nbDecisionVar);
66 access[nbDecisionVar-1]=1;
67 access[nbDecisionVar-2]=boardSize;
68 for (int i=nbDecisionVar-3; i>=0; i--)
69 access[i]=access[i+2]*2;
70
71 // debug
72 for (int i=0; i<boardSize; i++)
73 {
74 for (int j=0; j<boardSize; j++)
75 cout << board[j*boardSize+i] << " ";
76 cout << endl;
77 }
78 cout << endl;
79 // for (int i=0; i<nbDecisionVar; i++)
80// cout << access[i] << " ";
81// cout << endl;
82 // end debug
83
84 int * scopesSize = new int[nbScope];
85 for (int i=0; i<nbScope-1; i++)
86 scopesSize[i]=1;
87 scopesSize[nbScope-1]=2;
88
89 Qcop p(nbScope, qtScopes, scopesSize);
90
91 // Defining the variable of the n first scopes ...
92 for (int i=0; i<nbDecisionVar; i++)
93 {
94 p.QIntVar(i, 0, 1);
95 IntVarArgs b(i+1);
96 for (int plop=0;plop<(i+1);plop++)
97 b[plop] = p.var(plop);
98 branch(*(p.space()),b,INT_VAR_SIZE_MIN(),INT_VAL_MIN());
99 p.nextScope();
100 }
101
102 // Declaring last scope variables ...
103

Callers

nothing calls this directly

Calls 13

INT_VAR_SIZE_MINFunction · 0.85
INT_VAL_MINFunction · 0.85
powFunction · 0.50
branchFunction · 0.50
relFunction · 0.50
linearFunction · 0.50
elementFunction · 0.50
QIntVarMethod · 0.45
varMethod · 0.45
spaceMethod · 0.45
nextScopeMethod · 0.45
makeStructureMethod · 0.45

Tested by

no test coverage detected