Tests with marking of Edges and Vertexes
Adding Visualisation of Edge weight and Vertex name fixed AStar
This commit is contained in:
parent
79198f4f4a
commit
ebd1173cbc
@ -1,14 +1,11 @@
|
||||
package OurApplication;
|
||||
|
||||
import graph.*;
|
||||
import graph.Graph;
|
||||
import logging.LogElementList;
|
||||
import visualisation.DrawArea;
|
||||
import visualizationElements.*;
|
||||
import visualizationElements.Edge;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* This class provides an example for using visualization.DrawArea.
|
||||
@ -53,6 +50,9 @@ public class OurDrawArea extends DrawArea{
|
||||
|
||||
OurLogElement logElement = (OurLogElement) logList.get();
|
||||
logElement.getGraph().draw(g);
|
||||
for(Edge screenEdge : currentGraph.getEdges()){
|
||||
g.drawString(screenEdge.getMarking(), (screenEdge.getSource().getXpos() + screenEdge.getDestination().getXpos())/2, (screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos())/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
package graph;
|
||||
|
||||
import OurApplication.OurAlgorithm;
|
||||
import OurApplication.OurLogElement;
|
||||
import logging.LogElementList;
|
||||
import visualizationElements.Edge;
|
||||
import visualizationElements.EdgeStyle;
|
||||
import visualizationElements.Vertex;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.awt.Color;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.PriorityQueue;
|
||||
@ -316,6 +314,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
int dist = 0;
|
||||
// Variable, die Distanz zwischen dem potenziell nächsten Knoten und dem Zielknoten speichert
|
||||
int airDist = 0;
|
||||
// Variable, die Distanz zwischen dem aktuellen Knoten bis zum Endknoten speichert
|
||||
int distToFinish = 0;
|
||||
// Zähler für LogList
|
||||
int step = 0;
|
||||
|
||||
@ -350,7 +350,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
+ Math.pow((i.getCords()[1] - n2.getCords()[1]), 2));
|
||||
|
||||
// Berechne Distanz zu nächstem Knoten
|
||||
dist = distance.get(nextVertex.getElement()) + j.getWeighting() + airDist;
|
||||
dist = distance.get(nextVertex.getElement()) + j.getWeighting();
|
||||
distToFinish = distance.get(nextVertex.getElement()) + j.getWeighting() + airDist;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -369,7 +370,7 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
this.logList.add(new OurLogElement(step, "Step: " + step, 0, this.getScreenGraphCopy()));
|
||||
|
||||
// Nehme nächsten Knoten in die Queue auf
|
||||
queue.add(new WrapperElement<>(i, dist));
|
||||
queue.add(new WrapperElement<>(i, distToFinish));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,3 +2,18 @@ package graph;
|
||||
|
||||
public abstract class EdgeMarking extends Marking{
|
||||
}
|
||||
|
||||
class EdgeWeightMarking extends EdgeMarking{
|
||||
private int weight;
|
||||
|
||||
EdgeWeightMarking(int weight){
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public void setWeight(int weight){
|
||||
this.weight=weight;
|
||||
}
|
||||
public int getWeight(){
|
||||
return this.weight;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class ExampleGraphs {
|
||||
DirectedGraph<VertexMarking, EdgeMarking> example1 = new DirectedGraph<>();
|
||||
|
||||
int size = 5;
|
||||
MarkedVertex[][] vertices = new MarkedVertex[size][size];
|
||||
MarkedVertex<VertexMarking>[][] vertices = new MarkedVertex[size][size];
|
||||
|
||||
// Knoten erstellen und zum Graph hinzufügen
|
||||
for (int row = 0; row < size; row++) {
|
||||
@ -47,10 +47,10 @@ public class ExampleGraphs {
|
||||
for (int row = 0; row < size; row++) {
|
||||
for (int col = 0; col < size; col++) {
|
||||
if (col < size - 1) {
|
||||
addBidirectionalEdge(example1, vertices[row][col], vertices[row][col + 1], 1);
|
||||
addBidirectionalEdge(example1, vertices[row][col], vertices[row][col + 1], new EdgeWeightMarking(1));
|
||||
}
|
||||
if (row < size - 1) {
|
||||
addBidirectionalEdge(example1, vertices[row][col], vertices[row + 1][col], 1);
|
||||
addBidirectionalEdge(example1, vertices[row][col], vertices[row + 1][col], new EdgeWeightMarking(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,9 +58,9 @@ public class ExampleGraphs {
|
||||
return example1;
|
||||
}
|
||||
|
||||
private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex from, MarkedVertex to, int weight) {
|
||||
MarkedEdge forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, null, weight);
|
||||
MarkedEdge backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, null, weight);
|
||||
private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex<VertexMarking> from, MarkedVertex<VertexMarking> to, EdgeWeightMarking weight) {
|
||||
MarkedEdge<EdgeMarking> forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, weight, weight.getWeight());
|
||||
MarkedEdge<EdgeMarking> backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, weight, weight.getWeight());
|
||||
graph.addEdge(forwardEdge);
|
||||
graph.addEdge(backwardEdge);
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
|
||||
|
||||
|
||||
// TODO ACHTUNG DEBUG!!!!
|
||||
public MarkedEdge(String s, Vertex n1, Vertex n2, U u, int w) {
|
||||
public MarkedEdge(String s, Vertex n1, Vertex n2, U u, int weighting) {
|
||||
super(s, n1, n2);
|
||||
this.marking = u;
|
||||
this.weighting = w;
|
||||
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), "u.toString()", Color.BLACK);
|
||||
this.weighting = weighting;
|
||||
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), Integer.toString(weighting), Color.BLACK);
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,10 +34,10 @@ public class MarkedVertex<T extends VertexMarking> extends Vertex{
|
||||
|
||||
|
||||
// TODO ACHTUNG DEBUG!!!!
|
||||
public MarkedVertex(int xCord, int yCord, String s, T t, Color color) {
|
||||
super(s);
|
||||
public MarkedVertex(int xCord, int yCord, String name, T t, Color color) {
|
||||
super(name);
|
||||
this.marking = t;
|
||||
this.screenVertex = new visualizationElements.Vertex(xCord, yCord, "t.toString()", color);
|
||||
this.screenVertex = new visualizationElements.Vertex(xCord, yCord, name, color);
|
||||
this.xCord = xCord;
|
||||
this.yCord = yCord;
|
||||
}
|
||||
|
@ -2,3 +2,18 @@ package graph;
|
||||
|
||||
public abstract class VertexMarking extends Marking {
|
||||
}
|
||||
|
||||
class VertexWeightMarking extends VertexMarking{
|
||||
private int weight;
|
||||
|
||||
VertexWeightMarking(int weight){
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public void setWeight(int weight){
|
||||
this.weight=weight;
|
||||
}
|
||||
public int getWeight(){
|
||||
return this.weight;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user