Skip to content

Commit 64a27df

Browse files
committed
Resolving bug that removes certain solutions from the best front if the best front is larger than the half of the population
1 parent 04673c7 commit 64a27df

24 files changed

+8461
-1036
lines changed

alg/NSGA_II/base_nsga_ii.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def __init__(self,
3535

3636

3737
def print_performance(self, cur_result: dict):
38-
print(f"{cur_result['Iteration']} : Makespan: [min : {cur_result['Makespan']['Min']:.2f}, avg : {cur_result['Makespan']['Avg']:.2f}], " + \
39-
f"Mean flow time: [min : {cur_result['Mean flow time']['Min']:.2f}, avg : {cur_result['Mean flow time']['Avg']:.2f}], " + \
38+
objective_1, objective_2, *_ = list(cur_result)
39+
print(f"{cur_result['Iteration']} : {objective_1}: [min : {cur_result[objective_1]['Min']:.2f}, avg : {cur_result[objective_1]['Avg']:.2f}], " + \
40+
f"{objective_2}: [min : {cur_result[objective_2]['Min']:.2f}, avg : {cur_result[objective_2]['Avg']:.2f}], " + \
4041
f"Spread : {cur_result['Spread']}, n_fronts: {cur_result['n_fronts']}, n_non_dominated_solutions: {cur_result['n_non_dominated_solutions']}")
4142

4243
def dump_population(self, dump_folder, file_name):
@@ -150,8 +151,8 @@ def save_objective_space_plot(self, log_path: str, figure_name: str, folder_name
150151
ax.set_title(figure_name)
151152
#ax.set_xticks(np.linspace(np.min(point_list[:, 0])-10, np.max(point_list[:, 0])+10, 10))
152153
#ax.set_yticks(np.linspace(np.min(point_list[:, 1])-10, np.max(point_list[:, 1])+10, 10))
153-
ax.set_xlabel("Makespan")
154-
ax.set_ylabel("Mean Flow Time")
154+
ax.set_xlabel(self.pop_object.objectives[0])
155+
ax.set_ylabel(self.pop_object.objectives[1])
155156

156157
fig.savefig(os.path.join(img_folder, figure_name))
157158
plt.close()
@@ -198,6 +199,12 @@ def execute(self):
198199
self.pop_object.non_dominated_sorting()
199200
self.pop_object.crowding_distance_sort_all_fronts()
200201
max_iteration = self.n_iterations
202+
203+
previous_makespan_min = np.inf
204+
previous_flow_min = np.inf
205+
cur_makespan_ind = None
206+
cur_flow_ind = None
207+
201208
while self.n_iterations > 0:
202209
# Higher tournament size -> more elitism, smaller torunament size -> less elitism
203210
self.pop_object.select_parents()
@@ -213,6 +220,31 @@ def execute(self):
213220
cur_result["Iteration"] = max_iteration - self.n_iterations
214221
self.print_performance(cur_result)
215222

223+
# Debug help
224+
#cur_min_makespan = cur_result["Makespan"]["Min"]
225+
#cur_min_mean_flow_time = cur_result["Mean Completion Time"]["Min"]
226+
#if cur_min_makespan > previous_makespan_min or cur_min_mean_flow_time > previous_flow_min:
227+
# print("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
228+
# self.pop_object.non_dominated_sorting()
229+
# self.pop_object.crowding_distance_sort_all_fronts()
230+
231+
#min_makespan_found = False
232+
#min_mean_flow_time_found = False
233+
#for indiv in self.pop_object.R:
234+
# if not min_makespan_found and indiv.cur_fitness[0] == cur_min_makespan:
235+
# min_makespan_found = True
236+
# indiv.watch_individual = True
237+
# cur_makespan_ind = indiv
238+
# elif not min_mean_flow_time_found and indiv.cur_fitness[1] == cur_min_mean_flow_time:
239+
# min_mean_flow_time_found = True
240+
# indiv.watch_individual = True
241+
# cur_flow_ind = indiv
242+
# else:
243+
# indiv.watch_individual = False
244+
245+
#previous_makespan_min = cur_min_makespan
246+
#previous_flow_min = cur_min_mean_flow_time
247+
216248
if self.activate_logging:
217249
# The method will act as generator if logging is active
218250
yield cur_result

alg/NSGA_II/conf/experiment_1.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ classical:
99
_target_: base_nsga_ii.ClassicalPopulation
1010
N: 50
1111
decoding_method: "apply_operation_based_bierwirth"
12+
objectives: ["Makespan", "Mean Completion Time"]
1213
activate_schedule: True
1314
tournament_size: 2
1415
mating_pool_size: 50
@@ -26,6 +27,7 @@ quantum_base_encoding:
2627
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
2728
activate_schedule: True
2829
decoding_method: "apply_operation_based_bierwirth"
30+
objectives: ["Makespan", "Mean Completion Time"]
2931
individual_type: QChromosomeBaseEncoding
3032
time_log: False
3133
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"
@@ -43,6 +45,7 @@ quantum_position_encoding:
4345
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
4446
activate_schedule: True
4547
decoding_method: "apply_operation_based_bierwirth"
48+
objectives: ["Makespan", "Mean Completion Time"]
4649
individual_type: QChromosomePositionEncoding
4750
time_log: False
4851
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"
@@ -62,6 +65,7 @@ quantum_position_encoding_restricted:
6265
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
6366
activate_schedule: True
6467
decoding_method: "apply_operation_based_bierwirth"
68+
objectives: ["Makespan", "Mean Completion Time"]
6569
individual_type: QChromosomePositionEncoding
6670
time_log: False
6771
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"
@@ -80,6 +84,7 @@ quantum_hash_base_encoding:
8084
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
8185
activate_schedule: True
8286
decoding_method: "apply_operation_based_bierwirth"
87+
objectives: ["Makespan", "Mean Completion Time"]
8388
individual_type: QChromosomeHashBaseEncoding
8489
time_log: False
8590
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"
@@ -98,6 +103,7 @@ quantum_hash_reduced_encoding:
98103
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
99104
activate_schedule: True
100105
decoding_method: "apply_operation_based_bierwirth"
106+
objectives: ["Makespan", "Mean Completion Time"]
101107
individual_type: QChromosomeHashReducedEncoding
102108
time_log: False
103109
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"

alg/NSGA_II/conf/experiment_1_base.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ quantum_base_encoding:
1616
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
1717
activate_schedule: True
1818
decoding_method: "apply_operation_based_bierwirth"
19+
objectives: ["Makespan", "Mean Completion Time"]
1920
individual_type: QChromosomeRepairPermutationEncoding
2021
time_log: False
2122
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"

alg/NSGA_II/conf/experiment_1_hash_base.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ quantum_hash_base_encoding:
1818
reset_fraction: 0 # Clip the bottom % -> reset chromosomes back to 50/50
1919
activate_schedule: True
2020
decoding_method: "apply_operation_based_bierwirth"
21+
objectives: ["Makespan", "Mean Completion Time"]
2122
individual_type: QChromosomeHashMultisetImprovedEncoding #QChromosomeHashMultisetEncoding
2223
time_log: False
2324
rotation_angles: "[0.1*np.pi, 0, 0.02*np.pi, 0, 0.02*np.pi, 0, 0.1*np.pi, 0]" # "[0.1*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.1*np.pi, 0]"

alg/NSGA_II/conf/experiment_1_hash_restricted.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ quantum_hash_reduced_encoding:
1717
reset_fraction: 0.25 # Clip the bottom quarter -> reset chromosomes back to 50/50
1818
activate_schedule: True
1919
decoding_method: "apply_operation_based_bierwirth"
20+
objectives: ["Makespan", "Mean Completion Time"]
2021
individual_type: QChromosomeHashPermutationEncoding
2122
time_log: False
2223
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"

alg/NSGA_II/conf/experiment_1_restricted_pos.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ quantum_position_encoding_restricted:
1919
reset_fraction: 0 # Clip the bottom quarter -> reset chromosomes back to 50/50
2020
activate_schedule: True
2121
decoding_method: "apply_operation_based_bierwirth"
22+
objectives: ["Makespan", "Mean Completion Time"]
2223
individual_type: QChromosomePositionEncoding
2324
time_log: False
2425
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]" #"[0.2*np.pi, 0, 0.02*np.pi, 0, 0.02*np.pi, 0, 0.2*np.pi, 0]" #"[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"

alg/NSGA_II/conf/experiment_2.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ classical:
1414
_target_: base_nsga_ii.ClassicalPopulation
1515
N: 50
1616
decoding_method: "apply_operation_based_bierwirth"
17+
objectives: ["Makespan", "Mean Completion Time"]
1718
activate_schedule: True
1819
tournament_size: 2
1920
mating_pool_size: 50
@@ -29,6 +30,7 @@ quantum_position_encoding:
2930
reset_fraction: 0 # Clip the bottom quarter -> reset chromosomes back to 50/50
3031
activate_schedule: True
3132
decoding_method: "apply_operation_based_bierwirth"
33+
objectives: ["Makespan", "Mean Completion Time"]
3234
individual_type: QChromosomePositionEncoding
3335
time_log: False
3436
rotation_angles: "[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]" #"[0.2*np.pi, 0, 0.02*np.pi, 0, 0.02*np.pi, 0, 0.2*np.pi, 0]" #"[0.02*np.pi, 0, 0.05*np.pi, 0, 0.05*np.pi, 0, 0.02*np.pi, 0]"
@@ -47,6 +49,7 @@ quantum_hash_base_encoding:
4749
reset_fraction: 0 # Clip the bottom quarter -> reset chromosomes back to 50/50
4850
activate_schedule: True
4951
decoding_method: "apply_operation_based_bierwirth"
52+
objectives: ["Makespan", "Mean Completion Time"]
5053
individual_type: QChromosomeHashMultisetImprovedEncoding
5154
time_log: False
5255
rotation_angles: "[0.1*np.pi, 0, 0.02*np.pi, 0, 0.02*np.pi, 0, 0.1*np.pi, 0]"

alg/NSGA_II/conf/experiment_classical.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defaults:
44
experiment:
55
repetitions: 10
66
n_iterations: 150
7-
problem_names: ["la21", "la22", "la23", "la24", "la25", "la26", "la27", "la29"] #["ft06", "ft10", "ft20", "abz7", "abz8", "abz9", "la28", "la40"]
7+
problem_names: ["ft06", "ft10", "ft20", "abz7", "abz8", "abz9", "la28", "la40"] # ["la21", "la22", "la23", "la24", "la25", "la26", "la27", "la29"]
88
dump_population: False
99

1010
classical:
@@ -15,6 +15,7 @@ classical:
1515
_target_: base_nsga_ii.ClassicalPopulation
1616
N: 50
1717
decoding_method: "apply_operation_based_bierwirth"
18+
objectives: ["Makespan", "Mean Flow Time"]
1819
activate_schedule: True
1920
tournament_size: 2
2021
mating_pool_size: 50
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defaults:
2+
- experiment: basic
3+
4+
experiment:
5+
repetitions: 10
6+
n_iterations: 150
7+
problem_names: ["la21", "la22", "la23", "la24", "la25", "la26", "la27", "la29"]
8+
dump_population: False
9+
10+
classical:
11+
_target_: base_nsga_ii.ClassicalNSGAII
12+
_partial_: True
13+
activate_logging: True
14+
pop_object:
15+
_target_: base_nsga_ii.ClassicalPopulation
16+
N: 50
17+
decoding_method: "apply_operation_based_bierwirth"
18+
objectives: ["Makespan", "Mean Flow Time"]
19+
activate_schedule: True
20+
tournament_size: 2
21+
mating_pool_size: 50
22+
mutation_probability: 0.6
23+

alg/NSGA_II/conf/experiment_classical_test.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defaults:
44
experiment:
55
repetitions: 1
66
n_iterations: 150
7-
problem_names: ['ft10']
7+
problem_names: ['ft20']
88

99
classical:
1010
_target_: base_nsga_ii.ClassicalNSGAII
@@ -14,8 +14,9 @@ classical:
1414
_target_: base_nsga_ii.ClassicalPopulation
1515
N: 50
1616
decoding_method: "apply_operation_based_bierwirth"
17+
objectives: ["Makespan", "Mean Completion Time"]
1718
activate_schedule: True
1819
tournament_size: 2
19-
mating_pool_size: 20
20-
mutation_probability: 0.3
20+
mating_pool_size: 50
21+
mutation_probability: 0.8
2122

0 commit comments

Comments
 (0)