Repository navigation
Expand file tree
/
Copy pathChromosome.java
More file actions
147 lines (121 loc) · 4.02 KB
/
Copy pathChromosome.java
File metadata and controls
147 lines (121 loc) · 4.02 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package entity;
import java.io.*;
/**
* Created by Sam on 18.11.2016.
*/
public class Chromosome implements Cloneable, Serializable {
int position;
String binary;
double value;
double funcValue;
double probability;
String partner;
public Chromosome(int position, String binary, double value, double funcValue) {
this.position = position;
this.binary = binary;
this.value = value;
this.funcValue = funcValue;
}
public Chromosome() {
}
public Chromosome(Chromosome chromosome) {
this.position = chromosome.getPosition();
this.binary = chromosome.getBinary();
this.value = chromosome.getValue();
this.funcValue = chromosome.getFuncValue();
this.probability = chromosome.getProbability();
this.partner = chromosome.getPartner();
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public String getBinary() {
return binary;
}
public void setBinary(String binary) {
this.binary = Operations.checkLength(binary);
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public double getFuncValue() {
return funcValue;
}
public void setFuncValue(double funcValue) {
this.funcValue = funcValue;
}
public double getProbability() {
return probability;
}
public void setProbability(double probability) {
this.probability = probability;
}
public String getPartner() {
return partner;
}
public void setPartner(String partner) {
this.partner = partner;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Chromosome that = (Chromosome) o;
if (position != that.position) return false;
if (Double.compare(that.value, value) != 0) return false;
if (Double.compare(that.funcValue, funcValue) != 0) return false;
if (Double.compare(that.probability, probability) != 0) return false;
if (binary != null ? !binary.equals(that.binary) : that.binary != null) return false;
return partner != null ? partner.equals(that.partner) : that.partner == null;
}
@Override
public int hashCode() {
int result;
long temp;
result = position;
result = 31 * result + (binary != null ? binary.hashCode() : 0);
temp = Double.doubleToLongBits(value);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(funcValue);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(probability);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (partner != null ? partner.hashCode() : 0);
return result;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public static Object deepClone(Object object) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public String toString() {
return "entity.Chromosome{" +
"position=" + position +
", binary='" + binary + '\'' +
", value=" + value +
", funcValue=" + funcValue +
", probability=" + probability +
", partner='" + partner + '\'' +
'}';
}
}