Nix funktioniert

This commit is contained in:
cmerkens 2024-07-08 21:15:24 +02:00
parent dc371da1f2
commit dd18dbd55e
20 changed files with 237 additions and 99 deletions

55
.idea/workspace.xml generated
View File

@ -5,8 +5,25 @@
</component>
<component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Weighting gefixt">
<change afterPath="$PROJECT_DIR$/graph/VertexWeightMarking.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/ExampleGraphs.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/ExampleGraphs.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/Graph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/Graph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/UndirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/UndirectedGraph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/VertexMarking.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/VertexMarking.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/Graph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/Graph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/UndirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/UndirectedGraph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/VertexWeightMarking.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/VertexWeightMarking.class" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -38,17 +55,17 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Application.Display.executor&quot;: &quot;Run&quot;,
&quot;Application.OurApplication.executor&quot;: &quot;Run&quot;,
&quot;Application.OurLegendArea.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Application.Display.executor": "Run",
"Application.OurApplication.executor": "Run",
"Application.OurLegendArea.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Git/ProjektGraphMain"
}
}</component>
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Git\ProjektGraph" />
@ -180,4 +197,20 @@
<MESSAGE value="Weighting gefixt" />
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurDrawArea.java</url>
<line>51</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurAlgorithm.java</url>
<line>46</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View File

