ometah-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oMetah-devel] ometah/metaheuristic itsMetaheuristic.cpp itsMe...


From: Johann
Subject: [oMetah-devel] ometah/metaheuristic itsMetaheuristic.cpp itsMe...
Date: Mon, 21 Feb 2005 04:40:16 -0500

CVSROOT:        /cvsroot/ometah
Module name:    ometah
Branch:         
Changes by:     Johann <address@hidden> 05/02/21 09:40:15

Modified files:
        metaheuristic  : itsMetaheuristic.cpp itsMetaheuristic.hpp 
Added files:
        metaheuristic  : itsEstimationOfDistribution.cpp 
                         itsEstimationOfDistribution.hpp 

Log message:
        * more stuff for the main class
        * a first step to the EDA class

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsEstimationOfDistribution.cpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsEstimationOfDistribution.hpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsMetaheuristic.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/metaheuristic/itsMetaheuristic.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: ometah/metaheuristic/itsMetaheuristic.cpp
diff -u ometah/metaheuristic/itsMetaheuristic.cpp:1.1 
ometah/metaheuristic/itsMetaheuristic.cpp:1.2
--- ometah/metaheuristic/itsMetaheuristic.cpp:1.1       Mon Feb  7 12:45:35 2005
+++ ometah/metaheuristic/itsMetaheuristic.cpp   Mon Feb 21 09:40:15 2005
@@ -10,42 +10,113 @@
  *  for difficult optimization.
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
+ *  it under the terms of the GNU Lesser General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Library General Public License for more details.
+ *  GNU Lesser General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
+ *  You should have received a copy of the GNU Lesser General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
  
- #include "itsMetaheuristic.hpp"
+#include "itsMetaheuristic.hpp"
+#include "../common/random.hpp"
  
- //! global optimization methods 
- /*! 
-     All these methods are to be partially or completly 
-     instanciated by the user who creates a special 
-     metaheuristics
- */
+//! global optimization methods 
+/*! 
+  All these methods are to be partially or completly 
+  instanciated by the user who creates a special 
+  metaheuristics
+*/
  
- itsMetaheuristic::intensification()
- { }
- itsMetaheuristic::diversification()
- { }
- itsMetaheuristic::learning()
- { }
- itsMetaheuristic::parseSpecific()
- { }
- itsMetaheuristic::start()
- { }
- itsMetaheuristic::evaluate()
- { }
- itsMetaheuristic::parse()
- { }
- itsMetaheuristic::parseCommon()
- { }
+itsMetaheuristic::intensification()
+{ }
+itsMetaheuristic::diversification()
+{ }
+itsMetaheuristic::learning()
+{ }
+itsMetaheuristic::parseSpecific()
+{ }
+
+
+itsMetaheuristic::itsMetaheuristic()
+{
+  setName("Unknown");
+  setAccronym("Unknown");
+  setFamily("Unknown");
+  setDescription("Unknown");
+  setCitation("Unknown");
+
+  setSampleSize(1);
+
+  setIterationsMaxNumber(2);
+
+  this->outEndResult = &cout;
+  this->outProcessResult = &cout;
+  this->outErrors = &cerr;
+  this->outLog = &clog;
+  this->outDebug = &clog;
+
+  this->iterationsCurrent=0;
+}
+
+itsMetaheuristic::initialization()
+{
+  // ask for the bounds
+  vector<double> min = problem->boundsMinima();
+  vector<double> max = problem->boundsMaxima();
+  
+  // create the initial sample
+  for(unsigned int i=0; i<getSampleSize(); i++) {
+    itsPoint aRandomPoint;
+    // draw a vector in the bounds
+    aRandomPoint.setSolution( randomUniform(min,max) );
+    // ask for the associated values
+    aRandomPoint = problem->call(aRandomPoint);
+    // add it to the sample
+    sample.push_back(aRandomPoint);
+  }
+}
+
+itsMetaheuristic::start()
+{
+  initialization();
+
+  // no iterations has been computed
+  iterationsCurrent=0;
+
+  // while no stopping criterion reached
+  do {
+    // main phases
+    learning();
+    diversification();
+    intensification();
+    
+    // one more iteration
+    iterationsCurrent++;
+  } while( !isStoppingCriteria() )
+}
+
+itsMetaheuristic::evaluate()
+{ }
+itsMetaheuristic::parse()
+{ }
+itsMetaheuristic::parseCommon()
+{ }
+
+bool isStoppingCriteria()
+{
+  // if the maximum iterations number has been reached
+  if(iterationsCurrent>=iterationsMaxNumber) {
+    return true;
+
+  } else {
+    // no stopping criterion reached
+    return false;
+  }
+}
Index: ometah/metaheuristic/itsMetaheuristic.hpp
diff -u ometah/metaheuristic/itsMetaheuristic.hpp:1.1 
ometah/metaheuristic/itsMetaheuristic.hpp:1.2
--- ometah/metaheuristic/itsMetaheuristic.hpp:1.1       Mon Feb  7 12:45:35 2005
+++ ometah/metaheuristic/itsMetaheuristic.hpp   Mon Feb 21 09:40:15 2005
@@ -9,65 +9,200 @@
  *  for difficult optimization.
  *  
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
+ *  it under the terms of the GNU Lesser General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Library General Public License for more details.
+ *  GNU Lesser General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
+ *  You should have received a copy of the GNU Lesser General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
  
 #ifndef ITSMETAHEURISTIC
 #define ITSMETAHEURISTIC
