Added the signal handling - see eoCtrlCContinue.h
I've disabled it in case of MSC as I don't know if this works there ... Also added a couple of "virtual" in the ga dir
This commit is contained in:
parent
4cb797544a
commit
ddc6650ce5
8 changed files with 180 additions and 265 deletions
|
|
@ -80,7 +80,9 @@
|
|||
#include <eoGenContinue.h>
|
||||
#include <eoSteadyFitContinue.h>
|
||||
#include <eoFitContinue.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <eoCtrlCContinue.h> // CtrlC handling (using 2 global variables!)
|
||||
#endif
|
||||
// Selection
|
||||
// the eoSelectOne's
|
||||
#include <eoRandomSelect.h> // also contains the eoSequentialSelect
|
||||
|
|
|
|||
92
eo/src/eoCtrlCContinue.h
Normal file
92
eo/src/eoCtrlCContinue.h
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoCtrlCContinue.h
|
||||
// (c) EEAAX 1996 - GeNeura Team, 1998 - Maarten Keijzer 2000
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef eoCtrlCContinue_h
|
||||
#define eoCtrlCContinue_h
|
||||
|
||||
#include <signal.h>
|
||||
#include <eoContinue.h>
|
||||
|
||||
// --- Global variables - but don't know what else to do - MS ---
|
||||
static bool arret_demande = false;
|
||||
static bool existCtrlCContinue = false;
|
||||
|
||||
//
|
||||
// The signal handler - installed in the eoCtrlCContinue Ctor
|
||||
//
|
||||
void signal_handler( int sig )
|
||||
// ---------------------------
|
||||
{
|
||||
// --- On veut la paix, jusqu'a la fin ---
|
||||
signal( SIGINT, SIG_IGN );
|
||||
signal( SIGQUIT, SIG_IGN );
|
||||
cerr << "Ctrl C entered ... closing down" << endl ;
|
||||
arret_demande = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Permet de savoir si on a appuye sur Control-C
|
||||
// (renvoie alors 1)
|
||||
//
|
||||
int AppliArretDemande()
|
||||
// --------------------
|
||||
{
|
||||
return arret_demande;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Ctrl C handling: this eoContinue tells whether the user pressed Ctrl C
|
||||
*/
|
||||
template< class EOT>
|
||||
class eoCtrlCContinue: public eoContinue<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
/// Ctor : installs the signal handler
|
||||
eoCtrlCContinue()
|
||||
{
|
||||
// First checks that no other eoCtrlCContinue does exist
|
||||
if (existCtrlCContinue)
|
||||
throw runtime_error("A signal handler for Ctrl C is already defined!\n");
|
||||
signal( SIGINT, signal_handler );
|
||||
signal( SIGQUIT, signal_handler );
|
||||
existCtrlCContinue = true;
|
||||
}
|
||||
|
||||
/** Returns false when Ctrl C has been typed in
|
||||
* reached */
|
||||
virtual bool operator() ( const eoPop<EOT>& _vEO )
|
||||
{
|
||||
if (arret_demande)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -64,7 +64,7 @@ template <class FitT> class eoBit: public eoVector<FitT, bool>
|
|||
eoVector<FitT, bool>(size, value) {}
|
||||
|
||||
/// My class name.
|
||||
string className() const
|
||||
virtual string className() const
|
||||
{
|
||||
return "eoBit";
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ template <class FitT> class eoBit: public eoVector<FitT, bool>
|
|||
* To print me on a stream.
|
||||
* @param os The ostream.
|
||||
*/
|
||||
void printOn(ostream& os) const
|
||||
virtual void printOn(ostream& os) const
|
||||
{
|
||||
EO<FitT>::printOn(os);
|
||||
os << ' ';
|
||||
|
|
@ -85,7 +85,7 @@ template <class FitT> class eoBit: public eoVector<FitT, bool>
|
|||
* To read me from a stream.
|
||||
* @param is The istream.
|
||||
*/
|
||||
void readFrom(istream& is)
|
||||
virtual void readFrom(istream& is)
|
||||
{
|
||||
EO<FitT>::readFrom(is);
|
||||
unsigned s;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ template<class Chrom> class eoOneBitFlip: public eoMonOp<Chrom>
|
|||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoOneBitFlip"; }
|
||||
virtual string className() const { return "eoOneBitFlip"; }
|
||||
|
||||
/**
|
||||
* Change one bit.
|
||||
|
|
@ -99,7 +99,7 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<Chrom>
|
|||
eoDetBitFlip(const unsigned& _num_bit = 1): num_bit(_num_bit) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoDetBitFlip"; }
|
||||
virtual string className() const { return "eoDetBitFlip"; }
|
||||
|
||||
/**
|
||||
* Change num_bit bits.
|
||||
|
|
@ -135,7 +135,7 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
|||
eoBitMutation(const double& _rate = 0.01): rate(_rate) {}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoBitMutation"; }
|
||||
virtual string className() const { return "eoBitMutation"; }
|
||||
|
||||
/**
|
||||
* Mutate a chromosome.
|
||||
|
|
@ -168,7 +168,7 @@ template<class Chrom> class eoBitInversion: public eoMonOp<Chrom>
|
|||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBitInversion"; }
|
||||
virtual string className() const { return "eoBitInversion"; }
|
||||
|
||||
/**
|
||||
* Inverts a range of bits in a binary chromosome.
|
||||
|
|
@ -196,7 +196,7 @@ template<class Chrom> class eoBitNext: public eoMonOp<Chrom>
|
|||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBitNext"; }
|
||||
virtual string className() const { return "eoBitNext"; }
|
||||
|
||||
/**
|
||||
* Change the bit string x to be x+1.
|
||||
|
|
@ -230,7 +230,7 @@ template<class Chrom> class eoBitPrev: public eoMonOp<Chrom>
|
|||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eoBitPrev"; }
|
||||
virtual string className() const { return "eoBitPrev"; }
|
||||
|
||||
/**
|
||||
* Change the bit string x to be x-1.
|
||||
|
|
@ -264,7 +264,7 @@ template<class Chrom> class eo1PtBitXover: public eoQuadOp<Chrom>
|
|||
{
|
||||
public:
|
||||
/// The class name.
|
||||
string className() const { return "eo1PtBitXover"; }
|
||||
virtual string className() const { return "eo1PtBitXover"; }
|
||||
|
||||
/**
|
||||
* 1-point crossover for binary chromosomes.
|
||||
|
|
@ -302,7 +302,7 @@ template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
|||
runtime_error("UxOver --> invalid preference");
|
||||
}
|
||||
/// The class name.
|
||||
string className() const { return "eoUBitXover"; }
|
||||
virtual string className() const { return "eoUBitXover"; }
|
||||
|
||||
/**
|
||||
* Uniform crossover for binary chromosomes.
|
||||
|
|
@ -348,7 +348,7 @@ template<class Chrom> class eoNPtsBitXover: public eoQuadOp<Chrom>
|
|||
}
|
||||
|
||||
/// The class name.
|
||||
string className() const { return "eoNPtsBitXover"; }
|
||||
virtual string className() const { return "eoNPtsBitXover"; }
|
||||
|
||||
/**
|
||||
* n-point crossover for binary chromosomes.
|
||||
|
|
@ -416,7 +416,7 @@ template<class Chrom> class eoBitGxOver: public eoQuadOp<Chrom>
|
|||
}
|
||||
|
||||
/// The class name
|
||||
string className() const { return "eoBitGxOver"; }
|
||||
virtual string className() const { return "eoBitGxOver"; }
|
||||
|
||||
/**
|
||||
* Gene crossover for binary chromosomes.
|
||||
|
|
|
|||
Reference in a new issue