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   ParityEvalOp.hpp
29  *  \brief  Definition of the type ParityEvalOp.
30  *  \author Christian Gagne
31  *  \author Marc Parizeau
32  *  $Revision: 1.9.2.2 $
33  *  $Date: 2007/05/11 20:04:33 $
34  */
35 
36 /*!
37  *  \defgroup Parity Even-6 Parity Example
38  *  \brief Even-6 parity (parity): A GP example using ADFs with Open BEAGLE.
39  *
40  *  \par Objective
41  *  Find a program that produces the value of the Boolean parity problem given
42  *  six independent Boolean inputs.
43  *
44  *  \par Terminal set
45  *  - IN0, IN1, IN2, IN3, IN4, and IN5, the inputs of the function.
46  *
47  *  \par Function set
48  *  - AND
49  *  - OR
50  *  - NAND
51  *  - NOR
52  *
53  *  \par Automatically defined functions
54  *  Two ADFs used, each with two arguments inputs.
55  *
56  *  \par Fitness cases
57  *  All the \f$2^6 = 64\f$ combinations of the six input Booleans.
58  *
59  *  \par Fitness
60  *  Rate of correct outputs obtained over all the 64 fitness cases.
61  *
62  *  \par Stopping criteria
63  *  When the evolution reaches the maximum number of generations.
64  *
65  *  \par Reference
66  *  John R. Koza, "Genetic Programming II: Automatic Discovery of Reusable
67  *  Programs", MIT Press, 1994, pages 157-199.
68  *
69  */
70 
71 
72 #ifndef ParityEvalOp_hpp
73 #define ParityEvalOp_hpp
74 
75 #include "beagle/GP.hpp"
76 #include <string>
77 #include <vector>
78 
79 #define ParitySizeM  64
80 #define ParityFanInM 6
81 
82 
83 /*!
84  *  \class ParityEvalOp ParityEvalOp.hpp "ParityEvalOp.hpp"
85  *  \brief The individual evaluation class operator for the even-6 parity problem.
86  *  \ingroup Parity
87  */
88 class ParityEvalOp : public Beagle::GP::EvaluationOp {
89 
90 public:
91 
92   //! ParityEvalOp allocator type.
93   typedef Beagle::AllocatorT<ParityEvalOp,Beagle::GP::EvaluationOp::Alloc>
94           Alloc;
95   //!< ParityEvalOp handle type.
96   typedef Beagle::PointerT<ParityEvalOp,Beagle::GP::EvaluationOp::Handle>
97           Handle;
98   //!< ParityEvalOp bag type.
99   typedef Beagle::ContainerT<ParityEvalOp,Beagle::GP::EvaluationOp::Bag>
100           Bag;
101 
102   explicit ParityEvalOp();
103 
104   virtual void postInit(Beagle::System& ioSystem);
105   virtual Beagle::Fitness::Handle evaluate(Beagle::GP::Individual& inIndividual,
106                                            Beagle::GP::Context& ioContext);
107 
108 protected:
109   std::vector< std::vector<Beagle::Bool> > mInputs;
110   std::vector<Beagle::Bool>                mOutputs;
111 
112 };
113 
114 #endif // ParityEvalOp_hpp
115