ProjektGraph/OurApplication/OurAlgorithm.java

84 lines
2.3 KiB
Java

package OurApplication;
import graph.*;
import logging.Algorithm;
import logging.LogElementList;
import java.util.Objects;
/**
* 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.
*
* @see Algorithm
*/
public class OurAlgorithm extends Algorithm {
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
private OurMethodButtons methodButtons;
/**
* Standard constructor.
* Initializes an instance of OurAlgorithm.
*/
public OurAlgorithm() {
super();
}
/**
* 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)
*/
public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons) {
super(parameterArea, "Thema II: Kürzeste Wege");
this.methodButtons = methodButtons;
}
/**
* 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
*/
public LogElementList<OurLogElement> run() {
this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph());
MarkedVertex<VertexMarking> start = null;
for (MarkedVertex<VertexMarking> i : this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Start")) {
start = i;
}
}
MarkedVertex<VertexMarking> end = null;
for (MarkedVertex<VertexMarking> i : this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Ende")) {
end = i;
}
}
if (this.methodButtons.getSelectedMethod()) {
this.currentGraph.getShortestPathDijkstra(start, end);
} else {
this.currentGraph.getShortestPathAStar(start, end);
}
return this.currentGraph.getLogList();
}
/**
* Sets the current graph for the algorithm.
*
* @param graph the graph to be set as the current graph
*/
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph;
}
}