@@ -65,6 +65,31 @@ void CompareWorlds(const CrystVector_long &idx,const CrystVector_long &swap, con
65
65
// #################################################################################
66
66
ObjRegistry<OptimizationObj> gOptimizationObjRegistry (" List of all Optimization objects" );
67
67
68
+ OptimizationObj::OptimizationObj ():
69
+ mName (" " ),mSaveFileName (" GlobalOptim.save" ),
70
+ mNbTrialPerRun (10000000 ),mNbTrial (0 ),mRun (0 ),mBestCost (-1 ),
71
+ mBestParSavedSetIndex (-1 ),
72
+ mContext (0 ),
73
+ mIsOptimizing (false ),mStopAfterCycle (false ),
74
+ mRefinedObjList (" OptimizationObj: " +mName +" RefinableObj registry" ),
75
+ mRecursiveRefinedObjList (" OptimizationObj: " +mName +" recursive RefinableObj registry" ),
76
+ mLastOptimTime (0 )
77
+ {
78
+ VFN_DEBUG_ENTRY (" OptimizationObj::OptimizationObj()" ,5 )
79
+ // This must be done in a real class to avoid calling a pure virtual method
80
+ // if a graphical representation is automatically called upon registration.
81
+ // gOptimizationObjRegistry.Register(*this);
82
+
83
+ static bool need_initRandomSeed=true ;
84
+ if (need_initRandomSeed==true )
85
+ {
86
+ srand (time (NULL ));
87
+ need_initRandomSeed=false ;
88
+ }
89
+ // We only copy parameters, so do not delete them !
90
+ mRefParList .SetDeleteRefParInDestructor (false );
91
+ VFN_DEBUG_EXIT (" OptimizationObj::OptimizationObj()" ,5 )
92
+ }
68
93
69
94
OptimizationObj::OptimizationObj (const string name):
70
95
mName (name),mSaveFileName (" GlobalOptim.save" ),
@@ -92,6 +117,36 @@ mLastOptimTime(0)
92
117
VFN_DEBUG_EXIT (" OptimizationObj::OptimizationObj()" ,5 )
93
118
}
94
119
120
+ OptimizationObj::OptimizationObj (const OptimizationObj &old):
121
+ mName (old.mName ),mSaveFileName (old.mSaveFileName ),
122
+ mNbTrialPerRun (old.mNbTrialPerRun ),mNbTrial (old.mNbTrial ),mRun (old.mRun ),mBestCost (old.mBestCost ),
123
+ mBestParSavedSetIndex (-1 ),
124
+ mContext (0 ),
125
+ mIsOptimizing (false ),mStopAfterCycle (false ),
126
+ mRefinedObjList (" OptimizationObj: " +mName +" RefinableObj registry" ),
127
+ mRecursiveRefinedObjList (" OptimizationObj: " +mName +" recursive RefinableObj registry" ),
128
+ mLastOptimTime (0 )
129
+ {
130
+ VFN_DEBUG_ENTRY (" OptimizationObj::OptimizationObj(&old)" ,5 )
131
+ // This must be done in a real class to avoid calling a pure virtual method
132
+ // if a graphical representation is automatically called upon registration.
133
+ // gOptimizationObjRegistry.Register(*this);
134
+
135
+ static bool need_initRandomSeed=true ;
136
+ if (need_initRandomSeed==true )
137
+ {
138
+ srand (time (NULL ));
139
+ need_initRandomSeed=false ;
140
+ }
141
+ // We only copy parameters, so do not delete them !
142
+ mRefParList .SetDeleteRefParInDestructor (false );
143
+
144
+ for (unsigned int i=0 ;i<old.mRefinedObjList .GetNb ();i++)
145
+ this ->AddRefinableObj (old.mRefinedObjList .GetObj (i));
146
+
147
+ VFN_DEBUG_EXIT (" OptimizationObj::OptimizationObj(&old)" ,5 )
148
+ }
149
+
95
150
OptimizationObj::~OptimizationObj ()
96
151
{
97
152
VFN_DEBUG_ENTRY (" OptimizationObj::~OptimizationObj()" ,5 )
@@ -366,7 +421,7 @@ long OptimizationObj::GetParamSetIndex(const unsigned int i) const
366
421
{
367
422
if (i>=mvSavedParamSet.size ())
368
423
throw ObjCrystException (" OptimizationObj::GetSavedParamSetIndex(i): i > nb saved param set" );
369
-
424
+
370
425
return mvSavedParamSet[i].first ;
371
426
}
372
427
@@ -463,16 +518,14 @@ void OptimizationObj::InitOptions()
463
518
VFN_DEBUG_MESSAGE (" OptimizationObj::InitOptions():End" ,5 )
464
519
}
465
520
466
- void OptimizationObj::UpdateDisplay ()
521
+ void OptimizationObj::UpdateDisplay () const
467
522
{
468
523
Chronometer chrono;
469
- #ifdef __WX__CRYST__
470
- if (0 !=this ->WXGet ()) this ->WXGet ()->CrystUpdate (true ,true );
471
- #endif
472
524
for (int i=0 ;i<mRefinedObjList .GetNb ();i++)
473
525
mRefinedObjList .GetObj (i).UpdateDisplay ();
474
526
mMainTracker .UpdateDisplay ();
475
527
}
528
+
476
529
void OptimizationObj::BuildRecursiveRefObjList ()
477
530
{
478
531
// First check if anything has changed (ie if a sub-object has been
@@ -501,6 +554,27 @@ void OptimizationObj::AddOption(RefObjOpt *opt)
501
554
// MonteCarloObj
502
555
//
503
556
// #################################################################################
557
+ MonteCarloObj::MonteCarloObj ():
558
+ OptimizationObj (" " ),
559
+ mCurrentCost (-1 ),
560
+ mTemperatureMax (1e6 ),mTemperatureMin (.001 ),mTemperatureGamma (1.0 ),
561
+ mMutationAmplitudeMax (8 .),mMutationAmplitudeMin (.125 ),mMutationAmplitudeGamma (1.0 ),
562
+ mNbTrialRetry (0 ),mMinCostRetry (0 )
563
+ #ifdef __WX__CRYST__
564
+ ,mpWXCrystObj(0 )
565
+ #endif
566
+ {
567
+ VFN_DEBUG_ENTRY (" MonteCarloObj::MonteCarloObj()" ,5 )
568
+ this ->InitOptions ();
569
+ mGlobalOptimType .SetChoice (GLOBAL_OPTIM_PARALLEL_TEMPERING);
570
+ mAnnealingScheduleTemp .SetChoice (ANNEALING_SMART);
571
+ mAnnealingScheduleMutation .SetChoice (ANNEALING_EXPONENTIAL);
572
+ mXMLAutoSave .SetChoice (5 );// Save after each Run
573
+ mAutoLSQ .SetChoice (0 );
574
+ gOptimizationObjRegistry .Register (*this );
575
+ VFN_DEBUG_EXIT (" MonteCarloObj::MonteCarloObj()" ,5 )
576
+ }
577
+
504
578
MonteCarloObj::MonteCarloObj (const string name):
505
579
OptimizationObj (name),
506
580
mCurrentCost (-1 ),
@@ -522,6 +596,27 @@ mNbTrialRetry(0),mMinCostRetry(0)
522
596
VFN_DEBUG_EXIT (" MonteCarloObj::MonteCarloObj()" ,5 )
523
597
}
524
598
599
+ MonteCarloObj::MonteCarloObj (const MonteCarloObj &old):
600
+ OptimizationObj (old),
601
+ mCurrentCost (old.mCurrentCost ),
602
+ mTemperatureMax (old.mTemperatureMax ),mTemperatureMin (old.mTemperatureMin ),
603
+ mTemperatureGamma (old.mTemperatureGamma ),
604
+ mMutationAmplitudeMax (old.mMutationAmplitudeMax ),mMutationAmplitudeMin (old.mMutationAmplitudeMin ),
605
+ mMutationAmplitudeGamma (old.mMutationAmplitudeGamma ),
606
+ mNbTrialRetry (old.mNbTrialRetry ),mMinCostRetry (old.mMinCostRetry )
607
+ #ifdef __WX__CRYST__
608
+ ,mpWXCrystObj(0 )
609
+ #endif
610
+ {
611
+ VFN_DEBUG_ENTRY (" MonteCarloObj::MonteCarloObj(&old)" ,5 )
612
+ this ->InitOptions ();
613
+ for (unsigned int i=0 ;i<this ->GetNbOption ();i++)
614
+ this ->GetOption (i).SetChoice (old.GetOption (i).GetChoice ());
615
+
616
+ gOptimizationObjRegistry .Register (*this );
617
+ VFN_DEBUG_EXIT (" MonteCarloObj::MonteCarloObj(&old)" ,5 )
618
+ }
619
+
525
620
MonteCarloObj::MonteCarloObj (const bool internalUseOnly):
526
621
OptimizationObj (" " ),
527
622
mCurrentCost (-1 ),
@@ -2221,6 +2316,15 @@ void MonteCarloObj::InitLSQ(const bool useFullPowderPatternProfile)
2221
2316
mLSQ .SetParIsFixed (gpRefParTypeRadiation,true );
2222
2317
}
2223
2318
2319
+ void MonteCarloObj::UpdateDisplay () const
2320
+ {
2321
+ Chronometer chrono;
2322
+ #ifdef __WX__CRYST__
2323
+ if (0 !=mpWXCrystObj) mpWXCrystObj->CrystUpdate (true ,true );
2324
+ #endif
2325
+ this ->OptimizationObj ::UpdateDisplay ();
2326
+ }
2327
+
2224
2328
#ifdef __WX__CRYST__
2225
2329
WXCrystObjBasic* MonteCarloObj::WXCreate (wxWindow *parent)
2226
2330
{
0 commit comments