1 /*
2  *  Open BEAGLE
3  *  Copyright (C) 2001-2007 by Christian Gagne and Marc Parizeau
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2.1 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  *  Contact:
20  *  Laboratoire de Vision et Systemes Numeriques
21  *  Departement de genie electrique et de genie informatique
22  *  Universite Laval, Quebec, Canada, G1K 7P4
23  *  http://vision.gel.ulaval.ca
24  *
25  */
26 
27 /*!
28  *  \file   beagle/Evolver.hpp
29  *  \brief  Definition of the class Evolver.
30  *  \author Christian Gagne
31  *  \author Marc Parizeau
32  *  $Revision: 1.8.2.1 $
33  *  $Date: 2007/05/09 01:51:10 $
34  */
35 
36 #ifndef Beagle_Evolver_hpp
37 #define Beagle_Evolver_hpp
38 
39 #include "beagle/config.hpp"
40 #include "beagle/macros.hpp"
41 #include "beagle/Object.hpp"
42 #include "beagle/Pointer.hpp"
43 #include "beagle/PointerT.hpp"
44 #include "beagle/Allocator.hpp"
45 #include "beagle/AllocatorT.hpp"
46 #include "beagle/Container.hpp"
47 #include "beagle/ContainerT.hpp"
48 #include "beagle/AbstractAllocT.hpp"
49 #include "beagle/WrapperT.hpp"
50 #include "beagle/System.hpp"
51 #include "beagle/Operator.hpp"
52 #include "beagle/Map.hpp"
53 #include "beagle/OperatorMap.hpp"
54 #include "beagle/Vivarium.hpp"
55 #include "beagle/ConfigurationDumper.hpp"
56 #include "beagle/UInt.hpp"
57 
58 namespace Beagle {
59 
60 /*!
61  *  \class Evolver beagle/Evolver.hpp "beagle/Evolver.hpp"
62  *  \brief Beagle's basic evolver class.
63  *  \ingroup ECF
64  *  \ingroup Op
65  */
66 class Evolver : public Object {
67 
68 public:
69 
70   //! Evolver allocator type.
71   typedef AllocatorT<Evolver,Object::Alloc>
72           Alloc;
73   //! Evolver handle type.
74   typedef PointerT<Evolver,Object::Handle>
75           Handle;
76   //! Evolver bag type.
77   typedef ContainerT<Evolver,Object::Bag>
78           Bag;
79 
80            Evolver();
~Evolver()81   virtual ~Evolver() { }
82 
83   void                   addBootStrapOp(string inName);
84   void                   addMainLoopOp(string inName);
85   void                   addOperator(Operator::Handle inOperator);
86   const Operator::Handle getOperator(string inName) const;
87   Operator::Handle       getOperator(string inName);
88   virtual void           initialize(System::Handle ioSystem, int& ioArgc, char** ioArgv);
89   virtual void           initialize(System::Handle ioSystem, string inConfigFilename);
90   virtual void           evolve(Vivarium::Handle ioVivarium);
91   virtual void           read(PACC::XML::ConstIterator inIter);
92   virtual void           readEvolverFile(string inFilename);
93   Operator::Handle       removeOperator(string inName);
94   virtual void           write(PACC::XML::Streamer& ioStreamer, bool inIndent=true) const;
95 
96   /*!
97    *  \brief Return a constant reference to the bootstrap operator set.
98    *  \return Bootstrap operator set constant reference.
99    */
getBootStrapSet() const100   inline const Operator::Bag& getBootStrapSet() const
101   {
102     Beagle_StackTraceBeginM();
103     return mBootStrapSet;
104     Beagle_StackTraceEndM("const Operator::Bag& Evolver::getBootStrapSet() const");
105   }
106 
107   /*!
108    *  \brief Return a reference to the bootstrap operator set.
109    *  \return Bootstrap operator set reference.
110    */
getBootStrapSet()111   inline Operator::Bag& getBootStrapSet()
112   {
113     Beagle_StackTraceBeginM();
114     return mBootStrapSet;
115     Beagle_StackTraceEndM("Operator::Bag& Evolver::getBootStrapSet()");
116   }
117 
118   /*!
119    *  \brief Return a constant reference to the main-loop operator set.
120    *  \return Main-loop operator set constant reference.
121    */
getMainLoopSet() const122   inline const Operator::Bag& getMainLoopSet() const
123   {
124     Beagle_StackTraceBeginM();
125     return mMainLoopSet;
126     Beagle_StackTraceEndM("const Operator::Bag& Evolver::getMainLoopSet() const");
127   }
128 
129   /*!
130    *  \brief Return a reference to the main-loop operator set.
131    *  \return Main-loop operator set reference.
132    */
getMainLoopSet()133   inline Operator::Bag& getMainLoopSet()
134   {
135     Beagle_StackTraceBeginM();
136     return mMainLoopSet;
137     Beagle_StackTraceEndM("Operator::Bag& Evolver::getMainLoopSet()");
138   }
139 
140   /*!
141    *  \return Operators map.
142    */
getOperatorMap()143   inline OperatorMap& getOperatorMap()
144   {
145     Beagle_StackTraceBeginM();
146     return mOperatorMap;
147     Beagle_StackTraceEndM("OperatorMap& Evolver::getOperatorMap()");
148   }
149 
150   /*!
151    *  \return Operators map.
152    */
getOperatorMap() const153   inline const OperatorMap& getOperatorMap() const
154   {
155     Beagle_StackTraceBeginM();
156     return mOperatorMap;
157     Beagle_StackTraceEndM("const OperatorMap& Evolver::getOperatorMap() const");
158   }
159 
160 protected:
161   virtual void addBasicOperators();
162   virtual void initializeOperators(System& ioSystem);
163   virtual void logWelcomeMessages();
164   virtual void parseCommandLine(System& ioSystem, int& ioArgc, char** ioArgv);
165   virtual void postInitOperators(System& ioSystem);
166 
167   System::Handle              mSystemHandle;  //!< Handle to the used system.
168   Operator::Bag               mBootStrapSet;  //!< Bootstrap operator set.
169   Operator::Bag               mMainLoopSet;   //!< Main-loop operator set.
170   OperatorMap                 mOperatorMap;   //!< Operator map.
171   ConfigurationDumper::Handle mConfigDumper;  //!< Configuration dumper to file parameter.
172   String::Handle              mFileName;      //!< Configuration file name.
173   UIntArray::Handle           mPopSize;       //!< Population size for the evolution.
174 
175 };
176 
177 }
178 
179 #endif // Beagle_Evolver_hpp
180