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
152 lines (117 loc) · 3.61 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/env python
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(1)
# --- Define the set of parameters
# Maximum times
times = [60] # [60, 300, 600, 3600]
# Initial population sizes
populations = [20]
# Mutation rates
mutations = [5]
# Competitors
competitors = [3]
weigths = ["True", "False"]
includes = ["True", "False"]
rooms = [20]
keys = [4]
locks = [4]
enemies = [30]
linear_coefficients = [1.7]
# --- Perform experiment
# Choose the executable
if platform.system() == 'Linux':
executable = './bin/Debug/net5.0/publish/LevelGenerator '
elif platform.system() == 'Windows':
executable = 'bin\\Debug\\net5.0\\publish\\LevelGenerator.exe '
else:
print('This script is not able to run in this OS.')
exit()
# Compile project
os.system('dotnet publish')
def get_parameters(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11):
# Build the parameters
parameters = ""
for i in [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11]:
parameters += str(i) + ' '
return parameters
def get_total():
return len(times) * \
len(populations) * \
len(mutations) * \
len(competitors) * \
len(weigths) * \
len(includes) * \
len(rooms) * \
len(keys) * \
len(locks) * \
len(enemies) * \
len(linear_coefficients) * \
len(executions)
def run(parameters):
# Generate a random seed
rs = random.randint(0, np.iinfo(np.int32).max - 1)
parameters = str(rs) + ' ' + parameters
# Print parameters
print('Parameters=[ ' + parameters + ']')
# Run algoritm for the current set of parameters
os.system(executable + parameters)
# Variables to control the experiment progress
total = get_total()
i = 1
for p1 in times:
for p2 in populations:
for p3 in mutations:
for p4 in competitors:
for p5 in weigths:
for p6 in includes:
for p7 in rooms:
for p8 in keys:
for p9 in locks:
for p10 in enemies:
for p11 in linear_coefficients:
for e in executions:
# Run execuble
parameters = get_parameters(p1, p2, p3, p4, p5, p6,
p7, p8, p9, p10, p11)
run(parameters)
# Print progress
print("%.2f" % ((i / total) * 100))
i += 1
# --- Plot charts of the experiment results
def plot(parameters):
os.system('python plot.py ' + parameters)
# Variables to control the plotting progress
total = get_total()
i = 1
# Plot charts for all sets of parameters
print('Plotting')
for p1 in times:
for p2 in populations:
for p3 in mutations:
for p4 in competitors:
for p5 in weigths:
for p6 in includes:
for p7 in rooms:
for p8 in keys:
for p9 in locks:
for p10 in enemies:
for p11 in linear_coefficients:
# Plot charts
parameters = get_parameters(p1, p2, p3, p4, p5, p6,
p7, p8, p9, p10, p11)
parameters += str(len(executions))
plot(parameters)
# Print progress
print("%.2f" % ((i / total) * 100))
i += 1