OptimizationAlgorithm.cpp

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*   O P T I M I Z A T I O N   A L G O R I T H M   C L A S S                  */
00004 /*                                                                            */
00005 /*   Roberto Lopez                                                            */
00006 /*   International Center for Numerical Methods in Engineering (CIMNE)        */
00007 /*   Technical University of Catalonia (UPC)                                  */
00008 /*   Barcelona, Spain                                                         */
00009 /*   E-mail: rlopez@cimne.upc.edu                                             */
00010 /*                                                                            */
00011 /******************************************************************************/
00012 
00013 #include<iostream>
00014 
00015 #include "OptimizationAlgorithm.h"
00016 
00017 namespace Purple
00018 {
00019 
00020 // GENERAL CONSTRUCTOR
00021 //
00022 /// General constructor. It creates an optimization algorithm object associated
00023 /// to an objective function object. 
00024 ///
00025 /// @param newObjectiveFunction: Pointer to an objective function object.
00026 ///
00027 /// @see ObjectiveFunction.
00028 
00029 OptimizationAlgorithm
00030 ::OptimizationAlgorithm(ObjectiveFunction* newObjectiveFunction)
00031 {
00032    objectiveFunction = newObjectiveFunction;
00033 }
00034 
00035 
00036 // DEFAULT CONSTRUCTOR
00037 
00038 /// Default constructor. It creates an optimization algorithm object not associated
00039 /// to any objective function object.
00040 
00041 OptimizationAlgorithm::OptimizationAlgorithm(void)
00042 {
00043    objectiveFunction = NULL;
00044 }
00045 
00046 
00047 // DESTRUCTOR 
00048 
00049 /// Destructor.
00050 
00051 OptimizationAlgorithm::~OptimizationAlgorithm(void)
00052 { 
00053 
00054 }
00055 
00056 
00057 // METHODS
00058 
00059 // ObjectiveFunction* getObjectiveFunction(void) method
00060 
00061 /// This method returns a pointer to the objective function object to which
00062 /// the optimization algorithm is associated.
00063 
00064 ObjectiveFunction* OptimizationAlgorithm::getObjectiveFunction(void)
00065 {
00066    return(objectiveFunction);
00067 }
00068 
00069 
00070 // double getEvaluationGoal(void) method
00071 
00072 /// This method returns the objective function evaluation goal value.
00073 /// This is used as a stopping criterium when optimizing a function.
00074 ///  
00075 /// @see getMinimalArgument(void).
00076 
00077 double OptimizationAlgorithm::getEvaluationGoal(void)
00078 {
00079    return(evaluationGoal);
00080 }
00081 
00082 
00083 // int getMaximumTime(void) method
00084 
00085 /// This method returns the maximum optimization time.
00086 ///  
00087 /// @see getMinimalArgument(void).
00088 
00089 double OptimizationAlgorithm::getMaximumTime(void)
00090 {
00091    return(maximumTime);
00092 }
00093 
00094 
00095 
00096 // void setObjectiveFunction(ObjectiveFunction*) method
00097 
00098 /// This method sets a pointer to an objective function object to be associated 
00099 /// to the optimization algorithm.
00100 ///
00101 /// @param newObjectiveFunction: Pointer to an objective function object. 
00102 /// 
00103 /// @see getMinimalArgument(void).
00104 
00105 void OptimizationAlgorithm
00106 ::setObjectiveFunction(ObjectiveFunction* newObjectiveFunction)
00107 {
00108    objectiveFunction = newObjectiveFunction;
00109 }
00110 
00111 
00112 // void setEvaluationGoal(double) method
00113 
00114 /// This method sets a new goal value for the objective function evaluation. 
00115 /// This is used as a stopping criterium when optimizing an objective function.
00116 ///
00117 /// @param newEvaluationGoal: Goal value for the evaluation.
00118 /// 
00119 /// @see getMinimalArgument(void).
00120 
00121 void OptimizationAlgorithm::setEvaluationGoal(double newEvaluationGoal)
00122 {
00123    evaluationGoal = newEvaluationGoal;
00124 }
00125 
00126 
00127 // void setMaximumTime(double) method
00128 
00129 /// This method sets a new maximum optimization time.  
00130 ///
00131 /// @param newMaximumTime: Maximum optimization time.
00132 /// 
00133 /// @see getMinimalArgument(void).
00134 
00135 void OptimizationAlgorithm::setMaximumTime(double newMaximumTime)
00136 {
00137    if(newMaximumTime <= 0.0)
00138    {
00139       std::cout << std::endl 
00140                 << "Error: OptimizationAlgorithm class. " << std::endl
00141                 << "void setMaximumTime(double) method." << std::endl
00142                 << "Maximum time must be greater than 0." << std::endl
00143                 << std::endl;
00144 
00145       exit(1);
00146    }
00147 
00148    // Set maximum time
00149    
00150    maximumTime = newMaximumTime;
00151 }
00152 
00153 }
00154 
00155 
00156 // Purple: An Open Source Numerical Optimization C++ Library.
00157 // Copyright (C) 2005 Roberto Lopez 
00158 //
00159 // This library is free software; you can redistribute it and/or
00160 // modify it under the terms of the GNU Lesser General Public
00161 // License as published by the Free Software Foundation; either
00162 // version 2.1 of the License, or any later version.
00163 //
00164 // This library is distributed in the hope that it will be useful,
00165 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00166 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00167 // Lesser General Public License for more details.
00168 
00169 // You should have received a copy of the GNU Lesser General Public
00170 // License along with this library; if not, write to the Free Software
00171 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Generated on Wed Jun 21 13:10:38 2006 for Purple by  doxygen 1.4.7