Generated on Thu Apr 11 13:59:03 2019 for Gecode by doxygen 1.6.3

nodestats.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining
00014  * a copy of this software and associated documentation files (the
00015  * "Software"), to deal in the Software without restriction, including
00016  * without limitation the rights to use, copy, modify, merge, publish,
00017  * distribute, sublicense, and/or sell copies of the Software, and to
00018  * permit persons to whom the Software is furnished to do so, subject to
00019  * the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/gist/nodestats.hh>
00035 #include <gecode/gist/nodewidget.hh>
00036 #include <gecode/gist/nodecursor.hh>
00037 #include <gecode/gist/nodevisitor.hh>
00038 #include <gecode/gist/drawingcursor.hh>
00039 
00040 namespace Gecode { namespace Gist {
00041 
00042   NodeStatInspector::NodeStatInspector(QWidget* parent)
00043     : QWidget(parent) {
00044     setWindowFlags(Qt::Tool);
00045     QGraphicsScene* scene = new QGraphicsScene();
00046 
00047     scene->addEllipse(70,10,16,16,QPen(),QBrush(DrawingCursor::white));
00048     scene->addEllipse(70,60,16,16,QPen(),QBrush(DrawingCursor::blue));
00049     scene->addRect(32,100,12,12,QPen(),QBrush(DrawingCursor::red));
00050 
00051     QPolygonF poly;
00052     poly << QPointF(78,100) << QPointF(78+8,100+8)
00053          << QPointF(78,100+16) << QPointF(78-8,100+8);
00054     scene->addPolygon(poly,QPen(),QBrush(DrawingCursor::green));
00055 
00056     scene->addEllipse(110,100,16,16,QPen(),QBrush(DrawingCursor::white));
00057 
00058     QPen pen;
00059     pen.setStyle(Qt::DotLine);
00060     pen.setWidth(0);
00061     scene->addLine(78,26,78,60,pen);
00062     scene->addLine(78,76,38,100,pen);
00063     scene->addLine(78,76,78,100,pen);
00064     scene->addLine(78,76,118,100,pen);
00065 
00066     scene->addLine(135,10,145,10);
00067     scene->addLine(145,10,145,110);
00068     scene->addLine(145,60,135,60);
00069     scene->addLine(145,110,135,110);
00070 
00071     nodeDepthLabel = scene->addText("0");
00072     nodeDepthLabel->setPos(150,20);
00073     subtreeDepthLabel = scene->addText("0");
00074     subtreeDepthLabel->setPos(150,75);
00075 
00076     choicesLabel = scene->addText("0");
00077     choicesLabel->setPos(45,57);
00078 
00079     solvedLabel = scene->addText("0");
00080     solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120);
00081     failedLabel = scene->addText("0");
00082     failedLabel->setPos(30,120);
00083     openLabel = scene->addText("0");
00084     openLabel->setPos(110,120);
00085 
00086     QGraphicsView* view = new QGraphicsView(scene);
00087     view->setRenderHints(view->renderHints() | QPainter::Antialiasing);
00088     view->show();
00089 
00090     scene->setBackgroundBrush(Qt::white);
00091 
00092     boxLayout = new QVBoxLayout();
00093     boxLayout->setContentsMargins(0,0,0,0);
00094     boxLayout->addWidget(view);
00095     setLayout(boxLayout);
00096 
00097     setWindowTitle("Gist node statistics");
00098     setAttribute(Qt::WA_QuitOnClose, false);
00099     setAttribute(Qt::WA_DeleteOnClose, false);
00100   }
00101 
00102   void
00103   NodeStatInspector::node(const VisualNode::NodeAllocator& na,
00104                           VisualNode* n, const Statistics&, bool) {
00105     if (isVisible()) {
00106       int nd = -1;
00107       for (VisualNode* p = n; p != NULL; p = p->getParent(na))
00108         nd++;
00109       nodeDepthLabel->setPlainText(QString("%1").arg(nd));;
00110       StatCursor sc(n,na);
00111       PreorderNodeVisitor<StatCursor> pnv(sc);
00112       pnv.run();
00113 
00114       subtreeDepthLabel->setPlainText(
00115         QString("%1").arg(pnv.getCursor().depth));
00116       solvedLabel->setPlainText(QString("%1").arg(pnv.getCursor().solved));
00117       solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120);
00118       failedLabel->setPlainText(QString("%1").arg(pnv.getCursor().failed));
00119       failedLabel->setPos(44-failedLabel->document()->size().width(),120);
00120       choicesLabel->setPlainText(QString("%1").arg(pnv.getCursor().choice));
00121       choicesLabel->setPos(66-choicesLabel->document()->size().width(),57);
00122       openLabel->setPlainText(QString("%1").arg(pnv.getCursor().open));
00123     }
00124   }
00125 
00126   void
00127   NodeStatInspector::showStats(void) {
00128     show();
00129     activateWindow();
00130   }
00131 
00132 }}
00133 
00134 // STATISTICS: gist-any