-from problems.abstract_problem import AbstractProblem
+
+from problems.abstract_problem import AbstractProblem
[docs]
class Maxcut100(AbstractProblem):
"""
-
A class used to represent the Maximum Cut (MAXCUT) function for 100 nodes.
+
A class to represent the Maximum Cut (MAXCUT) problem for 100 nodes.
Attributes
----------
-
None
+
problema : list of list of float
+
A matrix representing the weights between nodes in the MAXCUT problem.
Methods
-------
f(x: list) -> float
-
Calculates the fitness value of a given chromosome.
-
-
Notes
-
-----
-
Length of chromosomes = 100
-
Maximum Fitness Value = 1077.0
-
"""
-
-
[docs]
-
def f(self, x: list) -> float:
-
"""
Calculates the fitness value of a given chromosome for the Maxcut problem.
-
-
Parameters
-
----------
-
x : list
-
A list representing a chromosome.
-
-
Returns
-
-------
-
float
-
The fitness value of the chromosome.
-
"""
-
-
problema = [
+
"""
+
+
+
[docs]
+
def __init__(self):
+
+
self.problema = [
[0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 10.000000, 0.000000, 10.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000],
[0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 10.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
@@ -566,18 +551,34 @@
Source code for pycellga.problems.single_objective.discrete.binary.maxcut100
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 10.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000],
[0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 10.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 10.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000],
- ]
+ ]
-
cols = 100
-
fitness = 0.0
-
for i in range(cols-1):
-
j = i
-
for j in range(cols):
-
if (x[i] ^ x[j]):
-
fitness = fitness + problema[i][j]
+
+
[docs]
+
def f(self, x: list) -> float:
+
"""
+
Calculates the fitness value of a given chromosome for the Maxcut problem.
+
+
Parameters
+
----------
+
x : list
+
A list representing a chromosome.
+
+
Returns
+
-------
+
float
+
The fitness value of the chromosome.
+
"""
+
fitness = 0.0
+
n = len(self.problema)
+
+
for i in range(n):
+
for j in range(i + 1, n):
+
if x[i] != x[j]: # Nodes are in different subsets
+
fitness += self.problema[i][j]
-
return round(fitness, 6)
+
return fitness
diff --git a/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_01.html b/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_01.html
index 59b4b4c..b7b8e0a 100644
--- a/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_01.html
+++ b/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_01.html
@@ -327,46 +327,36 @@
diff --git a/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_09.html b/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_09.html
index f413a39..33b64c1 100644
--- a/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_09.html
+++ b/_modules/pycellga/problems/single_objective/discrete/binary/maxcut20_09.html
@@ -327,98 +327,120 @@
from problems.abstract_problem import AbstractProblem
+
[docs]
class Maxcut20_09(AbstractProblem):
"""
-
Maximum Cut (MAXCUT) function implementation for optimization problems.
+
Maximum Cut (MAXCUT) function for optimization on a 20-node graph.
-
The MAXCUT function is used for testing optimization algorithms, particularly those involving maximum cut problems.
+
This class is used to evaluate the cut value by summing weights of edges
+
between nodes in different partitions defined by binary variables.
Attributes
----------
-
None
+
problema : list of list of float
+
Adjacency matrix representing edge weights between nodes.
Methods
-------
f(x: list) -> float
-
Calculates the MAXCUT function value for a given list of variables.
-
-
Notes
-
-----
-
Length of chromosomes = 20
-
Maximum Fitness Value = 56.740064
+
Calculates the MAXCUT function value for a given list of binary variables.
"""
-
-
[docs]
-
def f(self, x: list) -> float:
-
"""
-
Calculate the MAXCUT function value for a given list of variables.
-
-
Parameters
-
----------
-
x : list
-
A list of binary variables.
-
-
Returns
-
-------
-
float
-
The MAXCUT function value.
-
"""
-
problema = [
+
+
[docs]
+
def __init__(self, design_variables=20, bounds=None, objectives=1):
+
if bounds is None:
+
bounds = [(0, 1) for _ in range(design_variables)]
+
super().__init__(design_variables=design_variables, bounds=bounds, objectives=objectives)
+
+
# Define adjacency matrix (20x20 matrix of edge weights)
+
self.problema = [
[0.000000, 0.130622, 0.694577, 0.922028, 0.335786, 0.359902, 0.279580, 0.880418, 0.201529, 0.313702,
-
0.322765, 0.399944, 0.000000, 0.848267, 0.933051, 0.085267, 0.957646, 0.331033, 0.389269, 0.193177],
+
0.322765, 0.399944, 0.000000, 0.848267, 0.933051, 0.085267, 0.957646, 0.331033, 0.389269, 0.193177],
[0.130622, 0.000000, 0.946416, 0.388165, 0.000000, 0.232571, 0.605770, 0.065642, 0.114155, 0.737786,
-
0.033571, 0.843579, 0.465199, 0.043667, 0.000000, 0.382358, 0.661252, 0.931556, 0.206577, 0.262331],
+
0.033571, 0.843579, 0.465199, 0.043667, 0.000000, 0.382358, 0.661252, 0.931556, 0.206577, 0.262331],
[0.694577, 0.946416, 0.000000, 0.989211, 0.000000, 0.152213, 0.000000, 0.084579, 0.610150, 0.131790,
-
0.950083, 0.426541, 0.721013, 0.428389, 0.308932, 0.861261, 0.479196, 0.863363, 0.000000, 0.110013],
+
0.950083, 0.426541, 0.721013, 0.428389, 0.308932, 0.861261, 0.479196, 0.863363, 0.000000, 0.110013],
[0.922028, 0.388165, 0.989211, 0.000000, 0.785464, 0.227321, 0.469172, 0.032054, 0.574073, 0.736906,
-
0.764415, 0.000000, 0.495863, 0.602718, 0.684042, 0.492622, 0.000000, 0.918634, 0.974679, 0.134843],
+
0.764415, 0.000000, 0.495863, 0.602718, 0.684042, 0.492622, 0.000000, 0.918634, 0.974679, 0.134843],
[0.335786, 0.000000, 0.000000, 0.785464, 0.000000, 0.478171, 0.684823, 0.594988, 0.000000, 0.043655,
-
0.266736, 0.265187, 0.167750, 0.539353, 0.120596, 0.483133, 0.928091, 0.571874, 0.118362, 0.808725],
+
0.266736, 0.265187, 0.167750, 0.539353, 0.120596, 0.483133, 0.928091, 0.571874, 0.118362, 0.808725],
[0.359902, 0.232571, 0.152213, 0.227321, 0.478171, 0.000000, 0.969750, 0.948758, 0.527900, 0.652776,
-
0.990039, 0.945809, 0.831436, 0.355298, 0.049061, 0.103966, 0.897422, 0.732376, 0.491590, 0.526179],
+
0.990039, 0.945809, 0.831436, 0.355298, 0.049061, 0.103966, 0.897422, 0.732376, 0.491590, 0.526179],
[0.279580, 0.605770, 0.000000, 0.469172, 0.684823, 0.969750, 0.000000, 0.652418, 0.123045, 0.368941,
-
0.000000, 0.053590, 0.035474, 0.000000, 0.360846, 0.665888, 0.757456, 0.000000, 0.912162, 0.974535],
+
0.000000, 0.053590, 0.035474, 0.000000, 0.360846, 0.665888, 0.757456, 0.000000, 0.912162, 0.974535],
[0.880418, 0.065642, 0.084579, 0.032054, 0.594988, 0.948758, 0.652418, 0.000000, 0.656499, 0.879623,
-
0.656778, 0.572563, 0.107108, 0.550337, 0.230315, 0.568378, 0.000000, 0.915765, 0.659182, 0.688311],
+
0.656778, 0.572563, 0.107108, 0.550337, 0.230315, 0.568378, 0.000000, 0.915765, 0.659182, 0.688311],
[0.201529, 0.114155, 0.610150, 0.574073, 0.000000, 0.527900, 0.123045, 0.656499, 0.000000, 0.995883,
-
0.172727, 0.442540, 0.974869, 0.000000, 0.997630, 0.035737, 0.835247, 0.139724, 0.859992, 0.000000],
+
0.172727, 0.442540, 0.974869, 0.000000, 0.997630, 0.035737, 0.835247, 0.139724, 0.859992, 0.000000],
[0.313702, 0.737786, 0.131790, 0.736906, 0.043655, 0.652776, 0.368941, 0.879623, 0.995883, 0.000000,
-
0.120131, 0.483339, 0.969497, 0.300482, 0.879444, 0.000000, 0.836946, 0.084211, 0.723167, 0.195939],
+
0.120131, 0.483339, 0.969497, 0.300482, 0.879444, 0.000000, 0.836946, 0.084211, 0.723167, 0.195939],
[0.322765, 0.033571, 0.950083, 0.764415, 0.266736, 0.990039, 0.000000, 0.656778, 0.172727, 0.120131,
-
0.000000, 0.950398, 0.236138, 0.268245, 0.701255, 0.894728, 0.303465, 0.989424, 0.228973, 0.978178],
+
0.000000, 0.950398, 0.236138, 0.268245, 0.701255, 0.894728, 0.303465, 0.989424, 0.228973, 0.978178],
[0.399944, 0.843579, 0.426541, 0.000000, 0.265187, 0.945809, 0.053590, 0.572563, 0.442540, 0.483339,
-
0.950398, 0.000000, 0.060377, 0.854370, 0.488094, 0.581746, 0.935845, 0.723815, 0.225213, 0.424806],
+
0.950398, 0.000000, 0.060377, 0.854370, 0.488094, 0.581746, 0.935845, 0.723815, 0.225213, 0.424806],
[0.000000, 0.465199, 0.721013, 0.495863, 0.167750, 0.831436, 0.035474, 0.107108, 0.974869, 0.969497,
-
0.236138, 0.060377, 0.000000, 0.404249, 0.867185, 0.865152, 0.330739, 0.876005, 0.978220, 0.651577],
+
0.236138, 0.060377, 0.000000, 0.404249, 0.867185, 0.865152, 0.330739, 0.876005, 0.978220, 0.651577],
[0.848267, 0.043667, 0.428389, 0.602718, 0.539353, 0.355298, 0.000000, 0.550337, 0.000000, 0.300482,
-
0.268245, 0.854370, 0.404249, 0.000000, 0.492553, 0.088188, 0.690603, 0.287630, 0.000000, 0.690291],
+
0.268245, 0.854370, 0.404249, 0.000000, 0.492553, 0.088188, 0.690603, 0.287630, 0.000000, 0.690291],
[0.933051, 0.000000, 0.308932, 0.684042, 0.120596, 0.049061, 0.360846, 0.230315, 0.997630, 0.879444,
-
0.701255, 0.488094, 0.867185, 0.492553, 0.000000, 0.000000, 0.593581, 0.076547, 0.297751, 0.159191],
+
0.701255, 0.488094, 0.867185, 0.492553, 0.000000, 0.000000, 0.593581, 0.076547, 0.297751, 0.159191],
[0.085267, 0.382358, 0.861261, 0.492622, 0.483133, 0.103966, 0.665888, 0.568378, 0.035737, 0.000000,
-
0.894728, 0.581746, 0.865152, 0.088188, 0.000000, 0.000000, 0.747596, 0.562290, 0.000000, 0.955731],
+
0.894728, 0.581746, 0.865152, 0.088188, 0.000000, 0.000000, 0.747596, 0.562290, 0.000000, 0.955731],
[0.957646, 0.661252, 0.479196, 0.000000, 0.928091, 0.897422, 0.757456, 0.000000, 0.835247, 0.836946,
-
0.303465, 0.935845, 0.330739, 0.690603, 0.593581, 0.747596, 0.000000, 0.244949, 0.994884, 0.067050],
+
0.303465, 0.935845, 0.330739, 0.690603, 0.593581, 0.747596, 0.000000, 0.244949, 0.994884, 0.067050],
[0.331033, 0.931556, 0.863363, 0.918634, 0.571874, 0.732376, 0.000000, 0.915765, 0.139724, 0.084211,
-
0.989424, 0.723815, 0.876005, 0.287630, 0.076547, 0.562290, 0.244949, 0.000000, 0.621331, 0.752926],
+
0.989424, 0.723815, 0.876005, 0.287630, 0.076547, 0.562290, 0.244949, 0.000000, 0.621331, 0.752926],
[0.389269, 0.206577, 0.000000, 0.974679, 0.118362, 0.491590, 0.912162, 0.659182, 0.859992, 0.723167,
-
0.228973, 0.225213, 0.978220, 0.000000, 0.297751, 0.000000, 0.994884, 0.621331, 0.000000, 0.224879],
+
0.228973, 0.225213, 0.978220, 0.000000, 0.297751, 0.000000, 0.994884, 0.621331, 0.000000, 0.224879],
[0.193177, 0.262331, 0.110013, 0.134843, 0.808725, 0.526179, 0.974535, 0.688311, 0.000000, 0.195939,
-
0.978178, 0.424806, 0.651577, 0.690291, 0.159191, 0.955731, 0.067050, 0.752926, 0.224879, 0.000000]
-
]
+
0.978178, 0.424806, 0.651577, 0.690291, 0.159191, 0.955731, 0.067050, 0.752926, 0.224879, 0.000000]
+
]
+
+
+
+
[docs]
+
def f(self, x: list) -> float:
+
"""
+
Calculate the MAXCUT function value for a given list of binary variables.
+
+
Parameters
+
----------
+
x : list
+
A list of binary variables representing node partitions.
-
cols = 20
+
Returns
+
-------
+
float
+
The MAXCUT function value representing the total weight of edges cut by the partition.
+
"""
fitness = 0.0
+
cols = len(self.problema)
-
for i in range(cols-1):
-
j = i
-
for j in range(cols):
-
if x[i] ^ x[j]:
-
fitness += problema[i][j]
+
for i in range(cols - 1):
+
for j in range(i + 1, cols):
+
if x[i] != x[j]: # Nodes are in different partitions
+
fitness += self.problema[i][j]
return round(fitness, 6)
+
+
+
+
[docs]
+
def evaluate(self, x, out, *args, **kwargs):
+
"""
+
Evaluate function for compatibility with pymoo's optimizer.
+
+
Parameters
+
----------
+
x : numpy.ndarray
+
Array of input variables.
+
out : dict
+
Dictionary to store the output fitness values.
+
"""
+
out["F"] = self.f(x.tolist())
diff --git a/_modules/pycellga/problems/single_objective/discrete/binary/mmdp.html b/_modules/pycellga/problems/single_objective/discrete/binary/mmdp.html
index dcd4574..f2521e0 100644
--- a/_modules/pycellga/problems/single_objective/discrete/binary/mmdp.html
+++ b/_modules/pycellga/problems/single_objective/discrete/binary/mmdp.html
@@ -327,6 +327,7 @@
Source code for pycellga.problems.single_objective.discrete.binary.mmdp
from problems.abstract_problem import AbstractProblem
+from typing import List, Tuple
[docs]
@@ -340,7 +341,14 @@
Source code for pycellga.problems.single_objective.discrete.binary.mmdp
Attributes
----------
-
None
+
design_variables : List[str]
+
Names of the design variables (in this case, binary chromosome genes).
+
bounds : List[Tuple[float, float]]
+
Bounds for each design variable (0 or 1).
+
objectives : List[str]
+
Objectives for optimization, e.g., "maximize" in this case.
+
constraints : List[str]
+
Any constraints for the optimization problem.
Methods
-------
@@ -353,9 +361,24 @@
Source code for pycellga.problems.single_objective.discrete.binary.mmdp
# Maximum Fitness Value = 40
"""
+
+
[docs]
+
def __init__(self):
+
"""
+
Initializes the MMDP problem with predefined design variables, bounds,
+
objectives, and constraints.
+
"""
+
design_variables = ["gene" + str(i) for i in range(240)]
+
bounds = [(0, 1) for _ in range(240)]
+
objectives = ["maximize"]
+
constraints = []
+
+
super().__init__(design_variables, bounds, objectives, constraints)
+
+
[docs]
-
def f(self, x: list) -> float:
+
def f(self, x: List[int]) -> float:
"""
Evaluates the fitness of a given chromosome for the MMDP.
@@ -364,7 +387,7 @@
Source code for pycellga.problems.single_objective.discrete.binary.mmdp
Parameters
----------
-
x : list
+
x : List[int]
A list representing the chromosome, where each element is a binary
value (0 or 1).
@@ -374,18 +397,12 @@
Source code for pycellga.problems.single_objective.discrete.binary.mmdp
The normalized fitness value of the chromosome, rounded to three
decimal places.
"""
-
subproblems_length = 6
subproblems_number = 40
-
total_ones = 0
-
partial_fitness = 0.0
fitness = 0.0
for i in range(subproblems_number):
-
total_ones = 0
-
for j in range(subproblems_length):
-
if x[i * subproblems_length + j] == 1:
-
total_ones += 1
+
total_ones = sum(x[i * subproblems_length + j] for j in range(subproblems_length))
if total_ones == 0 or total_ones == 6:
partial_fitness = 1.0
@@ -398,8 +415,7 @@
Source code for pycellga.problems.single_objective.discrete.binary.mmdp
fitness += partial_fitness
-
fitness_normalized = fitness / 40
-
+
fitness_normalized = fitness / subproblems_number
return round(fitness_normalized, 3)
diff --git a/_modules/pycellga/problems/single_objective/discrete/binary/one_max.html b/_modules/pycellga/problems/single_objective/discrete/binary/one_max.html
index e9048b1..698d8a7 100644
--- a/_modules/pycellga/problems/single_objective/discrete/binary/one_max.html
+++ b/_modules/pycellga/problems/single_objective/discrete/binary/one_max.html
@@ -327,6 +327,7 @@
Source code for pycellga.problems.single_objective.discrete.binary.one_max
from problems.abstract_problem import AbstractProblem
+from typing import List, Tuple
[docs]
@@ -339,7 +340,14 @@
Source code for pycellga.problems.single_objective.discrete.binary.one_max
Attributes
----------
- None
+ design_variables : int
+ Number of design variables (chromosome length).
+ bounds : List[Tuple[float, float]]
+ Bounds for each design variable as (min, max).
+ objectives : List[str]
+ Objectives for optimization, e.g., "maximize".
+ constraints : List[str]
+ Any constraints for the optimization problem.
Methods
-------
@@ -347,9 +355,34 @@ Source code for pycellga.problems.single_objective.discrete.binary.one_max
Evaluates the fitness of a given chromosome.
"""
+
+
[docs]
+
def __init__(self,
+
design_variables: int = 100,
+
bounds: List[Tuple[float, float]] = [(0, 1)] * 100,
+
objectives: List[str] = ["maximize"],
+
constraints: List[str] = []):
+
"""
+
Initialize the OneMax problem with default design variables, bounds,
+
objectives, and optional constraints.
+
+
Parameters
+
----------
+
design_variables : int, optional
+
Number of design variables (default is 100).
+
bounds : List[Tuple[float, float]], optional
+
Bounds for each design variable in (min, max) format (default is [(0, 1)] * 100).
+
objectives : List[str], optional
+
Objectives for optimization, e.g., "maximize" (default is ["maximize"]).
+
constraints : List[str], optional
+
Constraints for the problem (default is an empty list).
+
"""
+
super().__init__(design_variables=design_variables, bounds=bounds, objectives=objectives, constraints=constraints)
+
+
[docs]
-
def f(self, x) -> float:
+
def f(self, x: List[int]) -> float:
"""
Evaluates the fitness of a given chromosome for the OneMax problem.
@@ -357,7 +390,7 @@
Source code for pycellga.problems.single_objective.discrete.binary.one_max
Parameters
----------
- x : list
+ x : List[int]
A list representing the chromosome, where each element is a binary
value (0 or 1).
@@ -366,7 +399,7 @@ Source code for pycellga.problems.single_objective.discrete.binary.one_max
float
The fitness value of the chromosome, which is the sum of its bits.
"""
- return sum(x)
+ return float(sum(x))
diff --git a/_modules/pycellga/problems/single_objective/discrete/binary/peak.html b/_modules/pycellga/problems/single_objective/discrete/binary/peak.html
index 22ed9d2..2eb9805 100644
--- a/_modules/pycellga/problems/single_objective/discrete/binary/peak.html
+++ b/_modules/pycellga/problems/single_objective/discrete/binary/peak.html
@@ -328,6 +328,7 @@
Source code for pycellga.problems.single_objective.discrete.binary.peak
from problems.abstract_problem import AbstractProblem
from numpy import random
+from typing import List, Tuple
[docs]
@@ -340,7 +341,14 @@
Source code for pycellga.problems.single_objective.discrete.binary.peak
Attributes
----------
-
None
+
design_variables : List[str]
+
Names of the design variables.
+
bounds : List[Tuple[float, float]]
+
Bounds for each design variable as (min, max).
+
objectives : List[str]
+
Objectives for optimization, e.g., "minimize" or "maximize".
+
constraints : List[str]
+
Any constraints for the optimization problem.
Methods
-------
@@ -353,9 +361,23 @@
Source code for pycellga.problems.single_objective.discrete.binary.peak
# Maximum Fitness Value = 1.0
"""
+
+
[docs]
+
def __init__(self):
+
"""
+
Initializes the Peak problem with default values.
+
"""
+
design_variables = ["x" + str(i) for i in range(100)]
+
bounds = [(0, 1) for _ in range(100)] # Each gene is binary (0 or 1)
+
objectives = ["maximize"] # Aim to maximize fitness value
+
constraints = [] # No additional constraints
+
+
super().__init__(design_variables, bounds, objectives, constraints)
+
+
[docs]
-
def f(self, x: list) -> float:
+
def f(self, x: List[int]) -> float:
"""
Evaluates the fitness of a given chromosome for the Peak problem.
@@ -394,6 +416,22 @@
Source code for pycellga.problems.single_objective.discrete.binary.peak
fitness = min_distance / problem_length
return round(fitness, 3)
+
+
+
+
[docs]
+
def evaluate(self, x, out, *args, **kwargs):
+
"""
+
Evaluate function for compatibility with pymoo's optimizer.
+
+
Parameters
+
----------
+
x : numpy.ndarray
+
Array of input variables.
+
out : dict
+
Dictionary to store the output fitness values.
+
"""
+
out["F"] = self.f(x)
diff --git a/_modules/pycellga/problems/single_objective/discrete/permutation/tsp.html b/_modules/pycellga/problems/single_objective/discrete/permutation/tsp.html
index d52a1ff..6a08415 100644
--- a/_modules/pycellga/problems/single_objective/discrete/permutation/tsp.html
+++ b/_modules/pycellga/problems/single_objective/discrete/permutation/tsp.html
@@ -331,6 +331,7 @@