-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConnectionHistory.js
41 lines (38 loc) · 1.91 KB
/
ConnectionHistory.js
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
class connectionHistory {
constructor(from, to, inno, innovationNos) {
this.fromNode = from;
this.toNode = to;
this.innovationNumber = inno;
this.innovationNumbers = [];
arrayCopy(innovationNos, this.innovationNumbers); //copy (from, to)
}
// ArrayList<Integer> innovationNumbers = new ArrayList<Integer>();//the innovation Numbers from the connections of the genome which first had this mutation
//this represents the genome and allows us to test if another genoeme is the same
//this is before this connection was added
//---------------------------------------------------------------------------------------------------------------------------------------------------------
// //constructor
// connectionHistory(int from, int to, int inno, ArrayList<Integer> innovationNos) {
// fromNode = from;
// toNode = to;
// innovationNumber = inno;
// innovationNumbers = (ArrayList)innovationNos.clone();
// }
// //---------------------------------------------------------------------------------------------------------------------------------------------------------
//returns whether the genome matches the original genome and the connection is between the same nodes
matches(genome, from, to) {
if(genome.genes.length === this.innovationNumbers.length) { //if the number of connections are different then the genoemes aren't the same
if(from.number === this.fromNode && to.number === this.toNode) {
//next check if all the innovation numbers match from the genome
for(var i = 0; i < genome.genes.length; i++) {
if(!this.innovationNumbers.includes(genome.genes[i].innovationNo)) {
return false;
}
}
//if reached this far then the innovationNumbers match the genes innovation numbers and the connection is between the same nodes
//so it does match
return true;
}
}
return false;
}
}