| 371 | }; |
| 372 | |
| 373 | void |
| 374 | SearcherThread::run(void) { |
| 375 | { |
| 376 | if (!node->isOpen()) |
| 377 | return; |
| 378 | t->mutex.lock(); |
| 379 | emit statusChanged(false); |
| 380 | |
| 381 | unsigned int kids = |
| 382 | node->getNumberOfChildNodes(*t->na, t->curBest, t->stats, |
| 383 | t->c_d, t->a_d); |
| 384 | if (kids == 0 || node->getStatus() == STOP) { |
| 385 | t->mutex.unlock(); |
| 386 | updateCanvas(); |
| 387 | emit statusChanged(true); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | std::stack<SearchItem> stck; |
| 392 | stck.push(SearchItem(node,kids)); |
| 393 | t->stats.maxDepth = |
| 394 | std::max(static_cast<long unsigned int>(t->stats.maxDepth), |
| 395 | static_cast<long unsigned int>(depth+stck.size())); |
| 396 | |
| 397 | VisualNode* sol = nullptr; |
| 398 | int nodeCount = 0; |
| 399 | t->stopSearchFlag = false; |
| 400 | while (!stck.empty() && !t->stopSearchFlag) { |
| 401 | if (t->refresh > 0 && nodeCount >= t->refresh) { |
| 402 | node->dirtyUp(*t->na); |
| 403 | updateCanvas(); |
| 404 | emit statusChanged(false); |
| 405 | nodeCount = 0; |
| 406 | if (t->refreshPause > 0) |
| 407 | msleep(t->refreshPause); |
| 408 | } |
| 409 | SearchItem& si = stck.top(); |
| 410 | si.i++; |
| 411 | if (si.i == si.noOfChildren) { |
| 412 | stck.pop(); |
| 413 | } else { |
| 414 | VisualNode* n = si.n->getChild(*t->na,si.i); |
| 415 | if (n->isOpen()) { |
| 416 | if (n->getStatus() == UNDETERMINED) |
| 417 | nodeCount++; |
| 418 | kids = n->getNumberOfChildNodes(*t->na, t->curBest, t->stats, |
| 419 | t->c_d, t->a_d); |
| 420 | if (t->moveDuringSearch) |
| 421 | emit moveToNode(n,false); |
| 422 | if (kids == 0) { |
| 423 | if (n->getStatus() == SOLVED) { |
| 424 | assert(n->hasCopy()); |
| 425 | emit solution(n->getWorkingSpace()); |
| 426 | n->purge(*t->na); |
| 427 | sol = n; |
| 428 | if (!a) |
| 429 | break; |
| 430 | } |
no test coverage detected