-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalArchive.py
More file actions
71 lines (58 loc) · 2.65 KB
/
ExternalArchive.py
File metadata and controls
71 lines (58 loc) · 2.65 KB
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
import numpy as np
import random
class ExternalArchive:
def __init__(self, capacity):
self.capacity = capacity
self.archive = []
def add_solution(self, solution):
if not self.is_dominated(solution) and not self.is_duplicate(solution):
self.archive.append(solution)
self.archive = self.filter_non_dominated(self.archive)
if len(self.archive) > self.capacity:
self.reduce_to_capacity()
def is_dominated(self, candidate):
# Check if candidate is dominated by any solution in the archive
for solution in self.archive:
if self.dominates(, candidate):
return True
return False
def is_duplicate(self, candidate):
# Check for duplicate solutions in the archive
for solution in self.archive:
if np.array_equal(solution.objectives, candidate.objectives):
return True
return False
def filter_non_dominated(self, solutions):
# Filter and return non-dominated solutions
non_dominated = []
for i, candidate in enumerate(solutions):
if not self.is_dominated(candidate):
non_dominated.append(candidate)
return non_dominated
def dominates(self, solution1, solution2):
# Assuming minimization
return all(m1 <= m2 for m1, m2 in zip(solution1.objectives, solution2.objectives)) and any(m1 < m2 for m1, m2 in zip(solution1.objectives, solution2.objectives))
def reduce_to_capacity(self):
# Reduce the archive size to the capacity limit (placeholder for a specific strategy, e.g., crowding distance)
self.archive = sorted(self.archive, key=lambda x: x.crowding_distance, reverse=True)[:self.capacity]
def select_random(self):
# Randomly select a solution from the archive
return random.choice(self.archive)
class ExternalArchive:
def __init__(self, NEXA, K, ideal_point, nadir_point, lower_bounds, upper_bounds, evaluator):
self.NEXA = NEXA
self.K = K
self.ideal_point = ideal_point
self.nadir_point = nadir_point
self.lower_bounds = lower_bounds
self.upper_bounds = upper_bounds
self.evaluator = evaluator
self.EXA = []
self.GEXA = {}
self.S_EXA = set()
def improve_EXA(self):
# Implementation similar to AGMOEA.improve_EXA(), adjusted for this class
def select_subspace_EXA(self):
# Implementation similar to AGMOEA.select_subspace_EXA(), adjusted for this class
def manage_exa_capacity(self):
# Implementation similar to AGMOEA.manage_exa_capacity(), adjusted for this class