Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion demos/bbo_realvalued/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions gomea/EmbeddedFitness.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ cdef public double gomea_pyfitness_similarity_measure(obj, size_t var_a, size_t
fitness_obj = <GBOFitnessFunction?>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 = <FitnessFunction?>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 = <FitnessFunction?>obj
cdef double result = fitness_obj.upper_range_bound(variable_index)
return result
2 changes: 2 additions & 0 deletions gomea/fitness.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions gomea/fitness.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ cdef class FitnessFunction:
rotation_matrix = <np.ndarray?> 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,
Expand Down
36 changes: 16 additions & 20 deletions gomea/src/fitness/py_bbo_fitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,35 @@ double pyBBOFitnessFunction_t<double>::constraintFunction( vec_t<double> &variab
}

template<class T>
double pyBBOFitnessFunction_t<T>::getLowerRangeBound( int dimension )
double pyBBOFitnessFunction_t<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<class T>
double pyBBOFitnessFunction_t<T>::getUpperRangeBound( int dimension )
double pyBBOFitnessFunction_t<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<char>::getLowerRangeBound( int dimension )
double pyBBOFitnessFunction_t<char>::getLowerRangeBound( int variable_index )
{
return( 0 );
}

template<>
double pyBBOFitnessFunction_t<char>::getUpperRangeBound( int dimension )
{
return( alphabet_size-1 );
}

template<>
double pyBBOFitnessFunction_t<double>::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<double>::getUpperRangeBound( int dimension )
double pyBBOFitnessFunction_t<char>::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<char>;
Expand Down
26 changes: 16 additions & 10 deletions gomea/src/fitness/py_gbo_fitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,35 @@ double pyGBOFitnessFunction_t<T>::getSimilarityMeasure( size_t var_a, size_t var
}

template<class T>
double pyGBOFitnessFunction_t<T>::getLowerRangeBound( int dimension )
double pyGBOFitnessFunction_t<T>::getLowerRangeBound( int variable_index )
{
assert(0);
return( -1 );
return gomea_pyfitness_lower_range_bound(py_class,variable_index);
}

template<class T>
double pyGBOFitnessFunction_t<T>::getUpperRangeBound( int dimension )
double pyGBOFitnessFunction_t<T>::getUpperRangeBound( int variable_index )
{
assert(0);
return( -1 );
return gomea_pyfitness_upper_range_bound(py_class,variable_index);
}

template<>
double pyGBOFitnessFunction_t<double>::getLowerRangeBound( int dimension )
double pyGBOFitnessFunction_t<char>::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<double>::getUpperRangeBound( int dimension )
double pyGBOFitnessFunction_t<char>::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<char>;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down