Skip to content

Commit dbef417

Browse files
committed
added files from onedrive
1 parent 3aa7894 commit dbef417

13 files changed

Lines changed: 48241 additions & 0 deletions

ConnectionGene.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//a connection between 2 nodes
2+
class connectionGene {
3+
constructor(from, to, w, inno) {
4+
this.fromNode = from;
5+
this.toNode = to;
6+
this.weight = w;
7+
this.enabled = true;
8+
this.innovationNo = inno; //each connection is given a innovation number to compare genomes
9+
10+
}
11+
12+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13+
//changes the this.weight
14+
mutateWeight() {
15+
var rand2 = random(1);
16+
if (rand2 < 0.1) { //10% of the time completely change the this.weight
17+
this.weight = random(-1, 1);
18+
} else { //otherwise slightly change it
19+
this.weight += (randomGaussian() / 50);
20+
//keep this.weight between bounds
21+
if (this.weight > 1) {
22+
this.weight = 1;
23+
}
24+
if (this.weight < -1) {
25+
this.weight = -1;
26+
27+
}
28+
}
29+
}
30+
31+
//----------------------------------------------------------------------------------------------------------
32+
//returns a copy of this connectionGene
33+
clone(from, to) {
34+
var clone = new connectionGene(from, to, this.weight, this.innovationNo);
35+
clone.enabled = this.enabled;
36+
37+
return clone;
38+
}
39+
}

ConnectionHistory.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class connectionHistory {
2+
constructor(from, to, inno, innovationNos) {
3+
this.fromNode = from;
4+
this.toNode = to;
5+
this.innovationNumber = inno;
6+
this.innovationNumbers = []; //the innovation Numbers from the connections of the genome which first had this mutation
7+
//this represents the genome and allows us to test if another genoeme is the same
8+
//this is before this connection was added
9+
arrayCopy(innovationNos, this.innovationNumbers); //copy (from, to)
10+
}
11+
12+
//----------------------------------------------------------------------------------------------------------------
13+
//returns whether the genome matches the original genome and the connection is between the same nodes
14+
matches(genome, from, to) {
15+
if (genome.genes.length === this.innovationNumbers.length) { //if the number of connections are different then the genoemes aren't the same
16+
if (from.number === this.fromNode && to.number === this.toNode) {
17+
//next check if all the innovation numbers match from the genome
18+
for (var i = 0; i < genome.genes.length; i++) {
19+
if (!this.innovationNumbers.includes(genome.genes[i].innovationNo)) {
20+
return false;
21+
}
22+
}
23+
//if reached this far then the innovationNumbers match the genes innovation numbers and the connection is between the same nodes
24+
//so it does match
25+
return true;
26+
}
27+
}
28+
return false;
29+
}
30+
}

0 commit comments

Comments
 (0)