Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

GlobalOptimObj.h

00001 /* 
00002 * ObjCryst++ : a Crystallographic computing library in C++
00003 *        http://objcryst.sourceforge.net
00004 *        http://www.ccp14.ac.uk/ccp/web-mirrors/objcryst/
00005 *
00006 *  (c) 2000-2001 Vincent FAVRE-NICOLIN vincefn@users.sourceforge.net
00007 *
00008 */
00009 /*   GlobalOptimObj.h
00010 *  header file for the Global Optimization object
00011 *
00012 */
00013 #ifndef _GLOBALOPTIMOBJ_H
00014 #define _GLOBALOPTIMOBJ_H
00015 
00016 #include "ObjCryst/General.h"
00017 
00018 #ifdef __WX__CRYST__
00019 namespace ObjCryst
00020 {
00021    class GlobalOptimObj;
00022 }
00023    //#undef GetClassName // Conflict from wxMSW headers ? (cygwin)
00024 #include "wxCryst/wxGlobalOptimObj.h"
00025 #endif
00026 
00027 #include "RefinableObj/RefinableObj.h"
00028 #include "RefinableObj/IO.h"
00029 #include <string>
00030 #include <iostream>
00031 
00032 namespace ObjCryst
00033 {
00051 enum AnnealingSchedule
00052 {
00053    ANNEALING_CONSTANT,
00054    ANNEALING_BOLTZMANN,
00055    ANNEALING_CAUCHY,
00056 //   ANNEALING_QUENCHING,
00057    ANNEALING_EXPONENTIAL,
00058    ANNEALING_SMART
00059 };
00060 
00066 enum GlobalOptimType
00067 {
00068    GLOBAL_OPTIM_SIMULATED_ANNEALING,
00069    GLOBAL_OPTIM_PARALLEL_TEMPERING,
00070    GLOBAL_OPTIM_GENETIC
00071 };
00072 
00089 class GlobalOptimObj
00090 {
00091    public:
00093       GlobalOptimObj(const string name="");
00095       virtual ~GlobalOptimObj();
00096       
00099       void RandomizeStartingConfig();
00100       
00128       void SetAlgorithmSimulAnnealing(const AnnealingSchedule scheduleTemp,
00129                                  const double tMax, const double tMin,
00130                                  const AnnealingSchedule scheduleMutation=ANNEALING_CONSTANT,
00131                                  const double mutMax=16., const double mutMin=.125,
00132                                  const long nbTrialRetry=0,const double minCostRetry=0.,
00133                                  const long maxNbTrialSinceBest=0);
00152       void SetAlgorithmParallTempering(const AnnealingSchedule scheduleTemp,
00153                                  const double tMax, const double tMin,
00154                                  const AnnealingSchedule scheduleMutation=ANNEALING_CONSTANT,
00155                                  const double mutMax=16., const double mutMin=.125);
00156       
00160       void Optimize(long &nbSteps);
00161       
00162       //Parameter Access by name
00163       //RefinablePar& GetPar(const string& parName);
00164    //Set Refinable parameters status
00166       void FixAllPar();
00168       void SetParIsFixed(const string& parName,const bool fix);
00170       void SetParIsFixed(const RefParType *type,const bool fix);
00172       void UnFixAllPar();
00174       void SetParIsUsed(const string& parName,const bool use);
00176       void SetParIsUsed(const RefParType *type,const bool use);
00178       void SetLimitsRelative(const string &parName, const double min, const double max);
00180       void SetLimitsRelative(const RefParType *type, const double min, const double max);
00182       void SetLimitsAbsolute(const string &parName, const double min, const double max);
00184       void SetLimitsAbsolute(const RefParType *type, const double min, const double max);
00185 
00186       
00187       // Print information about the current state of optimization (parameters value, 
00188       // characteristic figures...)
00189       //virtual ostream& operator<<(ostream& os)const;
00193       void SaveOptimHistory() const;
00199       virtual double GetCostFunctionValue();
00201       void StopAfterCycle();
00203       virtual void DisplayReport();
00205       void AddRefinableObj(RefinableObj &);
00210       void AddCostFunction(RefinableObj &,const unsigned int id, const double weight=1.);
00217       virtual void XMLOutput(ostream &os,int indent=0)const;
00223       virtual void XMLInput(istream &is,const XMLCrystTag &tag);
00224       //virtual void XMLInputOld(istream &is,const IOCrystTag &tag);
00226       const string& GetName()const;
00228       void SetName(const string&);
00230       const string GetClassName()const;
00232       void Print()const;
00233    protected:
00234       
00248       virtual void NewConfiguration();
00249       
00251       void PrepareRefParList();
00252       
00254       void InitRandomSeedFromTime()const;
00255       
00257       void InitOptions();
00260       void UpdateDisplay();
00261       
00266       mutable RefinableObj mRefParList;
00268       string mName;
00270       string mSaveFileName;
00271       
00274       RefObjOpt mGlobalOptimType;
00275       
00276       //Status of optimization
00278          long mNbTrial;
00280          double mCurrentCost;
00282          double mBestCost;
00283          /* :TODO:
00284          // Current cost array. one row contains the different contributions to the cost,
00285          // if more than one cost function is used, and each row correspond to each
00286          // 'world' refinement (one world for simulated annealing, more for parallel
00287          // tempering).
00288          // This is used for reporting results.
00289          CrystMatrix_double mCurrentCostArray;
00290          */
00291          
00292       //Keep an history with the evolution of optimization
00294          long mHistoryNb;
00296          CrystVector_long mHistoryTrialNumber;
00298          CrystVector_double mHistoryCostFunction;
00300          CrystVector_long mHistorySavedParamSetIndex;
00302          bool mHistorySaveAfterEachOptim;
00304          string mHistorySaveFileName;
00305          
00307          long mBestParSavedSetIndex;
00309          long mLastParSavedSetIndex;
00310       
00311       // Annealing parameters
00313          double mTemperatureMax;
00315          double mTemperatureMin;
00317          RefObjOpt mAnnealingScheduleTemp;
00318       //Parameters to create new configurations
00323          double mMutationAmplitude;
00325          double mMutationAmplitudeMax;
00327          double mMutationAmplitudeMin;
00329          RefObjOpt mAnnealingScheduleMutation;
00330       //Automatic retry 
00333          long mNbTrialRetry;
00335          double mMinCostRetry;
00340          long mMaxNbTrialSinceBest;
00342       bool mIsOptimizing;
00344       bool mStopAfterCycle;
00345       
00346       // Refined objects
00348          ObjRegistry<RefinableObj> mRefinedObjList;
00350          ObjRegistry<RefinableObj> mRecursiveRefinedObjList;
00352          unsigned int mNbCostFunction;
00354          unsigned int mMaxNbCostFunction;
00356          RefinableObj *mpCostFunctionRefinableObj[20];
00358          CrystVector_int mpCostFunctionId;
00360          CrystVector_double mCostFunctionWeight;
00361    private:
00362    #ifdef __WX__CRYST__
00363    public:
00365       virtual WXCrystObj* WXCreate(wxWindow*);
00366       WXCrystObj* WXGet();
00367       void WXDelete();
00368       void WXNotifyDelete();
00369    protected:
00370       WXGlobalOptimObj *mpWXGlobalOptimObj;
00371       friend class ObjCryst::WXGlobalOptimObj;
00372    #endif
00373 };
00374 
00376 extern ObjRegistry<GlobalOptimObj> gGlobalOptimObjRegistry;
00377 
00378 }// namespace
00379 
00380 #endif //_GLOBALOPTIMOBJ_H

Generated on Wed Nov 14 19:48:35 2001 for ObjCryst++ by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001