Hipster4j is a lightweight and powerful heuristic search library for Java and Android. It contains common, fully customizable algorithms such as Dijkstra, A* (A-Star), DFS, BFS, Bellman-Ford and more.
Executing the following code, using one of the graph of the examples, raises a NullPointerException when using Bellman-Ford algorithm:
/_/
String first = "A";
String goal = "F";
List list = new ArrayList<>();
list.add(new Link("A","B",2));
list.add(new Link("A","C",6));
list.add(new Link("B","C",1));
list.add(new Link("B","D",9));
list.add(new Link("B","F",11));
list.add(new Link("C","E",3));
list.add(new Link("D","F",2));
list.add(new Link("E","D",2));
HashBasedHipsterDirectedGraph g = new HashBasedHipsterDirectedGraph<>();
for(Link l : list)
g.connect(l.getSource(), l.getTarget(), l.getWeight());
SearchProblem p = GraphSearchProblem.startingFrom(first).in(g).takeCostsFromEdges().build();
Algorithm.SearchResult o = Hipster.createBellmanFord(p).search(goal);
/_/
Note: "Link" is a simple bean class with "source", "target" and "weight" fields.
Replacing the algorithm with other such as Dijkstra or Breadth, it works fine.
Executing the following code, using one of the graph of the examples, raises a NullPointerException when using Bellman-Ford algorithm:
/_/ String first = "A"; String goal = "F"; List list = new ArrayList<>(); list.add(new Link("A","B",2)); list.add(new Link("A","C",6)); list.add(new Link("B","C",1)); list.add(new Link("B","D",9)); list.add(new Link("B","F",11)); list.add(new Link("C","E",3)); list.add(new Link("D","F",2)); list.add(new Link("E","D",2)); HashBasedHipsterDirectedGraph g = new HashBasedHipsterDirectedGraph<>(); for(Link l : list) g.connect(l.getSource(), l.getTarget(), l.getWeight()); SearchProblem p = GraphSearchProblem.startingFrom(first).in(g).takeCostsFromEdges().build(); Algorithm.SearchResult o = Hipster.createBellmanFord(p).search(goal); /_/ Note: "Link" is a simple bean class with "source", "target" and "weight" fields.
Replacing the algorithm with other such as Dijkstra or Breadth, it works fine.