Skip to content

Commit

Permalink
changed termination
Browse files Browse the repository at this point in the history
  • Loading branch information
sverrejb committed Mar 23, 2017
1 parent 60b1859 commit e5ab116
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion EA/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
DECKSIZE = 40
CROSSOVER_RATE = 0.1
MUTATION_RATE = 0.2
NUMBER_OF_GENERATIONS = 200
NUMBER_OF_GENERATIONS = 400
MATCHES_PER_OPPONENT = '50' # must be string!
CARD_POOL = read_card_pool('../AER-POOL-1.txt')
CARD_POOL_SIZE = len(CARD_POOL)
Expand All @@ -18,4 +18,5 @@
OPPONENTS = ["GB-sealed-opponent.dck", "UWg-sealed-opponent.dck", "UW-sealed-opponent.dck", "BGw-sealed-opponent.dck"]
EXPERIMENT_TIMESTAMP = datetime.datetime.now().strftime("%d%m%H%M")
EXPERIMENT_FOLDER = "results/" + EXPERIMENT_TIMESTAMP
TERMINATION_TRESHOLD = 65
# CARDS = read_cards_json()
5 changes: 4 additions & 1 deletion EA/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def build_cmd(candidate_name, opponent_name, nr_matches):


def evaluate_deck_by_wins(individual):

number_of_matches = len(ct.OPPONENTS) * ct.MATCHES_PER_OPPONENT

decklist = genome_to_decklist(individual)
filename = "candidate.dck"
write_decklist(ct.CARD_DIRECTORY + filename, decklist)
Expand All @@ -25,5 +28,5 @@ def evaluate_deck_by_wins(individual):
result = line.split(' ')
wins += int(result[3])
p.wait()
fitness = wins
fitness = (wins / float(number_of_matches)) * 100
return fitness, # MUST BE TUPLE!
6 changes: 0 additions & 6 deletions EA/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

import matplotlib

import constants as ct
Expand All @@ -10,12 +8,8 @@


def log_experiment(top_list, median_list, worst_list, global_maximum, time_to_complete, alpha_deck):
matches_per_generation = int(ct.MATCHES_PER_OPPONENT) * len(ct.OPPONENTS)
log_name = ct.EXPERIMENT_TIMESTAMP + '.txt'
graph_name = ct.EXPERIMENT_TIMESTAMP + '.png'
top_list[:] = [(x / float(matches_per_generation)) * 100 for x in top_list]
median_list[:] = [(x / float(matches_per_generation)) * 100 for x in median_list]
worst_list[:] = [(x / float(matches_per_generation)) * 100 for x in worst_list]
write_log(top_list, median_list, worst_list, global_maximum, time_to_complete, alpha_deck, log_name)
write_graph(top_list, median_list, worst_list, graph_name)
send_mail(['[email protected]', '[email protected]'],
Expand Down
13 changes: 8 additions & 5 deletions EA/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,24 @@ def main():
card_location = ct.EXPERIMENT_FOLDER + "/" + str(gen)
os.makedirs(card_location)

counter = 0
for solution in population: # TODO: use enumerate()?
write_decklist(card_location + "/" + str(counter) + '.dck', genome_to_decklist(solution))
counter += 1
for i, solution in enumerate(population):
write_decklist(card_location + "/" + str(i) + '.dck', genome_to_decklist(solution))
fitness_list = [x[0] for x in fits]
maximum = max(fitness_list)

strongest_individual = tools.selBest(population, k=1)

median_score = median(fitness_list)

if maximum >= global_maximum:
global_maximum = maximum
alpha_deck = strongest_individual

if median_score >= 65:
break

top_list.append(maximum)
median_list.append(median(fitness_list))
median_list.append(median_score)
worst_list.append(min(fitness_list))

runtime = (time.time() - start_time)
Expand Down

0 comments on commit e5ab116

Please sign in to comment.