-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParellcromosomes.cc
84 lines (64 loc) · 2.06 KB
/
Parellcromosomes.cc
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
/** @file Parellcromosomes.cc
@brief Codi de la classe parellcromosomes
*/
#include "Parellcromosomes.hh"
using namespace std;
Parell_cromosomes::Parell_cromosomes(){
}
void Parell_cromosomes::creuament(Parell_cromosomes pare, Parell_cromosomes mare, int npare, int nmare, int k, int lo){
int i;
for (i = 0; i < lo; i++){ // Fins al punt de creuament
if (i < k) {
c1.push_back(mare.consultar_cromosoma(nmare)[i]);
c2.push_back(pare.consultar_cromosoma(npare)[i]);
}
else {
c1.push_back(pare.consultar_cromosoma(npare)[i]);
c2.push_back(mare.consultar_cromosoma(nmare)[i]);
}
}
if (i >= lo){ // Des del punt de creuament fins el final
int aux = i;
while (mare.consultar_cromosoma(nmare).size() != c1.size()){
c1.push_back(mare.consultar_cromosoma(nmare)[i]);
++i;
}
i = aux;
while (pare.consultar_cromosoma(npare).size() != c2.size()){
c2.push_back(pare.consultar_cromosoma(npare)[i]);
++i;
}
}
}
void Parell_cromosomes::llegir_cromosomes_no_sexuals(int llargada_parell){
int alel;
for (int i = 0; i < llargada_parell; i++){
cin >> alel;
c1.push_back(alel);
}
for (int i = 0; i < llargada_parell; i++){
cin >> alel;
c2.push_back(alel);
}
}
void Parell_cromosomes::llegir_cromosomes_sexuals(int primer, int segon, char sexe){
int alel;
for (int i = 0; i < primer; i++){
cin >> alel;
c1.push_back(alel);
}
if (sexe == 'X') segon = primer;
for (int i = 0; i < segon; i++){
cin >> alel;
c2.push_back(alel);
}
}
void Parell_cromosomes::escriure_cromosoma(int num) const {
if (num == 1) for (int i = 0; i < c1.size(); i++) cout << " " << c1[i];
else for (int i = 0; i < c2.size(); i++) cout << " " << c2[i];
cout << endl;
}
vector<int> Parell_cromosomes::consultar_cromosoma(int num) const {
if (num == 0) return c1;
else return c2;
}