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

sigel.cpp

00001 #include <qapplication.h>
00002 #include <qwindowsstyle.h>
00003 
00004 #include <pvm3.h>
00005 #include <csignal>
00006 
00007 #include "SIGEL_GP/SIG_GPManager.h"
00008 #include "SIGEL_MasterGUI/SIG_MainWindow.h"
00009 #include "SIGEL_Tools/SIG_IO.h"
00010 
00011 
00012 extern "C"
00013 {
00014   void sigelStandardSignalHandler(int signal)
00015   {
00016 
00017     int result = 1;
00018     switch ( signal )
00019       {
00020       case SIGABRT:
00021         SIGEL_Tools::SIG_IO::cerr << "Abort\n";
00022         break;
00023       case SIGFPE:
00024         SIGEL_Tools::SIG_IO::cerr << "Arithmetic error signal\n";
00025         break;
00026       case SIGILL:
00027         SIGEL_Tools::SIG_IO::cerr << "Invalid execution\n";
00028         break;
00029       case SIGINT:
00030         SIGEL_Tools::SIG_IO::cerr << "Asynchronous interactive attention\n";
00031         break;
00032       case SIGSEGV:
00033         SIGEL_Tools::SIG_IO::cerr << "Invalid storage access\n";
00034         break;
00035       case SIGTERM:
00036         //      SIGEL_Tools::SIG_IO::cerr << "Asynchronous termination request\n";
00037         result = 0;
00038         break;
00039       };
00040 
00041     pvm_halt();
00042 
00043     exit( result );
00044 
00045   };
00046 };
00047 
00048 int main( int argc, char *argv[] )
00049 {
00050 
00051   // Install the sigel sandard signal handler
00052   std::signal( SIGABRT, sigelStandardSignalHandler );
00053   std::signal( SIGFPE, sigelStandardSignalHandler );
00054   std::signal( SIGILL, sigelStandardSignalHandler );
00055   std::signal( SIGINT, sigelStandardSignalHandler );
00056   std::signal( SIGSEGV, sigelStandardSignalHandler );
00057   std::signal( SIGTERM, sigelStandardSignalHandler );
00058 
00059   // Start PVM
00060   int info = pvm_start_pvmd( 0, 0, 0 );
00061 
00062   // Register to PVM
00063   int myTaskId=pvm_mytid();
00064 
00065   bool guiEnabled = TRUE;
00066   if(argc >= 2)
00067     {
00068       QString option( argv[1] );
00069       if( option == "-evolve" )
00070         guiEnabled = FALSE;
00071       else
00072         guiEnabled = TRUE;
00073     };
00074 
00075   if ( guiEnabled )
00076     { 
00077       QApplication app( argc, argv, true );
00078       app.setStyle( new QWindowsStyle() );
00079 
00080       SIGEL_MasterGUI::SIG_MainWindow *mainWindow = new SIGEL_MasterGUI::SIG_MainWindow( 0 , "MainWindow" );
00081       app.setMainWidget( mainWindow );
00082       mainWindow->show();
00083 
00084       int result = app.exec();
00085 
00086       pvm_halt();
00087 
00088       return result;
00089     }
00090   else
00091     {
00092       SIGEL_Tools::SIG_IO::cerr << "Master is used to evolve!\n";
00093 
00094       if (argc < 3)
00095         {
00096           SIGEL_Tools::SIG_IO::cerr << "No experiment name supplied! Cannot start evolution loop!\n";
00097           pvm_halt();
00098           return 1;
00099         };
00100 
00101       QString experimentName( argv[2] );
00102       QFile experimentFile( experimentName );
00103       if (!experimentFile.open( IO_ReadOnly ))
00104         {
00105           SIGEL_Tools::SIG_IO::cerr << "Error opening " << experimentName << "!\n";
00106           pvm_halt();
00107           return 1;
00108         };
00109 
00110       SIGEL_GP::SIG_GPExperiment experiment;
00111 
00112       experiment.experimentName = experimentName;
00113       QTextStream experimentLoadStream( &experimentFile );
00114       experiment.loadExperiment( experimentLoadStream );
00115       experimentFile.close();
00116 
00117       SIGEL_GP::SIG_GPManager gpManager( experiment );
00118       gpManager.start();
00119       gpManager.wait();
00120 
00121       if (!experimentFile.open( IO_WriteOnly ))
00122         {
00123           SIGEL_Tools::SIG_IO::cerr << "Error opening " << experimentName << "!\n";
00124           pvm_halt();
00125           return 1;
00126         };
00127 
00128       QTextStream experimentSaveStream( &experimentFile );
00129       experiment.saveExperiment( experimentSaveStream );
00130       experimentFile.close();
00131 
00132       pvm_halt();
00133 
00134    return 0;
00135 
00136     };
00137 
00138 };

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