Skip to content

Instantly share code, notes, and snippets.

View pablormier's full-sized avatar

Pablo R. Mier pablormier

View GitHub Profile
@pablormier
pablormier / Parallel.java
Created December 17, 2013 12:08
This class contains some useful classes and methods to parallelize code in an easy and fluent way. Parallel class is self-contained to enable an easier integration and reuse in different java projects.
/**
* The MIT License
*
* Copyright (c) 2013 Pablo R. Mier <pablo.rodriguez.mier@usc.es>.
* Centro de Investigación en Tecnoloxías da Información (CITIUS) http://citius.usc.es
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
@pablormier
pablormier / shortest-path-graph-hipster.java
Last active August 29, 2015 13:58
Shortest path in a directed weighted graph with Hipster
// Create a simple weighted directed graph with Hipster where
// vertices are Strings and edge values are just doubles
HipsterDirectedGraph<String,Double> graph = GraphBuilder.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)
@pablormier
pablormier / maven-hipster-0.0.1-SNAPSHOT.xml
Last active August 29, 2015 14:00
maven-hipster-0.0.1-SNAPSHOT
<!-- Use sonatype oss public for snapshots -->
<repositories>
<repository>
<id>sonatype-oss-public</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
// Builder example with Hipster
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(initialState)
.defineProblemWithExplicitActions()
.useActionFunction(af)
.useTransitionFunction(atf)
.useCostFunction(cf)
.useHeuristicFunction(hf)
.build();
enum Action { UP, DOWN, LEFT, RIGHT }
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(Arrays.asList(5,4,0,7,2,6,8,1,3))
.defineProblemWithExplicitActions()
.useActionFunction(new ActionFunction<Action, List<Integer>>() {
public Iterable<Action> actionsFor(List<Integer> board) {
return validMovements(board);
}
enum Action { UP, DOWN, LEFT, RIGHT }
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(Arrays.asList(5,4,0,7,2,6,8,1,3))
.defineProblemWithExplicitActions()
.useActionFunction( (state) -> return validMovementsFor(state) )
.useTransitionFunction( (action, state) -> applyActionToState(action, state) )
.useCostFunction( (transition) -> return 1d )
.build();
@pablormier
pablormier / HipsterEightPuzzleExample.java
Last active August 29, 2015 14:02
Solving the 8-Puzzle problem with Hipster
/*
* Copyright 2014 CITIUS <http://citius.usc.es>, University of Santiago de Compostela.
*
* 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
@pablormier
pablormier / hipster-bibtex.bib
Last active August 29, 2015 14:02
Hipster BibTeX citation entry
@inproceedings{RodriguezMier2014,
author = {Rodriguez-Mier, Pablo and Gonzalez-Sieira, Adrian and Mucientes, Manuel and and Lama, Manuel and Bugarin, Alberto},
booktitle = {9th Iberian Conference on Information Systems and Technologies (CISTI 2014)},
month = jun,
volume = 1,
title = {{Hipster: An Open Source Java Library for Heuristic Search}},
pages = {481--486},
isbn = "978-989-98434-2-4"
address = "Barcelona",
year = {2014}
#!/bin/sh
cd /tmp
wget https://oss.sonatype.org/service/local/repositories/releases/content/es/usc/citius/hipster/hipster-all/1.0.0-rc2/hipster-all-1.0.0-rc2.jar
java -cp hipster-all-1.0.0-rc2.jar es.usc.citius.hipster.examples.ASCIIMazeVisualizer
@pablormier
pablormier / multiobjective-graph.graphml
Last active August 29, 2015 14:05
Multiobjective Graph
<?xml version='1.0' encoding='UTF-8'?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="c1" for="edge" attr.name="c1" attr.type="int" />
<key id="c2" for="edge" attr.name="c2" attr.type="int" />
<graph id="G" edgedefault="directed">
<node id="v1" />
<node id="v5" />
<node id="v6" />
<node id="v4" />
<node id="v3" />