Skip to content
Snippets Groups Projects
Commit 4236043d authored by istkabra's avatar istkabra
Browse files

* Fixed overlaps not being printed (instead number of bonds were used twice)

* Added isStretched flag in Vertex because visualizer was getting 0 for bonds and overlaps
parent e0e7c0be
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@ package Evaluators;
import Interfaces.Evaluator;
import MainClasses.Candidate;
import MainClasses.Config;
import MainClasses.Vertex;
public class EvaluatorNESW implements Evaluator {
......@@ -66,7 +65,6 @@ public class EvaluatorNESW implements Evaluator {
}
}
overlaps /= 2;
overlaps = overlaps;
return overlaps;
}
......
......@@ -2,9 +2,9 @@ package Interfaces;
import Enums.State;
import MainClasses.Candidate;
import MainClasses.Cell;
import MainClasses.GeneticAlgorithm;
import MainClasses.Vertex;
import MainClasses.Cell;
import java.util.ArrayList;
import java.util.List;
......@@ -52,6 +52,7 @@ public interface Visualizer {
vertex.x *= 2;
vertex.y += Math.abs(minY);
vertex.y *= 2;
vertex.isStretched = true;
}
// Add vertexes and connections to 2d array
......
......@@ -5,11 +5,13 @@ public class Vertex {
public int x;
public int y;
public int outgoingDirection;
public boolean isStretched; // Meaning it has room for connections
public Vertex(int x, int y, int outgoingDirection) {
this.x = x;
this.y = y;
this.outgoingDirection = outgoingDirection;
this.isStretched = false;
}
public boolean equalsPosition(Vertex vertex) {
......@@ -17,16 +19,21 @@ public class Vertex {
}
public boolean neighbouringPosition(Vertex vertex) {
if (x == vertex.x && y == vertex.y + 1) {
int neighbourDistance = 1;
if (isStretched) {
neighbourDistance *= 2;
}
if (x == vertex.x && y == vertex.y + neighbourDistance) {
return true; // South
}
else if (x == vertex.x && y == vertex.y -1) {
else if (x == vertex.x && y == vertex.y -neighbourDistance) {
return true; // North
}
else if (x == vertex.x + 1 && y == vertex.y) {
else if (x == vertex.x + neighbourDistance && y == vertex.y) {
return true; // West
}
else if (x == vertex.x - 1 && y == vertex.y) {
else if (x == vertex.x - neighbourDistance && y == vertex.y) {
return true; // East
}
else {
......
......@@ -3,19 +3,15 @@ package Visualizers;
import Enums.State;
import Evaluators.EvaluatorNESW;
import Interfaces.Visualizer;
import MainClasses.Candidate;
import MainClasses.Config;
import MainClasses.GeneticAlgorithm;
import MainClasses.Vertex;
import MainClasses.Cell;
import MainClasses.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
public class BestFoldingToImage implements Visualizer {
......@@ -145,7 +141,7 @@ public class BestFoldingToImage implements Visualizer {
//TODO Get the labels from the new Generation class?
EvaluatorNESW evaluator = new EvaluatorNESW(1,isHydrophobic);
int bonds = evaluator.evaluateBonds(bestCandidateOfGeneration);
int overlaps = evaluator.evaluateBonds(bestCandidateOfGeneration);
int overlaps = evaluator.evaluateOverlaps(bestCandidateOfGeneration);
String label = "Gen: " + geneticAlgorithm.generation
+ " Fitness: " + String.format("%.4f", bestCandidateOfGeneration.getFitness())
+ " H/H Bonds: " + bonds
......
......@@ -5,9 +5,6 @@ import Interfaces.Visualizer;
import MainClasses.Candidate;
import MainClasses.Config;
import MainClasses.GeneticAlgorithm;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class GenerationOverviewToConsole implements Visualizer {
......@@ -33,7 +30,7 @@ public class GenerationOverviewToConsole implements Visualizer {
}
int bonds = bondsOverlapsEvaluator.evaluateBonds(bestCandidateOfGeneration);
int overlaps = bondsOverlapsEvaluator.evaluateBonds(bestCandidateOfGeneration);
int overlaps = bondsOverlapsEvaluator.evaluateOverlaps(bestCandidateOfGeneration);
System.out.println("Generation " + geneticAlgorithm.generation + "/" + config.getTotalGenerations() + ":");
System.out.println("Population size: " + generation.length);
......
......@@ -5,6 +5,7 @@ import Interfaces.Visualizer;
import MainClasses.Candidate;
import MainClasses.Config;
import MainClasses.GeneticAlgorithm;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
......@@ -52,7 +53,7 @@ public class GenerationProgressToLog implements Visualizer {
}
int bonds = bondsOverlapsEvaluator.evaluateBonds(bestCandidateOfGeneration);
int overlaps = bondsOverlapsEvaluator.evaluateBonds(bestCandidateOfGeneration);
int overlaps = bondsOverlapsEvaluator.evaluateOverlaps(bestCandidateOfGeneration);
String log = String.format("%d\t%.4f\t%.4f\t%.4f\t %d\t%d\n",
geneticAlgorithm.generation,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment