| 114 | public: |
| 115 | |
| 116 | QCSPMatrixGame(const MatrixGameOptions& opt) : Script(opt), QSpaceInfo() |
| 117 | { |
| 118 | std::cout << "Loading problem" << std::endl; |
| 119 | if (!opt.printStrategy()) strategyMethod(0); // disable build and print strategy |
| 120 | using namespace Int; |
| 121 | int depth = opt.n;// Size of the matrix is 2^depth. Large values may take long to solve... |
| 122 | int boardSize = (int)pow((double)2,(double)depth); |
| 123 | std::srand(static_cast<unsigned int>(std::time(NULL))); |
| 124 | |
| 125 | // If a file is given we take the matrix from the file |
| 126 | bool bFile = false; |
| 127 | std::vector<int> tab; |
| 128 | if (opt.file() != NULL) { |
| 129 | std::ifstream inS(opt.file()); |
| 130 | if(!inS.is_open()) |
| 131 | bFile = false; |
| 132 | else { |
| 133 | bFile = true; |
| 134 | int x; |
| 135 | while (inS >> x) tab.push_back(x); |
| 136 | boardSize = (int)sqrt(tab.size()); |
| 137 | depth = (int) (log(boardSize) / log(2)); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | IntArgs board(boardSize*boardSize); |
| 142 | for (int i=0; i<boardSize; i++) |
| 143 | for (int j=0; j<boardSize; j++) |
| 144 | if (bFile) |
| 145 | board[j*boardSize+i] = tab[j*boardSize+i]; |
| 146 | else |
| 147 | board[j*boardSize+i] = (int)( (double)rand() / ((double)RAND_MAX + 1) * 50 ) < 25 ? 0:1; |
| 148 | |
| 149 | int nbDecisionVar = 2*depth; |
| 150 | IntArgs access(nbDecisionVar); |
| 151 | access[nbDecisionVar-1]=1; |
| 152 | access[nbDecisionVar-2]=boardSize; |
| 153 | for (int i=nbDecisionVar-3; i>=0; i--) |
| 154 | access[i]=access[i+2]*2; |
| 155 | |
| 156 | // Print initial board |
| 157 | if (opt.printBoard()) { |
| 158 | for (int i=0; i<boardSize; i++) |
| 159 | { |
| 160 | for (int j=0; j<boardSize; j++) |
| 161 | std::cout << board[i*boardSize+j] << " "; |
| 162 | std::cout << std::endl; |
| 163 | } |
| 164 | std::cout << std::endl; |
| 165 | } |
| 166 | |
| 167 | // Defining the player variables |
| 168 | IntVarArgs x; |
| 169 | X = IntVarArray(*this,nbDecisionVar,0,1); |
| 170 | for (int i=0; i<nbDecisionVar; i++) |
| 171 | { |
| 172 | x << X[i]; |
| 173 | if ((i%2) == 1) setForAll(*this, X[i]); |
nothing calls this directly
no test coverage detected