-
Notifications
You must be signed in to change notification settings - Fork 5
/
evolution.py
50 lines (33 loc) · 1.27 KB
/
evolution.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
from player import Player
import numpy as np
from config import CONFIG
class Evolution():
def __init__(self, mode):
self.mode = mode
# calculate fitness of players
def calculate_fitness(self, players, delta_xs):
for i, p in enumerate(players):
p.fitness = delta_xs[i]
def mutate(self, child):
# TODO
# child: an object of class `Player`
pass
def generate_new_population(self, num_players, prev_players=None):
# in first generation, we create random players
if prev_players is None:
return [Player(self.mode) for _ in range(num_players)]
else:
# TODO
# num_players example: 150
# prev_players: an array of `Player` objects
# TODO (additional): a selection method other than `fitness proportionate`
# TODO (additional): implementing crossover
new_players = prev_players
return new_players
def next_population_selection(self, players, num_players):
# TODO
# num_players example: 100
# players: an array of `Player` objects
# TODO (additional): a selection method other than `top-k`
# TODO (additional): plotting
return players[: num_players]