Search in sources :

Example 1 with GraphBuilder

use of graph.GraphBuilder in project SimpleAsteroids by ljialin.

the class MazeModel method findShortestPath.

public List<Vertex> findShortestPath(Vertex from, Vertex to) {
    this.from = from;
    this.to = to;
    ShortestPath shortestPath = new ShortestPath();
    shortestPath.runShortestPath(new GraphBuilder().buildGraph(this), from, to);
    path = shortestPath.getPath(from, to);
    return path;
}
Also used : ShortestPath(graph.ShortestPath) GraphBuilder(graph.GraphBuilder)

Example 2 with GraphBuilder

use of graph.GraphBuilder in project SimpleAsteroids by ljialin.

the class MazeView method main.

public static void main(String[] args) {
    int n = 400;
    int[] bits = new int[n];
    Random random = new Random();
    for (int i = 0; i < n; i++) {
        bits[i] = random.nextInt(2);
    }
    MazeView mazeView = new MazeView(bits);
    new JEasyFrame(mazeView, "Maze Test");
    MazeModel mazeModel = new MazeModel(bits);
    Graph graph = new GraphBuilder().buildGraph(mazeModel);
    System.out.println(graph.getArcs());
    System.out.println("Finding shortest path:");
    Vertex from = new Vertex(0, 0);
    Vertex to = new Vertex(2, 2);
    System.out.println(new ShortestPath().runShortestPath(graph, from, to));
}
Also used : Vertex(graph.Vertex) Graph(graph.Graph) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) ShortestPath(graph.ShortestPath) GraphBuilder(graph.GraphBuilder)

Example 3 with GraphBuilder

use of graph.GraphBuilder in project SimpleAsteroids by ljialin.

the class ShortestPathTest method findShortestPath.

public Integer findShortestPath(int[] bits) {
    MazeModel mazeModel = new MazeModel(bits);
    Graph graph = new GraphBuilder().buildGraph(mazeModel);
    // System.out.println(graph.getArcs());
    // System.out.println("Finding shortest path:");
    // Vertex from = new Vertex(0, 0);
    // Vertex to = new Vertex(5, 5);
    ShortestPath shortestPath = new ShortestPath();
    Integer result = shortestPath.runShortestPath(graph, from, to);
    return result;
}
Also used : Graph(graph.Graph) ShortestPath(graph.ShortestPath) GraphBuilder(graph.GraphBuilder)

Aggregations

GraphBuilder (graph.GraphBuilder)3 ShortestPath (graph.ShortestPath)3 Graph (graph.Graph)2 Vertex (graph.Vertex)1 Random (java.util.Random)1 JEasyFrame (utilities.JEasyFrame)1