diff --git a/demos/bbo_realvalued/main.py b/demos/bbo_realvalued/main.py index 49c2a82..c8ca0b9 100644 --- a/demos/bbo_realvalued/main.py +++ b/demos/bbo_realvalued/main.py @@ -10,10 +10,16 @@ def objective_function( self, objective_index, variables ): y = variables[i+1] f += 100*(y-x*x)*(y-x*x) + (1.0-x)*(1.0-x) return f + + def lower_range_bound(self, variable_index): + return -10 + + def upper_range_bound(self, variable_index): + return 10 dim = 10 frv = CustomRosenbrockFunction(dim,value_to_reach=1e-6) lm = gomea.linkage.Univariate() -rvgom = gomea.RealValuedGOMEA(fitness=frv, linkage_model=lm, lower_init_range=-115, upper_init_range=-100, max_number_of_populations=1, base_population_size=100, max_number_of_evaluations=1000000) +rvgom = gomea.RealValuedGOMEA(fitness=frv, linkage_model=lm, lower_init_range=-10, upper_init_range=10, max_number_of_populations=1, base_population_size=100, max_number_of_evaluations=1000000) result = rvgom.run() result.printAllStatistics() diff --git a/environment.yml b/environment.yml index 5c045bc..9b5c049 100644 --- a/environment.yml +++ b/environment.yml @@ -6,9 +6,9 @@ dependencies: - c-compiler - cxx-compiler - python=3.12 - - python-devtools=0.9.0 + - python-devtools==0.9.0 - numpy==2.0.1 - - ninja-1.12.1 + - ninja==1.12.1 - pip - pip: - meson==1.5.1 diff --git a/gomea/EmbeddedFitness.pxi b/gomea/EmbeddedFitness.pxi index deb7aab..831155e 100644 --- a/gomea/EmbeddedFitness.pxi +++ b/gomea/EmbeddedFitness.pxi @@ -120,3 +120,13 @@ cdef public double gomea_pyfitness_similarity_measure(obj, size_t var_a, size_t fitness_obj = obj cdef double result = fitness_obj.similarity_measure(var_a,var_b) return result + +cdef public double gomea_pyfitness_lower_range_bound(obj, int variable_index) except? -INFINITY: + fitness_obj = obj + cdef double result = fitness_obj.lower_range_bound(variable_index) + return result + +cdef public double gomea_pyfitness_upper_range_bound(obj, int variable_index) except? INFINITY: + fitness_obj = obj + cdef double result = fitness_obj.upper_range_bound(variable_index) + return result diff --git a/gomea/fitness.pxd b/gomea/fitness.pxd index 64bc3dc..39e71b6 100644 --- a/gomea/fitness.pxd +++ b/gomea/fitness.pxd @@ -114,6 +114,8 @@ cdef class FitnessFunction: cpdef void initialize_rotation_matrix(self, int rotation_block_size, double rotation_angle) cpdef np.ndarray rotate_variables(self, np.ndarray variables, double rotation_angle) + cpdef double lower_range_bound(self, int variable_index) + cpdef double upper_range_bound(self, int variable_index) cdef class GBOFitnessFunction(FitnessFunction): cpdef double subfunction( self, int subfunction_index, np.ndarray variables ) except? INFINITY diff --git a/gomea/fitness.pyx b/gomea/fitness.pyx index aa5446a..d153fd3 100644 --- a/gomea/fitness.pyx +++ b/gomea/fitness.pyx @@ -41,7 +41,12 @@ cdef class FitnessFunction: rotation_matrix = self.rotation_matrices[(len(variables),rotation_angle)] rotated_variables = np.matmul(rotation_matrix, variables) return rotated_variables + + cpdef double lower_range_bound(self, int variable_index): + return -INFINITY + cpdef double upper_range_bound(self, int variable_index): + return INFINITY cdef class YourFitnessFunctionDiscrete(FitnessFunction): def __cinit__(self, diff --git a/gomea/src/fitness/py_bbo_fitness.cpp b/gomea/src/fitness/py_bbo_fitness.cpp index 94d1785..5430ed8 100644 --- a/gomea/src/fitness/py_bbo_fitness.cpp +++ b/gomea/src/fitness/py_bbo_fitness.cpp @@ -76,39 +76,35 @@ double pyBBOFitnessFunction_t::constraintFunction( vec_t &variab } template -double pyBBOFitnessFunction_t::getLowerRangeBound( int dimension ) +double pyBBOFitnessFunction_t::getLowerRangeBound( int variable_index ) { - throw std::runtime_error("FitnessFunction does not implement getLowerRangeBound(int)."); + return gomea_pyfitness_lower_range_bound(py_class,variable_index); } template -double pyBBOFitnessFunction_t::getUpperRangeBound( int dimension ) +double pyBBOFitnessFunction_t::getUpperRangeBound( int variable_index ) { - throw std::runtime_error("FitnessFunction does not implement getUpperRangeBound(int)."); + return gomea_pyfitness_upper_range_bound(py_class,variable_index); } template<> -double pyBBOFitnessFunction_t::getLowerRangeBound( int dimension ) +double pyBBOFitnessFunction_t::getLowerRangeBound( int variable_index ) { - return( 0 ); -} - -template<> -double pyBBOFitnessFunction_t::getUpperRangeBound( int dimension ) -{ - return( alphabet_size-1 ); -} - -template<> -double pyBBOFitnessFunction_t::getLowerRangeBound( int dimension ) -{ - return( -1e308 ); + double result = gomea_pyfitness_lower_range_bound(py_class,variable_index); + if( result == -INFINITY ){ + return 0; + } + return result; } template<> -double pyBBOFitnessFunction_t::getUpperRangeBound( int dimension ) +double pyBBOFitnessFunction_t::getUpperRangeBound( int variable_index ) { - return( 1e308 ); + double result = gomea_pyfitness_upper_range_bound(py_class,variable_index); + if( result == INFINITY ){ + return alphabet_size-1; + } + return result; } template class pyBBOFitnessFunction_t; diff --git a/gomea/src/fitness/py_gbo_fitness.cpp b/gomea/src/fitness/py_gbo_fitness.cpp index 97f1481..992dbf7 100644 --- a/gomea/src/fitness/py_gbo_fitness.cpp +++ b/gomea/src/fitness/py_gbo_fitness.cpp @@ -118,29 +118,35 @@ double pyGBOFitnessFunction_t::getSimilarityMeasure( size_t var_a, size_t var } template -double pyGBOFitnessFunction_t::getLowerRangeBound( int dimension ) +double pyGBOFitnessFunction_t::getLowerRangeBound( int variable_index ) { - assert(0); - return( -1 ); + return gomea_pyfitness_lower_range_bound(py_class,variable_index); } template -double pyGBOFitnessFunction_t::getUpperRangeBound( int dimension ) +double pyGBOFitnessFunction_t::getUpperRangeBound( int variable_index ) { - assert(0); - return( -1 ); + return gomea_pyfitness_upper_range_bound(py_class,variable_index); } template<> -double pyGBOFitnessFunction_t::getLowerRangeBound( int dimension ) +double pyGBOFitnessFunction_t::getLowerRangeBound( int variable_index ) { - return( -1e308 ); + double result = gomea_pyfitness_lower_range_bound(py_class,variable_index); + if( result == -INFINITY ){ + return 0; + } + return result; } template<> -double pyGBOFitnessFunction_t::getUpperRangeBound( int dimension ) +double pyGBOFitnessFunction_t::getUpperRangeBound( int variable_index ) { - return( 1e308 ); + double result = gomea_pyfitness_upper_range_bound(py_class,variable_index); + if( result == INFINITY ){ + return alphabet_size-1; + } + return result; } template class pyGBOFitnessFunction_t; diff --git a/pyproject.toml b/pyproject.toml index 03829e9..47f5e2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ['meson-python', 'numpy>=2.0.1', 'Cython>=3.0'] [project] name = 'gomea' -version = '1.0.8' +version = '1.0.9' description = 'Library for the use of various variants of the Gene-pool Optimal Mixing Evolutionary Algorithm (GOMEA).' readme = 'README.md' requires-python = '>=3.9' diff --git a/setup.py b/setup.py index 26db8ab..e26bc5a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_PATCH = 5 +VERSION_PATCH = 9 VERSION_STRING = '%s.%s.%s' % (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) __version__ = VERSION_STRING