-
Notifications
You must be signed in to change notification settings - Fork 0
/
small_middle_callbacks.py
54 lines (39 loc) · 1.24 KB
/
small_middle_callbacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 28 14:01:49 2021
@author: qtckp
"""
import sys
sys.path.append('..')
import numpy as np
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Actions, ActionConditions, MiddleCallbacks
from geneticalgorithm2 import Crossover, Mutations
def f(X):
return np.sum(X)
varbound = [[0,10]]*20
model = ga(function=f,
dimension=20,
variable_type='real',
variable_boundaries=varbound)
model.run(
no_plot = False,
middle_callbacks = [
#MiddleCallbacks.UniversalCallback(Actions.Stop(), ActionConditions.EachGen(30)),
#MiddleCallbacks.UniversalCallback(Actions.ReduceMutationProb(reduce_coef = 0.98), ActionConditions.EachGen(30)),
MiddleCallbacks.UniversalCallback(
Actions.ChangeRandomCrossover([
Crossover.shuffle(),
Crossover.two_point()
]),
ActionConditions.EachGen(30)
),
MiddleCallbacks.UniversalCallback(
Actions.ChangeRandomMutation([
Mutations.uniform_by_x(),
Mutations.gauss_by_x()
]),
ActionConditions.EachGen(50)
)
]
)