Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo.rodriguez.mier committed Aug 12, 2015
2 parents 8582e2a + 75ea2fa commit 628438b
Show file tree
Hide file tree
Showing 76 changed files with 1,793 additions and 753 deletions.
2 changes: 1 addition & 1 deletion .config/deploy-artifacts.sh
Expand Up @@ -8,7 +8,7 @@ if [ "$TRAVIS_REPO_SLUG" == "citiususc/hipster" ] && [ "$TRAVIS_JDK_VERSION" ==
# Deploy to CITIUS
#mvn --settings .config/maven-settings.xml -P citius-snapshot-deploy deploy -DskipTests=true
# Deploy to Sonatype Nexus OSS
mvn --settings .config/maven-settings.xml deploy -DskipTests=true
mvn --settings .config/maven-settings.xml -P sonatype-nexus-snapshots deploy -DskipTests=true
else
echo "Skipping deployment for this build..."
fi
Expand Down
11 changes: 6 additions & 5 deletions .travis.yml
Expand Up @@ -4,14 +4,15 @@ jdk:
- oraclejdk8
- openjdk7
branches:
only:
- master
- development
except:
- /^(?i:wip).*$/
sudo: false
after_success:
- chmod +x .config/deploy-site.sh
#- chmod +x .config/deploy-site.sh
#- .config/deploy-site.sh
- chmod +x .config/deploy-artifacts.sh
#- .config/deploy-artifacts.sh
- .config/deploy-artifacts.sh
- mvn clean cobertura:cobertura coveralls:report
env:
global:
- secure: ILdOYjPt+8g5rlexXBYAhECtn5Zm26FRf0/nwCxUU303qtzFQyMcxinIC93aun880OnINjA7fzQeBkG4P+LSVOAXbmGTGhtyPBzMOGcnZouJM/RyXHUft6tAXPimXQ7JjDFjyv7EzSeStk/4WEp0mkxheIryZS3X1pbED1TqgUM=
Expand Down
15 changes: 8 additions & 7 deletions README.md
@@ -1,6 +1,6 @@
![Hipster](src/main/doclava/custom/assets/hipster-template/assets/images/header-logo.png?raw=true)

A powerful and friendly heuristic search library implemented in pure java.
A powerful and friendly heuristic search library implemented in Java.

## What's Hipster?

Expand All @@ -20,14 +20,14 @@ The current version of the library comes with some very well-known and wide used
* Dijkstra.
* Bellman-Ford.
* Informed search:
* A\*. \\A star\\
* IDA\*: Iterative Deepening A\*. \\IDA star\\
* AD\*: Anytime Dynamic A\*. \\AD star\\
* A star (A*).
* IDA star (IDA*), Iterative Deepening A*.
* AD star (AD*): Anytime Dynamic A*.
* Local search:
* Hill-Climbing.
* Enforced-Hill-Climbing.
* Other (experimental implementations)
* Multiobjective LS algorithm. Original paper: Martins, E. D. Q. V., & Santos, J. L. E. (1999). *"The labeling algorithm for the multiobjective shortest path problem"*. <i>Departamento de Matematica, Universidade de Coimbra, Portugal, Tech. Rep. TR-99/005
* Multiobjective LS algorithm. Original paper: Martins, E. D. Q. V., & Santos, J. L. E. (1999). *"The labeling algorithm for the multiobjective shortest path problem"*. <i>Departamento de Matematica, Universidade de Coimbra, Portugal, Tech. Rep. TR-99/005</i>
* 3rd party adapters:
* [Java Universal/Graph (JUNG)](http://jung.sourceforge.net/) adapter.

Expand Down Expand Up @@ -101,15 +101,16 @@ we use the GraphSearchProblem to create the required components to solve it usin
```java
// Create a simple weighted directed graph with Hipster where
// vertices are Strings and edge values are just doubles
HipsterDirectedGraph<String,Double> graph = GraphBuilder.create()
HipsterDirectedGraph<String,Double> graph =
GraphBuilder.<String,Double>create()
.connect("A").to("B").withEdge(4d)
.connect("A").to("C").withEdge(2d)
.connect("B").to("C").withEdge(5d)
.connect("B").to("D").withEdge(10d)
.connect("C").to("E").withEdge(3d)
.connect("D").to("F").withEdge(11d)
.connect("E").to("D").withEdge(4d)
.buildDirectedGraph();
.createDirectedGraph();

// Create the search problem. For graph problems, just use
// the GraphSearchProblem util class to generate the problem with ease.
Expand Down
2 changes: 1 addition & 1 deletion hipster-all/pom.xml
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>es.usc.citius.hipster</groupId>
<artifactId>hipster-pom</artifactId>
<version>1.0.0-rc1</version>
<version>1.0.0-rc2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hipster-all</artifactId>
Expand Down
8 changes: 3 additions & 5 deletions hipster-core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.usc.citius.hipster</groupId>
<artifactId>hipster-pom</artifactId>
<version>1.0.0-rc1</version>
<version>1.0.0-rc2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hipster-core</artifactId>
Expand All @@ -18,10 +18,8 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Expand Up @@ -63,9 +63,9 @@
*/
public class ADStarForward<A,S,C extends Comparable<C>, N extends es.usc.citius.hipster.model.ADStarNode<A, S, C, N>> extends Algorithm<A, S, N> {

private S begin;
private Collection<S> goals;
private ADStarNodeExpander<A, S, C, N> expander;
protected S begin;
protected Collection<S> goals;
protected ADStarNodeExpander<A, S, C, N> expander;

/**
* Create an instance of the algorithm with a begin, a goal and a component to
Expand Down Expand Up @@ -103,15 +103,15 @@ public Iterator iterator() {
*/
public class Iterator implements java.util.Iterator<N> {
//queues used by the algorithm
private Map<S, N> open;
private Map<S, N> closed;
private Map<S, N> incons;
private Iterable<Transition<A, S>> transitionsChanged;
private Queue<N> queue;
private final N beginNode;
private final Collection<N> goalNodes;
protected Map<S, N> open;
protected Map<S, N> closed;
protected Map<S, N> incons;
protected Iterable<Transition<A, S>> transitionsChanged;
protected Queue<N> queue;
protected final N beginNode;
protected final Collection<N> goalNodes;

public Iterator() {
protected Iterator() {
//initialize nodes
this.beginNode = expander.makeNode(null, new Transition<A, S>(null, begin));
//initialize goal node collection
Expand Down Expand Up @@ -146,7 +146,7 @@ public Iterator() {
*
* @param node instance of node to add
*/
private void insertOpen(N node) {
protected void insertOpen(N node) {
this.open.put(node.state(), node);
this.queue.offer(node);
}
Expand All @@ -157,7 +157,7 @@ private void insertOpen(N node) {
*
* @return most promising node
*/
private N takePromising() {
protected N takePromising() {
while (!queue.isEmpty()) {
N head = queue.peek();
if (!open.containsKey(head.state())) {
Expand All @@ -174,7 +174,7 @@ private N takePromising() {
*
* @param node instance of node
*/
private void updateQueues(N node) {
protected void updateQueues(N node) {
S state = node.state();
if (node.getV().compareTo(node.getG()) != 0) {
if (!this.closed.containsKey(state)) {
Expand Down Expand Up @@ -220,6 +220,12 @@ public N next() {
//s removed from OPEN
open.remove(state);
//this.queue.remove(current);
//expand successors
for (N successorNode : expander.expand(current)) {
if(successorNode.isDoUpdate()){
updateQueues(successorNode);
}
}
//if v(s) > g(s)
if (current.isConsistent()) {
//v(s) = g(s)
Expand All @@ -231,12 +237,6 @@ public N next() {
expander.setMaxV(current);
updateQueues(current);
}

for (N successorNode : expander.expand(current)) {
if(successorNode.isDoUpdate()){
updateQueues(successorNode);
}
}
} else {
// for all directed edges (u, v) with changed edge costs
for(N nodeTransitionsChanged : expander.expandTransitionsChanged(beginNode.state(), current, transitionsChanged)){
Expand Down
Expand Up @@ -26,7 +26,7 @@
* Implementation of the A* algorithm. The A* algorithm extends the original
* Dijkstra's algorithm by including heuristics to improve the search. By default,
* the implementation uses a {@link java.util.PriorityQueue} for the nodes, which requires
* {@literal O(n*log n)} time for insertions. The queue can be changed to use another
* {@literal O(log n)} time for insertions. The queue can be changed to use another
* type of queue, for example a fibonacci heap as a queue, which works with constant amortized
* time for insertions.
* </p>
Expand All @@ -43,8 +43,8 @@
*/
public class AStar<A,S,C extends Comparable<C>,N extends HeuristicNode<A,S,C,N>> extends Algorithm<A,S,N> {

private final N initialNode;
private final NodeExpander<A,S,N> expander;
protected final N initialNode;
protected final NodeExpander<A,S,N> expander;

/**
* Default constructor for ADStarForward. Requires the initial state, the successor function to generate
Expand All @@ -67,11 +67,11 @@ public Iterator iterator() {
* Internal iterator that implements all the logic of the A* search
*/
public class Iterator implements java.util.Iterator<N> {
private Map<S, N> open;
private Map<S, N> closed;
private Queue<N> queue;
protected Map<S, N> open;
protected Map<S, N> closed;
protected Queue<N> queue;

private Iterator() {
protected Iterator() {
open = new HashMap<S, N>();
closed = new HashMap<S, N>();
queue = new PriorityQueue<N>();
Expand All @@ -86,7 +86,7 @@ public boolean hasNext() {
return !open.values().isEmpty();
}

private N takePromising() {
protected N takePromising() {
// Poll until a valid state is found
N node = queue.poll();
while (!open.containsKey(node.state())) {
Expand Down
Expand Up @@ -17,9 +17,8 @@
package es.usc.citius.hipster.algorithm;


import com.google.common.base.Predicate;
import com.google.common.base.Stopwatch;
import es.usc.citius.hipster.model.Node;
import es.usc.citius.hipster.util.Predicate;

import java.util.*;

Expand All @@ -40,30 +39,29 @@ public abstract class Algorithm<A,S,N extends Node<A,S,N>> implements Iterable<N
* Holds information about the search process.
*/
public final class SearchResult {
Stopwatch stopwatch;
int iterations;
Collection<N> goalNodes;
private int iterations;
private Collection<N> goalNodes;
private long elapsed;


public SearchResult(N goalNode, int iterations, Stopwatch stopwatch) {
public SearchResult(N goalNode, int iterations, long elapsed) {
this.goalNodes = Collections.singletonList(goalNode);
this.iterations = iterations;
this.stopwatch = stopwatch;
this.elapsed = elapsed;
}

public SearchResult(Collection<N> goalNodes, int iterations, Stopwatch stopwatch) {
public SearchResult(Collection<N> goalNodes, int iterations, long elapsed) {
this.goalNodes = goalNodes;
this.iterations = iterations;
this.stopwatch = stopwatch;
this.elapsed = elapsed;
}

/**
* Returns a stopped {@link Stopwatch} with the total search time.
* Use stopwatch.toString() to print the formatted time.
* @return stopwatch with the total search time.
* @return the elapsed time (in milliseconds) between the begin of the search and the
* search result generation.
*/
public Stopwatch getStopwatch() {
return stopwatch;
public long getElapsed() {
return elapsed;
}

/**
Expand Down Expand Up @@ -99,7 +97,7 @@ public String toString() {
final String ls = System.getProperty("line.separator");
StringBuilder builder = new StringBuilder();
builder.append("Total solutions: ").append(goalNodes.size()).append(ls);
builder.append("Total time: ").append(getStopwatch().toString()).append(ls);
builder.append("Total time: ").append(getElapsed()).append(ls);
builder.append("Total number of iterations: ").append(getIterations()).append(ls);
// Take solutions
int solution=1;
Expand Down Expand Up @@ -149,7 +147,7 @@ public boolean apply(N n) {
public SearchResult search(Predicate<N> condition){
int iteration = 0;
Iterator<N> it = iterator();
Stopwatch w = Stopwatch.createStarted();
long begin = System.currentTimeMillis();
N currentNode = null;
while(it.hasNext()){
iteration++;
Expand All @@ -159,8 +157,8 @@ public SearchResult search(Predicate<N> condition){
}

}
w.stop();
return new SearchResult(currentNode, iteration, w);
long end = System.currentTimeMillis();
return new SearchResult(currentNode, iteration, end - begin);
}

/**
Expand Down Expand Up @@ -202,7 +200,6 @@ public static <S, N extends Node<?,S,N>> List<S> recoverStatePath(N node){
for(N n : node.path()){
states.add(n.state());
}
Collections.reverse(states);
return states;
}

Expand Down

0 comments on commit 628438b

Please sign in to comment.