00001 #include "obj_funct.h" 00002 #include <math.h> 00003 #include <stdlib.h> 00004 00005 /** 00006 The constructor obj_funct ( long oDim ) allocates memmory for 00007 objective function. Each optimization variable is limited by three 00008 values in Domain: [min,max,precision]. Therefore the whole domain is 00009 defined by Domain[Dim][3]. User can also specify and allocate 00010 optimum, if it is known. If Return_to_domain is set to zero, the 00011 algorithm will have chance to find optimum even outside given 00012 boundaries. At the end, this function calls obj_funct::user_allocate (), 00013 placed in user_obj_funct.cpp, where the user can specify his own 00014 allocation statements. 00015 00016 @param oDim is number of optimized variables 00017 00018 @b Requirements : 00019 oDim must be non-negative. 00020 00021 created $Date: 2003/12/05 20:31:07 $, $Author: leps $ 00022 */ 00023 obj_funct::obj_funct ( long oDim ) 00024 { 00025 long i; 00026 Dim=oDim; 00027 Domain = new p_double [Dim]; 00028 for ( i=0; i<Dim; i++ ) Domain[i] = new double [3]; 00029 optimum = NULL; 00030 precision = 0.0; 00031 Return_to_domain=0; 00032 outfile = new char [256]; 00033 00034 this->user_allocate () ; 00035 } 00036 00037 /** 00038 The destructor ~obj_funct () deallocates all basic dynamic 00039 variables. It also calls obj_funct::user_deallocate (), placed in 00040 user_obj_funct.cpp, where user must specify deleting statements for 00041 variables allocated by him in obj_funct::user_allocate (). 00042 00043 created $Date: 2003/12/05 20:31:07 $, $Author: leps $ 00044 */ 00045 obj_funct::~obj_funct ( void ) 00046 { 00047 this->user_deallocate () ; 00048 00049 long i; 00050 for ( i=0; i<Dim; i++ ) delete [] Domain[i]; 00051 delete [] Domain; 00052 if ( optimum ) delete optimum; 00053 } 00054 00055 /** 00056 The "value ( double *oCH )" function returns value of objective 00057 function. Calls sifel_value(), where some preparations for 00058 appropriate problem (MEFEL,TRFEL,...) are placed and secondly, calls 00059 user_value(), which is placed in user_obj_funct.cpp, and where user 00060 can specify his own objective function. 00061 00062 @param oCH is pointer to actual set of optimized variables ( x[i] ) 00063 00064 @b Requirements : 00065 oCH must be different from NULL. 00066 00067 @retval double precision number = objective value f( x[i] ) 00068 00069 created $Date: 2003/12/05 20:31:07 $, $Author: leps $ 00070 */ 00071 double obj_funct::value ( double *oCH ) 00072 { 00073 this->sifel_value( oCH ) ; 00074 return ( this->user_value( oCH ) ) ; 00075 } 00076