Skip to content
Snippets Groups Projects
Commit e4731af4 authored by Lennart Eichhorn's avatar Lennart Eichhorn
Browse files

Removed bonds and overlaps from Candidate.

parent 72b456a5
Branches
No related tags found
No related merge requests found
...@@ -30,48 +30,40 @@ public class EvaluatorNESW implements Evaluator { ...@@ -30,48 +30,40 @@ public class EvaluatorNESW implements Evaluator {
} }
public int evaluateBonds(Candidate candidate) { public int evaluateBonds(Candidate candidate) {
if (candidate.bonds <= -1) { // Not calculated before
int bonds = 0; int bonds = 0;
for (int i = 0; i < candidate.vertexList.size() - 2; i++) { for (int i = 0; i < candidate.vertexList.size() - 2; i++) {
Vertex toCompare = candidate.vertexList.get(i); Vertex toCompare = candidate.vertexList.get(i);
if (toCompare.isHydrophobic) { if (toCompare.isHydrophobic) {
for (int j = i + 2; j < candidate.vertexList.size(); j++) { for (int j = i + 2; j < candidate.vertexList.size(); j++) {
Vertex vertex = candidate.vertexList.get(j); Vertex vertex = candidate.vertexList.get(j);
if (vertex.isHydrophobic) { if (vertex.isHydrophobic) {
if (toCompare.neighbouringPosition(vertex)) { if (toCompare.neighbouringPosition(vertex)) {
bonds++; bonds++;
}
} }
} }
} }
} }
candidate.bonds = bonds;
} }
// Return cached value if this is not the first time the value is needed return bonds;
return candidate.bonds;
} }
public int evaluateOverlaps(Candidate candidate) { public int evaluateOverlaps(Candidate candidate) {
if (candidate.overlaps <= -1) { // Not calculated before
int overlaps = 0;
for (int i = 0; i < candidate.vertexList.size(); i++) { int overlaps = 0;
Vertex toCompare = candidate.vertexList.get(i); for (int i = 0; i < candidate.vertexList.size(); i++) {
for (Vertex vertex : candidate.vertexList) { Vertex toCompare = candidate.vertexList.get(i);
if (toCompare.equalsPosition(vertex) && toCompare != vertex) { for (Vertex vertex : candidate.vertexList) {
overlaps++; if (toCompare.equalsPosition(vertex) && toCompare != vertex) {
} overlaps++;
} }
} }
overlaps /= 2;
candidate.overlaps = overlaps;
} }
// Return cached value if this is not the first time the value is needed overlaps /= 2;
return candidate.overlaps; overlaps = overlaps;
return overlaps;
} }
} }
...@@ -9,8 +9,6 @@ public class Candidate { ...@@ -9,8 +9,6 @@ public class Candidate {
int[] outgoingDirection; // 0 = North | 1 = East | 2 = South | 3 = West int[] outgoingDirection; // 0 = North | 1 = East | 2 = South | 3 = West
public ArrayList<Vertex> vertexList; public ArrayList<Vertex> vertexList;
public double fitness; public double fitness;
public int bonds;
public int overlaps;
public Candidate(int[] isH, int[] oD) { public Candidate(int[] isH, int[] oD) {
this.isHydrophobic = isH; this.isHydrophobic = isH;
...@@ -18,8 +16,6 @@ public class Candidate { ...@@ -18,8 +16,6 @@ public class Candidate {
this.vertexList = constructVertexes(); this.vertexList = constructVertexes();
this.fitness = -1d; // Not calculated yet this.fitness = -1d; // Not calculated yet
this.bonds = -1;
this.overlaps = -1;
} }
private ArrayList<Vertex> constructVertexes() { private ArrayList<Vertex> constructVertexes() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment