40 |
#include "containerlist.h" |
#include "containerlist.h" |
41 |
#include "containerhash.h" |
#include "containerhash.h" |
42 |
#include "containermnvector.h" |
#include "containermnvector.h" |
43 |
|
#include "containerminimalvector.h" |
44 |
|
|
45 |
#include "config.h" |
#include "config.h" |
46 |
|
|
83 |
m_sizeSelector->setValue( 8 ); |
m_sizeSelector->setValue( 8 ); |
84 |
m_board->setSize( 8 ); |
m_board->setSize( 8 ); |
85 |
|
|
86 |
m_storage = StorageMatrix; |
m_storage = StorageInt; |
87 |
m_sortalgo = SortList; |
m_sortalgo = SortMinimalVector; |
88 |
m_solutions = NULL; |
m_solutions = NULL; |
89 |
m_queens = NULL; |
m_queens = NULL; |
90 |
m_sol = NULL; |
m_sol = NULL; |
130 |
QueensMain::~QueensMain() |
QueensMain::~QueensMain() |
131 |
{ |
{ |
132 |
delete m_board; |
delete m_board; |
133 |
|
|
134 |
|
if (m_solutions != NULL) |
135 |
|
delete m_solutions; |
136 |
|
if (m_sol != NULL) |
137 |
|
delete m_sol; |
138 |
} |
} |
139 |
|
|
140 |
void QueensMain::start() |
void QueensMain::start() |
145 |
m_list->clear(); |
m_list->clear(); |
146 |
m_status->setText( QString("Searching ...") ); |
m_status->setText( QString("Searching ...") ); |
147 |
|
|
148 |
|
m_board->setMatrix(0); |
149 |
|
|
150 |
if (m_queens != NULL) { |
if (m_queens != NULL) { |
151 |
m_queens->wait(); |
m_queens->wait(); |
152 |
delete m_queens; |
delete m_queens; |
153 |
|
m_queens = 0; |
154 |
} |
} |
155 |
|
|
156 |
if (m_solutions != NULL) |
if (m_solutions != NULL) |
168 |
case SortMNVector: |
case SortMNVector: |
169 |
m_solutions = new ContainerMNVector(this); |
m_solutions = new ContainerMNVector(this); |
170 |
break; |
break; |
171 |
|
case SortMinimalVector: |
172 |
|
m_solutions = new ContainerMinimalVector(this); |
173 |
|
break; |
174 |
} |
} |
175 |
|
|
176 |
if (m_sol != NULL) |
if (m_sol != NULL) |
266 |
|
|
267 |
void QueensMain::uniqueSolutions() |
void QueensMain::uniqueSolutions() |
268 |
{ |
{ |
269 |
m_totalcount = m_solutions->numSolutions(); |
m_totalcount = m_solutions->totalSolutions(); |
270 |
m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") ); |
m_status->setText( QString("sorting ") + QString::number(m_totalcount,10).append(" solutions...") ); |
271 |
|
|
272 |
m_elapsed.restart(); |
m_elapsed.restart(); |
289 |
{ |
{ |
290 |
QPopupMenu *contextMenu = new QPopupMenu( this ); |
QPopupMenu *contextMenu = new QPopupMenu( this ); |
291 |
contextMenu->setCheckable( true ); |
contextMenu->setCheckable( true ); |
292 |
QLabel *sortCaption = new QLabel("<b><i>Sort algorithm</i></b>", this); |
QLabel *sortCaption = new QLabel("<b><i>Container class</i></b>", this); |
293 |
sortCaption->setAlignment( Qt::AlignCenter ); |
sortCaption->setAlignment( Qt::AlignCenter ); |
294 |
contextMenu->insertItem( sortCaption ); |
contextMenu->insertItem( sortCaption ); |
295 |
|
|
297 |
contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2); |
contextMenu->insertItem("Vector", this, SLOT( sortVector() ), 0, 2); |
298 |
contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3); |
contextMenu->insertItem("Hash", this, SLOT( sortHash() ), 0, 3); |
299 |
contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4); |
contextMenu->insertItem("M*N Vector", this, SLOT(sortMNVector()), 0, 4); |
300 |
|
contextMenu->insertItem("Minimal Vector", this, SLOT(sortMinimalVector()), 0, 5); |
301 |
|
|
302 |
QLabel *storageCaption = new QLabel("<b><i>Storage class</i></b>", this); |
QLabel *storageCaption = new QLabel("<b><i>Solution class</i></b>", this); |
303 |
|
storageCaption->setAlignment( Qt::AlignCenter ); |
304 |
contextMenu->insertItem( storageCaption ); |
contextMenu->insertItem( storageCaption ); |
305 |
contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 5); |
contextMenu->insertItem("Matrix Solution", this, SLOT( storageMatrix() ), 0, 6); |
306 |
contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 6); |
contextMenu->insertItem("Int Solution", this, SLOT( storageInt() ), 0, 7); |
307 |
|
|
308 |
|
|
309 |
switch (m_sortalgo) { |
switch (m_sortalgo) { |
319 |
case SortMNVector: |
case SortMNVector: |
320 |
contextMenu->setItemChecked( 4, true); |
contextMenu->setItemChecked( 4, true); |
321 |
break; |
break; |
322 |
|
case SortMinimalVector: |
323 |
|
contextMenu->setItemChecked( 5, true); |
324 |
|
break; |
325 |
} |
} |
326 |
|
|
327 |
switch (m_storage) { |
switch (m_storage) { |
328 |
case StorageMatrix: |
case StorageMatrix: |
329 |
contextMenu->setItemChecked(5, true); |
contextMenu->setItemChecked(6, true); |
330 |
break; |
break; |
331 |
case StorageInt: |
case StorageInt: |
332 |
contextMenu->setItemChecked(6, true); |
contextMenu->setItemChecked(7, true); |
333 |
break; |
break; |
334 |
} |
} |
335 |
|
|
370 |
m_sortalgo = SortMNVector; |
m_sortalgo = SortMNVector; |
371 |
} |
} |
372 |
|
|
373 |
|
void QueensMain::sortMinimalVector() |
374 |
|
{ |
375 |
|
m_sortalgo = SortMinimalVector; |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
void QueensMain::storageInt() |
void QueensMain::storageInt() |
380 |
{ |
{ |
381 |
m_storage = StorageInt; |
m_storage = StorageInt; |
387 |
} |
} |
388 |
|
|
389 |
|
|
390 |
|
|