-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParNode.java
More file actions
executable file
·42 lines (36 loc) · 893 Bytes
/
ParNode.java
File metadata and controls
executable file
·42 lines (36 loc) · 893 Bytes
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
/* ParNode.java - Operator superclass */
package se.ga4;
import java.io.*;
import java.lang.*;
import se.util.*;
public class ParNode extends TerminalNode
implements Serializable, Cloneable {
static final long serialVersionUID=GeneticAlgorithm.globalSerial;
private double par;
public ParNode(double par) {
this.par=par;
}
public ParNode() {
par=randomPar(DynGA.paramin,DynGA.paramax);
}
public Object clone() {
ParNode nn=new ParNode(par);
copy(nn);
return nn;
}
/** Parameter mutation is one of:
1) Draw a new parameter altogether.
2) Slightly modify (+/- 10%) */
public void mutate(double pmut) {
if(mutated=Util.dran()<pmut) {
par=randomPar(DynGA.paramin,DynGA.paramax);
}
if(mutated|=Util.dran()<pmut) {
par*=Util.dran(0.9,1.1);
}
}
public String string() {
if(longform) return "("+par+")";
else return Util.dec.format(par);
}
}