This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
134 lines (104 loc) · 2.93 KB
/
run.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import sys
import platform
import random
import numpy as np
# --- Initialization
# Initialize the random seed
seed = random.randrange(sys.maxsize)
random.seed(seed)
print("Seed:", seed)
# random.seed(0)
# Define the number of executions of each set of parameters
executions = range(10)
# --- Define the set of parameters
# Numbers of generations
generations = [500]
# Initial population sizes
populations = [35]
# Intermediate population sizes
intermediates = [100]
# Mutation rates
mutations = [20]
# Mutation rates for genes
genemutations = [40]
# Competitors
competitors = [3]
# Difficulties
difficulties = [26]
# --- Perform experiment
# Choose the executable
if platform.system() == 'Linux':
executable = './bin/Debug/net5.0/publish/EnemyGenerator '
elif platform.system() == 'Windows':
executable = 'bin\\Debug\\net5.0\\publish\\EnemyGenerator '
else:
print('This script is not able to run in this OS.')
exit()
# Compile project
os.system('dotnet publish')
def run(ge, po, ip, mu, gm, co, di):
# Generate a random seed
rs = random.randint(0, np.iinfo(np.int32).max - 1)
# Build the parameters
parameters = ""
for i in [rs, ge, po, ip, mu, gm, co, di]:
parameters += str(i) + ' '
# Print parameters
print('Parameters=[', parameters, ']')
# Run algoritm for the current set of parameters
os.system(executable + parameters)
# Variables to control the experiment progress
total = len(generations) * \
len(populations) * \
len(intermediates) * \
len(mutations) * \
len(genemutations) * \
len(competitors) * \
len(difficulties) * \
len(executions)
i = 1
# Run the algorithm for all sets of parameters
print('Running')
for ge in generations:
for po in populations:
for ip in intermediates:
for mu in mutations:
for gm in genemutations:
for co in competitors:
for di in difficulties:
for e in executions:
# Run execuble
run(ge, po, ip, mu, gm, co, di)
# Print progress
print("%.2f" % ((i / total) * 100))
i += 1
# --- Plot charts of the experiment results
def plot(ge, po, ip, mu, gm, co, di):
parameters = ''
for i in [ge, po, ip, mu, gm, co, di]:
parameters += str(i) + ' '
os.system('python plot.py ' + parameters)
# Variables to control the plotting progress
total = len(generations) * \
len(populations) * \
len(intermediates) * \
len(mutations) * \
len(genemutations) * \
len(competitors) * \
len(difficulties)
i = 1
# Plot charts for all sets of parameters
print('Plotting')
for ge in generations:
for po in populations:
for ip in intermediates:
for mu in mutations:
for gm in genemutations:
for co in competitors:
for di in difficulties:
# Plot charts
plot(ge, po, ip, mu, gm, co, di)
# Print progress
print("%.2f" % ((i / total) * 100))
i += 1