-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems.py
More file actions
67 lines (59 loc) · 1.7 KB
/
problems.py
File metadata and controls
67 lines (59 loc) · 1.7 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Collection of toy problems for testing the algorithm."""
import fitness, mutation, crossover, selection, init, show_best
def get_problem(name):
if name == "queens":
return queens
elif name == "ackley":
return ackley
elif name == "even_odd":
return even_odd
elif name == "maze":
return maze
else:
raise Exception("Problem not found")
queens = {
"description": "queens problem considering variable weights",
"encoding": "int-perm",
"init_population": init.int_perm,
"fitness": fitness.queens,
"crossover": crossover.pmx,
"mutation": mutation.inversion,
"show_best": show_best.best,
}
ackley = {
"description": "ackley functions for N dimensions",
"encoding": "real",
"init_population": init.real,
"fitness": fitness.ackley,
"crossover": crossover.arithmetic,
"mutation": mutation.delta,
"selection": selection.roulette,
"show_best": show_best.best,
}
ackley_bin = {
"description": "ackley functions for N dimensions using bin encoding",
"encoding": "bin",
"init_population": init.bin,
"fitness": None,
"crossover": crossover.uniform,
"mutation": mutation.bitflip,
"show_best": show_best.best,
}
even_odd = {
"description": "even/odd alternance",
"encoding": "int",
"init_population": init.int,
"fitness": fitness.even_odd,
"crossover": crossover.uniform,
"mutation": mutation.randint,
"show_best": show_best.best,
}
maze = {
"description": "maze solver",
"encoding": "int",
"init_population": init.int,
"fitness": fitness.maze,
"crossover": crossover.one_point,
"mutation": mutation.randint,
"show_best": show_best.maze_solution,
}