Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

SIG_GPParameter.cpp

00001 #include <qfiledialog.h>
00002 #include <qdatetime.h>
00003 #include <qspinbox.h>
00004 #include <qslider.h>
00005 #include <qcombobox.h>
00006 #include <qcheckbox.h>
00007 #include <qradiobutton.h>
00008 #include <qlcdnumber.h>
00009 #include <qmessagebox.h>
00010 
00011 #include "SIGEL_MasterGUI/SIG_GPParameter.h"
00012 #include "SIGEL_MasterGUI/SIG_EditHostDialog.h"
00013 
00014 #include "SIGEL_GP/SIG_GPPVMHost.h"
00015 
00016 #include "SIGEL_Program/SIG_Program.h"
00017 
00018 #include "SIGEL_Tools/SIG_IO.h" // take it out! Only DEBUG!
00019 
00020 #include <cstdlib>
00021 
00022 namespace SIGEL_MasterGUI
00023 {
00024 
00025 /* 
00026  *  Constructs a SIG_GPParameter which is a child of 'parent', with the 
00027  *  name 'name' and widget flags set to 'f' 
00028  */
00029 SIG_GPParameter::SIG_GPParameter( QWidget* parent,  const char* name, WFlags fl, SIGEL_GP::SIG_GPExperiment &theExperiment )
00030   : SIG_GPParameterBase( parent, name, fl ), theExperiment( theExperiment ), sigelRoot( std::getenv( "SIGEL_ROOT" ) )
00031 {
00032   QObject::connect( listviewHosts,
00033                     SIGNAL( doubleClicked( QListViewItem * ) ),
00034                     SLOT( slotItemDoubleClicked( QListViewItem * ) ) );
00035 }
00036 
00037 /*  
00038  *  Destroys the object and frees any allocated resources
00039  */
00040 SIG_GPParameter::~SIG_GPParameter()
00041 {
00042     // no need to delete child widgets, Qt does it all for us
00043 }
00044 
00045 void SIG_GPParameter::slotChangeGraveyardDir()
00046 {
00047   lineeditGraveyardDir->setText( QFileDialog::getExistingDirectory( "./", this, "getExistingDirDialogGraveyard", "Select Directory...", true ) );
00048 };
00049 
00050 void SIG_GPParameter::slotChangePoolImageDir()
00051 {
00052   lineeditPoolImageDir->setText( QFileDialog::getExistingDirectory( "./", this, "getExistingDirDialogPoolImage", "Select Directory...", true ) );
00053 };
00054 
00055 void SIG_GPParameter::putIntoExperiment()
00056 {
00057   theExperiment.gpParameter.setRandomSeed( spinboxRandomSeed->value() );
00058   theExperiment.population.getRandomizerPointer()->setNewSeed( spinboxRandomSeed->value() );
00059   theExperiment.gpParameter.setMinIndLength( spinboxMinIndLength->value() );
00060   if( checkboxIgnoreMaxIndLength->isChecked() )
00061     theExperiment.gpParameter.setMaxIndLength( 0 );
00062   else
00063     theExperiment.gpParameter.setMaxIndLength( spinboxMaxIndLength->value() );
00064   theExperiment.gpParameter.setMaxAge( spinboxMaxAge->value() );
00065 
00066   // put the probabilities into the experiment
00067   theExperiment.gpParameter.setXoverProb( sliderCrossover->value() );
00068   theExperiment.gpParameter.setMutationProb( sliderMutation->value() );
00069   theExperiment.gpParameter.setReproductionProb( 1000 - sliderMutation->value() - sliderCrossover->value() );
00070 
00071   // put the fitness function name into the experiment
00072   // theExperiment.gpParameter.setFitnessName( lineeditFitnessFunctionName->text() );
00073   switch( comboboxFitnessName->currentItem() )
00074     {
00075     case 0: // simple fitnessFunction
00076       theExperiment.gpParameter.setFitnessName("SimpleFitnessFunction");
00077       break;
00078     case 1:
00079       theExperiment.gpParameter.setFitnessName("RealSpeedFitnessFunction");
00080       break;
00081     case 2:
00082       theExperiment.gpParameter.setFitnessName("NiceWalkingFitnessFunction");
00083       break;
00084     }
00085 
00086   // put the probabilities into the experiment
00087   theExperiment.gpParameter.setProbability( SIGEL_Program::ADD, sliderADD->value() );
00088   theExperiment.gpParameter.setProbability( SIGEL_Program::CMP, sliderCMP->value() );
00089   theExperiment.gpParameter.setProbability( SIGEL_Program::COPY, sliderCOPY->value() );
00090   theExperiment.gpParameter.setProbability( SIGEL_Program::DELAY, sliderDELAY->value() );
00091   theExperiment.gpParameter.setProbability( SIGEL_Program::DIV, sliderDIV->value() );
00092   theExperiment.gpParameter.setProbability( SIGEL_Program::JMP, sliderJMP->value() );
00093   theExperiment.gpParameter.setProbability( SIGEL_Program::LOAD, sliderLOAD->value() );
00094   theExperiment.gpParameter.setProbability( SIGEL_Program::MAX, sliderMAX->value() );
00095   theExperiment.gpParameter.setProbability( SIGEL_Program::MIN, sliderMIN->value() );
00096   theExperiment.gpParameter.setProbability( SIGEL_Program::MOD, sliderMOD->value() );
00097   theExperiment.gpParameter.setProbability( SIGEL_Program::MOVE, sliderMOVE->value() );
00098   theExperiment.gpParameter.setProbability( SIGEL_Program::MUL, sliderMUL->value() );
00099   theExperiment.gpParameter.setProbability( SIGEL_Program::NOP, sliderNOP->value() );
00100   theExperiment.gpParameter.setProbability( SIGEL_Program::SENSE, sliderSENSE->value() );
00101   theExperiment.gpParameter.setProbability( SIGEL_Program::SUB, sliderSUB->value() );
00102   
00103   switch( comboboxTerminationBy->currentItem() )
00104     {
00105     case 0:
00106       theExperiment.gpParameter.setTerminationModel( SIGEL_GP::SIG_GPParameter::byUser );
00107       break;
00108     case 1:
00109       theExperiment.gpParameter.setTerminationModel( SIGEL_GP::SIG_GPParameter::byTime );
00110       break;
00111     case 2:
00112       theExperiment.gpParameter.setTerminationModel( SIGEL_GP::SIG_GPParameter::byGeneration );
00113       break;
00114     case 3:
00115       theExperiment.gpParameter.setTerminationModel( SIGEL_GP::SIG_GPParameter::byTimeGeneration );
00116       break;
00117     }
00118 
00119   // put the date into the experiment
00120   QDate theDate;
00121   theDate.setYMD( spinboxByTimeYear->value(), spinboxByTimeMonth->value(), spinboxByTimeDay->value());
00122   QTime theTime;
00123   theTime.setHMS( spinboxByTimeHour->value(), spinboxByTimeMins->value(), spinboxByTimeSecs->value() );
00124   QDateTime theDateTime( theDate, theTime );
00125   theExperiment.gpParameter.setTerminationTime( theDateTime );
00126 
00127   // put the duration into the experiment
00128   theExperiment.gpParameter.setTerminationDurationDays( spinboxByDurationDays->value() );
00129   theExperiment.gpParameter.setTerminationDurationHours( spinboxByDurationHours->value() );
00130   theExperiment.gpParameter.setTerminationDurationMinutes( spinboxByDurationMins->value() );
00131   theExperiment.gpParameter.setTerminationDurationSeconds( spinboxByDurationSecs->value() );
00132 
00133   // set whether the date should be used.
00134   if( radiobuttonInterpreteAsDate->isChecked() )
00135     theExperiment.gpParameter.setTerminationUsesDate( true );
00136   else
00137     theExperiment.gpParameter.setTerminationUsesDate( false );
00138 
00139   theExperiment.gpParameter.setTerminationGenerationNo( spinboxByGenerationNumber->value() );
00140 
00141   // set the tournaments per generation parameter
00142   double tournamentsPerGeneration = static_cast<double>( sliderTournamentsPerGeneration->value() ) / 1000;
00143   theExperiment.gpParameter.setTournamentsPerGeneration( tournamentsPerGeneration );
00144 
00145   // set the priority
00146   switch( comboboxPriority->currentItem() )
00147     {
00148     case 0:
00149       theExperiment.gpParameter.setPriority(SIGEL_GP::SIG_GPParameter::veryLow);
00150       break;
00151     case 1:
00152       theExperiment.gpParameter.setPriority(SIGEL_GP::SIG_GPParameter::low);
00153       break;
00154     case 2:
00155       theExperiment.gpParameter.setPriority(SIGEL_GP::SIG_GPParameter::normal);
00156       break;
00157     case 3:
00158       theExperiment.gpParameter.setPriority(SIGEL_GP::SIG_GPParameter::high);
00159       break;
00160     case 4:
00161       theExperiment.gpParameter.setPriority(SIGEL_GP::SIG_GPParameter::veryHigh);
00162       break;
00163     }
00164 
00165   // set live undead
00166   theExperiment.gpParameter.setLiveUndead( checkboxUseGraveyard->isChecked() );
00167   QDir graveyardDir( lineeditGraveyardDir->text() );
00168   theExperiment.gpParameter.setGraveYardDirectory( graveyardDir );
00169 
00170   // set poolimage directory options
00171   QDir poolImageDir( lineeditPoolImageDir->text() );
00172   theExperiment.gpParameter.setPoolImageDirectory( poolImageDir );
00173   if( checkboxUsePoolImage->isChecked() )
00174     theExperiment.gpParameter.setPoolImageGeneration( spinboxPoolImageFrequency->value() );
00175   else
00176     theExperiment.gpParameter.setPoolImageGeneration( 0 );
00177   
00178   // set the timeout
00179   theExperiment.gpParameter.setTimeOutMinutes( spinboxTimeout->value() );
00180 };
00181 
00182 void SIG_GPParameter::getOutOfExperiment()
00183 {
00184   spinboxRandomSeed->setValue( theExperiment.gpParameter.getRandomSeed() );
00185   spinboxMinIndLength->setValue( theExperiment.gpParameter.getMinIndLength() );
00186   int maxLength = theExperiment.gpParameter.getMaxIndLength();
00187   if( maxLength == 0 )
00188     {
00189       checkboxIgnoreMaxIndLength->setChecked( true );
00190       spinboxMaxIndLength->setValue( theExperiment.gpParameter.getMinIndLength() );
00191     }
00192   else
00193     spinboxMaxIndLength->setValue( maxLength );
00194   spinboxMaxAge->setValue( theExperiment.gpParameter.getMaxAge() );
00195   
00196   // sliderReproduction->setValue( theExperiment.gpParameter.getReproductionProb() );
00197   sliderCrossover->setValue( theExperiment.gpParameter.getXoverProb() );
00198   sliderMutation->setValue( theExperiment.gpParameter.getMutationProb() );
00199 
00200   // get the fitness function name
00201   QString fitnessName = theExperiment.gpParameter.getFitnessName();
00202   if( fitnessName == "SimpleFitnessFunction" )
00203     comboboxFitnessName->setCurrentItem(0);
00204   else
00205     if( fitnessName == "RealSpeedFitnessFunction" )
00206       comboboxFitnessName->setCurrentItem(1);
00207     else
00208       if( fitnessName == "NiceWalkingFitnessFunction" )
00209       comboboxFitnessName->setCurrentItem(2);
00210       else
00211         comboboxFitnessName->setCurrentItem(0);
00212 
00213   // get the probabilities
00214   sliderADD->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::ADD ) );
00215   sliderCMP->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::CMP ) );
00216   sliderCOPY->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::COPY ) );
00217   sliderDELAY->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::DELAY ) );
00218   sliderDIV->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::DIV ) );
00219   sliderJMP->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::JMP ) );
00220   sliderLOAD->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::LOAD ) );
00221   sliderMAX->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::MAX ) );
00222   sliderMIN->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::MIN ) );
00223   sliderMOD->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::MOD ) );
00224   sliderMOVE->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::MOVE ) );
00225   sliderMUL->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::MUL ) );
00226   sliderNOP->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::NOP ) );
00227   sliderSENSE->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::SENSE ) );
00228   sliderSUB->setValue( theExperiment.gpParameter.getProbability( SIGEL_Program::SUB ) );
00229 
00230   // set the termination model combo box
00231   switch( theExperiment.gpParameter.getTerminationModel() )
00232     {
00233     case SIGEL_GP::SIG_GPParameter::byUser:
00234       comboboxTerminationBy->setCurrentItem( 0 );
00235       break;
00236     case SIGEL_GP::SIG_GPParameter::byTime:
00237       comboboxTerminationBy->setCurrentItem( 1 );
00238       break;
00239     case SIGEL_GP::SIG_GPParameter::byGeneration:
00240       comboboxTerminationBy->setCurrentItem( 2 );
00241       break;
00242     case SIGEL_GP::SIG_GPParameter::byTimeGeneration:
00243       comboboxTerminationBy->setCurrentItem( 3 );
00244       break;
00245     }
00246   
00247   QDateTime theDateTime = theExperiment.gpParameter.getTerminationTime();
00248   spinboxByTimeDay->setValue( theDateTime.date().day() );
00249   spinboxByTimeMonth->setValue( theDateTime.date().month() );
00250   spinboxByTimeYear->setValue( theDateTime.date().year() );
00251   spinboxByTimeHour->setValue( theDateTime.time().hour() );
00252   spinboxByTimeMins->setValue( theDateTime.time().minute() );
00253   spinboxByTimeSecs->setValue( theDateTime.time().second() );
00254 
00255   // get the duration out of the experiment
00256   spinboxByDurationDays->setValue( theExperiment.gpParameter.getTerminationDurationDays() );
00257   spinboxByDurationHours->setValue( theExperiment.gpParameter.getTerminationDurationHours() );
00258   spinboxByDurationMins->setValue( theExperiment.gpParameter.getTerminationDurationMinutes() );
00259   spinboxByDurationSecs->setValue( theExperiment.gpParameter.getTerminationDurationSeconds() );
00260   
00261   // get whether the date should be used.
00262   if( theExperiment.gpParameter.getTerminationUsesDate() )
00263     radiobuttonInterpreteAsDate->setChecked( true );
00264   else
00265     radiobuttonInterpreteAsDuration->setChecked( true );
00266   
00267   spinboxByGenerationNumber->setValue( theExperiment.gpParameter.getTerminationGenerationNo() );
00268 
00269   // set the tournaments per generation parameter
00270   int tournamentsPerGeneration = static_cast<int>( theExperiment.gpParameter.getTournamentsPerGeneration() * 1000 );
00271   sliderTournamentsPerGeneration->setValue( tournamentsPerGeneration );
00272 
00273   // get the priority
00274   switch( theExperiment.gpParameter.getPriority() )
00275     {
00276     case SIGEL_GP::SIG_GPParameter::veryLow:
00277       comboboxPriority->setCurrentItem( 0 );
00278       break;
00279     case SIGEL_GP::SIG_GPParameter::low:
00280       comboboxPriority->setCurrentItem( 1 );
00281       break;
00282     case SIGEL_GP::SIG_GPParameter::normal:
00283       comboboxPriority->setCurrentItem( 2 );
00284       break;
00285     case SIGEL_GP::SIG_GPParameter::high:
00286       comboboxPriority->setCurrentItem( 3 );
00287       break;
00288     case SIGEL_GP::SIG_GPParameter::veryHigh:
00289       comboboxPriority->setCurrentItem( 4 );
00290       break;
00291     }
00292   
00293   // set the graveyard stuff widgets
00294   if( theExperiment.gpParameter.getLiveUndead() )
00295     checkboxUseGraveyard->setChecked( true );
00296   else
00297     checkboxUseGraveyard->setChecked( false );
00298   QDir graveyardDir = theExperiment.gpParameter.getGraveYardDirectory();
00299   lineeditGraveyardDir->setText( graveyardDir.absPath() );
00300 
00301   QDir poolImageDir = theExperiment.gpParameter.getPoolImageDirectory();
00302   lineeditPoolImageDir->setText( poolImageDir.absPath() );
00303   int poolImageGeneration = theExperiment.gpParameter.getPoolImageGeneration();
00304   if (poolImageGeneration == 0)
00305     checkboxUsePoolImage->setChecked( false );
00306   else
00307     {
00308       checkboxUsePoolImage->setChecked( true );
00309       spinboxPoolImageFrequency->setValue( poolImageGeneration );
00310     }
00311   
00312   // enter the PVM hosts into the list...
00313   // clear list
00314   listviewHosts->clear();
00315   QList<SIGEL_GP::SIG_GPPVMHost> &hostList = theExperiment.gpParameter.getHostList();
00316   QListIterator<SIGEL_GP::SIG_GPPVMHost> it( hostList );
00317   for ( ; it.current(); ++it )
00318     {
00319       // create a new listview item for each found host
00320       QListViewItem *newItem = new QListViewItem( listviewHosts );
00321       // set the pixmap
00322       if( it.current()->enabled )
00323         newItem->setPixmap(0, QPixmap( sigelRoot + "/pixmaps/allow.xpm" ) );
00324       else
00325         newItem->setPixmap(0, QPixmap( sigelRoot + "/pixmaps/disallow.xpm" ) );
00326       // set the hostname
00327       newItem->setText( 1, it.current()->name );
00328       // set maximal slaves
00329       newItem->setText( 2, QString::number( it.current()->maxSlaves ) );
00330       newItem->setText( 3, it.current()->executableDir.absPath() );
00331     }
00332 
00333   // set the timeout
00334   spinboxTimeout->setValue( theExperiment.gpParameter.getTimeOutMinutes() );
00335 };
00336 
00337 void SIG_GPParameter::slotAddHost()
00338 {
00339   // create an show the dialog
00340   SIG_EditHostDialog editDialog( 0, "editDialogAddHosts", true, 0 );
00341   editDialog.checkboxEnableHost->setChecked( true );
00342   editDialog.lineeditHostName->setFocus();
00343   editDialog.lineeditSlaveDirectory->setText( QDir::currentDirPath() );
00344   editDialog.setCaption( "Add host..." );
00345   switch ( editDialog.exec() )
00346     {
00347       // the OK button was pressed
00348     case QDialog::Accepted:
00349       // lets first see if there is no host under that name...
00350       QList<SIGEL_GP::SIG_GPPVMHost> &hostList = theExperiment.gpParameter.getHostList();
00351       QListIterator<SIGEL_GP::SIG_GPPVMHost> it( hostList );
00352       bool isThere = false;
00353       for ( ; it.current(); ++it )
00354         {
00355           if( it.current()->name == editDialog.lineeditHostName->text() )
00356             {
00357               isThere = true;
00358               break;
00359             }
00360         }
00361       if( !isThere && !editDialog.lineeditHostName->text().isEmpty() )
00362         {
00363           QString newName = editDialog.lineeditHostName->text();
00364           int newMaxSlaves = editDialog.spinboxMaximalNumberOfProcesses->value();
00365           bool newEnabled = editDialog.checkboxEnableHost->isChecked();
00366           QString newSlaveDirectory = editDialog.lineeditSlaveDirectory->text();
00367 
00368           // has to changed!!! has to be changed!!! QDir has to be set right!!!
00369           SIGEL_GP::SIG_GPPVMHost *newHost = new SIGEL_GP::SIG_GPPVMHost( newName, newMaxSlaves, newEnabled, QDir( newSlaveDirectory ) );
00370 
00371           QListViewItem *newListViewItem = new QListViewItem( listviewHosts );
00372           // set enabled
00373           if ( newEnabled )
00374             newListViewItem->setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/allow.xpm" ) );
00375           else
00376             newListViewItem->setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/disallow.xpm" ) );
00377           // set Hostname
00378           newListViewItem->setText( 1, newName );
00379           //set maximal slaves
00380           newListViewItem->setText( 2, QString::number( newMaxSlaves ) );
00381           newListViewItem->setText( 3, newSlaveDirectory );
00382           hostList.append( newHost );
00383         }
00384       else
00385         {
00386           QMessageBox::information( 0, "Error...", "The host " + editDialog.lineeditHostName->text() + " is either already present or you entered no name!" );
00387         }
00388       break;
00389     }
00390 };
00391 
00392 void SIG_GPParameter::slotEditHost()
00393 {
00394   slotItemDoubleClicked( listviewHosts->currentItem() );
00395 };
00396 
00397 void SIG_GPParameter::slotDeleteHost()
00398 {
00399   /*
00400    * this is the list of SIG_GPPVMHosts which have to be deleted as setAutoDelete is NOT true
00401    * in the host list. we don't delete the host directly as the iterator would get confused.
00402    */
00403   QList<SIGEL_GP::SIG_GPPVMHost> deleteListHosts;
00404   QList<QListViewItem> deleteListViewItems;
00405   
00406   // iterate over the list items
00407   QListViewItemIterator listIt( listviewHosts );
00408   for( ; listIt.current(); listIt++ )
00409     // is the current one selected?
00410     if( listIt.current()->isSelected() )
00411       {
00412         // first enter the item into the list of items to delete
00413         deleteListViewItems.append( listIt.current() );
00414 
00415         // get the name of the host to find it in the host list
00416         QString currentName = listIt.current()->text( 1 );
00417         // SIGEL_GP::SIG_GPPVMHost *theHost = 0; i think i don't need this anymore
00418         QList<SIGEL_GP::SIG_GPPVMHost> &hostList = theExperiment.gpParameter.getHostList();
00419         QListIterator<SIGEL_GP::SIG_GPPVMHost> it( hostList );
00420         // iterate over the host list to find the SIG_GPPVMHost object belonging to host currentName
00421         for ( ; it.current(); ++it )
00422           {
00423             if( it.current()->name == currentName )
00424               {
00425                 deleteListHosts.append( it.current() );
00426                 break;
00427               }
00428           }      
00429         /* if( theHost )
00430          * hostList.remove( theHost );
00431          * listviewHosts->takeItem( listIt.current() );
00432          */
00433       }
00434   
00435 // now lets break the shit up!
00436   QList<SIGEL_GP::SIG_GPPVMHost> &hostList2 = theExperiment.gpParameter.getHostList();
00437   QListIterator<SIGEL_GP::SIG_GPPVMHost> hostIt( deleteListHosts );
00438   for( ; hostIt.current(); ++hostIt )
00439     hostList2.remove( hostIt.current() );
00440   QListIterator<QListViewItem> itemIt( deleteListViewItems );
00441   for( ; itemIt.current(); ++itemIt )
00442     listviewHosts->takeItem( itemIt.current() );
00443   
00444 };
00445 
00446 void SIG_GPParameter::slotEnableAllHosts()
00447 {
00448   QList<SIGEL_GP::SIG_GPPVMHost> &hostList = theExperiment.gpParameter.getHostList();
00449   QListIterator<SIGEL_GP::SIG_GPPVMHost> it( hostList );
00450   for ( ; it.current(); ++it )
00451     {
00452       it.current()->enabled = true;
00453     }
00454   QListViewItemIterator listIt( listviewHosts );
00455   for ( ; listIt.current(); ++listIt )
00456     {
00457       listIt.current()->setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/allow.xpm" ) );
00458     }
00459 };
00460 
00461 void SIG_GPParameter::slotDisableAllHosts()
00462 {
00463   QList<SIGEL_GP::SIG_GPPVMHost> &hostList = theExperiment.gpParameter.getHostList();
00464   QListIterator<SIGEL_GP::SIG_GPPVMHost> it( hostList );
00465   for ( ; it.current(); ++it )
00466     {
00467       it.current()->enabled = false;
00468     }
00469   QListViewItemIterator listIt( listviewHosts );
00470   for ( ; listIt.current(); ++listIt )
00471     {
00472       listIt.current()->setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/disallow.xpm" ) );
00473     }
00474 };
00475 
00476 void SIG_GPParameter::slotItemDoubleClicked( QListViewItem * theItem )
00477 {
00478   if( theItem )
00479     {
00480       // count how many host items are selected, so we can display the dialog the right way
00481       int numberOfSelectedHosts = 0;
00482       QListViewItemIterator itemIt( listviewHosts );
00483       for( ; itemIt.current(); ++itemIt )
00484         {
00485           if( itemIt.current()->isSelected() )
00486             ++numberOfSelectedHosts;
00487         }
00488       
00489       QString currentName = theItem->text( 1 );
00490       SIGEL_GP::SIG_GPPVMHost *theHost = 0;
00491       QList<SIGEL_GP::SIG_GPPVMHost> &hostList = theExperiment.gpParameter.getHostList();
00492       QListIterator<SIGEL_GP::SIG_GPPVMHost> it( hostList );
00493       for ( ; it.current(); ++it )
00494         {
00495           if( it.current()->name == currentName )
00496             {
00497               // we found the host, so save it in the pointer and quit
00498               theHost = it.current();
00499               break;
00500             }
00501         }
00502       
00503       SIG_EditHostDialog editDialog( 0, "editDialogEditHosts", true, 0 );
00504       if( numberOfSelectedHosts == 1 )
00505         {
00506           editDialog.lineeditHostName->setText( theHost->name );
00507           editDialog.spinboxMaximalNumberOfProcesses->setValue( theHost->maxSlaves );
00508           editDialog.lineeditSlaveDirectory->setText( theHost->executableDir.absPath() );
00509           if( theHost->enabled )
00510             editDialog.checkboxEnableHost->setChecked( true );
00511           else
00512             editDialog.checkboxEnableHost->setChecked( false );
00513           editDialog.lineeditHostName->setFocus();
00514           editDialog.setCaption( "Edit host " + theHost->name + "..." );
00515         }
00516       else
00517         {
00518           editDialog.lineeditHostName->hide();
00519           editDialog.lineeditSlaveDirectory->setText( theHost->executableDir.absPath() );
00520           editDialog.spinboxMaximalNumberOfProcesses->setValue( theHost->maxSlaves );
00521           
00522           if( theHost->enabled )
00523             editDialog.checkboxEnableHost->setChecked( true );
00524           else
00525             editDialog.checkboxEnableHost->setChecked( false );
00526           editDialog.setCaption( "Edit hosts..." );
00527           editDialog.resize( QSize() );
00528         }
00529       switch( editDialog.exec() )
00530         {
00531         case QDialog::Accepted:
00532           /*
00533            * warning! it is important that if one item was selected the hostname can be changed
00534            * but must NOT be changed into an existing name oder empty name!!!
00535            */
00536 
00537           if( numberOfSelectedHosts == 1 )
00538             {
00539               QString newName = editDialog.lineeditHostName->text();
00540               bool isThere = false;
00541               if( newName != currentName )
00542                 {
00543                   QListIterator<SIGEL_GP::SIG_GPPVMHost> it2( hostList );
00544                   for ( ; it2.current(); ++it2 )
00545                     {
00546                       if( it2.current()->name == newName )
00547                         {
00548                           isThere = true;
00549                           break;
00550                         }
00551                     }
00552                 }
00553               if( !isThere && !newName.isEmpty() )
00554                 {
00555                   int newMaxSlaves = editDialog.spinboxMaximalNumberOfProcesses->value();
00556                   bool newEnabled = editDialog.checkboxEnableHost->isChecked();
00557                   QString newSlaveDirectory = editDialog.lineeditSlaveDirectory->text();
00558                   theHost->name = newName;
00559                   theHost->maxSlaves = newMaxSlaves;
00560                   theHost->enabled = newEnabled;
00561                   theHost->executableDir = QDir( newSlaveDirectory );
00562                   if ( newEnabled )
00563                     theItem->setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/allow.xpm" ) );
00564                   else
00565                     theItem->setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/disallow.xpm" ) );
00566                   // set Hostname
00567                   theItem->setText( 1, newName );
00568                   //set maximal slaves
00569                   theItem->setText( 2, QString::number( newMaxSlaves ) );
00570                   theItem->setText( 3, newSlaveDirectory );
00571                 }
00572               else
00573                 {
00574                   QMessageBox::information( 0, "Error...", "The host " + editDialog.lineeditHostName->text() + " is either already present or you entered no name!" );
00575                 }
00576             }
00577           else
00578             {
00579               int newMaxSlaves = editDialog.spinboxMaximalNumberOfProcesses->value();
00580               bool newEnabled = editDialog.checkboxEnableHost->isChecked();
00581               QString newSlaveDirectory = editDialog.lineeditSlaveDirectory->text();
00582               QListViewItemIterator itemIt2( listviewHosts );
00583               for( ; itemIt2.current(); ++itemIt2 )
00584                 {
00585                   if( itemIt2.current()->isSelected() )
00586                     {
00587                       QString currentHostName = itemIt2.current()->text( 1 );
00588                       QListIterator<SIGEL_GP::SIG_GPPVMHost> hostIt( hostList );
00589                       for ( ; hostIt.current(); ++hostIt )
00590                         {
00591                           if( hostIt.current()->name == currentHostName )
00592                             {
00593                               // set all the stuff according to the dialog
00594                               hostIt.current()->maxSlaves = newMaxSlaves;
00595                               hostIt.current()->enabled = newEnabled;
00596                               hostIt.current()->executableDir = QDir( newSlaveDirectory );
00597                             }
00598                         } // for over all
00599 
00600                       // set the listviewItems right...
00601                       if( newEnabled)
00602                         itemIt2.current()->setPixmap(0, QPixmap( sigelRoot + "/pixmaps/allow.xpm" ) );
00603                       else
00604                         itemIt2.current()->setPixmap(0, QPixmap( sigelRoot + "/pixmaps/disallow.xpm" ) );
00605                       itemIt2.current()->setText(2, QString::number( newMaxSlaves ) );
00606                       itemIt2.current()->setText(3, newSlaveDirectory );
00607                     } // if( itemIt2.current()->isSelected )
00608                 }
00609             }
00610           break;
00611         } // end of switch statement
00612     } // end of if( theItem )
00613 };
00614 
00615 void SIG_GPParameter::slotMutationChanged( int newMutationValue )
00616 {
00617   if( newMutationValue + sliderCrossover->value() > 1000 )
00618     sliderMutation->setValue( 1000 - sliderCrossover->value() );
00619   double mutationValue = static_cast<double>( sliderMutation->value() );
00620   double crossoverValue = static_cast<double>( sliderCrossover->value() );
00621   lcdnumberMutation->display( mutationValue / 10 );
00622   sliderReproduction->setValue( 1000 - sliderMutation->value() - sliderCrossover->value() );
00623   lcdnumberReproduction->display( ( 1000 - mutationValue - crossoverValue) / 10 );
00624 }
00625 
00626 void SIG_GPParameter::slotCrossoverChanged( int newCrossoverValue )
00627 {
00628   if( newCrossoverValue + sliderMutation->value() > 1000 )
00629     sliderCrossover->setValue( 1000 - sliderMutation->value() );
00630   double mutationValue = static_cast<double>( sliderMutation->value() );
00631   double crossoverValue = static_cast<double>( sliderCrossover->value() );
00632   lcdnumberCrossover->display( crossoverValue / 10 );
00633   sliderReproduction->setValue( 1000 - sliderMutation->value() - sliderCrossover->value() );
00634   lcdnumberReproduction->display( (1000 - crossoverValue - mutationValue) / 10 );
00635 }
00636 
00637 }
00638 
00639 
00640 
00641 
00642 
00643 
00644 

Generated at Mon Sep 3 01:32:24 2001 for PG 368 - SIGEL by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000