Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
nodestats.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2006
8  *
9  * Last modified:
10  * $Date: 2010-08-11 12:41:24 +0200 (Wed, 11 Aug 2010) $ by $Author: tack $
11  * $Revision: 11340 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/gist/nodestats.hh>
43 
44 namespace Gecode { namespace Gist {
45 
47  : QWidget(parent) {
48  setWindowFlags(Qt::Tool);
49  QGraphicsScene* scene = new QGraphicsScene();
50 
51  scene->addEllipse(70,10,16,16,QPen(),QBrush(DrawingCursor::white));
52  scene->addEllipse(70,60,16,16,QPen(),QBrush(DrawingCursor::blue));
53  scene->addRect(32,100,12,12,QPen(),QBrush(DrawingCursor::red));
54 
55  QPolygonF poly;
56  poly << QPointF(78,100) << QPointF(78+8,100+8)
57  << QPointF(78,100+16) << QPointF(78-8,100+8);
58  scene->addPolygon(poly,QPen(),QBrush(DrawingCursor::green));
59 
60  scene->addEllipse(110,100,16,16,QPen(),QBrush(DrawingCursor::white));
61 
62  QPen pen;
63  pen.setStyle(Qt::DotLine);
64  pen.setWidth(0);
65  scene->addLine(78,26,78,60,pen);
66  scene->addLine(78,76,38,100,pen);
67  scene->addLine(78,76,78,100,pen);
68  scene->addLine(78,76,118,100,pen);
69 
70  scene->addLine(135,10,145,10);
71  scene->addLine(145,10,145,110);
72  scene->addLine(145,60,135,60);
73  scene->addLine(145,110,135,110);
74 
75  nodeDepthLabel = scene->addText("0");
76  nodeDepthLabel->setPos(150,20);
77  subtreeDepthLabel = scene->addText("0");
78  subtreeDepthLabel->setPos(150,75);
79 
80  choicesLabel = scene->addText("0");
81  choicesLabel->setPos(45,57);
82 
83  solvedLabel = scene->addText("0");
84  solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120);
85  failedLabel = scene->addText("0");
86  failedLabel->setPos(30,120);
87  openLabel = scene->addText("0");
88  openLabel->setPos(110,120);
89 
90  QGraphicsView* view = new QGraphicsView(scene);
91  view->setRenderHints(view->renderHints() | QPainter::Antialiasing);
92  view->show();
93 
94  scene->setBackgroundBrush(Qt::white);
95 
96  boxLayout = new QVBoxLayout();
97  boxLayout->setContentsMargins(0,0,0,0);
98  boxLayout->addWidget(view);
99  setLayout(boxLayout);
100 
101  setWindowTitle("Gist node statistics");
102  setAttribute(Qt::WA_QuitOnClose, false);
103  setAttribute(Qt::WA_DeleteOnClose, false);
104  }
105 
106  void
108  VisualNode* n, const Statistics&, bool) {
109  if (isVisible()) {
110  int nd = -1;
111  for (VisualNode* p = n; p != NULL; p = p->getParent(na))
112  nd++;
113  nodeDepthLabel->setPlainText(QString("%1").arg(nd));;
114  StatCursor sc(n,na);
116  pnv.run();
117 
118  subtreeDepthLabel->setPlainText(
119  QString("%1").arg(pnv.getCursor().depth));
120  solvedLabel->setPlainText(QString("%1").arg(pnv.getCursor().solved));
121  solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120);
122  failedLabel->setPlainText(QString("%1").arg(pnv.getCursor().failed));
123  failedLabel->setPos(44-failedLabel->document()->size().width(),120);
124  choicesLabel->setPlainText(QString("%1").arg(pnv.getCursor().choice));
125  choicesLabel->setPos(66-choicesLabel->document()->size().width(),57);
126  openLabel->setPlainText(QString("%1").arg(pnv.getCursor().open));
127  }
128  }
129 
130  void
132  show();
133  activateWindow();
134  }
135 
136 }}
137 
138 // STATISTICS: gist-any
static const QColor white
White color.
NodeStatInspector(QWidget *parent)
Definition: nodestats.cpp:46
Node allocator.
Definition: node.hh:52
static const QColor green
The color for solved nodes.
A cursor that collects statistics.
Definition: nodecursor.hh:162
static const QColor blue
The color for choice nodes.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Cursor & getCursor(void)
Return the cursor.
Definition: nodevisitor.hpp:50
static const QColor red
The color for failed nodes.
void run(void)
Execute visitor.
Run a cursor over a tree, processing nodes in pre-order.
Definition: nodevisitor.hh:76
Node class that supports visual layout
Definition: visualnode.hh:129
Gecode toplevel namespace
void node(const VisualNode::NodeAllocator &, VisualNode *n, const Statistics &stat, bool finished)
Update display to reflect information about n.
Definition: nodestats.cpp:107
Statistics about the search tree
Definition: spacenode.hh:63
void showStats(void)
Show this window and bring it to the front.
Definition: nodestats.cpp:131