Bug Summary

File:OMOptim/ParadisEO-2.0.1/eo/src/es/make_op_real.cpp
Warning:line 283, column 3
Forming reference to null pointer

Annotated Source Code

[?] Use j/k keys for keyboard navigation

/var/lib/jenkins1/ws/iodic_Jenkins.slow_omlib-staging/OMOptim/ParadisEO-2.0.1/eo/src/es/make_op_real.cpp

1// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
2
3//-----------------------------------------------------------------------------
4// make_op_real.cpp
5// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
6/*
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 Contact: todos@geneura.ugr.es, http://geneura.ugr.es
22 Marc.Schoenauer@polytechnique.fr
23 mkeijzer@dhi.dk
24 */
25//-----------------------------------------------------------------------------
26
27#ifdef _MSC_VER
28// to avoid long name warnings
29#pragma warning(disable:4786)
30#endif
31
32/** This file contains ***INSTANCIATED DEFINITIONS*** of operators fns
33 * of the library for ***eoReal*** evolution inside EO.
34 * It should be included in the file that calls any of the corresponding fns
35 * Compiling this file allows one to generate part of the library (i.e. object
36 * files that you just need to link with your own main and fitness code).
37 *
38 * The corresponding ***INSTANCIATED DECLARATIONS*** are contained
39 * in es.h in src/es dir
40 * while the TEMPLATIZED code is define in make_op.h in the es dir
41 *
42 */
43
44// Templatized code
45#include <es/make_op_real.h>
46
47/// The following function merely call the templatized do_* functions above
48
49// oeprators
50////////////
51eoGenOp<eoReal<double> >& make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<eoReal<double> >& _init)
52{
53 return do_make_op(_parser, _state, _init);
54}
55
56eoGenOp<eoReal<eoMinimizingFitness> >& make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<eoReal<eoMinimizingFitness> >& _init)
57{
58 return do_make_op(_parser, _state, _init);
1
Calling 'do_make_op'
59}

/var/lib/jenkins1/ws/iodic_Jenkins.slow_omlib-staging/OMOptim/ParadisEO-2.0.1/eo/src/es/make_op_real.h

1// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
2
3//-----------------------------------------------------------------------------
4// make_op.h - the real-valued version
5// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
6/*
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 Contact: todos@geneura.ugr.es, http://geneura.ugr.es
22 Marc.Schoenauer@polytechnique.fr
23 mkeijzer@dhi.dk
24 */
25//-----------------------------------------------------------------------------
26
27#ifndef _make_op_h
28#define _make_op_h
29
30// the operators
31#include <eoOp.h>
32#include <eoGenOp.h>
33#include <eoCloneOps.h>
34#include <eoOpContainer.h>
35// combinations of simple eoOps (eoMonOp and eoQuadOp)
36#include <eoProportionalCombinedOp.h>
37
38// the specialized Real stuff
39#include <es/eoReal.h>
40#include <es/eoEsChromInit.h>
41#include <es/eoRealOp.h>
42#include <es/eoNormalMutation.h>
43 // also need the parser and param includes
44#include <utils/eoParser.h>
45#include <utils/eoState.h>
46
47
48/** @addtogroup Builders
49 * @{
50 */
51
52/*
53 * This function builds the operators that will be applied to the eoReal
54 *
55 * It uses a parser (to get user parameters) and a state (to store the memory)
56 * the last argument is an individual, needed for 2 reasons
57 * it disambiguates the call after instanciations
58 * some operator might need some private information about the indis
59 *
60 * This is why the template is the complete EOT even though only the fitness
61 * is actually templatized here: the following only applies to bitstrings
62 *
63 * Note : the last parameter is an eoInit: if some operator needs some info
64 * about the gneotypes, the init has it all (e.g. bounds, ...)
65 * Simply do
66 * EOT myEO;
67 * _init(myEO);
68 * and myEO is then an ACTUAL object
69*/
70
71template <class EOT>
72eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<EOT>& _init)
73{
74 // get std::vector size
75 unsigned vecSize = _init.size();
76
77 // First, decide whether the objective variables are bounded
78 eoValueParam<eoRealVectorBounds>& boundsParam
79 = _parser.getORcreateParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds), "objectBounds",
80 "Bounds for variables", 'B', "Variation Operators");
81
82 // this is a temporary version(!),
83 // while Maarten codes the full tree-structured general operator input
84 // BTW we must leave that simple version available somehow, as it is the one
85 // that 90% people use!
86 eoValueParam<std::string>& operatorParam
87 = _parser.getORcreateParam(std::string("SGA"), "operator",
88 "Description of the operator (SGA only now)",
89 'o', "Variation Operators");
90
91 if (operatorParam.value() != std::string("SGA"))
2
Taking false branch
92 throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
93
94 // now we read Pcross and Pmut,
95 // the relative weights for all crossovers -> proportional choice
96 // the relative weights for all mutations -> proportional choice
97 // and create the eoGenOp that is exactly
98 // crossover with pcross + mutation with pmut
99
100 eoValueParam<double>& pCrossParam
101 = _parser.getORcreateParam(0.6, "pCross",
102 "Probability of Crossover",
103 'C', "Variation Operators" );
104 // minimum check
105 if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
3
Taking false branch
106 throw std::runtime_error("Invalid pCross");
107
108 eoValueParam<double>& pMutParam
109 = _parser.getORcreateParam(0.1, "pMut",
110 "Probability of Mutation",
111 'M', "Variation Operators" );
112 // minimum check
113 if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
4
Taking false branch
114 throw std::runtime_error("Invalid pMut");
115
116 // the crossovers
117 /////////////////
118 // the parameters
119 eoValueParam<double>& alphaParam
120 = _parser.getORcreateParam(double(0.0), "alpha",
121 "Bound for factor of linear recombinations",
122 'a', "Variation Operators" );
123 // minimum check
124 if ( (alphaParam.value() < 0) )
5
Taking false branch
125 throw std::runtime_error("Invalid BLX coefficient alpha");
126
127
128 eoValueParam<double>& segmentRateParam
129 = _parser.getORcreateParam(double(1.0), "segmentRate",
130 "Relative rate for segment crossover",
131 's', "Variation Operators" );
132 // minimum check
133 if ( (segmentRateParam.value() < 0) )
6
Taking false branch
134 throw std::runtime_error("Invalid segmentRate");
135
136 eoValueParam<double>& hypercubeRateParam
137 = _parser.getORcreateParam(double(1.0), "hypercubeRate",
138 "Relative rate for hypercube crossover",
139 'A', "Variation Operators" );
140 // minimum check
141 if ( (hypercubeRateParam.value() < 0) )
7
Taking false branch
142 throw std::runtime_error("Invalid hypercubeRate");
143
144 eoValueParam<double>& uxoverRateParam
145 = _parser.getORcreateParam(double(1.0), "uxoverRate",
146 "Relative rate for uniform crossover",
147 'A', "Variation Operators" );
148 // minimum check
149 if ( (uxoverRateParam.value() < 0) )
8
Taking false branch
150 throw std::runtime_error("Invalid uxoverRate");
151
152 // minimum check
153 bool bCross = true;
154 if (segmentRateParam.value()+hypercubeRateParam.value()+uxoverRateParam.value()==0)
9
Taking false branch
155 {
156 std::cerr << "Warning: no crossover" << std::endl;
157 bCross = false;
158 }
159
160 // Create the CombinedQuadOp
161 eoPropCombinedQuadOp<EOT> *ptCombinedQuadOp = NULL__null;
162 eoQuadOp<EOT> *ptQuad = NULL__null;
163
164 if (bCross)
10
Taking true branch
165 {
166 // segment crossover for bitstring - pass it the bounds
167 ptQuad = new eoSegmentCrossover<EOT>(boundsParam.value(), alphaParam.value());
168 _state.storeFunctor(ptQuad);
169 ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, segmentRateParam.value());
170
171 // hypercube crossover
172 ptQuad = new eoHypercubeCrossover<EOT>(boundsParam.value(), alphaParam.value());
173 _state.storeFunctor(ptQuad);
174 ptCombinedQuadOp->add(*ptQuad, hypercubeRateParam.value());
175
176 // uniform crossover
177 ptQuad = new eoRealUXover<EOT>();
178 _state.storeFunctor(ptQuad);
179 ptCombinedQuadOp->add(*ptQuad, uxoverRateParam.value());
180
181 // don't forget to store the CombinedQuadOp
182 _state.storeFunctor(ptCombinedQuadOp);
183 }
184
185 // the mutations
186 /////////////////
187 // the parameters
188 eoValueParam<double> & epsilonParam
189 = _parser.getORcreateParam(0.01, "epsilon",
190 "Half-size of interval for Uniform Mutation",
191 'e', "Variation Operators" );
192 // minimum check
193 if ( (epsilonParam.value() < 0) )
11
Taking false branch
194 throw std::runtime_error("Invalid epsilon");
195
196 eoValueParam<double> & uniformMutRateParam
197 = _parser.getORcreateParam(1.0, "uniformMutRate",
198 "Relative rate for uniform mutation",
199 'u', "Variation Operators" );
200 // minimum check
201 if ( (uniformMutRateParam.value() < 0) )
12
Taking false branch
202 throw std::runtime_error("Invalid uniformMutRate");
203
204 eoValueParam<double> & detMutRateParam
205 = _parser.getORcreateParam(1.0, "detMutRate",
206 "Relative rate for deterministic uniform mutation",
207 'd', "Variation Operators" );
208 // minimum check
209 if ( (detMutRateParam.value() < 0) )
13
Taking false branch
210 throw std::runtime_error("Invalid detMutRate");
211
212 eoValueParam<double> & normalMutRateParam
213 = _parser.getORcreateParam(1.0, "normalMutRate",
214 "Relative rate for Gaussian mutation", 'd', "Variation Operators" );
215 // minimum check
216 if ( (normalMutRateParam.value() < 0) )
14
Taking false branch
217 throw std::runtime_error("Invalid normalMutRate");
218
219 eoValueParam<double> & sigmaParam
220 = _parser.getORcreateParam(0.3, "sigma",
221 "Sigma (fixed) for Gaussian mutation",
222 's', "Variation Operators" );
223
224 eoValueParam<double> & pNormalParam
225 = _parser.getORcreateParam(1.0, "pNormal",
226 "Proba. to change each variable for Gaussian mutation",
227 's', "Variation Operators" );
228
229 // minimum check
230 bool bMut = true;
231 if (uniformMutRateParam.value()+detMutRateParam.value()+normalMutRateParam.value()==0)
15
Taking true branch
232 {
233 std::cerr << "Warning: no mutation" << std::endl;
234 bMut = false;
235 }
236 if (!bCross && !bMut)
237 throw std::runtime_error("No operator called in SGA operator definition!!!");
238
239 // Create the CombinedMonOp
240 eoPropCombinedMonOp<EOT> *ptCombinedMonOp = NULL__null;
16
'ptCombinedMonOp' initialized to a null pointer value
241 eoMonOp<EOT> *ptMon = NULL__null;
242
243 if (bMut)
17
Taking false branch
244 {
245 // uniform mutation on all components:
246 // offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
247 ptMon = new eoUniformMutation<EOT>(boundsParam.value(), epsilonParam.value());
248 _state.storeFunctor(ptMon);
249 // create the CombinedMonOp
250 ptCombinedMonOp = new eoPropCombinedMonOp<EOT>(*ptMon, uniformMutRateParam.value());
251
252 // mutate exactly 1 component (uniformly) per individual
253 ptMon = new eoDetUniformMutation<EOT>(boundsParam.value(), epsilonParam.value());
254 _state.storeFunctor(ptMon);
255 ptCombinedMonOp->add(*ptMon, detMutRateParam.value());
256
257 // mutate all component using Gaussian mutation
258 ptMon = new eoNormalVecMutation<EOT>(boundsParam.value(), sigmaParam.value(), pNormalParam.value());
259 _state.storeFunctor(ptMon);
260 ptCombinedMonOp->add(*ptMon, normalMutRateParam.value());
261 _state.storeFunctor(ptCombinedMonOp);
262 }
263
264 // now build the eoGenOp:
265 // to simulate SGA (crossover with proba pCross + mutation with proba pMut
266 // we must construct
267 // a sequential combination of
268 // with proba 1, a proportional combination of
269 // a QuadCopy and our crossover
270 // with proba pMut, our mutation
271
272 // the crossover - with probability pCross
273 eoProportionalOp<EOT> * cross = new eoProportionalOp<EOT> ;
274 _state.storeFunctor(cross);
275 ptQuad = new eoQuadCloneOp<EOT>;
276 _state.storeFunctor(ptQuad);
277 cross->add(*ptCombinedQuadOp, pCrossParam.value()); // user crossover
278 cross->add(*ptQuad, 1-pCrossParam.value()); // clone operator
279
280 // now the sequential
281 eoSequentialOp<EOT> & op = _state.storeFunctor(new eoSequentialOp<EOT>);
282 op.add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
283 op.add(*ptCombinedMonOp, pMutParam.value());
18
Forming reference to null pointer
284
285 // that's it!
286 return op;
287}
288/** @} */
289#endif