@ -44,10 +44,10 @@ public class OurAlgorithm extends Algorithm {
*/
public LogElementList<OurLogElement> run() {
OurParameterArea currentParameterArea = (OurParameterArea) this.getParameterArea();
this.setCurrentGraph(currentParameterArea.getSelectedGraph());
this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph());
/*
MarkedVertex<VertexMarking> start = null;
for (MarkedVertex<VertexMarking> i: this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Start")) {
@ -62,16 +62,18 @@ public class OurAlgorithm extends Algorithm {
}
}
/*
*/
Random random = new Random();
MarkedVertex<VertexMarking> start = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
MarkedVertex<VertexMarking> end = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
System.out.println(start.getName() + " to " + end.getName());
*/
if(this.methodButtons.getSelectedMethod()){
this.currentGraph.getShortestPathDijkstra(start, end);
// this.currentGraph.getShortestPathDijkstra(start, end);
}else{
this.currentGraph.getShortestPathAStar(start, end);
}

View File

@ -59,8 +59,6 @@ public class OurApplication {
JFrame frame = new JFrame("Visualise");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);

View File

@ -1,12 +1,13 @@
package OurApplication;
import graph.*;
import logging.LogElementList;
import visualisation.DrawArea;
import visualizationElements.Edge;
import visualizationElements.Vertex;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@ -22,7 +23,7 @@ public class OurDrawArea extends DrawArea{
private static final long serialVersionUID = 1L;
private visualizationElements.Graph currentGraph;
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
/**
@ -32,6 +33,7 @@ public class OurDrawArea extends DrawArea{
super();
}
/**
* Creates a test draw area and sets the specified log list.
* @param logList the draw area's log list test log elements.
@ -39,23 +41,111 @@ public class OurDrawArea extends DrawArea{
*/
public OurDrawArea(LogElementList<OurLogElement> logList, String drawAreaName){
super(logList, drawAreaName);
this.addMouseListener(new MouseListener() {
MarkedVertex<VertexMarking> temp = null;
@Override
public void mouseClicked(MouseEvent e) {
// Linksklick = Einfügen
if (SwingUtilities.isLeftMouseButton(e)) {
System.out.println("Left Mouse Clicked at (" + e.getX() + ", " + e.getY() + ")" + e.getPoint());
if (check(e.getPoint()) == null) {
addVertex(e.getPoint());
}
// Rechtsklick = Löschen
} else if (SwingUtilities.isRightMouseButton(e)) {
System.out.println("Right Mouse Clicked at (" + e.getX() + ", " + e.getY() + ")");
if (check(e.getPoint()) != null) {
removeVertex(check(e.getPoint()));
}
}
}
public void setCurrentGraph(visualizationElements.Graph graph) {
@Override
public void mousePressed(MouseEvent e) {
if (check(e.getPoint()) != null) {
temp = check(e.getPoint());
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (check(e.getPoint()) != null) {
addEdge(temp, check(e.getPoint()));
}
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
}
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph;
}
public graph.Graph<VertexMarking, EdgeMarking> getCurrentGraph() {
return this.currentGraph;
}
// TODO Vertex
private void addVertex(java.awt.Point point) {
this.currentGraph.addVertex(new MarkedVertex<>(point.x, point.y, "name", new VertexWeightMarking(1), Color.BLACK));
this.currentGraph.createLoglistElement();
this.drawStep();
}
private void removeVertex(MarkedVertex<VertexMarking> n) {
this.currentGraph.removeVertex(n);
this.currentGraph.createLoglistElement();
this.drawStep();
}
// TODO Edge
private void addEdge(MarkedVertex<VertexMarking> start, MarkedVertex<VertexMarking> end) {
this.currentGraph.addEdge(new MarkedEdge<>("", start, end, new EdgeWeightMarking(1)));
this.currentGraph.createLoglistElement();
this.drawStep();
}
private MarkedVertex<graph.VertexMarking> check(java.awt.Point point) {
for (MarkedVertex<graph.VertexMarking> i: this.currentGraph.getAllVertexes()) {
if (isWithinRadius(point.x, point.y, i.getCords()[0], i.getCords()[1], 20)) {
return i;
}
}
return null;
}
private static boolean isWithinRadius(int clickX, int clickY, int centerX, int centerY, int radius) {
int deltaX = clickX - centerX;
int deltaY = clickY - centerY;
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
return distance <= radius;
}
/**
* Draws a visualization element.
*/
public void draw(Graphics g) {
OurLogElement logElement = (OurLogElement) logList.get();
this.setCurrentGraph(((OurLogElement) logList.get()).getGraph());
logElement.getGraph().draw(g);
for(Edge screenEdge : currentGraph.getEdges()){
for(Edge screenEdge : ((OurLogElement) logList.get()).getGraph().getEdges()){
g.drawString(screenEdge.getMarking(), (screenEdge.getSource().getXpos() + screenEdge.getDestination().getXpos())/2, (screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos())/2);
}

View File

@ -86,9 +86,11 @@ public class OurParameterArea extends ParameterArea{
buttonAddGraph.addActionListener(e -> {
String input1 = textField1.getText();
String input2 = textField2.getText();
this.customGraph = createGraph(input1, input2);
});
// Buttons zum Panel hinzufügen
@ -103,6 +105,7 @@ public class OurParameterArea extends ParameterArea{
add(textField2);
}
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
ExampleGraphs temp = new ExampleGraphs();
switch (selectedExample) {

View File

@ -585,4 +585,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);
}
public void createLoglistElement() {
this.logList.add(new OurLogElement(0, "", 0, this.getScreenGraphCopy()));
}
}

View File

@ -413,5 +413,8 @@ public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> {
* @return Length of the shortest path between the vertices.
*/
public abstract double getShortestPathAStar(MarkedVertex<T> n1, MarkedVertex<T> n2);
public abstract void createLoglistElement();
}

View File

@ -487,4 +487,8 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
return distance.get(n2);
}
public void createLoglistElement() {
this.logList.add(new OurLogElement(0, "", 0, this.getScreenGraphCopy()));
}
}

View File

@ -8,53 +8,3 @@ public abstract class VertexMarking extends Marking {
// This class currently does not have any additional attributes or methods.
// It extends Marking, inheriting its properties and behaviors.
}
/**
* Represents a weight marking associated with a vertex in a graph.
* Extends {@link VertexMarking}.
*/
class VertexWeightMarking extends VertexMarking {
// ATTRIBUTE
private int weight;
// KONSTRUKTOREN
/**
* Constructs a vertex weight marking with the specified weight.
*
* @param weight The weight value associated with the vertex.
*/
VertexWeightMarking(int weight) {
this.weight = weight;
}
// GET-ER
/**
* Retrieves the weight associated with this vertex weight marking.
*
* @return The weight of the vertex marking.
*/
public int getWeight() {
return this.weight;
}
// SET-ER
/**
* Sets the weight associated with this vertex weight marking.
*
* @param weight The new weight value to set.
*/
public void setWeight(int weight) {
this.weight = weight;
}
}

View File

@ -0,0 +1,51 @@
package graph;
/**
* Represents a weight marking associated with a vertex in a graph.
* Extends {@link VertexMarking}.
*/
public class VertexWeightMarking extends VertexMarking {
// ATTRIBUTE
private int weight;
// KONSTRUKTOREN
/**
* Constructs a vertex weight marking with the specified weight.
*
* @param weight The weight value associated with the vertex.
*/
public VertexWeightMarking(int weight) {
this.weight = weight;
}
// GET-ER
/**
* Retrieves the weight associated with this vertex weight marking.
*
* @return The weight of the vertex marking.
*/
public int getWeight() {
return this.weight;
}
// SET-ER
/**
* Sets the weight associated with this vertex weight marking.
*
* @param weight The new weight value to set.
*/
public void setWeight(int weight) {
this.weight = weight;
}
}

View File

@ -4,22 +4,23 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Weighting gefixt">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurLogElement.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLogElement.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurTextArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurTextArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurLogElement.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurLogElement.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
@ -41,7 +42,7 @@
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Application.Display.executor&quot;: &quot;Run&quot;,
&quot;Application.OurApplication.executor&quot;: &quot;Debug&quot;,
&quot;Application.OurApplication.executor&quot;: &quot;Run&quot;,
&quot;Application.OurLegendArea.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
@ -147,7 +148,15 @@
<option name="project" value="LOCAL" />
<updated>1720347450647</updated>
</task>
<option name="localTasksCounter" value="11" />
<task id="LOCAL-00011" summary="Weighting gefixt">
<option name="closed" value="true" />
<created>1720362585915</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1720362585915</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -169,17 +178,7 @@
<MESSAGE value="small fix" />
<MESSAGE value="Beispiele überarbeitet" />
<MESSAGE value="LegendArea gestaltet" />
<option name="LAST_COMMIT_MESSAGE" value="LegendArea gestaltet" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurApplication.java</url>
<line>49</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<MESSAGE value="Weighting gefixt" />
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
</component>
</project>