3 #include <QApplication>
27 #define DbgLv(a) if(dbg_level>=a)qDebug()
31 int main(
int argc,
char* argv[] )
33 QApplication application( argc, argv );
41 return application.exec();
49 setWindowTitle( tr(
"Discrete Genetic Algorithm Initialization" ) );
55 QGridLayout*
main =
new QGridLayout(
this );
56 main->setSpacing( 2 );
57 main->setContentsMargins( 2, 2, 2, 2 );
63 QLabel* lb_modcnst =
us_banner( tr(
"Model and Constraints" ) );
74 QLabel* lb_gencntrl =
us_banner( tr(
"General Control" ) );
80 stpal.setColor( QPalette::Text, Qt::white );
81 stpal.setColor( QPalette::Base, Qt::blue );
87 main->addWidget( lb_modcnst, row++, 0, 1, 4 );
95 main->addWidget( lb_gencntrl, row++, 0, 1, 4 );
96 main->addWidget(
le_status, row++, 0, 1, 4 );
97 main->addWidget(
pb_help, row, 0, 1, 2 );
98 main->addWidget(
pb_close, row++, 2, 1, 2 );
115 connect(
pb_help, SIGNAL( clicked () ),
117 connect(
pb_close, SIGNAL( clicked () ),
122 const int sctmms = 1000;
123 sctm_id = startTimer( sctmms );
124 le_status->setText( tr(
"Scanning models for unassigned edits" ) );
125 qApp->processEvents();
140 DbgLv(1) <<
"dGA:load_model";
141 le_status->setText( tr(
"Loading a list of base models" ) );
142 qApp->processEvents();
144 QString mfilt =
"=m";
151 connect( &mldiag, SIGNAL( changed (
bool ) ),
154 if ( mldiag.exec() == QDialog::Accepted )
156 le_status->setText( tr(
"A base model has been loaded." ) );
162 le_status->setText( tr(
"No base model was loaded." ) );
165 qApp->processEvents();
171 DbgLv(1) <<
"dGA:define_model";
173 le_status->setText( tr(
"Editing or creating a base model" ) );
174 qApp->processEvents();
183 le_status->setText( tr(
"A base model has been created or edited." ) );
189 le_status->setText( tr(
"No base model was defined." ) );
192 qApp->processEvents();
198 DbgLv(1) <<
"dGA:load_constraints";
201 QString mfilt =
"=u Constr";
204 le_status->setText( tr(
"Loading a list of existing constraints models" ) );
205 qApp->processEvents();
209 connect( &mldiag, SIGNAL( changed (
bool ) ),
211 if ( mldiag.exec() != QDialog::Accepted )
217 if ( cediag.exec() == QDialog::Accepted )
219 le_status->setText( tr(
"A constraints model has been loaded." ) );
226 le_status->setText( tr(
"No constraints model was loaded." ) );
229 qApp->processEvents();
235 DbgLv(1) <<
"dGA:define_constraints";
244 le_status->setText( tr(
"Editor to define a constraints model" ) );
245 qApp->processEvents();
247 if ( cediag.exec() == QDialog::Accepted )
249 le_status->setText( tr(
"A constraints model has been defined." ) );
256 le_status->setText( tr(
"No constraints model was defined." ) );
259 qApp->processEvents();
265 DbgLv(1) <<
"dGA:save_model";
266 QString msg1 = tr(
"A Base Model has been loaded or created."
267 " It's description is:" )
269 + tr(
"It may be saved as it is or you may modify the description"
270 " or other attributes by clicking the <b>Cancel</b> button"
271 " here and clicking the <b>Define Base Model</b> in the"
272 " main dialog. The model may also be updated or saved within"
273 " the resulting dialog.<br/><br/>"
274 " Click:<br/>"
275 "<b>OK</b><br/> to output the model as is;<br/>"
276 "<b>Cancel</b><br/> to abort the model save.<br/>" );
279 mbox.setWindowTitle( tr(
"Save Current Base Model" ) );
280 mbox.setText ( msg1 );
281 QPushButton *pb_ok = mbox.addButton( tr(
"OK" ),
282 QMessageBox::YesRole );
283 QPushButton *pb_canc = mbox.addButton( tr(
"Cancel" ),
284 QMessageBox::RejectRole );
285 mbox.setEscapeButton ( pb_canc );
286 mbox.setDefaultButton( pb_ok );
290 if ( mbox.clickedButton() == pb_canc )
return;
309 if ( modelGuid.isEmpty() )
319 QString mtitle = tr(
"Base Model Saving ..." );
324 tr(
"local disk and database." ) :
326 QMessageBox::information(
this, mtitle,
328 + tr(
"\"\n was successfully saved to " ) + destination );
332 QMessageBox::warning(
this, mtitle,
334 + tr(
"\"\n resulted in error code %1 ." ).arg( code ) );
341 DbgLv(1) <<
"dGA:save_constraints";
342 QString now = QDateTime::currentDateTime()
343 .toUTC().toString(
"yyyyMMdd-hhmm" );
344 QString ftype = QString(
"-DMGA_Constraints" );
346 QString fext =
".model";
347 QString cmfdesc = now + ftype + suffix + fext;
353 QString msg1 = tr(
"A Discrete Model Genetic Algorithm Constraints"
354 " model has been created. It's description is:" )
355 +
"<br/><b>" + cmfdesc +
"</b>.<br/><br/"
356 + tr(
"Click:<br/><br/>"
357 " <b>OK</b> to output the model as is;<br/>"
358 " <b>Edit</b> to append custom text to the name;<br/>"
359 " <b>Cancel</b> to abort the model save.<br/>" );
362 mbox.setWindowTitle( tr(
"Save Constraints Model" ) );
363 mbox.setText ( msg1 );
364 QPushButton *pb_ok = mbox.addButton( tr(
"OK" ),
365 QMessageBox::YesRole );
366 QPushButton *pb_edit = mbox.addButton( tr(
"Edit" ),
367 QMessageBox::AcceptRole );
368 QPushButton *pb_canc = mbox.addButton( tr(
"Cancel" ),
369 QMessageBox::RejectRole );
370 mbox.setEscapeButton ( pb_canc );
371 mbox.setDefaultButton( pb_ok );
375 if ( mbox.clickedButton() == pb_canc )
return;
376 if ( mbox.clickedButton() == pb_edit )
379 QString msg2 = tr(
"Enter optional suffix text to the"
380 " model description.<br/> Use alphumeric"
381 " characters, underscores, or hyphens<br/>"
382 " (no spaces). Enter 1 to 20 characters." );
383 suffix = QInputDialog::getText(
this,
384 tr(
"Model Description Suffix" ),
392 suffix.remove( QRegExp(
"[^\\w\\d_-]" ) );
394 if ( suffix.length() > 20 ) suffix = suffix.left( 20 );
395 cmfdesc = now + ftype + suffix + fext;
418 QString mtitle = tr(
"Constraints Model Saving ..." );
423 tr(
"local disk and database." ) :
425 QMessageBox::information(
this, mtitle,
427 + tr(
"\"\n was successfully saved to " ) + destination );
431 QMessageBox::warning(
this, mtitle,
433 + tr(
"\"\n resulted in error code %1 ." ).arg( code ) );
446 le_status->setText( tr(
"Scanning models for unassigned edits" ) );
447 qApp->processEvents();
459 const QString uaeditID(
"1" );
460 int tm_id =
event->timerId();
463 if ( tm_id != sctm_id )
465 QObject::timerEvent( event );
470 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
474 DbgLv(1) <<
" Atype Man Cgr Dga" << atypeMan << atypeCgr << atypeDga;
475 qApp->processEvents();
485 DbgLv(1) <<
" Timing(count_models)" << timer.elapsed();
491 qry <<
"count_models_by_editID" << invID << uaeditID;
497 qry <<
"get_model_desc_by_editID" << invID << uaeditID;
502 QString mdlID = db.value( 0 ).toString();
503 QString mdesc = db.value( 2 ).toString();
504 QString edtGID = db.value( 5 ).toString();
505 int edtID = db.value( 6 ).toString().toInt();
507 if ( !mdesc.contains(
"Custom" ) )
512 DbgLv(1) <<
" mdlID" << mdlID <<
"mdesc" << mdesc <<
"editID" << edtID
513 <<
"editGUID" << edtGID;
515 DbgLv(1) <<
" Timing(get_model_desc)" << timer.elapsed();
518 for (
int ii = 0; ii < nlmodel; ii++ )
520 QString mdlID = mdlIDs[ ii ];
522 qry <<
"get_model_info" << mdlID;
525 QString xmlmdl = db.value( 2 ).toString();
526 int jj = xmlmdl.indexOf(
"analysisType=" );
527 QString atype = xmlmdl.mid( jj, 40 ).section(
"\"", 1, 1 );
528 DbgLv(1) <<
" mdlID" << mdlID <<
"atype" << atype <<
"jj" << jj;
530 if ( atype == atypeDga )
532 else if ( atype == atypeCgr )
534 else if ( atype == atypeMan )
537 DbgLv(1) <<
" Timing(get_model_info)" << timer.elapsed();
543 const QString uaGUID(
"00000000-0000-0000-0000-000000000000" );
546 if ( !dir.exists( path ) )
549 QStringList mfilt(
"M*.xml" );
550 QStringList f_names = dir.entryList( mfilt, QDir::Files, QDir::Name );
551 QXmlStreamAttributes attr;
553 for (
int ii = 0; ii < f_names.size(); ii++ )
555 QString fname( path +
"/" + f_names[ ii ] );
556 QFile m_file( fname );
557 if ( !m_file.open( QIODevice::ReadOnly | QIODevice::Text ) )
559 QXmlStreamReader xml( &m_file );
561 while( ! xml.atEnd() )
564 if ( xml.isStartElement() && xml.name() ==
"model" )
566 attr = xml.attributes();
567 QString edGUID = attr.value(
"editGUID" ).toString();
569 if ( ! edGUID.isEmpty() && edGUID != uaGUID )
574 QString atype = attr.value(
"analysisType" ).toString();
576 if ( atype == atypeDga )
578 else if ( atype == atypeCgr )
580 else if ( atype == atypeMan )
589 DbgLv(1) <<
" numodel" << numodel <<
"ndmodel ncmodel nmmodel"
590 << ndmodel << ncmodel << nmmodel;
592 le_status->setText( tr(
"%1 unassigned-edit models found"
593 " (%2 Manual, %3 DMGA, %4 CGrid)" )
594 .arg( numodel ).arg( nmmodel ).arg( ndmodel ).arg( ncmodel ) );
595 QApplication::restoreOverrideCursor();
596 QApplication::restoreOverrideCursor();
597 qApp->processEvents();