2024-07-02 19:13:30 +00:00
|
|
|
package OurApplication;
|
|
|
|
|
|
|
|
import graph.*;
|
|
|
|
import logging.Algorithm;
|
|
|
|
import logging.LogElementList;
|
|
|
|
|
2024-07-08 23:55:13 +00:00
|
|
|
import javax.swing.*;
|
2024-07-07 18:34:38 +00:00
|
|
|
import java.util.Objects;
|
2024-07-08 22:17:31 +00:00
|
|
|
|
2024-07-02 19:13:30 +00:00
|
|
|
|
|
|
|
/**
|
2024-07-08 22:17:31 +00:00
|
|
|
* This class provides an example of using logging.Algorithm.
|
|
|
|
* It implements a summation algorithm that computes the sum of integers starting from 0 up to a specified maximum value from the parameter area.
|
|
|
|
*
|
2024-07-02 19:13:30 +00:00
|
|
|
* @see Algorithm
|
|
|
|
*/
|
2024-07-03 17:41:46 +00:00
|
|
|
public class OurAlgorithm extends Algorithm {
|
|
|
|
|
|
|
|
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
|
2024-07-07 17:49:31 +00:00
|
|
|
private OurMethodButtons methodButtons;
|
2024-07-02 19:13:30 +00:00
|
|
|
|
2024-07-08 22:17:31 +00:00
|
|
|
/**
|
|
|
|
* Standard constructor.
|
|
|
|
* Initializes an instance of OurAlgorithm.
|
|
|
|
*/
|
2024-07-02 19:13:30 +00:00
|
|
|
public OurAlgorithm() {
|
|
|
|
super();
|
|
|
|
}
|
2024-07-08 22:17:31 +00:00
|
|
|
|
2024-07-02 19:13:30 +00:00
|
|
|
/**
|
2024-07-08 22:17:31 +00:00
|
|
|
* Constructs a summation algorithm with parameters from the parameter area.
|
|
|
|
*
|
|
|
|
* @param parameterArea the parameter area providing the selected graph for the algorithm
|
|
|
|
* @param methodButtons the method buttons determining the algorithm type (Dijkstra or A-Star)
|
2024-07-02 19:13:30 +00:00
|
|
|
*/
|
2024-07-08 22:17:31 +00:00
|
|
|
public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons) {
|
|
|
|
super(parameterArea, "Thema II: Kürzeste Wege");
|
2024-07-07 17:49:31 +00:00
|
|
|
this.methodButtons = methodButtons;
|
2024-07-02 19:13:30 +00:00
|
|
|
}
|
2024-07-08 22:17:31 +00:00
|
|
|
|
2024-07-02 19:13:30 +00:00
|
|
|
/**
|
2024-07-08 22:17:31 +00:00
|
|
|
* Overridden method from the superclass.
|
|
|
|
* Executes the summation algorithm.
|
|
|
|
* Computes the shortest path in the current graph based on the selected method (Dijkstra or A-Star).
|
|
|
|
*
|
|
|
|
* @return a LogElementList containing the single steps of the algorithm processing
|
2024-07-02 19:13:30 +00:00
|
|
|
*/
|
2024-07-03 17:41:46 +00:00
|
|
|
public LogElementList<OurLogElement> run() {
|
2024-07-07 17:49:31 +00:00
|
|
|
|
2024-07-08 23:55:13 +00:00
|
|
|
try{
|
|
|
|
this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph());
|
2024-07-07 14:27:22 +00:00
|
|
|
|
2024-07-08 23:55:13 +00:00
|
|
|
MarkedVertex<VertexMarking> start = null;
|
|
|
|
for (MarkedVertex<VertexMarking> i : this.currentGraph.getAllVertexes()) {
|
|
|
|
if (Objects.equals(i.getName(), "Start")) {
|
|
|
|
start = i;
|
|
|
|
}
|
2024-07-08 22:17:31 +00:00
|
|
|
}
|
2024-07-07 18:34:38 +00:00
|
|
|
|
2024-07-08 23:55:13 +00:00
|
|
|
MarkedVertex<VertexMarking> end = null;
|
|
|
|
for (MarkedVertex<VertexMarking> i : this.currentGraph.getAllVertexes()) {
|
|
|
|
if (Objects.equals(i.getName(), "Ende")) {
|
|
|
|
end = i;
|
|
|
|
}
|
2024-07-08 22:17:31 +00:00
|
|
|
}
|
2024-07-08 19:15:24 +00:00
|
|
|
|
2024-07-08 23:55:13 +00:00
|
|
|
if (this.methodButtons.getSelectedMethod()) {
|
|
|
|
this.currentGraph.getShortestPathDijkstra(start, end);
|
|
|
|
} else {
|
|
|
|
this.currentGraph.getShortestPathAStar(start, end);
|
|
|
|
}
|
|
|
|
//Fehlerbehandlung
|
|
|
|
}catch(Throwable e){
|
|
|
|
JFrame info = new JFrame();
|
|
|
|
JPanel contentpane = new JPanel();
|
|
|
|
info.setContentPane(contentpane);
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
contentpane,
|
|
|
|
"Bitte geben SIe einen gültige Graphen an. Hilfestellung für das Erstellen von Knoten und Kanten:\n" +
|
|
|
|
"Knoten: Name;X-Coordinate;Y-Coordinate\nKanten: StartKnoten;Endknoten;Gewichtung\n" +
|
|
|
|
"Hinweis: ein Koten benötigt den Namen 'Startknoten', ein anderer 'Endknoten'\n" +
|
|
|
|
"(Festlegen der Start und Endknoten für die Algorithmen)",
|
|
|
|
"Eingabefehler",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
LogElementList<OurLogElement> emptyLogList = new LogElementList<>();
|
|
|
|
emptyLogList.add(new OurLogElement());
|
|
|
|
return emptyLogList;
|
2024-07-07 17:49:31 +00:00
|
|
|
}
|
2024-07-03 17:41:46 +00:00
|
|
|
return this.currentGraph.getLogList();
|
|
|
|
}
|
|
|
|
|
2024-07-08 22:17:31 +00:00
|
|
|
/**
|
|
|
|
* Sets the current graph for the algorithm.
|
|
|
|
*
|
|
|
|
* @param graph the graph to be set as the current graph
|
|
|
|
*/
|
2024-07-03 17:41:46 +00:00
|
|
|
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
|
|
|
|
this.currentGraph = graph;
|
2024-07-02 19:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|