00001 #include <qpushbutton.h>
00002 #include <qmultilineedit.h>
00003 #include <qtextstream.h>
00004 #include <qfiledialog.h>
00005 #include <qmessagebox.h>
00006
00007 #include "SIGEL_MasterGUI/SIG_ExperimentView.h"
00008 #include "SIGEL_GP/SIG_GPExperimentHistoryEntry.h"
00009 #include "SIGEL_Tools/SIG_IO.h"
00010
00011 #include <unistd.h>
00012
00013 namespace SIGEL_MasterGUI
00014 {
00015
00016
00017
00018
00019
00020 SIG_ExperimentView::SIG_ExperimentView( QWidget* parent, const char* name, WFlags fl, SIGEL_GP::SIG_GPExperiment &theExperiment )
00021 : SIG_ExperimentViewBase( parent, name, fl ), theExperiment( theExperiment )
00022 {
00023 }
00024
00025
00026
00027
00028 SIG_ExperimentView::~SIG_ExperimentView()
00029 {
00030
00031 }
00032
00033 void SIG_ExperimentView::putIntoExperiment()
00034 {
00035 theExperiment.comment = multilineeditComment->text();
00036 };
00037
00038 void SIG_ExperimentView::getOutOfExperiment()
00039 {
00040 multilineeditComment->setText( theExperiment.comment );
00041 };
00042
00043 void SIG_ExperimentView::streamToGnuPlot( QTextStream &stream )
00044 {
00045 stream << "set data style lines\n"
00046 << "set title \"Maximal, minimal and average fitnessvalues\"\n"
00047 << "set xlabel 'Generation'\n"
00048 << "set ylabel 'Fitnessvalue'\n";
00049
00050 stream << "plot '-' title 'Maximal fitness', '-' title 'Minimal fitness', '-' title 'Average fitness'\n";
00051
00052 SIGEL_GP::SIG_GPExperimentHistoryEntry *actEntry = theExperiment.experimentHistory.first();
00053
00054 while (actEntry)
00055 {
00056 stream << actEntry->getGenerationNo()
00057 << " "
00058 << actEntry->getMaxFitness()
00059 << "\n";
00060
00061 actEntry = theExperiment.experimentHistory.next();
00062 };
00063
00064 stream << "e\n";
00065
00066 actEntry = theExperiment.experimentHistory.first();
00067
00068 while (actEntry)
00069 {
00070 stream << actEntry->getGenerationNo()
00071 << " "
00072 << actEntry->getMinFitness()
00073 << "\n";
00074
00075 actEntry = theExperiment.experimentHistory.next();
00076 };
00077
00078 stream << "e\n";
00079
00080 actEntry = theExperiment.experimentHistory.first();
00081
00082 while (actEntry)
00083 {
00084 stream << actEntry->getGenerationNo()
00085 << " "
00086 << actEntry->getAverageFitness()
00087 << "\n";
00088
00089 actEntry = theExperiment.experimentHistory.next();
00090 };
00091
00092 stream << "e\n";
00093 };
00094
00095 void SIG_ExperimentView::slotExportPostScript()
00096 {
00097 if (theExperiment.experimentHistory.isEmpty())
00098 {
00099 QMessageBox::information( this, "Info", "There is no evolution data to plot!", "Ok" );
00100 return;
00101 };
00102
00103 QString fileName = QFileDialog::getSaveFileName( QString::null,
00104 "Encapsulated postscript files (*.eps);;All files (*)",
00105 this );
00106
00107 if (fileName.isNull())
00108 return;
00109
00110 FILE *gnuPlotStdInPipe = popen( "gnuplot -persist -", "w" );
00111
00112 if (!gnuPlotStdInPipe)
00113 {
00114 QMessageBox::warning( this, "Error!", "Couldn't start gnuplot!", "Ok" );
00115 return;
00116 };
00117
00118 QFile pipeFile;
00119 pipeFile.open( IO_WriteOnly, gnuPlotStdInPipe );
00120
00121 QTextStream pipeStream( &pipeFile );
00122
00123 pipeStream << "set terminal postscript\n"
00124 << "set output '" << fileName << "'\n";
00125
00126 streamToGnuPlot( pipeStream );
00127
00128 pipeStream << "quit\n";
00129
00130 pipeFile.close();
00131
00132 pclose( gnuPlotStdInPipe );
00133
00134 };
00135
00136 void SIG_ExperimentView::slotShowFitnesscurve()
00137 {
00138 if (theExperiment.experimentHistory.isEmpty())
00139 {
00140 QMessageBox::information( this, "Info", "There is no evolution data to plot!", "Ok" );
00141 return;
00142 };
00143
00144 FILE *gnuPlotStdInPipe = popen( "gnuplot -persist -", "w" );
00145
00146 if (!gnuPlotStdInPipe)
00147 {
00148 QMessageBox::warning( this, "Error!", "Couldn't start gnuplot!", "Ok" );
00149 return;
00150 };
00151
00152 QFile pipeFile;
00153 pipeFile.open( IO_WriteOnly, gnuPlotStdInPipe );
00154
00155 QTextStream pipeStream( &pipeFile );
00156
00157 streamToGnuPlot( pipeStream );
00158
00159 pipeStream << "quit\n";
00160
00161 pipeFile.close();
00162
00163 pclose( gnuPlotStdInPipe );
00164 };
00165
00166 }