void SearcherThread::search(VisualNode* n, bool all, TreeCanvas* ti) { node = n; depth = -1; for (VisualNode* p = n; p != NULL; p = p->getParent(*ti->na)) depth++; a = all; t = ti; start(); }
void TreeCanvas::mousePressEvent(QMouseEvent* event) { if (mutex.tryLock()) { if (event->button() == Qt::LeftButton) { VisualNode* n = eventNode(event); if (compareNodes) { if (n != NULL && n->getStatus() != UNDETERMINED && currentNode != NULL && currentNode->getStatus() != UNDETERMINED) { Space* curSpace = NULL; Space* compareSpace = NULL; for (int i=0; i<comparators.size(); i++) { if (comparators[i].second) { if (curSpace == NULL) { curSpace = currentNode->getSpace(*na,curBest,c_d,a_d); if (!compareNodesBeforeFP || n->isRoot()) { compareSpace = n->getSpace(*na,curBest,c_d,a_d); } else { VisualNode* p = n->getParent(*na); compareSpace = p->getSpace(*na,curBest,c_d,a_d); switch (compareSpace->status()) { case SS_SOLVED: case SS_FAILED: break; case SS_BRANCH: compareSpace->commit(*p->getChoice(), n->getAlternative(*na)); break; default: GECODE_NEVER; } } } comparators[i].first->compare(*curSpace,*compareSpace); } } } } else { setCurrentNode(n); } compareNodes = false; setCursor(QCursor(Qt::ArrowCursor)); if (n != NULL) { event->accept(); mutex.unlock(); return; } } mutex.unlock(); } event->ignore(); }
void TreeCanvas::centerCurrentNode(void) { QMutexLocker locker(&mutex); int x=0; int y=0; VisualNode* c = currentNode; while (c != NULL) { x += c->getOffset(); y += Layout::dist_y; c = c->getParent(*na); } x = static_cast<int>((xtrans+x)*scale); y = static_cast<int>(y*scale); QAbstractScrollArea* sa = static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget()); x -= sa->viewport()->width() / 2; y -= sa->viewport()->height() / 2; sourceX = sa->horizontalScrollBar()->value(); targetX = std::max(sa->horizontalScrollBar()->minimum(), x); targetX = std::min(sa->horizontalScrollBar()->maximum(), targetX); sourceY = sa->verticalScrollBar()->value(); targetY = std::max(sa->verticalScrollBar()->minimum(), y); targetY = std::min(sa->verticalScrollBar()->maximum(), targetY); if (!smoothScrollAndZoom) { sa->horizontalScrollBar()->setValue(targetX); sa->verticalScrollBar()->setValue(targetY); } else { scrollTimeLine.stop(); scrollTimeLine.setFrameRange(0,100); scrollTimeLine.setDuration(std::max(200, std::min(1000, std::min(std::abs(sourceX-targetX), std::abs(sourceY-targetY))))); scrollTimeLine.start(); } }
void NodeStatInspector::node(const VisualNode::NodeAllocator& na, VisualNode* n, const Statistics&, bool) { if (isVisible()) { int nd = -1; for (VisualNode* p = n; p != NULL; p = p->getParent(na)) nd++; nodeDepthLabel->setPlainText(QString("%1").arg(nd));; StatCursor sc(n,na); PreorderNodeVisitor<StatCursor> pnv(sc); pnv.run(); subtreeDepthLabel->setPlainText( QString("%1").arg(pnv.getCursor().depth)); solvedLabel->setPlainText(QString("%1").arg(pnv.getCursor().solved)); solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); failedLabel->setPlainText(QString("%1").arg(pnv.getCursor().failed)); failedLabel->setPos(44-failedLabel->document()->size().width(),120); choicesLabel->setPlainText(QString("%1").arg(pnv.getCursor().choice)); choicesLabel->setPos(66-choicesLabel->document()->size().width(),57); openLabel->setPlainText(QString("%1").arg(pnv.getCursor().open)); } }
/// TODO void Gist::on_canvas_statusChanged(VisualNode* n, const Statistics& stats, bool finished) { nodeStatInspector->node(execution->getNA(),n,stats,finished); /// for single node stats if (!finished) { showNodeStats->setEnabled(false); // stop-> setEnabled(true); // reset->setEnabled(false); navNextSol->setEnabled(false); navPrevSol->setEnabled(false); // searchNext->setEnabled(false); // searchAll->setEnabled(false); toggleHidden->setEnabled(false); hideFailed->setEnabled(false); // hideSize->setEnabled(false); // labelBranches->setEnabled(false); // labelPath->setEnabled(false); // toggleStop->setEnabled(false); // unstopAll->setEnabled(false); center->setEnabled(false); /// ?? exportPDF->setEnabled(false); exportWholeTreePDF->setEnabled(false); print->setEnabled(false); // printSearchLog->setEnabled(false); bookmarkNode->setEnabled(false); bookmarksGroup->setEnabled(false); } else { // stop->setEnabled(false); // reset->setEnabled(true); if ( (n->isOpen() || n->hasOpenChildren()) && (!n->isHidden()) ) { // searchNext->setEnabled(true); // searchAll->setEnabled(true); } else { // searchNext->setEnabled(false); // searchAll->setEnabled(false); } if (n->getNumberOfChildren() > 0) { toggleHidden->setEnabled(true); hideFailed->setEnabled(true); // hideSize->setEnabled(true); // unstopAll->setEnabled(true); } else { toggleHidden->setEnabled(false); hideFailed->setEnabled(false); // hideSize->setEnabled(false); // unhideAll->setEnabled(false); // unstopAll->setEnabled(false); } toggleStop->setEnabled(n->getStatus() == STOP || n->getStatus() == UNSTOP); showNodeStats->setEnabled(true); labelPath->setEnabled(true); VisualNode* root = n; while (!root->isRoot()) { root = root->getParent(execution->getNA()); } NextSolCursor nsc(n, false, execution->getNA()); PreorderNodeVisitor<NextSolCursor> nsv(nsc); nsv.run(); navNextSol->setEnabled(nsv.getCursor().node() != root); NextSolCursor psc(n, true, execution->getNA()); PreorderNodeVisitor<NextSolCursor> psv(psc); psv.run(); navPrevSol->setEnabled(psv.getCursor().node() != root); center->setEnabled(true); exportPDF->setEnabled(true); exportWholeTreePDF->setEnabled(true); print->setEnabled(true); printSearchLog->setEnabled(true); bookmarkNode->setEnabled(true); bookmarksGroup->setEnabled(true); } emit statusChanged(stats,finished); }
void TreeCanvas::inspectCurrentNode(bool fix, int inspectorNo) { QMutexLocker locker(&mutex); if (currentNode->isHidden()) { toggleHidden(); return; } int failedInspectorType = -1; int failedInspector = -1; bool needCentering = false; try { switch (currentNode->getStatus()) { case UNDETERMINED: { unsigned int kids = currentNode->getNumberOfChildNodes(*na,curBest,stats,c_d,a_d); int depth = -1; for (VisualNode* p = currentNode; p != NULL; p=p->getParent(*na)) depth++; if (kids > 0) { needCentering = true; depth++; } stats.maxDepth = std::max(stats.maxDepth, depth); if (currentNode->getStatus() == SOLVED) { assert(currentNode->hasCopy()); emit solution(currentNode->getWorkingSpace()); currentNode->purge(*na); } emit statusChanged(currentNode,stats,true); for (int i=0; i<moveInspectors.size(); i++) { if (moveInspectors[i].second) { failedInspectorType = 0; failedInspector = i; moveInspectors[i].first-> inspect(*currentNode->getWorkingSpace()); failedInspectorType = -1; } } } break; case FAILED: case STOP: case UNSTOP: case BRANCH: case SOLVED: { // SizeCursor sc(currentNode); // PreorderNodeVisitor<SizeCursor> pnv(sc); // int nodes = 1; // while (pnv.next()) { nodes++; } // std::cout << "sizeof(VisualNode): " << sizeof(VisualNode) // << std::endl; // std::cout << "Size: " << (pnv.getCursor().s)/1024 << std::endl; // std::cout << "Nodes: " << nodes << std::endl; // std::cout << "Size / node: " << (pnv.getCursor().s)/nodes // << std::endl; Space* curSpace; if (fix) { if (currentNode->isRoot() && currentNode->getStatus() == FAILED) break; curSpace = currentNode->getSpace(*na,curBest,c_d,a_d); if (currentNode->getStatus() == SOLVED && curSpace->status() != SS_SOLVED) { // in the presence of weakly monotonic propagators, we may have to // use search to find the solution here Space* dfsSpace = Gecode::dfs(curSpace); delete curSpace; curSpace = dfsSpace; } } else { if (currentNode->isRoot()) break; VisualNode* p = currentNode->getParent(*na); curSpace = p->getSpace(*na,curBest,c_d,a_d); switch (curSpace->status()) { case SS_SOLVED: case SS_FAILED: break; case SS_BRANCH: curSpace->commit(*p->getChoice(), currentNode->getAlternative(*na)); break; default: GECODE_NEVER; } } if (inspectorNo==-1) { for (int i=0; i<doubleClickInspectors.size(); i++) { if (doubleClickInspectors[i].second) { failedInspectorType = 1; failedInspector = i; doubleClickInspectors[i].first->inspect(*curSpace); failedInspectorType = -1; } } } else { failedInspectorType = 1; failedInspector = inspectorNo; doubleClickInspectors[inspectorNo].first->inspect(*curSpace); failedInspectorType = -1; } delete curSpace; } break; } } catch (Exception e) { switch (failedInspectorType) { case 0: std::cerr << "Exception in move inspector " << failedInspector; break; case 1: std::cerr << "Exception in double-click inspector " << failedInspector; break; default: std::cerr << "Exception "; break; } std::cerr << ": " << e.what() << "." << std::endl; std::cerr << "Stopping..." << std::endl; std::exit(EXIT_FAILURE); } currentNode->dirtyUp(*na); update(); if (needCentering) centerCurrentNode(); }