ProjektGraph/OurApplication/OurAlgorithm.java

89 lines
2.6 KiB
Java
Raw Normal View History

2024-07-02 19:13:30 +00:00
package OurApplication;
import graph.*;
import logging.Algorithm;
import logging.LogElementList;
2024-07-03 17:41:46 +00:00
import visualizationElements.Vertex;
2024-07-02 19:13:30 +00:00
import java.awt.*;
2024-07-07 18:34:38 +00:00
import java.util.Objects;
2024-07-02 19:13:30 +00:00
import java.util.Random;
import java.util.Vector;
/**
* This class provides an example for using logging.Algorithm.
* It sums up integer number starting with 0 up to the maximum value specified in the parameter area.
* @see Algorithm
* @author MSch<EFBFBD>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/
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
public OurAlgorithm() {
super();
}
/**
* Creates a sum up algorithm.
* @param parameterArea the sum up parameter area the algorithm gets its parameters from
*/
2024-07-07 17:49:31 +00:00
public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons){
2024-07-02 19:13:30 +00:00
super(parameterArea,"GraphAlgorithm");
2024-07-07 17:49:31 +00:00
this.methodButtons = methodButtons;
2024-07-02 19:13:30 +00:00
}
/**
* Overwritten from super class.
* Runs the algorithm..
* Returns the LogElementList produced by the algorithm processing.
* Adds integer number starting with 0 up to the maximum value.
* @return a LogElementList containing the algorithm processing single steps
*/
2024-07-03 17:41:46 +00:00
public LogElementList<OurLogElement> run() {
2024-07-07 17:49:31 +00:00
OurParameterArea currentParameterArea = (OurParameterArea) this.getParameterArea();
this.setCurrentGraph(currentParameterArea.getSelectedGraph());
2024-07-02 19:13:30 +00:00
2024-07-07 18:34:38 +00:00
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;
}
}
/*
2024-07-03 17:41:46 +00:00
Random random = new Random();
2024-07-02 19:13:30 +00:00
2024-07-03 17:41:46 +00:00
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());
2024-07-02 19:13:30 +00:00
2024-07-07 18:34:38 +00:00
*/
2024-07-07 17:49:31 +00:00
if(this.methodButtons.getSelectedMethod()){
this.currentGraph.getShortestPathDijkstra(start, end);
}else{
this.currentGraph.getShortestPathAStar(start, end);
}
2024-07-02 19:13:30 +00:00
2024-07-03 17:41:46 +00:00
return this.currentGraph.getLogList();
}
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph;
2024-07-02 19:13:30 +00:00
}
}
2024-07-03 17:41:46 +00:00