Generated on Mon Nov 30 23:53:19 2009 for Gecode by doxygen 1.6.1

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