-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoalescence.java
More file actions
128 lines (105 loc) · 3.9 KB
/
Coalescence.java
File metadata and controls
128 lines (105 loc) · 3.9 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
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
import java.io.IOException;
import java.util.*;
public class Coalescence {
//pères
private TreeMap pointsCoalescenceP = new TreeMap();
//mères
private TreeMap pointsCoalescenceM = new TreeMap();
//verificateur
private HashSet<Sim> verif;
public Coalescence(TasBinaire populationEntrante) throws IOException {
System.out.println("transformation du heap");
// on cree des copies de la population et
// on transforme l'ordre du heap
TasBinaire populationF = new TasBinaire();
TasBinaire populationF2 = new TasBinaire();
TasBinaire populationH2 = new TasBinaire();
TasBinaire populationH = new TasBinaire();
while (!populationEntrante.isEmpty()) {
// on transfer la population dans un minPQ
// (maxPQ mais avec leurs naissance negative)
Event E = populationEntrante.deleteMin();
E.setTime(E.getTime() * (-1));
if (E.getSubject().getSex().equals(Sim.Sex.F)) {
populationF.insert(E);
populationF2.insert(E); // pour les meres des femmes
} else {
populationH.insert(E);
populationH2.insert(E);// pour les meres des hommes
}
}
checkAncestorsDAD(populationH);
checkAncestorsMOM(populationH2);
checkAncestorsDAD(populationF);
checkAncestorsMOM(populationF2);
}
public void checkAncestorsDAD(TasBinaire tasAnalyse) throws IOException {
verif = new HashSet<Sim>();
// on gere la coalescence pour les peres
while (!tasAnalyse.isEmpty()) {
Event E = tasAnalyse.deleteMin();
if (!E.getSubject().isFounder()) {
Sim pere = E.getSubject().getFather();
if (!verif.contains(pere)) {
Event P = new Event(pere.getBirthTime() * (-1), pere, 'z');
tasAnalyse.insert(P);
verif.add(pere);
} else {
PointCoalescence point = new PointCoalescence((float)E.getSubject().getBirthTime(), tasAnalyse.size());
pointsCoalescenceP.put(point.getT(), point.getN());
}
} else {
break;
}
}
}
public void checkAncestorsMOM(TasBinaire tasAnalyse) throws IOException {
verif = new HashSet<Sim>();
// gere la coalescence pour les meres
while (!tasAnalyse.isEmpty()) {
Event E = tasAnalyse.deleteMin();
if (!E.getSubject().isFounder()) {
Sim mere = E.getSubject().getMother();
if (!verif.contains(mere)) {
Event P = new Event(mere.getBirthTime() * (-1), mere, 'z');
tasAnalyse.insert(P);
verif.add(mere);
} else {
PointCoalescence point = new PointCoalescence((float)E.getSubject().getBirthTime(), tasAnalyse.size());
pointsCoalescenceM.put(point.getT(), point.getN());
}
}
else {
break;
}
}
}
@Override
public String toString() {
return "peres : "+ pointsCoalescenceP.size()+ ":" + pointsCoalescenceP.toString() + " \n" + "meres : "+ pointsCoalescenceM.size() + ":" + pointsCoalescenceM.toString();
}
private class PointCoalescence {
private float t;
private int n = 0;
public PointCoalescence(float t, int n) {
this.t = t;
this.n= n;
}
public void setN() {
this.n++;
}
public float getT() {
return t;
}
public int getN() {
return n;
}
@Override
public String toString() {
return "{" +
"t=" + t +
", n=" + n +
'}';
}
}
}