ProjektGraph/OurApplication/OurAlgorithm.java

112 lines
3.5 KiB
Java
Raw Normal View History

2024-06-27 13:05:22 +00:00
package OurApplication;
2024-07-01 15:08:11 +00:00
import graph.*;
2024-06-27 13:05:22 +00:00
import logging.Algorithm;
import logging.LogElementList;
2024-07-01 18:10:25 +00:00
import java.awt.*;
import java.util.HashMap;
import java.util.PriorityQueue;
2024-07-01 15:08:11 +00:00
import java.util.Random;
2024-07-01 18:10:25 +00:00
import java.util.Vector;
2024-07-01 15:08:11 +00:00
2024-06-27 13:05:22 +00:00
/**
* 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>
*/
public class OurAlgorithm extends Algorithm{
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){
super(parameterArea,"GraphAlgorithm");
}
/**
* 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-01 18:10:25 +00:00
2024-06-27 13:05:22 +00:00
public LogElementList run(){
LogElementList<OurLogElement>logList = new LogElementList<OurLogElement>();
2024-07-01 18:10:25 +00:00
/*
2024-07-01 15:08:11 +00:00
for(int x=1;x<=10;x++){
Random random = new Random();
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
for (int i = 0; i < 10; i++) {
myGraph.addVertex(new MarkedVertex<>(String.valueOf(i), null, random.nextInt(i, 350), random.nextInt(i, 350)));
}
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
}
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
}
2024-06-27 13:05:22 +00:00
try{
2024-07-01 15:08:11 +00:00
logList.add(new OurLogElement(x, "Value", x, myGraph));
2024-06-27 13:05:22 +00:00
}
catch(OutOfMemoryError e){
2024-07-01 15:08:11 +00:00
System.err.println("Out of memory");
2024-06-27 13:05:22 +00:00
}
}
2024-07-01 18:10:25 +00:00
*/
Random random = new Random();
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
for (int i = 0; i < 10; i++) {
myGraph.addVertex(new MarkedVertex<>(random.nextInt(i, 350), random.nextInt(i, 350), String.valueOf(i) + " :", Color.BLACK , null));
}
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
}
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
}
MarkedVertex<VertexMarking> start = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size()));
MarkedVertex<VertexMarking> end = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size()));
Vector<DirectedGraph<VertexMarking, EdgeMarking>> items = new Vector<>();
items = myGraph.DikstraVisualization(start, end);
for(DirectedGraph<VertexMarking, EdgeMarking> i : items){
logList.add(new OurLogElement(1, "Value", 1, i));
}
2024-06-27 13:05:22 +00:00
return logList;
}
2024-07-01 18:10:25 +00:00
//Erstelle eines zufälligen Graphen
//Auf den graphen Diktra aufrufen --> liefert Vektor mit Steps
//for each über die Steps und fügen sie zur Loglist hinzu
//return die Log list
2024-06-27 13:05:22 +00:00
}