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: 2010-08-11 12:41:24 +0200 (Wed, 11 Aug 2010) $ by $Author: tack $ 00011 * $Revision: 11340 $ 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) 00047 : QWidget(parent) { 00048 setWindowFlags(Qt::Tool); 00049 QGraphicsScene* scene = new QGraphicsScene(); 00050 00051 scene->addEllipse(70,10,16,16,QPen(),QBrush(DrawingCursor::white)); 00052 scene->addEllipse(70,60,16,16,QPen(),QBrush(DrawingCursor::blue)); 00053 scene->addRect(32,100,12,12,QPen(),QBrush(DrawingCursor::red)); 00054 00055 QPolygonF poly; 00056 poly << QPointF(78,100) << QPointF(78+8,100+8) 00057 << QPointF(78,100+16) << QPointF(78-8,100+8); 00058 scene->addPolygon(poly,QPen(),QBrush(DrawingCursor::green)); 00059 00060 scene->addEllipse(110,100,16,16,QPen(),QBrush(DrawingCursor::white)); 00061 00062 QPen pen; 00063 pen.setStyle(Qt::DotLine); 00064 pen.setWidth(0); 00065 scene->addLine(78,26,78,60,pen); 00066 scene->addLine(78,76,38,100,pen); 00067 scene->addLine(78,76,78,100,pen); 00068 scene->addLine(78,76,118,100,pen); 00069 00070 scene->addLine(135,10,145,10); 00071 scene->addLine(145,10,145,110); 00072 scene->addLine(145,60,135,60); 00073 scene->addLine(145,110,135,110); 00074 00075 nodeDepthLabel = scene->addText("0"); 00076 nodeDepthLabel->setPos(150,20); 00077 subtreeDepthLabel = scene->addText("0"); 00078 subtreeDepthLabel->setPos(150,75); 00079 00080 choicesLabel = scene->addText("0"); 00081 choicesLabel->setPos(45,57); 00082 00083 solvedLabel = scene->addText("0"); 00084 solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); 00085 failedLabel = scene->addText("0"); 00086 failedLabel->setPos(30,120); 00087 openLabel = scene->addText("0"); 00088 openLabel->setPos(110,120); 00089 00090 QGraphicsView* view = new QGraphicsView(scene); 00091 view->setRenderHints(view->renderHints() | QPainter::Antialiasing); 00092 view->show(); 00093 00094 scene->setBackgroundBrush(Qt::white); 00095 00096 boxLayout = new QVBoxLayout(); 00097 boxLayout->setContentsMargins(0,0,0,0); 00098 boxLayout->addWidget(view); 00099 setLayout(boxLayout); 00100 00101 setWindowTitle("Gist node statistics"); 00102 setAttribute(Qt::WA_QuitOnClose, false); 00103 setAttribute(Qt::WA_DeleteOnClose, false); 00104 } 00105 00106 void 00107 NodeStatInspector::node(const VisualNode::NodeAllocator& na, 00108 VisualNode* n, const Statistics&, bool) { 00109 if (isVisible()) { 00110 int nd = -1; 00111 for (VisualNode* p = n; p != NULL; p = p->getParent(na)) 00112 nd++; 00113 nodeDepthLabel->setPlainText(QString("%1").arg(nd));; 00114 StatCursor sc(n,na); 00115 PreorderNodeVisitor<StatCursor> pnv(sc); 00116 pnv.run(); 00117 00118 subtreeDepthLabel->setPlainText( 00119 QString("%1").arg(pnv.getCursor().depth)); 00120 solvedLabel->setPlainText(QString("%1").arg(pnv.getCursor().solved)); 00121 solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); 00122 failedLabel->setPlainText(QString("%1").arg(pnv.getCursor().failed)); 00123 failedLabel->setPos(44-failedLabel->document()->size().width(),120); 00124 choicesLabel->setPlainText(QString("%1").arg(pnv.getCursor().choice)); 00125 choicesLabel->setPos(66-choicesLabel->document()->size().width(),57); 00126 openLabel->setPlainText(QString("%1").arg(pnv.getCursor().open)); 00127 } 00128 } 00129 00130 void 00131 NodeStatInspector::showStats(void) { 00132 show(); 00133 activateWindow(); 00134 } 00135 00136 }} 00137 00138 // STATISTICS: gist-any