From db8ae3465315d6c6a6b1e128bb49699ec88aedee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sverre=20Johann=20Bj=C3=B8rke?= Date: Tue, 21 Mar 2017 15:12:52 +0100 Subject: [PATCH 1/3] ready for long run --- EA/constants.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EA/constants.py b/EA/constants.py index 554cd0d..40a175f 100644 --- a/EA/constants.py +++ b/EA/constants.py @@ -7,15 +7,15 @@ DECKSIZE = 40 CROSSOVER_RATE = 0.1 MUTATION_RATE = 0.2 -NUMBER_OF_GENERATIONS = 1 -MATCHES_PER_OPPONENT = '1' # must be string! +NUMBER_OF_GENERATIONS = 200 +MATCHES_PER_OPPONENT = '50' # must be string! CARD_POOL = read_card_pool('../AER-POOL-1.txt') CARD_POOL_SIZE = len(CARD_POOL) CARD_DIRECTORY = config.CARD_DIR FORGE_PATH = config.FORGE_DIR DECKLIST_HEADER = '[metadata]\nName=candidate\n[Main]\n' -OPPONENTS = ["GB-sealed-opponent.dck"] -# OPPONENTS = ["GB-sealed-opponent.dck", "UWg-sealed-opponent.dck", "UW-sealed-opponent.dck", "BGw-sealed-opponent.dck"] +# OPPONENTS = ["GB-sealed-opponent.dck"] +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 -CARDS = read_cards_json() +# CARDS = read_cards_json() From b03bb0667be8307d708c8f1e2c0f915659363fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sverre=20Johann=20Bj=C3=B8rke?= Date: Wed, 22 Mar 2017 09:17:55 +0100 Subject: [PATCH 2/3] removed helloworld --- EA/helloworld.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 EA/helloworld.py diff --git a/EA/helloworld.py b/EA/helloworld.py deleted file mode 100644 index c6943ce..0000000 --- a/EA/helloworld.py +++ /dev/null @@ -1,34 +0,0 @@ -import random -from deap import creator, base, tools, algorithms - -creator.create("FitnessMax", base.Fitness, weights=(1.0,)) -creator.create("Individual", list, fitness=creator.FitnessMax) - -toolbox = base.Toolbox() - -toolbox.register("attr_bool", random.randint, 0, 1) -toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, n=100) -toolbox.register("population", tools.initRepeat, list, toolbox.individual) - - -def evalOneMax(individual): - return sum(individual), - -toolbox.register("evaluate", evalOneMax) -toolbox.register("mate", tools.cxTwoPoint) -toolbox.register("mutate", tools.mutFlipBit, indpb=0.05) -toolbox.register("select", tools.selTournament, tournsize=3) - -population = toolbox.population(n=300) - -NGEN=40 -for gen in range(NGEN): - offspring = algorithms.varAnd(population, toolbox, cxpb=0.5, mutpb=0.1) - fits = toolbox.map(toolbox.evaluate, offspring) - for fit, ind in zip(fits, offspring): - ind.fitness.values = fit - population = toolbox.select(offspring, k=len(population)) -top10 = tools.selBest(population, k=10) - -for individual in top10: - print(sum(individual)) \ No newline at end of file From 60b185905f5343efec46aa5124ca64dd4b00b4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sverre=20Johann=20Bj=C3=B8rke?= Date: Thu, 23 Mar 2017 12:40:56 +0100 Subject: [PATCH 3/3] minor stuff --- EA/fitness.py | 11 +---------- EA/logger.py | 3 +-- EA/main.py | 3 ++- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/EA/fitness.py b/EA/fitness.py index e1558ae..31801c9 100644 --- a/EA/fitness.py +++ b/EA/fitness.py @@ -15,24 +15,15 @@ def evaluate_deck_by_wins(individual): decklist = genome_to_decklist(individual) filename = "candidate.dck" write_decklist(ct.CARD_DIRECTORY + filename, decklist) - total_damage = 0 wins = 0 - # colors,lands = colorsymbols_in_deck(CARDS, decklist) for opponent in ct.OPPONENTS: cmd = build_cmd(filename, opponent, ct.MATCHES_PER_OPPONENT) p = subprocess.Popen(cmd, cwd=ct.FORGE_PATH, stdout=subprocess.PIPE) for line in p.stdout: line = line.decode("utf-8").strip() - #print(line) - # if 'combat damage to Ai(2' in line: - # hit_event = line.split(' ') - # # print(hit_event) #For debugging - # damage_index = hit_event.index('deals') + 1 - # damage = int(hit_event[damage_index]) - # total_damage += damage if 'Match result' in line: result = line.split(' ') wins += int(result[3]) p.wait() - fitness = wins # (wins/float(MATCHES_PER_OPPONENT*len(opponents)))*damage + fitness = wins return fitness, # MUST BE TUPLE! diff --git a/EA/logger.py b/EA/logger.py index ef3c838..852752f 100644 --- a/EA/logger.py +++ b/EA/logger.py @@ -55,8 +55,7 @@ def write_log(top_list, median_list, worst_list, global_maximum, time_to_complet def write_graph(top_list, median_list, worst_list, filename): - - plt.plot((top_list), 'blue') + plt.plot(top_list, 'blue') plt.plot(median_list, 'green') plt.plot(worst_list, 'red') plt.xlabel('Generations') diff --git a/EA/main.py b/EA/main.py index a06b980..5b3e702 100644 --- a/EA/main.py +++ b/EA/main.py @@ -70,8 +70,9 @@ def mate_individuals(ind1, ind2): def main(): # TODO: VELG BREEDING OG MUTASJONSSTRATEGI - + number_of_matches = int(ct.MATCHES_PER_OPPONENT) * len(ct.OPPONENTS) * ct.NUMBER_OF_GENERATIONS * ct.POPSIZE print('Starting experiment {}'.format(ct.EXPERIMENT_TIMESTAMP)) + print('Doing {} matches'.format(number_of_matches)) start_time = time.time() first_gen_decks = generate_first_generation_decks(ct.CARD_POOL)