-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchive.cpp
More file actions
70 lines (56 loc) · 1.2 KB
/
Archive.cpp
File metadata and controls
70 lines (56 loc) · 1.2 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
#include "Archive.h"
#include "Network.h"
#include "nsga-ii.h"
#include "Alignment.h"
#include <vector>
#include <set>
#include <algorithm>
#include <random>
//any aln given to Archive can be deleted at any time!
bool Archive::insert(Alignment* aln){
set<Alignment*> dominatedByAln;
bool alnIsDominated = false;
for(auto p : nonDominated){
if(dominates(aln->fitness,p->fitness)){
dominatedByAln.insert(p);
}
else if(dominates(p->fitness,aln->fitness)){
alnIsDominated = true;
break;
}
}
if(alnIsDominated){
delete aln;
return false;
}
else{
vector<Alignment*> newNonDominated;
for(auto p : nonDominated){
if(dominatedByAln.count(p)){
delete p;
}
else{
newNonDominated.push_back(p);
}
}
newNonDominated.push_back(aln);
nonDominated = newNonDominated;
return true;
}
}
void Archive::shrinkToSize(int size){
if(size >= nonDominated.size()){
return;
}
normalizeFitnesses(nonDominated);
setCrowdingDists(nonDominated);
sort(nonDominated.begin(), nonDominated.end(),
[](Alignment* p1, Alignment* p2){
return p1->crowdDist > p2->crowdDist;
}
);
while(nonDominated.size() > size){
delete nonDominated.back();
nonDominated.pop_back();
}
}