Skip to content

Commit

Permalink
Merge branch 'v.0.0.1-release'
Browse files Browse the repository at this point in the history
Conflicts:
	pom.xml
  • Loading branch information
pablo.rodriguez.mier committed May 8, 2014
2 parents d714a1b + 57b8733 commit 4489555
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 148 deletions.
13 changes: 13 additions & 0 deletions .config/deploy-artifacts.sh
@@ -0,0 +1,13 @@
#!/bin/bash

echo "Auto-deploying artifacts..."
echo "Current branch: $TRAVIS_BRANCH"

if [ "$TRAVIS_REPO_SLUG" == "citiususc/hipster" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk7" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
echo "Running mvn deploy..."
mvn deploy --settings .config/maven-settings.xml -DskipTests=true
else
echo "Skipping deployment for this build..."
fi

echo "Deployment script finished."
27 changes: 27 additions & 0 deletions .config/maven-settings.xml
@@ -0,0 +1,27 @@
<!--
~ Copyright 2014 Centro de Investigación en Tecnoloxías da Información (CITIUS),
~ University of Santiago de Compostela (USC) http://citius.usc.es.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>citius-nexus-snapshots</id>
<username>${env.NEXUS_SNAPSHOT_USERNAME}</username>
<password>${env.NEXUS_SNAPSHOT_PASSWORD}</password>
</server>
</servers>
</settings>

40 changes: 31 additions & 9 deletions README.md
Expand Up @@ -32,29 +32,26 @@ The current version of the library comes with some very well-known and wide used
If you don't find the algorithm or the feature you are looking for, please consider contributing to Hipster!. You can open a new issue or better fork this repository and create a pull request with your contribution. If you go for this second option, please follow the contribution guidelines.

## Getting started
TODO;

## Usage

The easiest way to use Hipster is adding it as a dependency with your favourite dependency manager.
Maven users can include the library using the following snippet:

#### Snapshots

````xml
<distributionManagement>
<snapshotRepository>
<repositories>
<repository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<name>CITIUS Snapshots</name>
<url>http://tec.citius.usc.es/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</repository>
</repositories>

<dependencies>
...
<dependency>
<groupId>es.usc.citius.lab</groupId>
<artifactId>hipster</artifactId>
<artifactId>hipster-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Expand All @@ -64,6 +61,31 @@ Maven users can include the library using the following snippet:

TODO;

#### Quick Example

Here is a quick example of how to search a shortest path in a graph with Dijkstra's algorithm:

```java
// Create a simple weighted directed graph with Hipster
HipsterDirectedGraph<String,Double> graph =
GraphBuilder.<String,Double>newDirectedGraph()
.from("A").to("B").withEdge(4d)
.from("A").to("C").withEdge(2d)
.from("B").to("C").withEdge(5d)
.from("B").to("D").withEdge(10d)
.from("C").to("E").withEdge(3d)
.from("D").to("F").withEdge(11d)
.from("E").to("D").withEdge(4d);

// Search the shortest path with Dijkstra's algorithm and print the result
System.out.println(Hipster.createDijkstra(GraphSearchProblem.from("A").to("F").in(graph)).search());
```
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, N-Queens problem, etc.

## 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/pablormier/hipster/wiki/Solving-problems-with-Hipster) and the JavaDoc documentation. There are also a few implemented examples here.

## License

This software is licensed under the Apache 2 license, quoted below.
Expand Down
2 changes: 1 addition & 1 deletion hipster-all/pom.xml
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>hipster</artifactId>
<groupId>es.usc.citius.lab</groupId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hipster-all</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion hipster-core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hipster</artifactId>
<groupId>es.usc.citius.lab</groupId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hipster-core</artifactId>
Expand Down
Expand Up @@ -93,15 +93,15 @@ public boolean updateConsistent(ADStarNode<S, T> node,
ADStarNode<S, T> parent, Transition<S> transition) {
T accumulatedCost = this.add.apply(parent.getG(),
this.costFunction.evaluate(transition)); // parent.getG().add(this.costFunction.evaluate(transition));
if (node.g.compareTo(accumulatedCost) > 0) {
if (node.getG().compareTo(accumulatedCost) > 0) {
node.setPreviousNode(parent);
// node.previousNode = parent;
node.g = accumulatedCost;
node.setG(accumulatedCost);
node.setState(transition);
// node.state = transition;
node.key = new ADStarNode.Key<T>(node.g, node.v,
node.setKey(new ADStarNode.Key<T>(node.getG(), node.getV(),
this.heuristicFunction.estimate(transition.to()),
this.epsilon, this.add, this.scale);
this.epsilon, this.add, this.scale));
return true;
}
return false;
Expand All @@ -122,7 +122,7 @@ public boolean updateInconsistent(ADStarNode<S, T> node,
Transition<S> minTransition = null;
for (Entry<Transition<S>, ADStarNode<S, T>> current : predecessorMap
.entrySet()) {
T value = this.add.apply(current.getValue().v, this.costFunction.evaluate(current.getKey()));
T value = this.add.apply(current.getValue().getV(), this.costFunction.evaluate(current.getKey()));
//T value = current.getValue().v.add(this.costFunction.evaluate(current.getKey()));
if (value.compareTo(minValue) < 0) {
minValue = value;
Expand All @@ -132,12 +132,12 @@ public boolean updateInconsistent(ADStarNode<S, T> node,
}
node.setPreviousNode(minParent);
// node.previousNode = minParent;
node.g = minValue;
node.setG(minValue);
node.setState(minTransition);
// node.state = minTransition;
node.key = new ADStarNode.Key<T>(node.g, node.v,
node.setKey(new ADStarNode.Key<T>(node.getG(), node.getV(),
this.heuristicFunction.estimate(minTransition.to()),
this.epsilon, this.add, this.scale);
this.epsilon, this.add, this.scale));
return true;
}

Expand Down
Expand Up @@ -16,87 +16,34 @@

package es.usc.citius.lab.hipster.algorithm;

import es.usc.citius.lab.hipster.algorithm.problem.HeuristicSearchProblem;
import es.usc.citius.lab.hipster.node.HeuristicNode;
import es.usc.citius.lab.hipster.node.Node;
import es.usc.citius.lab.hipster.util.map.MapBasedGraphSearchProblem;
import es.usc.citius.lab.hipster.util.map.MapBasedRomaniaProblem;
import org.junit.Before;
import org.junit.Test;

import java.util.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

/**
* Executes tests over predefined maze strings, comparing the results between
* Jung and AD* iterator.
* Concrete implementation of the test case suite for the A* algorithm based in the Romania problem.
* This test suite extends from {@link es.usc.citius.lab.hipster.algorithm.RomaniaProblemOptimalSearchTest}
* and adds the wollowing test cases:
* <ul>
* <li>Order and number of expansions performed by A*.</li>
* </ul>
*
* @author Adrián González Sieira <adrian.gonzalez@usc.es>
* @author Pablo Rodríguez Mier <pablo.rodriguez.mier@usc.es>
* @version 1.0
* @since 26/03/2013
* @since 0.1.0
*/
public class AStarRomaniaProblemTest {

private HeuristicSearchProblem<MapBasedRomaniaProblem.City, Double> problem;
private Iterator<HeuristicNode<MapBasedRomaniaProblem.City, Double>> astarIterator;
public class AStarRomaniaProblemTest extends RomaniaProblemOptimalSearchTest {

/**
* Constructor of the AStar test. The Romania problem is instantiated before all tests.
* Default constructor for this test suite that calls the parent constructor.
*/
public AStarRomaniaProblemTest() {
//obtain instance of Romanian problem
problem = new MapBasedGraphSearchProblem<MapBasedRomaniaProblem.City>(
MapBasedRomaniaProblem.City.Arad,
MapBasedRomaniaProblem.City.Bucharest,
MapBasedRomaniaProblem.transitions(),
MapBasedRomaniaProblem.costs(),
MapBasedRomaniaProblem.heuristics()
);
}

/**
* Instantiates the AStar iterator before each test.
*/
@Before
public void createAStarIterator(){
this.astarIterator = Algorithms.createAStar(problem).iterator();
}

/**
* Check the returned path of the algorithm to be the optimal for the problem definition.
*/
@Test
public void optimalPathFromAradToBucharest() {
HeuristicNode<MapBasedRomaniaProblem.City, Double> node;
//search optimal path
do{
//
node = astarIterator.next();
}while(astarIterator.hasNext() && !node.transition().to().equals(MapBasedRomaniaProblem.City.Bucharest));
//list of cities in the optimal path
List<MapBasedRomaniaProblem.City> optimalPath =
Arrays.asList(
MapBasedRomaniaProblem.City.Arad,
MapBasedRomaniaProblem.City.Sibiu,
MapBasedRomaniaProblem.City.Rimnicu_Vilcea,
MapBasedRomaniaProblem.City.Pitesti,
MapBasedRomaniaProblem.City.Bucharest
);
//path returned by A*
List<Node<MapBasedRomaniaProblem.City>> path = node.path();
//check elements returned by the search algorithm
for(int i = 0; i < path.size(); i++){
//check if current element of the path is equals to the
assertEquals(
"Failed checking element " + i + " of the path. Expected: " +
optimalPath.get(i) + ", found: " + path.get(i).transition().to(),
path.get(i).transition().to(),
optimalPath.get(i)
);
}
super();
}

/**
Expand All @@ -116,7 +63,7 @@ public void expansionsFromAradToBucharest() {
);
//compare expanded cities with expected ones
for(int i = 0; i < expansionsPerformed.size(); i++){
HeuristicNode<MapBasedRomaniaProblem.City, Double> current = astarIterator.next();
HeuristicNode<MapBasedRomaniaProblem.City, Double> current = searchIterator.next();
assertEquals(
"Failed checking expanded element no. " + (i + 1) + ". Expected: " +
expansionsPerformed.get(i) + ", found: " + current.transition().to(),
Expand All @@ -127,54 +74,12 @@ public void expansionsFromAradToBucharest() {
}

/**
* Check the costs of the elements expanded by the algorithm.
*/
public void costsFromAradToBucharest() {
//list of costs of the nodes expanded by A* during the search
List<Double> costsNodesExpanded =
Arrays.asList(
0d,
140d,
220d,
239d,
317d,
418d
);
//compare expected scores with
for(int i = 0; i < costsNodesExpanded.size(); i++){
HeuristicNode<MapBasedRomaniaProblem.City, Double> current = astarIterator.next();
assertEquals(
"Failed checking cost of expanded element no. " + (i + 1) + ". Expected: " +
costsNodesExpanded.get(i) + ", found: " + current.getCost(),
current.getCost(),
costsNodesExpanded.get(i)
);
}
}

/**
* Check the scores of the elements expanded by the algorithm.
* Instantiates the A* search iterator.
*
* @return search iterator according to the problem definition
*/
public void scoresFromAradToBucharest() {
//list of scores of the nodes expanded by A* during the search
List<Double> scoreNodesExpanded =
Arrays.asList(
366d,
393d,
413d,
415d,
417d,
418d
);
//compare expected scores with
for(int i = 0; i < scoreNodesExpanded.size(); i++){
HeuristicNode<MapBasedRomaniaProblem.City, Double> current = astarIterator.next();
assertEquals(
"Failed checking score of expanded element no. " + (i + 1) + ". Expected: " +
scoreNodesExpanded.get(i) + ", found: " + current.getScore(),
current.getScore(),
scoreNodesExpanded.get(i)
);
}
@Override
public Iterator<HeuristicNode<MapBasedRomaniaProblem.City, Double>> createIterator() {
return Algorithms.createAStar(problem).iterator();
}
}

0 comments on commit 4489555

Please sign in to comment.