-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Задачи с ограничениями и дискретными параметрами * Добавлены новые задачи с ограничениями и дискретными параметрами. Исправлены некоторые задачи по pep8 * Update problem.py * Update problem.py * removed comments * Update problem.py * Update problem.py
- Loading branch information
Showing
47 changed files
with
2,687 additions
and
1,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import numpy as np | ||
from iOpt.trial import Point | ||
from iOpt.trial import FunctionValue | ||
from iOpt.trial import FunctionType | ||
from iOpt.trial import Trial | ||
from iOpt.problem import Problem | ||
import math | ||
|
||
|
||
class Floudas(Problem): | ||
""" | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Конструктор класса Floudas problem. | ||
""" | ||
super(Floudas, self).__init__() | ||
self.name = "Floudas" | ||
self.dimension = 3 | ||
self.number_of_float_variables = 2 | ||
self.number_of_discrete_variables = 1 | ||
self.number_of_objectives = 1 | ||
self.number_of_constraints = 3 | ||
|
||
self.float_variable_names = np.ndarray(shape=(self.number_of_float_variables,), dtype=object) | ||
for i in range(self.number_of_float_variables): | ||
self.float_variable_names[i] = str(i) | ||
|
||
self.discrete_variable_names = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
for i in range(self.number_of_discrete_variables): | ||
self.discrete_variable_names[i] = str(i) | ||
|
||
self.lower_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.lower_bound_of_float_variables[0] = 0.2 | ||
self.lower_bound_of_float_variables[1] = -2.22554 | ||
self.upper_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.upper_bound_of_float_variables[0] = 1 | ||
self.upper_bound_of_float_variables[1] = -1 | ||
|
||
self.discrete_variable_values = [["0", "1"] for i in range(self.number_of_discrete_variables)] | ||
|
||
self.known_optimum = np.ndarray(shape=(1,), dtype=Trial) | ||
|
||
pointfv = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
pointfv = [0.499609, -1.305787] | ||
|
||
pointdv = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
pointdv[0] = "1" | ||
|
||
KOpoint = Point(pointfv, pointdv) | ||
KOfunV = np.ndarray(shape=(1,), dtype=FunctionValue) | ||
KOfunV[0] = FunctionValue() | ||
KOfunV[0].value = 0.100001 | ||
self.known_optimum[0] = Trial(KOpoint, KOfunV) | ||
|
||
|
||
def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValue: | ||
""" | ||
Вычисление значения выбранной функции в заданной точке. | ||
:param point: координаты точки испытания, в которой будет вычислено значение функции | ||
:param function_value: объект определяющий номер функции в задаче и хранящий значение функции | ||
:return: Вычисленное значение функции в точке point | ||
""" | ||
result: np.double = 0 | ||
x = point.float_variables | ||
b = point.discrete_variables | ||
|
||
if function_value.type == FunctionType.OBJECTIV: | ||
result = np.double(-0.7 * int(b[0]) + 5.0 * (x[0] - 0.5) * (x[0] - 0.5) + 0.8) | ||
elif function_value.functionID == 0: # constraint 1 | ||
result = np.double(-math.exp(x[0] - 0.2) - x[1]) | ||
elif function_value.functionID == 1: # constraint 2 | ||
result = np.double(x[1] + 1.1 * int(b[0]) - 1) | ||
elif function_value.functionID == 2: # constraint 3 | ||
result = np.double(x[0] - 1.2 * int(b[0]) - 0.2) | ||
|
||
function_value.value = result | ||
return function_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import numpy as np | ||
import math | ||
from problems.GKLS_function.gkls_random import GKLSRandomGenerator | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import numpy as np | ||
from iOpt.trial import Point | ||
from iOpt.trial import FunctionValue | ||
from iOpt.trial import FunctionType | ||
from iOpt.trial import Trial | ||
from iOpt.problem import Problem | ||
import math | ||
|
||
|
||
class Pern(Problem): | ||
""" | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Конструктор класса Pern problem. | ||
""" | ||
super(Pern, self).__init__() | ||
self.name = "Pern" | ||
self.dimension = 2 | ||
self.number_of_float_variables = 1 | ||
self.number_of_discrete_variables = 1 | ||
self.number_of_objectives = 1 | ||
self.number_of_constraints = 3 | ||
|
||
self.float_variable_names = np.ndarray(shape=(self.number_of_float_variables,), dtype=object) | ||
for i in range(self.number_of_float_variables): | ||
self.float_variable_names[i] = str(i) | ||
|
||
self.discrete_variable_names = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
for i in range(self.number_of_discrete_variables): | ||
self.discrete_variable_names[i] = str(i) | ||
|
||
self.lower_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.lower_bound_of_float_variables[0] = 1 | ||
self.upper_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.upper_bound_of_float_variables[0] = 10 | ||
|
||
self.discrete_variable_values = [[[str(i) for i in range(1, 7)]] for i in range(self.number_of_discrete_variables)] | ||
|
||
self.known_optimum = np.ndarray(shape=(1,), dtype=Trial) | ||
|
||
pointfv = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
pointfv[0] = 4 | ||
|
||
pointdv = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
pointdv[0] = "1" | ||
|
||
KOpoint = Point(pointfv, pointdv) | ||
KOfunV = np.ndarray(shape=(1,), dtype=FunctionValue) | ||
KOfunV[0] = FunctionValue() | ||
KOfunV[0].value = -17 | ||
self.known_optimum[0] = Trial(KOpoint, KOfunV) | ||
|
||
|
||
def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValue: | ||
""" | ||
Вычисление значения выбранной функции в заданной точке. | ||
:param point: координаты точки испытания, в которой будет вычислено значение функции | ||
:param function_value: объект определяющий номер функции в задаче и хранящий значение функции | ||
:return: Вычисленное значение функции в точке point | ||
""" | ||
result: np.double = 0 | ||
x = point.float_variables[0] | ||
b = int(point.discrete_variables[0]) | ||
|
||
if function_value.type == FunctionType.OBJECTIV: | ||
result = np.double(3.0 * b - 5.0 * x) | ||
elif function_value.functionID == 0: # constraint 1 | ||
result = np.double(2.0 * b * b - 2.0 * math.sqrt(b) - 2.0 * math.sqrt(x) * b * b | ||
+ 11.0 * b + 8 * x - 39.0) | ||
elif function_value.functionID == 1: # constraint 2 | ||
result = np.double(-b + x - 3.0) | ||
elif function_value.functionID == 2: # constraint 3 | ||
result = np.double(2.0 * b + 3 * x - 24.0) | ||
|
||
function_value.value = result | ||
return function_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import numpy as np | ||
from iOpt.trial import Point | ||
from iOpt.trial import FunctionValue | ||
from iOpt.trial import FunctionType | ||
from iOpt.trial import Trial | ||
from iOpt.problem import Problem | ||
import math | ||
|
||
|
||
class Synthes(Problem): | ||
""" | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Конструктор класса Synthes problem. | ||
""" | ||
super(Synthes, self).__init__() | ||
self.name = "Synthes" | ||
self.dimension = 6 | ||
self.number_of_float_variables = 3 | ||
self.number_of_discrete_variables = 3 | ||
self.number_of_objectives = 1 | ||
self.number_of_constraints = 6 | ||
|
||
self.float_variable_names = np.ndarray(shape=(self.number_of_float_variables,), dtype=object) | ||
for i in range(self.number_of_float_variables): | ||
self.float_variable_names[i] = str(i) | ||
|
||
self.discrete_variable_names = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
for i in range(self.number_of_discrete_variables): | ||
self.discrete_variable_names[i] = str(i) | ||
|
||
self.lower_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.lower_bound_of_float_variables.fill(0) | ||
self.upper_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.upper_bound_of_float_variables.fill(3) | ||
|
||
self.discrete_variable_values = [[[str(i) for i in range(0, 6)]] for i in range(self.number_of_discrete_variables)] | ||
|
||
self.known_optimum = np.ndarray(shape=(1,), dtype=Trial) | ||
# UNDEFINED | ||
|
||
|
||
def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValue: | ||
""" | ||
Вычисление значения выбранной функции в заданной точке. | ||
:param point: координаты точки испытания, в которой будет вычислено значение функции | ||
:param function_value: объект определяющий номер функции в задаче и хранящий значение функции | ||
:return: Вычисленное значение функции в точке point | ||
""" | ||
result: np.double = 0 | ||
x = point.float_variables | ||
b = [int(x) for x in point.discrete_variables] | ||
|
||
if function_value.type == FunctionType.OBJECTIV: | ||
result = np.double(5.0 * b[0] + 6.0 * b[1] + 8.0 * b[2] + 10.0 * x[0] | ||
- 7.0 * x[2] - 18.0 * math.log(x[1] + 1.0) | ||
- 19.2 * math.log(x[0] - x[1] + 1.0) + 10.0) | ||
elif function_value.functionID == 0: # constraint 1 | ||
result = np.double(b[0] + b[1] - 1.1) | ||
elif function_value.functionID == 1: # constraint 2 | ||
if ((x[0] - x[1] + 1.0) != 0): | ||
try: | ||
result = np.double(-(math.log(x[1] + 1.0) + 1.2* | ||
math.log(x[0] - x[1] + 1.0) - x[2]- 2 * b[2] + 2.0)) | ||
except ValueError: | ||
print("CalculateFuncs Error!!!") | ||
result = np.NaN | ||
pass # do nothing! | ||
else: | ||
result = 1 | ||
elif function_value.functionID == 2: # constraint 3 | ||
if ((x[0] - x[1] + 1.0) != 0): | ||
try: | ||
result = np.double(-(math.log(x[1] + 1.0) + 1.2* | ||
math.log(x[0] - x[1] + 1.0) - x[2]- 2 * b[2] + 2.0)) | ||
except ValueError: | ||
print("CalculateFuncs Error!!!") | ||
result = np.NaN | ||
pass # do nothing! | ||
|
||
else: | ||
result = 1 | ||
elif function_value.functionID == 3: # constraint 4 | ||
result = np.double(x[1] - x[0]) | ||
elif function_value.functionID == 4: # constraint 5 | ||
result = np.double(x[1] - 2.0 * b[0]) | ||
elif function_value.functionID == 5: # constraint 6 | ||
result = np.double(x[0] - x[1] - 2.0 * b[1]) | ||
|
||
function_value.value = result | ||
return function_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import numpy as np | ||
from iOpt.trial import Point | ||
from iOpt.trial import FunctionValue | ||
from iOpt.trial import FunctionType | ||
from iOpt.trial import Trial | ||
from iOpt.problem import Problem | ||
import math | ||
|
||
|
||
class Yuan(Problem): | ||
""" | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Конструктор класса Yuan problem. | ||
""" | ||
super(Yuan, self).__init__() | ||
self.name = "Yuan" | ||
self.dimension = 7 | ||
self.number_of_float_variables = 3 | ||
self.number_of_discrete_variables = 4 | ||
self.number_of_objectives = 1 | ||
self.number_of_constraints = 9 | ||
|
||
self.float_variable_names = np.ndarray(shape=(self.number_of_float_variables,), dtype=object) | ||
for i in range(self.number_of_float_variables): | ||
self.float_variable_names[i] = str(i) | ||
|
||
self.discrete_variable_names = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
for i in range(self.number_of_discrete_variables): | ||
self.discrete_variable_names[i] = str(i) | ||
|
||
self.lower_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.lower_bound_of_float_variables.fill(0) | ||
self.upper_bound_of_float_variables = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
self.upper_bound_of_float_variables.fill(3) | ||
|
||
self.discrete_variable_values = [["0", "1"] for i in range(self.number_of_discrete_variables)] | ||
|
||
self.known_optimum = np.ndarray(shape=(1,), dtype=Trial) | ||
|
||
pointfv = np.ndarray(shape=(self.number_of_float_variables,), dtype=np.double) | ||
pointfv = [0.2, 0.8, 1.908] | ||
|
||
pointdv = np.ndarray(shape=(self.number_of_discrete_variables,), dtype=object) | ||
pointdv = ["1", "1", "0", "1"] | ||
|
||
KOpoint = Point(pointfv, pointdv) | ||
KOfunV = np.ndarray(shape=(1,), dtype=FunctionValue) | ||
KOfunV[0] = FunctionValue() | ||
KOfunV[0].value = 4.5796 | ||
self.known_optimum[0] = Trial(KOpoint, KOfunV) | ||
|
||
|
||
def calculate(self, point: Point, function_value: FunctionValue) -> FunctionValue: | ||
""" | ||
Вычисление значения выбранной функции в заданной точке. | ||
:param point: координаты точки испытания, в которой будет вычислено значение функции | ||
:param function_value: объект определяющий номер функции в задаче и хранящий значение функции | ||
:return: Вычисленное значение функции в точке point | ||
""" | ||
result: np.double = 0 | ||
x = point.float_variables | ||
b = [int(x) for x in point.discrete_variables] | ||
|
||
if function_value.type == FunctionType.OBJECTIV: | ||
result = np.double((b[0] - 1.0) * (b[0] - 1.0) + (b[1] - 2.0) * (b[1] - 2.0) + | ||
(b[2] - 1.0) * (b[2] - 1.0) - math.log(b[3] + 1.0) + | ||
(x[0] - 1.0) * (x[0] - 1.0) + (x[1] - 2.0) * (x[1] - 2.0) + | ||
(x[2] - 3.0) * (x[2] - 3.0)) | ||
elif function_value.functionID == 0: # constraint 1 | ||
result = np.double(b[0] + b[1] + b[2] + x[0] + x[1] + x[2] - 5.0) | ||
elif function_value.functionID == 1: # constraint 2 | ||
result = np.double(b[2] * b[2] + x[0] * x[0] + x[1] * x[1] + x[2] * x[2] - 5.5) | ||
elif function_value.functionID == 2: # constraint 3 | ||
result = np.double(b[0] + x[0] - 1.2) | ||
elif function_value.functionID == 3: # constraint 4 | ||
result = np.double(b[1] + x[1] - 1.8) | ||
elif function_value.functionID == 4: # constraint 5 | ||
result = np.double(b[2] + x[2] - 2.5) | ||
elif function_value.functionID == 5: # constraint 6 | ||
result = np.double(b[3] + x[0] - 1.2) | ||
elif function_value.functionID == 6: # constraint 7 | ||
result = np.double(b[1] * b[1] + x[1] * x[1] - 1.64) | ||
elif function_value.functionID == 7: # constraint 8 | ||
result = np.double(b[2] * b[2] + x[2] * x[2] - 4.25) | ||
elif function_value.functionID == 8: # constraint 9 | ||
result = np.double(b[1] * b[1] + x[2] * x[2] - 4.64) | ||
|
||
function_value.value = result | ||
return function_value |
Oops, something went wrong.