# Conflicts:
#	.idea/workspace.xml
This commit is contained in:
Sean Reich 2024-07-07 00:05:03 +02:00
commit 3c74497254
15 changed files with 85 additions and 29 deletions

33
.idea/workspace.xml generated
View File

@ -4,8 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Stable Version 3.0"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="small fix">
<change beforePath="$PROJECT_DIR$/graph/ExampleGraphs.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/ExampleGraphs.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/EdgeWeightMarking.class" afterDir="false" />
<change afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" afterDir="false" />
<change afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/VertexWeightMarking.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -13,6 +15,11 @@
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="ebd1173cbc514ede7aa65ba6be90702c92e0e8b4" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RESET_MODE" value="HARD" /> <option name="RESET_MODE" value="HARD" />
</component> </component>
@ -101,7 +108,23 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720182049903</updated> <updated>1720182049903</updated>
</task> </task>
<option name="localTasksCounter" value="7" /> <task id="LOCAL-00007" summary="Tests with marking of Edges and Vertexes&#10;Adding Visualisation of Edge weight &#10;and Vertex name&#10;fixed AStar">
<option name="closed" value="true" />
<created>1720291413659</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1720291413659</updated>
</task>
<task id="LOCAL-00008" summary="small fix">
<option name="closed" value="true" />
<created>1720293774580</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1720293774580</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -119,6 +142,8 @@
<MESSAGE value="Adding AStar Algorithm" /> <MESSAGE value="Adding AStar Algorithm" />
<MESSAGE value="Stable Version with finished visualisation" /> <MESSAGE value="Stable Version with finished visualisation" />
<MESSAGE value="Stable Version 3.0" /> <MESSAGE value="Stable Version 3.0" />
<option name="LAST_COMMIT_MESSAGE" value="Stable Version 3.0" /> <MESSAGE value="Tests with marking of Edges and Vertexes&#10;Adding Visualisation of Edge weight &#10;and Vertex name&#10;fixed AStar" />
<MESSAGE value="small fix" />
<option name="LAST_COMMIT_MESSAGE" value="small fix" />
</component> </component>
</project> </project>

View File

@ -1,14 +1,11 @@
package OurApplication; package OurApplication;
import graph.*;
import graph.Graph;
import logging.LogElementList; import logging.LogElementList;
import visualisation.DrawArea; 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. * This class provides an example for using visualization.DrawArea.
@ -53,6 +50,9 @@ public class OurDrawArea extends DrawArea{
OurLogElement logElement = (OurLogElement) logList.get(); OurLogElement logElement = (OurLogElement) logList.get();
logElement.getGraph().draw(g); 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);
}
} }

View File

@ -1,14 +1,12 @@
package graph; package graph;
import OurApplication.OurAlgorithm;
import OurApplication.OurLogElement; import OurApplication.OurLogElement;
import logging.LogElementList; import logging.LogElementList;
import visualizationElements.Edge; import visualizationElements.Edge;
import visualizationElements.EdgeStyle; import visualizationElements.EdgeStyle;
import visualizationElements.Vertex; import visualizationElements.Vertex;
import java.awt.*; import java.awt.Color;
import java.io.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import java.util.PriorityQueue; import java.util.PriorityQueue;
@ -316,6 +314,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
int dist = 0; int dist = 0;
// Variable, die Distanz zwischen dem potenziell nächsten Knoten und dem Zielknoten speichert // Variable, die Distanz zwischen dem potenziell nächsten Knoten und dem Zielknoten speichert
int airDist = 0; int airDist = 0;
// Variable, die Distanz zwischen dem aktuellen Knoten bis zum Endknoten speichert
int distToFinish = 0;
// Zähler für LogList // Zähler für LogList
int step = 0; 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)); + Math.pow((i.getCords()[1] - n2.getCords()[1]), 2));
// Berechne Distanz zu nächstem Knoten // 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; 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())); this.logList.add(new OurLogElement(step, "Step: " + step, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf // Nehme nächsten Knoten in die Queue auf
queue.add(new WrapperElement<>(i, dist)); queue.add(new WrapperElement<>(i, distToFinish));
} }
} }

View File

@ -2,3 +2,18 @@ package graph;
public abstract class EdgeMarking extends Marking{ 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;
}
}

View File

@ -32,7 +32,7 @@ public class ExampleGraphs {
DirectedGraph<VertexMarking, EdgeMarking> example1 = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> example1 = new DirectedGraph<>();
int size = 5; int size = 5;
MarkedVertex[][] vertices = new MarkedVertex[size][size]; MarkedVertex<VertexMarking>[][] vertices = new MarkedVertex[size][size];
// Knoten erstellen und zum Graph hinzufügen // Knoten erstellen und zum Graph hinzufügen
for (int row = 0; row < size; row++) { for (int row = 0; row < size; row++) {
@ -47,10 +47,10 @@ public class ExampleGraphs {
for (int row = 0; row < size; row++) { for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) { for (int col = 0; col < size; col++) {
if (col < size - 1) { 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) { 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; return example1;
} }
private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex from, MarkedVertex to, int weight) { private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex<VertexMarking> from, MarkedVertex<VertexMarking> to, EdgeWeightMarking weight) {
MarkedEdge forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, null, weight); MarkedEdge<EdgeMarking> forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, weight, weight.getWeight());
MarkedEdge backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, null, weight); MarkedEdge<EdgeMarking> backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, weight, weight.getWeight());
graph.addEdge(forwardEdge); graph.addEdge(forwardEdge);
graph.addEdge(backwardEdge); graph.addEdge(backwardEdge);
} }

View File

@ -24,16 +24,16 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
public MarkedEdge(String s, Vertex n1, Vertex n2, U u) { public MarkedEdge(String s, Vertex n1, Vertex n2, U u) {
super(s, n1, n2); super(s, n1, n2);
this.marking = u; this.marking = u;
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), u.toString()); this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex());
} }
// TODO ACHTUNG DEBUG!!!! // 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); super(s, n1, n2);
this.marking = u; this.marking = u;
this.weighting = w; this.weighting = weighting;
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), "u.toString()", Color.BLACK); this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), Integer.toString(weighting), Color.BLACK);
} }

View File

@ -27,17 +27,17 @@ public class MarkedVertex<T extends VertexMarking> extends Vertex{
public MarkedVertex(String s, T t) { public MarkedVertex(String s, T t) {
super(s); super(s);
this.marking = t; this.marking = t;
this.screenVertex = new visualizationElements.Vertex(0, 0, t.toString()); this.screenVertex = new visualizationElements.Vertex(0, 0);
this.xCord = 0; this.xCord = 0;
this.yCord = 0; this.yCord = 0;
} }
// TODO ACHTUNG DEBUG!!!! // TODO ACHTUNG DEBUG!!!!
public MarkedVertex(int xCord, int yCord, String s, T t, Color color) { public MarkedVertex(int xCord, int yCord, String name, T t, Color color) {
super(s); super(name);
this.marking = t; 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.xCord = xCord;
this.yCord = yCord; this.yCord = yCord;
} }

View File

@ -2,3 +2,18 @@ package graph;
public abstract class VertexMarking extends Marking { 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;
}
}

Binary file not shown.