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

GnuPlotterSimulatedAnnealingObserver.cpp

Go to the documentation of this file.
00001 // GnuPlotterSimulatedAnnealingObserver.cpp: implementation of the GnuPlotterSimulatedAnnealingObserver class.
00002 //
00004 
00005 #include "GnuPlotterSimulatedAnnealingObserver.h"
00006 
00008 // Construction/Destruction
00010 
00011 GnuPlotterSimulatedAnnealingObserver::GnuPlotterSimulatedAnnealingObserver()
00012 {
00013 
00014 }
00015 
00016 GnuPlotterSimulatedAnnealingObserver::~GnuPlotterSimulatedAnnealingObserver()
00017 {
00018 
00019 }
00020 
00021 void GnuPlotterSimulatedAnnealingObserver::Update(Subject *theChangedSubject)
00022 {
00023         // static cast may be dangerous
00024         CSimulatedAnnealingStrategy *SA = (CSimulatedAnnealingStrategy *)theChangedSubject;
00025 
00026         // arrays to send to gnuplot
00027         char titlestring[100];
00028         char commandstring[1000];
00029 
00030         // write the appropriate quantities to the buffer
00031         double OneOverT = 1/(SA->GetTemperature());
00032         double Ratio = SA->GetAcceptanceRatio();
00033         double EBar = SA->GetEBar();
00034         double SpecHeat = (SA->GetE2Bar() - (EBar*EBar))*OneOverT*OneOverT;
00035         double EMin = SA->GetEMin();
00036         fprintf(buffer,"%e\t%e\t%e\t%e\t%e\n",OneOverT,EBar,Ratio,SpecHeat,EMin);
00037         
00038         // set up for multiplot
00039         SendPlotCommand("set multiplot\n");
00040 
00041         // FIRST PLOT
00042         SendPlotCommand("set origin 0.0,0.0\n");
00043         SendPlotCommand("set size 0.5,0.5\n");
00044         sprintf(titlestring,"set title \"Average Energy\"\n");
00045         SendPlotCommand(titlestring);
00046         SendPlotCommand("set grid\n");
00047         SendPlotCommand("set nokey\n");
00048         SendPlotCommand("set logscale x\n");
00049         SendPlotCommand("set xlabel \"1/T\"\n");
00050         SendPlotCommand("set ylabel \"<E>\"\n");
00051 
00052         sprintf(commandstring,"plot \"%s\" u 1:2 t \"<E>\" w linespoints\n",buffername);
00053 
00054         // change single backslashes to forward slashes to keep windows happy
00055 #ifdef _WIN32
00056         int iterator = 0;
00057         while(commandstring[iterator] != '\0')
00058         {
00059                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00060                 iterator++;
00061         }
00062 #endif
00063 
00064         fflush(buffer);
00065         SendPlotCommand(commandstring);
00066 
00067         // SECOND PLOT
00068         SendPlotCommand("set origin 0.5,0.0\n");
00069         SendPlotCommand("set size 0.5,0.5\n");
00070         sprintf(titlestring,"set title \"Acceptance Ratio\"\n");
00071         SendPlotCommand(titlestring);
00072         SendPlotCommand("set grid\n");
00073         SendPlotCommand("set nokey\n");
00074         SendPlotCommand("set logscale x\n");
00075         SendPlotCommand("set xlabel \"1/T\"\n");
00076         SendPlotCommand("set ylabel \"R\"\n");
00077 
00078         sprintf(commandstring,"plot \"%s\" u 1:3 t \"R\" w linespoints\n",buffername);
00079 
00080         // change single backslashes to forward slashes to keep windows happy
00081 #ifdef _WIN32
00082         iterator = 0;
00083         while(commandstring[iterator] != '\0')
00084         {
00085                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00086                 iterator++;
00087         }
00088 #endif
00089 
00090         fflush(buffer);
00091         SendPlotCommand(commandstring);
00092         
00093         // THIRD PLOT
00094         SendPlotCommand("set origin 0.0,0.5\n");
00095         SendPlotCommand("set size 0.5,0.5\n");
00096         sprintf(titlestring,"set title \"Specific Heat\"\n");
00097         SendPlotCommand(titlestring);
00098         SendPlotCommand("set grid\n");
00099         SendPlotCommand("set nokey\n");
00100         SendPlotCommand("set logscale x\n");
00101         SendPlotCommand("set xlabel \"1/T\"\n");
00102         SendPlotCommand("set ylabel \"C(T)\"\n");
00103 
00104         sprintf(commandstring,"plot \"%s\" u 1:4 t \"C(T)\" w linespoints\n",buffername);
00105 
00106         // change single backslashes to forward slashes to keep windows happy
00107 #ifdef _WIN32
00108         iterator = 0;
00109         while(commandstring[iterator] != '\0')
00110         {
00111                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00112                 iterator++;
00113         }
00114 #endif
00115         
00116         fflush(buffer);
00117         SendPlotCommand(commandstring);
00118 
00119         // FOURTH PLOT
00120         SendPlotCommand("set origin 0.5,0.5\n");
00121         SendPlotCommand("set size 0.5,0.5\n");
00122         sprintf(titlestring,"set title \"Minimum Energy\"\n");
00123         SendPlotCommand(titlestring);
00124         SendPlotCommand("set grid\n");
00125         SendPlotCommand("set nokey\n");
00126         SendPlotCommand("set logscale x\n");
00127         SendPlotCommand("set xlabel \"1/T\"\n");
00128         SendPlotCommand("set ylabel \"EMin\"\n");
00129 
00130         sprintf(commandstring,"plot \"%s\" u 1:5 t \"Emin\" w linespoints\n",buffername);
00131 
00132         // change single backslashes to forward slashes to keep windows happy
00133 #ifdef _WIN32
00134         iterator = 0;
00135         while(commandstring[iterator] != '\0')
00136         {
00137                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00138                 iterator++;
00139         }
00140 #endif
00141         
00142         fflush(buffer);
00143         SendPlotCommand(commandstring);
00144 }

Generated on Mon Nov 3 09:37:53 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002