Package progs.lib

Examples of progs.lib.BFS


        "   ",
        "   ",
        "   ",
    };
    Graph graph = Graph.fromStringArray(array);
    Assert.assertEquals(2, new BFS(graph).distanceFrom(new Node(0, 0), new Node(2, 2)));
    Assert.assertEquals(2, new BFS(graph).distanceFrom(new Node(0, 0), new Node(0, 2)));
    array = new String[]{
        " ",
        "#",
        " "};
    graph = Graph.fromStringArray(array);
    Assert.assertEquals(10 /*graph size = 3; so 3 * 3 + 1*/,
        new BFS(graph).distanceFrom(new Node(0, 0), new Node(2, 0)));
  }
View Full Code Here


  static class Solution {
    public Node solveFor(String[] room) {
      Graph graph = Graph.fromStringArray(room);
      List<Node> specialNodes = graph.getSpecialNodes();
      Set<Node> nodes = graph.getAllNodes();
      BFS bfs = new BFS(graph);
      int previousMinDistance = Integer.MAX_VALUE;
      Node bestNodeSoFar = null;
      for (Node node : nodes) {
        if (specialNodes.contains(node)) {
          continue;
        }
        int localDistance = 0;
        for (Node stationNode : specialNodes) {
          localDistance += bfs.distanceFrom(stationNode, node);
        }
        if (localDistance < previousMinDistance) {
          previousMinDistance = localDistance;
          bestNodeSoFar = node;
        }
View Full Code Here

TOP

Related Classes of progs.lib.BFS

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.