Skip to content

Commit

Permalink
(#57) fix overflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
SevgiAkten committed Aug 14, 2024
1 parent 1078ca0 commit 2a991e2
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ grip==4.6.2
iniconfig==2.0.0
Markdown==3.6
Markdown-Editor==1.0.7
mpmath==1.3.0
numpy==1.26.2
path-and-address==2.0.1
pluggy==1.5.0
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/bentcigar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class Bentcigar(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/bohachevsky.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from numpy import cos
from numpy import pi
from numpy import power as pw
from mpmath import power as pw
from problems.abstract_problem import AbstractProblem

class Bohachevsky(AbstractProblem):
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/holzman.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class Holzman(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/levy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from problems.abstract_problem import AbstractProblem
import math
from numpy import power as pw
from mpmath import power as pw

class Levy(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/matyas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class Matyas(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/pow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class Pow(AbstractProblem):
"""
Expand Down
11 changes: 6 additions & 5 deletions src/problems/single_objective/continuous/powell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from problems.abstract_problem import AbstractProblem
import numpy as np
from mpmath import power as pw


class Powell(AbstractProblem):
"""
Expand Down Expand Up @@ -42,10 +43,10 @@ def f(self, x: list) -> float:
d = n // 4

for i in range(d):
a = np.power(x[4*i] + 10 * x[4*i + 1], 2)
b = np.power(x[4*i + 2] - x[4*i + 3], 2)
c = np.power(x[4*i + 1] - 2 * x[4*i + 2], 4)
e = np.power(x[4*i] - x[4*i + 3], 4)
a = pw(x[4*i] + 10 * x[4*i + 1], 2)
b = pw(x[4*i + 2] - x[4*i + 3], 2)
c = pw(x[4*i + 1] - 2 * x[4*i + 2], 4)
e = pw(x[4*i] - x[4*i + 3], 4)
fitness += a + 5 * b + c + 10 * e

return round(fitness, 1)
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/rosenbrock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw
class Rosenbrock(AbstractProblem):
"""
Rosenbrock function implementation for optimization problems.
Expand Down
4 changes: 2 additions & 2 deletions src/problems/single_objective/continuous/rothellipsoid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
import numpy as np
from mpmath import power as pw

class Rothellipsoid(AbstractProblem):
"""
Expand Down Expand Up @@ -41,6 +41,6 @@ def f(self, x: list) -> float:
n = len(x)

for i in range(n):
fitness += (i + 2) * np.power(x[i], 2)
fitness += (i + 2) * pw(x[i], 2)

return round(fitness, 3)
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/schaffer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from numpy import power as pw
from mpmath import power as pw
from problems.abstract_problem import AbstractProblem


Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/styblinskitang.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class StyblinskiTang(AbstractProblem):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from mpmath import power as pw
from problems.abstract_problem import AbstractProblem

class Sumofdifferentpowers(AbstractProblem):
Expand All @@ -25,6 +26,6 @@ def f(self, x: list) -> float:
for i in range(len(x)):
a = np.abs(x[i])
b = i + 1
fitness += np.power(a, b)
fitness += pw(a, b)

return round(fitness, 3)
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/threehumps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class Threehumps(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/zakharov.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw
class Zakharov(AbstractProblem):
"""
Zakharov function implementation for optimization problems.
Expand Down
2 changes: 1 addition & 1 deletion src/problems/single_objective/continuous/zettle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from problems.abstract_problem import AbstractProblem
from numpy import power as pw
from mpmath import power as pw

class Zettle(AbstractProblem):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_optimizer_alpha_cga.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from optimizer import alpha_cga, GeneType, TournamentSelection, ByteOnePointCrossover, ByteMutationRandom, OnePointCrossover, BitFlipMutation, PMXCrossover, SwapMutation
import numpy as np
import mpmath as mp
from typing import List

class RealProblem:
Expand Down Expand Up @@ -30,7 +30,7 @@ def f(self, x):
float
The computed value of the function given the input x.
"""
return sum(np.power(xi, 2) for xi in x)
return sum(mp.power(xi, 2) for xi in x)

def test_optimizer_alpha_cga_real():
"""Test alpha_cga on a real-valued sum of squares problem."""
Expand Down
1 change: 0 additions & 1 deletion src/tests/test_optimizer_ccga.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from optimizer import ccga, GeneType, TournamentSelection, ByteOnePointCrossover, ByteMutationRandom, OnePointCrossover, BitFlipMutation, PMXCrossover, SwapMutation
import numpy as np
from typing import List

class BinaryProblem:
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_optimizer_cga.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from optimizer import cga, GeneType, TournamentSelection, ByteOnePointCrossover, ByteMutationRandom, OnePointCrossover, BitFlipMutation, PMXCrossover, SwapMutation
import numpy as np
import mpmath as mp
from typing import List

class RealProblem:
Expand Down Expand Up @@ -30,7 +30,7 @@ def f(self, x):
float
The computed value of the function given the input x.
"""
return sum(np.power(xi, 2) for xi in x)
return sum(mp.power(xi, 2) for xi in x)

def test_optimizer_cga_real():
"""Test CGA on a real-valued sum of squares problem."""
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_optimizer_mccga.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from optimizer import mcccga, GeneType, TournamentSelection, ByteOnePointCrossover, ByteMutationRandom, OnePointCrossover, BitFlipMutation, PMXCrossover, SwapMutation
import numpy as np
import mpmath as mp
from typing import List

class RealProblem:
Expand Down Expand Up @@ -30,7 +30,7 @@ def f(self, x):
float
The computed value of the function given the input x.
"""
return sum(np.power(xi, 2) for xi in x)
return sum(mp.power(xi, 2) for xi in x)

def test_optimizer_mcccga_binary():
"""Test mcccga on a binary OneMax problem."""
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_optimizer_sync_cga.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from optimizer import sync_cga, GeneType, TournamentSelection, ByteOnePointCrossover, ByteMutationRandom, OnePointCrossover, BitFlipMutation, PMXCrossover, SwapMutation
import numpy as np
import mpmath as mp
from typing import List

class RealProblem:
Expand Down Expand Up @@ -30,7 +30,7 @@ def f(self, x):
float
The computed value of the function given the input x.
"""
return sum(np.power(xi, 2) for xi in x)
return sum(mp.power(xi, 2) for xi in x)

def test_optimizer_sync_cga_real():
"""Test sync_cga on a real-valued sum of squares problem."""
Expand Down

0 comments on commit 2a991e2

Please sign in to comment.