Skip to content

Commit

Permalink
Merge branch 'development' into adstar-integration
Browse files Browse the repository at this point in the history
Conflicts:
	hipster-core/src/main/java/es/usc/citius/hipster/algorithm/Hipster.java
  • Loading branch information
gonzalezsieira committed Jul 31, 2014
2 parents c58b143 + 2e5bd16 commit 3fed358
Show file tree
Hide file tree
Showing 11 changed files with 709 additions and 119 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ SearchProblem p = GraphSearchProblem
// Search the shortest path from "A" to "F"
System.out.println(Hipster.createDijkstra(p).search("F"));
```
But that's not all. Hipster comes with different problem examples that illustrate how Hipster can be used to solve a wide variety of problems such as the eight puzzle problem or the N-Queens problem.
But that's not all. Hipster comes with different problem examples that illustrate how Hipster can be used to solve a wide variety of problems (not only graph search) such as the eight puzzle problem or the N-Queens problem.

## What's next?

If you want to learn how to solve a problem by searching with Hipster, check the wiki to [learn the basics](https://github.com/citiususc/hipster/wiki/Getting-Started) and the [JavaDoc documentation](http://citiususc.github.io/hipster/documentation/javadoc/1.0.0-SNAPSHOT). There are also a few implemented examples here.
If you want to learn how to solve a problem by searching with Hipster, check the wiki to [learn the basics](https://github.com/citiususc/hipster/wiki/Getting-Started) and the [JavaDoc documentation](http://citiususc.github.io/hipster/documentation/javadoc/1.0.0-SNAPSHOT). There are also a few implemented examples [here](https://github.com/citiususc/hipster/tree/development/hipster-examples/src/main/java/es/usc/citius/hipster/examples).
We also suggest you to check [this presentation](https://speakerdeck.com/pablormier/hipster-an-open-source-java-library-for-heuristic-search) for a quick introduction.

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@


import es.usc.citius.hipster.algorithm.localsearch.HillClimbing;
import es.usc.citius.hipster.model.ADStarNode;
import es.usc.citius.hipster.model.function.NodeExpander;
import es.usc.citius.hipster.model.CostNode;
import es.usc.citius.hipster.model.HeuristicNode;
import es.usc.citius.hipster.model.Node;
import es.usc.citius.hipster.model.function.impl.ADStarNodeExpander;
import es.usc.citius.hipster.model.function.impl.ADStarNodeFactory;
import es.usc.citius.hipster.model.impl.ADStarNodeImpl;
import es.usc.citius.hipster.model.impl.UnweightedNode;
import es.usc.citius.hipster.model.impl.WeightedNode;
import es.usc.citius.hipster.model.problem.SearchComponents;
import es.usc.citius.hipster.model.problem.SearchProblem;
import es.usc.citius.hipster.util.examples.RomanianProblem;
import es.usc.citius.hipster.util.graph.GraphSearchProblem;

import java.util.Collections;

Expand All @@ -38,38 +35,37 @@ private Hipster(){

}

public static <A,S,C extends Comparable<C>> AStar<A,S,C,WeightedNode<A,S,C>> createAStar(SearchProblem<A,S,WeightedNode<A,S,C>> components){
return new AStar<A, S, C, WeightedNode<A,S,C>>(components.getInitialNode(), components.getExpander());
public static <A,S,C extends Comparable<C>, N extends HeuristicNode<A,S,C,N>> AStar<A,S,C,N> createAStar(SearchProblem<A,S,N> components){
return new AStar<A, S, C, N>(components.getInitialNode(), components.getExpander());
}

public static <A,S,C extends Comparable<C>> AStar<A,S,C,WeightedNode<A,S,C>> createDijkstra(SearchProblem<A,S,WeightedNode<A,S,C>> components){
public static <A,S,C extends Comparable<C>, N extends HeuristicNode<A,S,C,N>> AStar<A,S,C,N> createDijkstra(SearchProblem<A,S,N> components){
//TODO: There is no difference with AStar. Actually if the NodeExpander uses heuristics, this "Dijkstra" impl works as the AStar. This should be changed!
return new AStar<A, S, C, WeightedNode<A,S,C>>(components.getInitialNode(), components.getExpander());
return new AStar<A, S, C, N>(components.getInitialNode(), components.getExpander());
}


public static <A,S,C extends Comparable<C>> BellmanFord<A,S,C,WeightedNode<A,S,C>> createBellmanFord(SearchProblem<A,S,WeightedNode<A,S,C>> components){
return new BellmanFord<A, S, C, WeightedNode<A,S,C>>(components.getInitialNode(), components.getExpander());
public static <A,S,C extends Comparable<C>, N extends CostNode<A,S,C,N>> BellmanFord<A,S,C,N> createBellmanFord(SearchProblem<A,S,N> components){
return new BellmanFord<A, S, C, N>(components.getInitialNode(), components.getExpander());
}

public static <A,S> BreadthFirstSearch<A,S,UnweightedNode<A,S>> createBreadthFirstSearch(SearchProblem<A,S,UnweightedNode<A,S>> components){
return new BreadthFirstSearch<A, S, UnweightedNode<A, S>>(components.getInitialNode(), components.getExpander());
public static <A,S,N extends Node<A,S,N>> BreadthFirstSearch<A,S,N> createBreadthFirstSearch(SearchProblem<A,S,N> components){
return new BreadthFirstSearch<A,S,N>(components.getInitialNode(), components.getExpander());
}

public static <A,S> DepthFirstSearch<A,S,UnweightedNode<A,S>> createDepthFirstSearch(SearchProblem<A,S,UnweightedNode<A,S>> components){
return new DepthFirstSearch<A, S, UnweightedNode<A, S>>(components.getInitialNode(), components.getExpander());
public static <A,S,N extends Node<A,S,N>> DepthFirstSearch<A,S,N> createDepthFirstSearch(SearchProblem<A,S,N> components){
return new DepthFirstSearch<A, S, N>(components.getInitialNode(), components.getExpander());
}

public static <A,S,C extends Comparable<C>> IDAStar<A,S,C,WeightedNode<A,S,C>> createIDAStar(SearchProblem<A,S,WeightedNode<A,S,C>> components){
return new IDAStar<A, S, C, WeightedNode<A, S, C>>(components.getInitialNode(), components.getExpander());
public static <A,S,C extends Comparable<C>, N extends HeuristicNode<A,S,C,N>> IDAStar<A,S,C,N> createIDAStar(SearchProblem<A,S,N> components){
return new IDAStar<A, S, C, N>(components.getInitialNode(), components.getExpander());
}

public static <A,S,C extends Comparable<C>> HillClimbing<A,S,C,WeightedNode<A,S,C>> createHillClimbing(SearchProblem<A,S,WeightedNode<A,S,C>> components, boolean enforced){
return new HillClimbing<A,S,C,WeightedNode<A,S,C>>(components.getInitialNode(), components.getExpander(), enforced);
public static <A,S,C extends Comparable<C>, N extends HeuristicNode<A,S,C,N>> HillClimbing<A,S,C,N> createHillClimbing(SearchProblem<A,S,N> components, boolean enforced){
return new HillClimbing<A,S,C,N>(components.getInitialNode(), components.getExpander(), enforced);
}

public static <A,S,C extends Comparable<C>> MultiobjectiveLS<A,S,C,WeightedNode<A,S,C>> createMultiobjectiveLS(SearchProblem<A,S,WeightedNode<A,S,C>> components){
return new MultiobjectiveLS<A, S, C, WeightedNode<A, S, C>>(components.getInitialNode(), components.getExpander());
public static <A,S,C extends Comparable<C>, N extends HeuristicNode<A,S,C,N>> MultiobjectiveLS<A,S,C,N> createMultiobjectiveLS(SearchProblem<A,S,N> components){
return new MultiobjectiveLS<A, S, C, N>(components.getInitialNode(), components.getExpander());
}

public static <A,S,C extends Comparable<C>> ADStarForward<A,S,C,ADStarNodeImpl<A,S,C>> createADStar(SearchComponents<A, S, C> components){
Expand All @@ -84,5 +80,4 @@ public static <A,S,C extends Comparable<C>> ADStarForward<A,S,C,ADStarNodeImpl<A
Collections.singleton(components.getGoal()),
expander);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ private StackFrameNode nextUnvisited(){
StackFrameNode nextNode;
do {
nextNode = processNextNode();
// No more neighbors to visit with the current fLimit. Update the new fLimit
if (nextNode == null){
// Reinitialize
if (minfLimit != null && minfLimit.compareTo(fLimit)>0){
fLimit = minfLimit;
reinitialization++;
//System.out.println("Reinitializing, new bound: " + fLimit);
minfLimit = null;
stack.add(new StackFrameNode(initialNode));
nextNode = processNextNode();
Expand Down Expand Up @@ -175,8 +175,7 @@ private StackFrameNode processNextNode(){
C fCurrent = current.node.getScore();
if (fCurrent.compareTo(fLimit)>0){
// Current node exceeds the limit bound, update minfLimit, pop and skip.
// Update minfLimit
updateMinFLimit(current.node.getScore());
updateMinFLimit(fCurrent);
// Remove from stack
current.processed = true;
return stack.pop();
Expand All @@ -186,7 +185,7 @@ private StackFrameNode processNextNode(){
if (current.successors.hasNext()){
// 3 - Node has at least one neighbor
N successor = current.successors.next();
// push the node;
// push the node
stack.add(new StackFrameNode(successor));
return current;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ private boolean isDominated(N node, Iterable<N> nonDominated) {
}
return false;
}

public Queue<N> getQueue() {
return queue;
}

public Multimap<S, N> getNonDominated() {
return nonDominated;
}
}

@Override
Expand Down
Loading

0 comments on commit 3fed358

Please sign in to comment.