Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


evocommon.h
00001 //---------------------------------------------------------------------
00002 //  Algorithmic Conjurings @ http://www.coyotegulch.com
00003 //  Evocosm -- An Object-Oriented Framework for Evolutionary Algorithms
00004 //
00005 //  evocommon.h
00006 //---------------------------------------------------------------------
00007 //
00008 //  Copyright 1996-2005 Scott Robert Ladd
00009 //
00010 //  This program is free software; you can redistribute it and/or modify
00011 //  it under the terms of the GNU General Public License as published by
00012 //  the Free Software Foundation; either version 2 of the License, or
00013 //  (at your option) any later version.
00014 //  
00015 //  This program is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //  
00020 //  You should have received a copy of the GNU General Public License
00021 //  along with this program; if not, write to the
00022 //      Free Software Foundation, Inc.
00023 //      59 Temple Place - Suite 330
00024 //      Boston, MA 02111-1307, USA.
00025 //
00026 //-----------------------------------------------------------------------
00027 //
00028 //  For more information on this software package, please visit
00029 //  Scott's web site, Coyote Gulch Productions, at:
00030 //
00031 //      http://www.coyotegulch.com
00032 //  
00033 //-----------------------------------------------------------------------
00034 
00035 #if !defined(LIBEVOCOSM_EVOGLOBAL_H)
00036 #define LIBEVOCOSM_EVOGLOBAL_H
00037 
00038 // Standard C++ Library
00039 #include <string>
00040 #include <iostream>
00041 #include <iomanip>
00042 
00043 // libcoyotl
00044 #include "libcoyotl/mtwister.h"
00045 
00046 namespace libevocosm
00047 {
00049 
00053     class globals
00054     {
00055     protected:
00057         static size_t rand_index(size_t n)
00058         {
00059             return g_random.get_rand_index(n);
00060         }
00061 
00063         static libcoyotl::mtwister g_random;
00064         
00066         static std::string g_version;
00067         
00068     public:        
00070         static void set_random_seed(uint32_t a_seed)
00071         {
00072             g_random.init(a_seed);
00073         }
00074 
00076         static uint32_t get_seed()
00077         {
00078             return g_random.get_seed();
00079         }
00080         
00082         static std::string version()
00083         {
00084             return g_version;
00085         }
00086     };
00087     
00089 
00094     class listener
00095     {
00096         public:
00098 
00102             virtual void ping_generation_begin(size_t a_generation_number) = 0;
00103         
00105 
00109             virtual void ping_generation_end(size_t a_generation_number) = 0;
00110         
00112 
00116             virtual void ping_population_begin(size_t a_population_number) = 0;
00117             
00119 
00123             virtual void ping_population_end(size_t a_population_number) = 0;
00124             
00126 
00130             virtual void ping_fitness_test_begin(size_t a_organism_number) = 0;
00131             
00133 
00137             virtual void ping_fitness_test_end(size_t a_organism_number) = 0;
00138             
00140 
00148             virtual void report(const std::string & a_text) = 0;
00149             
00151 
00158             virtual void report_error(const std::string & a_text) = 0;
00159             
00161 
00165             virtual void run_complete() = 0;
00166             
00168 
00173             virtual void yield() = 0;
00174     };
00175     
00177 
00180     class null_listener : public listener
00181     {
00182         public:
00184 
00188             virtual void ping_generation_begin(size_t a_generation_number)
00189             {
00190                 // do nothing
00191             }
00192         
00194 
00198             virtual void ping_generation_end(size_t a_generation_number)
00199             {
00200                 // do nothing
00201             }
00202         
00204 
00208             virtual void ping_population_begin(size_t a_population_number)
00209             {
00210                 // do nothing
00211             }
00212             
00214 
00218             virtual void ping_population_end(size_t a_population_number)
00219             {
00220                 // do nothing
00221             }
00222             
00224 
00228             virtual void ping_fitness_test_begin(size_t a_organism_number)
00229             {
00230                 // do nothing
00231             }
00232             
00234 
00238             virtual void ping_fitness_test_end(size_t a_organism_number)
00239             {
00240                 // do nothing
00241             }
00242             
00244 
00252             virtual void report(const std::string & a_text)
00253             {
00254                 // do nothing
00255             }
00256             
00258 
00265             virtual void report_error(const std::string & a_text)
00266             {
00267                 // do nothing
00268             }
00269             
00271 
00275             virtual void run_complete()
00276             {
00277                 // do nothing
00278             }
00279             
00281 
00286             virtual void yield()
00287             {
00288                 // do nothing
00289             }
00290     };
00291     
00293 
00297     class listener_stdout : public listener
00298     {
00299         public:
00301 
00305             virtual void ping_generation_begin(size_t a_generation_number)
00306             {
00307                 std::cout << "------------------------------------------------------------\ngeneration "
00308                           << a_generation_number << " begins" << std::endl;
00309             }
00310 
00312 
00316             virtual void ping_generation_end(size_t a_generation_number)
00317             {
00318                 // nada
00319             }
00320 
00322 
00326             virtual void ping_population_begin(size_t a_population_number)
00327             {
00328                 std::cout << "\npopulation " << std::setw(2) << a_population_number << ": " << std::flush;
00329             }
00330 
00332 
00336             virtual void ping_population_end(size_t a_population_number)
00337             {
00338                 // nada
00339             }
00340 
00342 
00346             virtual void ping_fitness_test_begin(size_t a_organism_number)
00347             {
00348                 // nada
00349             }
00350 
00352 
00356             virtual void ping_fitness_test_end(size_t a_organism_number)
00357             {
00358                 std::cout << "." << std::flush;
00359             }
00360 
00362 
00370             virtual void report(const std::string & a_text)
00371             {
00372                 std::cout << a_text;
00373             }
00374 
00376 
00383             virtual void report_error(const std::string & a_text)
00384             {
00385                 std::cerr << a_text;
00386             }
00387 
00389 
00393             virtual void run_complete()
00394             {
00395                 // nada
00396             }
00397 
00399 
00404             virtual void yield()
00405             {
00406                 usleep(50000);
00407             }
00408     };
00409     
00410 }
00411 
00412 #endif

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.