- 
+
+#include <fstream>
+
 #include "../common/itsPoint.hpp"
+#include "../communication/itsCommunicationClient.hpp"
  
 /*! 
-   is based on the "Abstract Factory" Pattern
+  is based on the "Abstract Factory" Pattern
 */
  
 class itsMetaheuristic
-  {
-    protected:
-      //! the intensification is a the a method
-      virtual void intensification();
+{
+protected:
+  //! The intensification phase
+  virtual void intensification();
       
-      //! the diversification
-      virtual void diversification();
+  //! The diversification phase
+  virtual void diversification();
       
-      //! the learning
-      virtual void learning();
+  //! The learning phase
+  virtual void learning();
       
-      //! A specific parse
-      /*! 
-          A particular protocole to pass data from 
-          the Metaheuristics to the Problems 
-      */
-      virtual void parseSpecific();
+  //! The initialization phase
+  void initialization();
+
+  //! Test if a stopping criteria have been reached
+  bool isStoppingCriteria();
+  
+
+  //! A specific parse
+  /*! 
+    A particular protocole to pass data from 
+    the Metaheuristics to the Problems 
+  */
+  virtual void parseSpecific();
     
-    public:
-      //! start executing a Metaheuristic
-      void start();
+  //! The name of the algorithm
+  /*! 
+    This must be a unique name in the source tree
+  */
+  string name;
+
+  //! The acronym of the algorithm
+  string accronym;
+
+  //! The family of the metaheuristic
+  /*!
+    One should put here :
+      - Evolutionnary Algorithm
+      - Simulated Annealing
+      - Ant Colony Algorithm
+      - Tabu Search
+      - Estimation of Distribution Algorithm
+      - Immunitary Algorithm
+      - Particule Swarm Optimization
+      - ...
+      - Unknown
+   */
+  string family;
+
+  //! A brief description 
+  string description;
+
+  //! The paper reference (if available)
+  /*!
+    The reference should be formated in BiBTeX.
+  */
+  string citation;
+
+  
+  //! The points sample
+  /*!
+    This is the main data structure of the metaheuristic.
+    This is the collection of point manipulated by the algorithm.
+   */
+  vector<itsPoint> sample;
+
+  //! Number of points in the sample
+  int sampleSize;
+
+  //! Current iterations number
+  int iterationsCurrent;
+
+  //! Maximum iterations number
+  /*!
+    This is used if you choose the associated stopping criteria
+   */
+  int iterationsMaxNumber;
+
+  //! The pointer to the problem
+  itsCommunicationClient* problem;
+  
+
+  //! Stream for the main result of the optimization
+  /*!  
+    This is used for the output of the global optimum point
+    (position and values).
+  */
+  ostream* outEndResult;
+
+  //! Stream for the in progress results of the optimization
+  /*!  
+    This is used for the output of the points during the
+    optimization process.
+  */
+  ostream* outProcessResult;
+
+  //! Stream for the errors
+  /*!
+    Use this stream to output unrecoverable errors.
+   */
+  ostream* outErrors;
+
+  //! Stream for log
+  ostream* outLog;
+
+  //! Stream for debug
+  ostream* outDebug;
+
+
+public:
+  //! start executing a Metaheuristic
+  void start();
     
-      //! evaluate
-      void evaluate();
+  //! evaluate
+  void evaluate();
       
-      //! parse data from Metaheuristics
-      void parse();
+  //! parse data from Metaheuristics
+  void parse();
     
-      //! a common parse
-      /*! 
-          A common protocole to pass data from 
-          the Metaheuristics to the Problems
-      */
-      void parseCommon();
-  };
+  //! a common parse
+  /*! 
+    A common protocole to pass data from 
+    the Metaheuristics to the Problems
+  */
+  void parseCommon();
+
+  
+  //! Simple attribute accesses
+  //address@hidden
+
+  //! Return the name
+  string getName();
+  //! Set the name
+  void setName(string name);
+
+  //! Return the accronym
+  string getAccronym();
+  //! Change the Accronym
+  void setAccronym(string citation);
+
+  //! Return the description
+  string getDescription();
+  //! Change the description
+  void setDescription(string description);
+  
+  //! Return the reference
+  string getCitation();
+  //! Change the reference
+  void setCitation(string citation);
+
+  //! Return the family
+  string getFamily();
+  //! Change the reference
+  void setFamily(string citation);
+
+  //! Return the sample size
+  string getSampleSize();
+  //! Change the sample size
+  void setSampleSize(string size);
+
+  //! Return the maximum iterations number
+  string getIterationsMaxNumber();
+  //! Change the  maximum iterations number
+  void setIterationsMaxNumber(string size);
+
+  //@}
+};
 
 
 
@@ -75,7 +210,7 @@
 //! Abstract factory base class for metaheuristic instances
 /*! 
   This is the base class for all factory classes
- */
+*/
 
 class itsMetaheuristicFactory:
 {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]