-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLink.java
More file actions
127 lines (110 loc) · 3.45 KB
/
Copy pathLink.java
File metadata and controls
127 lines (110 loc) · 3.45 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
package NEAT;
import java.util.Random;
/**
* Class that models the links between nodes in our network.
* @author Chance Simmons and Brandon Townsend
* @version 25 February 2019
*/
public class Link {
/** The weight of the connection between the input and output nodes. */
private double weight;
/** The node our connection is coming from. */
private Node input;
/** The node our connection is going to. */
private Node output;
/**Used to show if the link is enabled or not */
private boolean enabled;
/** The innovation number of this link */
private int innovationNum;
/**
* Constructor for a Link object. Creates it based on a passed in weight, input, and output
* node.
* @param in The specified input node for this connection.
* @param out The specified output node for this connection.
* @param innovationNum The specified innovation number of this link.
*/
public Link(Node in, Node out,int innovationNum) {
Random weightGenerator = new Random();
this.weight = weightGenerator.nextDouble() * 2 - 1;
this.input = in;
this.output = out;
this.enabled = true;
this.innovationNum = innovationNum;
}
/**
* Returns the weight of this connection link.
* @return The weight of this connection link.
*/
public double getWeight() {
return weight;
}
/**
* Gets the innovation number for this link
* @return the innovation number
*/
public int getInnovationNum(){
return this.innovationNum;
}
/**
* Used to adjust the weight of this connection link.
* @param weight The new weight this link should be set to.
*/
public void setWeight(double weight) {
this.weight = weight;
}
/**
* Returns the input node for this connection link.
* @return The input node for this connection link.
*/
public Node getInput() {
return input;
}
/**
* Sets a new input node for this connection link.
* @param input The specified node to be the new input node.
*/
public void setInput(Node input) {
this.input = input;
}
/**
* Returns the output node for this connection link.
* @return The output node for this connection link.
*/
public Node getOutput() {
return output;
}
/**
* Returns the value of enabled
* @return true if the link is enabled
*/
public boolean isEnabled(){
return enabled;
}
/**
* Sets whether or not this Link is enabled.
* @param enabled Whether this Link is enabled or not.
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Sets a new output node for this connection link.
* @param output The specified node to be the new input node.
*/
public void setOutput(Node output) {
this.output = output;
}
/**
* Checks to see if the object passed in is equal to this link
* @param o the object to check the equality of
* @return true if the object is equal to this link.
*/
@Override
public boolean equals(Object o) {
if (o instanceof Link) {
Link link = (Link) o;
return link.getInnovationNum() == this.getInnovationNum();
}
return false;
}
}