Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
mainwindow.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: 2013-05-06 09:02:17 +0200 (Mon, 06 May 2013) $ by $Author: tack $
11  * $Revision: 13613 $
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 
42 
44 
45 namespace Gecode { namespace Gist {
46 
47  AboutGist::AboutGist(QWidget* parent) : QDialog(parent) {
48 
49  Logos logos;
50  QPixmap myPic;
51  myPic.loadFromData(logos.logo, logos.logoSize);
52 
53  QPixmap myPic2;
54  myPic2.loadFromData(logos.gistLogo, logos.gistLogoSize);
55  setWindowIcon(myPic2);
56 
57 
58  setMinimumSize(300, 240);
59  setMaximumSize(300, 240);
60  QVBoxLayout* layout = new QVBoxLayout();
61  QLabel* logo = new QLabel();
62  logo->setPixmap(myPic);
63  layout->addWidget(logo, 0, Qt::AlignCenter);
64  QLabel* aboutLabel =
65  new QLabel(tr("<h2>Gist</h2>"
66  "<p><b>The Gecode Interactive Search Tool</b</p> "
67  "<p>You can find more information about Gecode and Gist "
68  "at</p>"
69  "<p><a href='http://www.gecode.org'>www.gecode.org</a>"
70  "</p"));
71  aboutLabel->setOpenExternalLinks(true);
72  aboutLabel->setWordWrap(true);
73  aboutLabel->setAlignment(Qt::AlignCenter);
74  layout->addWidget(aboutLabel);
75  setLayout(layout);
76  setWindowTitle(tr("About Gist"));
77  setAttribute(Qt::WA_QuitOnClose, false);
78  setAttribute(Qt::WA_DeleteOnClose, false);
79  }
80 
82  const Options& opt0)
83  : opt(opt0), aboutGist(this) {
84  c = new Gist(root,bab,this,opt);
85  setCentralWidget(c);
86  setWindowTitle(tr("Gist"));
87 
88  Logos logos;
89  QPixmap myPic;
90  myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
91  setWindowIcon(myPic);
92 
93  resize(500,500);
94  setMinimumSize(400, 200);
95 
96  menuBar = new QMenuBar(0);
97 
98  QMenu* fileMenu = menuBar->addMenu(tr("&File"));
99  fileMenu->addAction(c->print);
100 #if QT_VERSION >= 0x040400
101  fileMenu->addAction(c->exportWholeTreePDF);
102 #endif
103  QAction* quitAction = fileMenu->addAction(tr("Quit"));
104  quitAction->setShortcut(QKeySequence("Ctrl+Q"));
105  connect(quitAction, SIGNAL(triggered()),
106  this, SLOT(close()));
107  prefAction = fileMenu->addAction(tr("Preferences"));
108  connect(prefAction, SIGNAL(triggered()), this, SLOT(preferences()));
109 
110  QMenu* nodeMenu = menuBar->addMenu(tr("&Node"));
111 
112  inspectNodeMenu = new QMenu("Inspect");
113  inspectNodeMenu->addAction(c->inspect);
114  connect(inspectNodeMenu, SIGNAL(aboutToShow()),
115  this, SLOT(populateInspectors()));
116 
117  inspectNodeBeforeFPMenu = new QMenu("Inspect before fixpoint");
118  inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
119  connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
120  this, SLOT(populateInspectors()));
122 
123  nodeMenu->addMenu(inspectNodeMenu);
124  nodeMenu->addMenu(inspectNodeBeforeFPMenu);
125  nodeMenu->addAction(c->compareNode);
126  nodeMenu->addAction(c->compareNodeBeforeFP);
127  nodeMenu->addAction(c->setPath);
128  nodeMenu->addAction(c->inspectPath);
129  nodeMenu->addAction(c->showNodeStats);
130  bookmarksMenu = new QMenu("Bookmarks");
131  bookmarksMenu->addAction(c->bookmarkNode);
132  connect(bookmarksMenu, SIGNAL(aboutToShow()),
133  this, SLOT(populateBookmarks()));
134  nodeMenu->addMenu(bookmarksMenu);
135  nodeMenu->addSeparator();
136  nodeMenu->addAction(c->navUp);
137  nodeMenu->addAction(c->navDown);
138  nodeMenu->addAction(c->navLeft);
139  nodeMenu->addAction(c->navRight);
140  nodeMenu->addAction(c->navRoot);
141  nodeMenu->addAction(c->navNextSol);
142  nodeMenu->addAction(c->navPrevSol);
143  nodeMenu->addSeparator();
144  nodeMenu->addAction(c->toggleHidden);
145  nodeMenu->addAction(c->hideFailed);
146  nodeMenu->addAction(c->unhideAll);
147  nodeMenu->addAction(c->labelBranches);
148  nodeMenu->addAction(c->labelPath);
149  nodeMenu->addAction(c->toggleStop);
150  nodeMenu->addAction(c->unstopAll);
151  nodeMenu->addSeparator();
152  nodeMenu->addAction(c->zoomToFit);
153  nodeMenu->addAction(c->center);
154 #if QT_VERSION >= 0x040400
155  nodeMenu->addAction(c->exportPDF);
156 #endif
157 
158  QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
159  searchMenu->addAction(c->searchNext);
160  searchMenu->addAction(c->searchAll);
161  searchMenu->addSeparator();
162  searchMenu->addAction(c->stop);
163  searchMenu->addSeparator();
164  searchMenu->addAction(c->reset);
165 
166  QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
167  doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
168  connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
169  this, SLOT(populateInspectorSelection()));
170  toolsMenu->addMenu(doubleClickInspectorsMenu);
171  solutionInspectorsMenu = new QMenu("Solution inspectors");
172  connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
173  this, SLOT(populateInspectorSelection()));
174  toolsMenu->addMenu(solutionInspectorsMenu);
175  moveInspectorsMenu = new QMenu("Move inspectors");
176  connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
177  this, SLOT(populateInspectorSelection()));
178  toolsMenu->addMenu(moveInspectorsMenu);
179  comparatorsMenu = new QMenu("Comparators");
180  connect(comparatorsMenu, SIGNAL(aboutToShow()),
181  this, SLOT(populateInspectorSelection()));
182  toolsMenu->addMenu(comparatorsMenu);
183 
184  QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
185  QAction* aboutAction = helpMenu->addAction(tr("About"));
186  connect(aboutAction, SIGNAL(triggered()),
187  this, SLOT(about()));
188 
189  // Don't add the menu bar on Mac OS X
190 #ifndef Q_WS_MAC
191  setMenuBar(menuBar);
192 #endif
193 
194  // Set up status bar
195  QWidget* stw = new QWidget();
196  QHBoxLayout* hbl = new QHBoxLayout();
197  hbl->setContentsMargins(0,0,0,0);
198  wmpLabel = new QLabel("");
199  hbl->addWidget(wmpLabel);
200  hbl->addWidget(new QLabel("Depth:"));
201  depthLabel = new QLabel("0");
202  hbl->addWidget(depthLabel);
203  hbl->addWidget(new NodeWidget(SOLVED));
204  solvedLabel = new QLabel("0");
205  hbl->addWidget(solvedLabel);
206  hbl->addWidget(new NodeWidget(FAILED));
207  failedLabel = new QLabel("0");
208  hbl->addWidget(failedLabel);
209  hbl->addWidget(new NodeWidget(BRANCH));
210  choicesLabel = new QLabel("0");
211  hbl->addWidget(choicesLabel);
212  hbl->addWidget(new NodeWidget(UNDETERMINED));
213  openLabel = new QLabel(" 0");
214  hbl->addWidget(openLabel);
215  stw->setLayout(hbl);
216  statusBar()->addPermanentWidget(stw);
217 
218  isSearching = false;
219  statusBar()->showMessage("Ready");
220 
221  connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
222  this,SLOT(statusChanged(const Statistics&,bool)));
223 
224  connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));
225 
226  preferences(true);
227  show();
228  c->reset->trigger();
229  }
230 
231  void
232  GistMainWindow::closeEvent(QCloseEvent* event) {
233  if (c->finish())
234  event->accept();
235  else
236  event->ignore();
237  }
238 
239  void
240  GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
241  if (stats.maxDepth==0) {
242  isSearching = false;
243  statusBar()->showMessage("Ready");
244  prefAction->setEnabled(true);
245  } else if (isSearching && finished) {
246  isSearching = false;
247  double ms = searchTimer.stop();
248  double s = std::floor(ms / 1000.0);
249  ms -= s*1000.0;
250  double m = std::floor(s / 60.0);
251  s -= m*60.0;
252  double h = std::floor(m / 60.0);
253  m -= h*60.0;
254 
255  // QString t;
256  // if (static_cast<int>(h) != 0)
257  // t += QString().setNum(static_cast<int>(h))+"h ";
258  // if (static_cast<int>(m) != 0)
259  // t += QString().setNum(static_cast<int>(m))+"m ";
260  // if (static_cast<int>(s) != 0)
261  // t += QString().setNum(static_cast<int>(s));
262  // else
263  // t += "0";
264  // t += "."+QString().setNum(static_cast<int>(ms))+"s";
265  // statusBar()->showMessage(QString("Ready (search time ")+t+")");
266  statusBar()->showMessage("Ready");
267  prefAction->setEnabled(true);
268  } else if (!isSearching && !finished) {
269  prefAction->setEnabled(false);
270  statusBar()->showMessage("Searching");
271  isSearching = true;
272  searchTimer.start();
273  }
274  depthLabel->setNum(stats.maxDepth);
275  solvedLabel->setNum(stats.solutions);
276  failedLabel->setNum(stats.failures);
277  choicesLabel->setNum(stats.choices);
278  openLabel->setNum(stats.undetermined);
279  if (stats.wmp)
280  wmpLabel->setText("WMP");
281  else
282  wmpLabel->setText("");
283  }
284 
285  void
287  aboutGist.show();
288  }
289 
290  void
292  PreferencesDialog pd(opt, this);
293  if (setup) {
294  c->setAutoZoom(pd.zoom);
295  }
296  if (setup || pd.exec() == QDialog::Accepted) {
298  c->setRefresh(pd.refresh);
302  c->setRecompDistances(pd.c_d,pd.a_d);
303  opt.c_d = pd.c_d;
304  opt.a_d = pd.a_d;
305  c->setShowCopies(pd.copies);
306  }
307  }
308 
309  void
311  doubleClickInspectorsMenu->clear();
312  doubleClickInspectorsMenu->addActions(
313  c->doubleClickInspectorGroup->actions());
314  solutionInspectorsMenu->clear();
315  solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
316  moveInspectorsMenu->clear();
317  moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
318  comparatorsMenu->clear();
319  comparatorsMenu->addActions(c->comparatorGroup->actions());
320  }
321 
322  void
324  bookmarksMenu->clear();
325  bookmarksMenu->addAction(c->bookmarkNode);
326  bookmarksMenu->addSeparator();
327  bookmarksMenu->addActions(c->bookmarksGroup->actions());
328  }
329 
330  void
332  inspectNodeMenu->clear();
333  inspectNodeMenu->addAction(c->inspect);
334  inspectNodeMenu->addSeparator();
335  inspectNodeMenu->addActions(c->inspectGroup->actions());
336  inspectNodeBeforeFPMenu->clear();
337  inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
338  inspectNodeBeforeFPMenu->addSeparator();
339  inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
340  }
341 
342 }}
343 
344 // STATISTICS: gist-any
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:213
QAction * navNextSol
Navigate to next solution (to the left)
Definition: qtgist.hh:140
QActionGroup * doubleClickInspectorGroup
Group of all actions for double click inspectors.
Definition: qtgist.hh:188
void populateInspectors(void)
Populate the inspector menus from the actions found in Gist.
Definition: mainwindow.cpp:331
bool zoom
Whether to automatically zoom during search.
Definition: preferences.hh:79
Small node drawings for the status bar.
Definition: nodewidget.hh:47
QAction * toggleHidden
Toggle whether current node is hidden.
Definition: qtgist.hh:148
void setAutoHideFailed(bool b)
Set preference whether to automatically hide failed subtrees.
Definition: qtgist.cpp:778
int solutions
Number of solutions.
Definition: spacenode.hh:66
QAction * navDown
Navigate to leftmost child node.
Definition: qtgist.hh:132
QAction * navRoot
Navigate to root node.
Definition: qtgist.hh:138
QAction * bookmarkNode
Bookmark current node.
Definition: qtgist.hh:169
QAction * navUp
Navigate to parent node.
Definition: qtgist.hh:130
QAction * setPath
Set path from current node to the root.
Definition: qtgist.hh:175
Gist * c
The contained Gist object.
Definition: mainwindow.hh:97
Node representing a branch.
Definition: spacenode.hh:51
QAction * inspect
Inspect current node.
Definition: qtgist.hh:122
unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:211
void populateBookmarks(void)
Populate the bookmarks menus from the actions found in Gist.
Definition: mainwindow.cpp:323
GistMainWindow(Space *root, bool bab, const Options &opt)
Constructor.
Definition: mainwindow.cpp:81
QAction * compareNode
Compare current node to other node.
Definition: qtgist.hh:171
QAction * unstopAll
Bookmark current node.
Definition: qtgist.hh:183
QActionGroup * inspectBeforeFPGroup
Group of all actions for direct inspector selection.
Definition: qtgist.hh:198
int choices
Number of choice nodes.
Definition: spacenode.hh:70
QAction * hideFailed
Hide failed subtrees under current node.
Definition: qtgist.hh:150
Node representing failure.
Definition: spacenode.hh:50
void closeEvent(QCloseEvent *event)
Close Gist.
Definition: mainwindow.cpp:232
void setShowCopies(bool b)
Set preference whether to show copies in the tree.
Definition: qtgist.cpp:820
bool wmp
Whether a weakly monotonic propagator might have been executed.
Definition: core.hpp:1315
const unsigned char * logo
The Gecode logo.
Definition: gecodelogo.hh:47
QAction * navPrevSol
Navigate to previous solution (to the right)
Definition: qtgist.hh:142
QAction * navLeft
Navigate to left sibling.
Definition: qtgist.hh:134
bool finish(void)
Stop search and wait until finished.
Definition: qtgist.cpp:703
void setSmoothScrollAndZoom(bool b)
Set preference whether to use smooth scrolling and zooming.
Definition: qtgist.cpp:794
void statusChanged(const Statistics &stats, bool finished)
The status has changed (e.g., new solutions have been found)
Definition: mainwindow.cpp:240
bool hideFailed
Whether to automatically hide failed subtrees during search.
Definition: preferences.hh:77
void about(void)
Open the about dialog.
Definition: mainwindow.cpp:286
Computation spaces.
Definition: core.hpp:1362
QAction * toggleStop
Bookmark current node.
Definition: qtgist.hh:181
Node that has not been explored yet.
Definition: spacenode.hh:52
QAction * navRight
Navigate to right sibling.
Definition: qtgist.hh:136
void start(void)
Start timer.
Definition: timer.hpp:70
QActionGroup * bookmarksGroup
Group of all actions for bookmarks.
Definition: qtgist.hh:194
QAction * inspectBeforeFP
Inspect current node before fixpoint.
Definition: qtgist.hh:124
QAction * unhideAll
Unhide all hidden subtrees under current node.
Definition: qtgist.hh:152
Options opt
The options.
Definition: test.cpp:101
bool copies
Whether to show where copies are in the tree.
Definition: preferences.hh:81
QAction * center
Center on current node.
Definition: qtgist.hh:160
Node representing a solution.
Definition: spacenode.hh:49
QAction * exportPDF
Export PDF of current subtree.
Definition: qtgist.hh:162
Class holding Gecode and Gist logo icons.
Definition: gecodelogo.hh:44
int undetermined
Number of open, undetermined nodes.
Definition: spacenode.hh:72
Gecode Interactive Search Tool
Definition: qtgist.hh:85
void populateInspectorSelection(void)
Populate the inspector menus from the actions found in Gist.
Definition: mainwindow.cpp:310
AboutGist(QWidget *parent=0)
Constructor.
Definition: mainwindow.cpp:47
const unsigned char * gistLogo
A smaller logo used as a window icon.
Definition: gecodelogo.hh:52
void preferences(bool setup=false)
Open the preferences dialog.
Definition: mainwindow.cpp:291
double stop(void)
Get time since start of timer.
Definition: timer.hpp:80
int c_d
The copying distance.
Definition: preferences.hh:92
void setAutoZoom(bool b)
Set preference whether to automatically zoom to fit.
Definition: qtgist.cpp:780
Preferences dialog for Gist.
Definition: preferences.hh:52
const unsigned int logoSize
Size of the Gecode logo.
Definition: gecodelogo.hh:49
QActionGroup * moveInspectorGroup
Group of all actions for move inspectors.
Definition: qtgist.hh:190
QAction * labelPath
Label branches on path to root.
Definition: qtgist.hh:156
void setRecompDistances(int c_d, int a_d)
Set recomputation parameters c_d and a_d.
Definition: qtgist.cpp:806
QAction * stop
Stop search.
Definition: qtgist.hh:126
QAction * compareNodeBeforeFP
Compare current node to other node before fixpoint.
Definition: qtgist.hh:173
QMenuBar * menuBar
A menu bar.
Definition: mainwindow.hh:99
QAction * showNodeStats
Open node statistics inspector.
Definition: qtgist.hh:179
void setMoveDuringSearch(bool b)
Set preference whether to move cursor during search.
Definition: qtgist.cpp:802
int maxDepth
Maximum depth of the tree.
Definition: spacenode.hh:74
void setRefresh(int i)
Set refresh rate.
Definition: qtgist.cpp:786
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
Definition: preferences.hh:87
QActionGroup * solutionInspectorGroup
Group of all actions for solution inspectors.
Definition: qtgist.hh:186
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:212
QAction * searchNext
Search next solution in current subtree.
Definition: qtgist.hh:144
int refresh
How often to refresh the display during search.
Definition: preferences.hh:83
AboutGist aboutGist
About dialog.
Definition: mainwindow.hh:101
int refreshPause
Milliseconds to wait after each refresh (to slow down search)
Definition: preferences.hh:85
QActionGroup * inspectGroup
Group of all actions for direct inspector selection.
Definition: qtgist.hh:196
Gecode toplevel namespace
QAction * searchAll
Search all solutions in current subtree.
Definition: qtgist.hh:146
QAction * print
Print tree.
Definition: qtgist.hh:166
QAction * labelBranches
Label branches under current node.
Definition: qtgist.hh:154
QAction * reset
Reset Gist.
Definition: qtgist.hh:128
QAction * zoomToFit
Zoom tree to fit window.
Definition: qtgist.hh:158
QAction * exportWholeTreePDF
Export PDF of whole tree.
Definition: qtgist.hh:164
QAction * inspectPath
Inspect all nodes on selected path.
Definition: qtgist.hh:177
Options for Gist
Definition: gist.hh:238
bool moveDuringSearch
Whether to move cursor during search.
Definition: preferences.hh:89
int failures
Number of failures.
Definition: spacenode.hh:68
const unsigned int gistLogoSize
Size of the smaller logo.
Definition: gecodelogo.hh:54
QActionGroup * comparatorGroup
Group of all actions for comparators.
Definition: qtgist.hh:192
Statistics about the search tree
Definition: spacenode.hh:63
void setRefreshPause(int i)
Set refresh pause in msec.
Definition: qtgist.cpp:788
int a_d
The adaptive recomputation distance.
Definition: preferences.hh:94