62 lines
1.8 KiB
Java
62 lines
1.8 KiB
Java
|
package testApplication;
|
|||
|
|
|||
|
import graph.DirectedGraph;
|
|||
|
import graph.EdgeMarking;
|
|||
|
import graph.MarkedVertex;
|
|||
|
import graph.VertexMarking;
|
|||
|
import logging.*;
|
|||
|
|
|||
|
import javax.swing.*;
|
|||
|
import java.util.Random;
|
|||
|
|
|||
|
/**
|
|||
|
* 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 logging.Algorithm
|
|||
|
* @author MSch<EFBFBD>fer
|
|||
|
* DHBW Stuttgart/Campus Horb AI2008<br>
|
|||
|
* <br>
|
|||
|
*/
|
|||
|
public class TestAlgorithm extends Algorithm{
|
|||
|
|
|||
|
private graph.DirectedGraph<VertexMarking, EdgeMarking> graph;
|
|||
|
|
|||
|
public TestAlgorithm() {
|
|||
|
super();
|
|||
|
}
|
|||
|
/**
|
|||
|
* Creates a sum up algorithm.
|
|||
|
* @param parameterArea the sum up parameter area the algorithm gets its parameters from
|
|||
|
*/
|
|||
|
public TestAlgorithm(TestParameterArea parameterArea){
|
|||
|
super(parameterArea,"Visualized algorithm");
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 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<TestLogElement> run(){
|
|||
|
Random random = new Random();
|
|||
|
MarkedVertex<VertexMarking> start = this.graph.getAllVertexes().get(0);
|
|||
|
|
|||
|
String input = JOptionPane.showInputDialog("Enter 'BFS' to run BreadthFirstSearch algorithm or 'TopSort' for the TopSort algorithm:");
|
|||
|
|
|||
|
if ("BFS".equalsIgnoreCase(input)) {
|
|||
|
this.graph.breadthFirstSearch(start);
|
|||
|
}
|
|||
|
if ("TopSort".equalsIgnoreCase(input)) {
|
|||
|
this.graph.topSort(start);
|
|||
|
}
|
|||
|
|
|||
|
return this.graph.getNewLogList();
|
|||
|
}
|
|||
|
|
|||
|
public void actualizeGraph(graph.DirectedGraph<VertexMarking, EdgeMarking> graph) {
|
|||
|
this.graph = graph;
|
|||
|
}
|
|||
|
}
|