| 153 | } |
| 154 | |
| 155 | void |
| 156 | SpaceNode::acquireSpace(NodeAllocator& na, |
| 157 | BestNode* curBest, int c_d, int a_d) { |
| 158 | SpaceNode* p = getParent(na); |
| 159 | int parentIdx = getParent(); |
| 160 | int idx = getIndex(na); |
| 161 | |
| 162 | if (getStatus() == UNDETERMINED && curBest != nullptr && |
| 163 | na.best(idx) == nullptr && |
| 164 | p != nullptr && curBest->s != na.best(parentIdx)) { |
| 165 | na.setBest(idx, curBest->s->getIndex(na)); |
| 166 | } |
| 167 | SpaceNode* ownBest = na.best(idx); |
| 168 | |
| 169 | if (copy == nullptr && p != nullptr && p->copy != nullptr && |
| 170 | Support::marked(p->copy)) { |
| 171 | // If parent has a working space, steal it |
| 172 | copy = p->copy; |
| 173 | p->copy = nullptr; |
| 174 | if (p->choice != nullptr) |
| 175 | static_cast<Space*>(Support::unmark(copy))-> |
| 176 | commit(*p->choice, getAlternative(na)); |
| 177 | |
| 178 | if (ownBest != nullptr) { |
| 179 | ownBest->acquireSpace(na,curBest, c_d, a_d); |
| 180 | Space* ownBestSpace = |
| 181 | static_cast<Space*>(Support::funmark(ownBest->copy)); |
| 182 | if (ownBestSpace->status() != SS_SOLVED) { |
| 183 | // in the presence of weakly monotonic propagators, we may have to |
| 184 | // use search to find the solution here |
| 185 | |
| 186 | ownBestSpace = Gecode::dfs(ownBestSpace); |
| 187 | if (Support::marked(ownBest->copy)) { |
| 188 | delete static_cast<Space*>(Support::unmark(ownBest->copy)); |
| 189 | ownBest->copy = |
| 190 | static_cast<Space*>(Support::mark(ownBestSpace)); |
| 191 | } else { |
| 192 | delete ownBest->copy; |
| 193 | ownBest->copy = ownBestSpace; |
| 194 | } |
| 195 | } |
| 196 | static_cast<Space*>(Support::unmark(copy))->constrain(*ownBestSpace); |
| 197 | } |
| 198 | int d = p->getDistance()+1; |
| 199 | if (d > c_d && c_d >= 0 && |
| 200 | static_cast<Space*>(Support::unmark(copy))->status() == SS_BRANCH) { |
| 201 | copy = static_cast<Space*>(Support::unmark(copy)); |
| 202 | d = 0; |
| 203 | } |
| 204 | setDistance(d); |
| 205 | } |
| 206 | |
| 207 | if (copy == nullptr) { |
| 208 | if (recompute(na, curBest, c_d, a_d) > c_d && c_d >= 0 && |
| 209 | static_cast<Space*>(Support::unmark(copy))->status() == SS_BRANCH) { |
| 210 | copy = static_cast<Space*>(Support::unmark(copy)); |
| 211 | setDistance(0); |
| 212 | } |
no test coverage detected