ProjektGraph/OurApplication/OurAlgorithm.java
cmerkens 1313402f07 Merge branch 'main' of https://gitea.hb.dhbw-stuttgart.de/i23024/ProjektGraph
# Conflicts:
#	OurApplication/OurAlgorithm.java
#	OurApplication/OurApplication.java
#	graph/ExampleGraphs.java
#	out/production/ProjektGraph/OurApplication/OurAlgorithm.class
#	out/production/ProjektGraph/OurApplication/OurApplication.class
#	out/production/ProjektGraph/OurApplication/OurParameterArea.class
#	out/production/ProjektGraph/graph/ExampleGraphs.class
2024-07-07 20:43:35 +02:00

89 lines
2.6 KiB
Java
Raw Blame History

package OurApplication;
import graph.*;
import logging.Algorithm;
import logging.LogElementList;
import visualizationElements.Vertex;
import java.awt.*;
import java.util.Objects;
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<63>fer
* DHBW Stuttgart/Campus Horb AI2008<br>
* <br>
*/
public class OurAlgorithm extends Algorithm {
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
private OurMethodButtons methodButtons;
public OurAlgorithm() {
super();
}
/**
* Creates a sum up algorithm.
* @param parameterArea the sum up parameter area the algorithm gets its parameters from
*/
public OurAlgorithm(OurParameterArea parameterArea, OurMethodButtons methodButtons){
super(parameterArea,"GraphAlgorithm");
this.methodButtons = methodButtons;
}
/**
* 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
*/
public LogElementList<OurLogElement> run() {
OurParameterArea currentParameterArea = (OurParameterArea) this.getParameterArea();
this.setCurrentGraph(currentParameterArea.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;
}
}
/*
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);
}else{
this.currentGraph.getShortestPathAStar(start, end);
}
return this.currentGraph.getLogList();
}
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph;
}
}