3838
3939COptMethodGASR::COptMethodGASR (const CDataContainer * pParent,
4040 const CTaskEnum::Method & methodType,
41- const CTaskEnum::Task & taskType):
42- COptPopulationMethod(pParent, methodType, taskType, false ),
43- mCrossOverFalse(0 ),
44- mCrossOver(0 ),
45- mpPermutation(NULL ),
46- mWins(0 ),
47- mMutationVarians(0.1 ),
48- mStopAfterStalledGenerations(0 ),
49- mEvaluationValue(std::numeric_limits< C_FLOAT64 >::max()),
50- mBestIndex(C_INVALID_INDEX)
41+ const CTaskEnum::Task & taskType)
42+ : COptPopulationMethod(pParent, methodType, taskType, false )
43+ , mCrossOverFalse(0 )
44+ , mCrossOver(0 )
45+ , mpPermutation(NULL )
46+ , mWins(0 )
47+ , mMutationVariance(0.1 )
48+ , mStopAfterStalledGenerations(0 )
49+ , mBestIndex(C_INVALID_INDEX)
5150{
5251 assertParameter (" Number of Generations" , CCopasiParameter::Type::UINT, (unsigned C_INT32) 200 );
5352 assertParameter (" Population Size" , CCopasiParameter::Type::UINT, (unsigned C_INT32) 20 );
5453 assertParameter (" Random Number Generator" , CCopasiParameter::Type::UINT, (unsigned C_INT32) CRandom::mt19937, eUserInterfaceFlag::editable);
5554 assertParameter (" Seed" , CCopasiParameter::Type::UINT, (unsigned C_INT32) 0 , eUserInterfaceFlag::editable);
56- assertParameter (" Pf" , CCopasiParameter::Type::DOUBLE, (C_FLOAT64) 0.475 ); // *****ADDED for SR
55+ assertParameter (" Pf" , CCopasiParameter::Type::DOUBLE, (C_FLOAT64) 0.475 ); // *****ADDED for SR
5756 assertParameter (" Mutation Variance" , CCopasiParameter::Type::DOUBLE, (C_FLOAT64) 0.1 , eUserInterfaceFlag::editable);
5857 assertParameter (" Stop after # Stalled Generations" , CCopasiParameter::Type::UINT, (unsigned C_INT32) 0 , eUserInterfaceFlag::editable);
5958
6059 initObjects ();
6160}
6261
6362COptMethodGASR::COptMethodGASR (const COptMethodGASR & src,
64- const CDataContainer * pParent):
65- COptPopulationMethod(src, pParent),
66- mCrossOverFalse(0 ),
67- mCrossOver(0 ),
68- mpPermutation(NULL ),
69- mWins(0 ),
70- mMutationVarians(0.1 ),
71- mStopAfterStalledGenerations(0 ),
72- mEvaluationValue(std::numeric_limits< C_FLOAT64 >::max()),
73- mBestIndex(C_INVALID_INDEX)
74- {initObjects ();}
63+ const CDataContainer * pParent)
64+ : COptPopulationMethod(src, pParent)
65+ , mCrossOverFalse(0 )
66+ , mCrossOver(0 )
67+ , mpPermutation(NULL )
68+ , mWins(0 )
69+ , mMutationVariance(0.1 )
70+ , mStopAfterStalledGenerations(0 )
71+ , mBestIndex(C_INVALID_INDEX)
72+ {
73+ initObjects ();
74+ }
7575
7676COptMethodGASR::~COptMethodGASR ()
7777{cleanup ();}
@@ -109,7 +109,7 @@ bool COptMethodGASR::mutate(CVector< C_FLOAT64 > & individual)
109109 C_FLOAT64 & mut = individual[j];
110110
111111 // calculate the mutated parameter
112- mut *= mRandomContext .master ()->getRandomNormal (1 , mMutationVarians );
112+ mut *= mRandomContext .master ()->getRandomNormal (1 , mMutationVariance );
113113
114114 // for SR do not force to be within bounds
115115
@@ -176,7 +176,6 @@ bool COptMethodGASR::crossover(const CVector< C_FLOAT64 > & parent1,
176176bool COptMethodGASR::replicate ()
177177{
178178 size_t i;
179- bool Continue = true ;
180179
181180 // generate a random order for the parents
182181 mpPermutation->shuffle ();
@@ -193,16 +192,17 @@ bool COptMethodGASR::replicate()
193192 *mIndividuals [2 * mPopulationSize - 1 ] = *mIndividuals [mpPermutation->next ()];
194193
195194 // mutate the offspring
196- for (i = mPopulationSize ; i < 2 * mPopulationSize && Continue; i++)
195+ #pragma omp parallel for schedule(runtime)
196+ for (i = mPopulationSize ; i < 2 * mPopulationSize ; i++)
197197 {
198198 mutate (*mIndividuals [i]);
199- mValues [i] = mEvaluationValue = evaluate (EvaluationPolicyFlag::None);
199+ mValues [i] = evaluate (EvaluationPolicyFlag::None);
200200
201201 /* Calculate the phi value of the individual for SR*/
202202 mPhi [i] = phi (i);
203203 }
204204
205- return Continue ;
205+ return proceed () ;
206206}
207207
208208// select mPopulationSize individuals
@@ -320,20 +320,19 @@ bool COptMethodGASR::creation(size_t first,
320320 C_FLOAT64 mx;
321321 C_FLOAT64 la;
322322
323- bool Continue = true ;
324-
325- for (i = first; i < Last && Continue; i++)
323+ #pragma omp parallel for schedule(runtime)
324+ for (i = first; i < Last; i++)
326325 {
327326 createIndividual (i, COptItem::CheckPolicyFlag::None);
328327
329328 // calculate its fitness
330- mValues [i] = mEvaluationValue = evaluate (EvaluationPolicyFlag::None);
329+ mValues [i] = evaluate (EvaluationPolicyFlag::None);
331330
332331 /* Calculate the phi value of the individual for SR*/
333332 mPhi [i] = phi (i);
334333 }
335334
336- return Continue ;
335+ return proceed () ;
337336}
338337
339338void COptMethodGASR::initObjects ()
@@ -379,16 +378,16 @@ bool COptMethodGASR::initialize()
379378 mWins .resize (2 * mPopulationSize );
380379
381380 // initialize the variance for mutations
382- mMutationVarians = 0.1 ;
381+ mMutationVariance = 0.1 ;
383382
384383 if (getParameter (" Mutation Variance" ))
385384 {
386- mMutationVarians = getValue< C_FLOAT64 >(" Mutation Variance" );
385+ mMutationVariance = getValue< C_FLOAT64 >(" Mutation Variance" );
387386
388- if (mMutationVarians < 0.0 || 1.0 < mMutationVarians )
387+ if (mMutationVariance < 0.0 || 1.0 < mMutationVariance )
389388 {
390- mMutationVarians = 0.1 ;
391- setValue (" Mutation Variance" , mMutationVarians );
389+ mMutationVariance = 0.1 ;
390+ setValue (" Mutation Variance" , mMutationVariance );
392391 }
393392 }
394393
@@ -435,8 +434,8 @@ bool COptMethodGASR::optimise()
435434 // first individual is the initial guess
436435 createIndividual (C_INVALID_INDEX, COptItem::CheckPolicyFlag::None);
437436
438- mValues [0 ] = mEvaluationValue = evaluate (EvaluationPolicyFlag::None);
439- mProblemContext .master ()->setSolution (mEvaluationValue , *mIndividuals [0 ], true );
437+ mValues [0 ] = evaluate (EvaluationPolicyFlag::None);
438+ mProblemContext .master ()->setSolution (mValues [ 0 ] , *mIndividuals [0 ], true );
440439
441440 /* Calculate the phi value of the individual for SR*/
442441 mPhi [0 ] = phi (0 );
0 commit comments