Søk på google: Berits Smykker, der kommer den som nr. 1 eller 2, eller gå rett inn på Berits Smykker.
Flott, ikke sant!
class DijkstrasShortestPathAlgoritm {
def graph, start, destination
// PriorityQueue performs much better than List - O(log(n)) for poll.
def unsettledNodes = new PriorityQueue<String>(100, new Comparator<String>() {
public int compare(String node1, String node2) {
shortestDistance(node1).compareTo(shortestDistance(node2))
}
});
def shortestDistances = [:]
def predecessors = [:]
def settledNodes = [] as Set
DijkstrasShortestPathAlgoritm(graph, start, destination) {
this.graph = graph
this.start = start
this.destination = destination
unsettledNodes.add(start)
shortestDistances[(start)] = 0
}
int shortestDistance(node) {
shortestDistances.containsKey(node) ? shortestDistances[node] : Integer.MAX_VALUE
}
def extractMin() {
unsettledNodes.poll()
}
def unsettledNeighbours(node) {
graph.findAll { edge ->
edge.node1 == node && !settledNodes.contains(edge.node2)
}
}
def relaxNeighbours(node) {
unsettledNeighbours(node).each { edge ->
if (shortestDistance(edge.node2) > shortestDistance(edge.node1) + edge.distance) {
shortestDistances[edge.node2] = shortestDistance(edge.node1) + edge.distance
predecessors[edge.node2] = edge.node1
if (!unsettledNodes.contains(edge.node2)) {
unsettledNodes.add(edge.node2)
}
}
}
}
def calculateShortestPath() {
while (!unsettledNodes.isEmpty()) {
String node = extractMin()
if (node == destination) {
break
}
settledNodes += node
relaxNeighbours(node)
}
shortestDistances[destination]
}
private def getShortestPath(node, path) {
node == start ? [node]+path : getShortestPath(predecessors[node], [node]+path)
}
def getShortestPath() {
getShortestPath(destination, [])
}
}
class Edge {
String node1, node2
int distance
}
graph = [
new Edge(node1:'a', node2:'b', distance:4),
new Edge(node1:'a', node2:'c', distance:2),
new Edge(node1:'b', node2:'c', distance:3),
new Edge(node1:'c', node2:'b', distance:1),
new Edge(node1:'c', node2:'d', distance:5),
new Edge(node1:'b', node2:'d', distance:1),
new Edge(node1:'a', node2:'e', distance:1),
new Edge(node1:'e', node2:'d', distance:4)
]
def dijkstra = new DijkstrasShortestPathAlgoritm(graph, 'a', 'd')
d = dijkstra.calculateShortestPath();
assert d == 4
assert dijkstra.shortestPath == ['a','c','b','d']
#!/bin/bash # # Run grails tests continously. # # Author trygve.amundsen@gmail.com # logfile=.grailsAutoTest.log last_filestatus="" imagesDir=`dirname $0`/images curdir=`pwd` project=`basename $curdir` echo "Starting autotest for $project" while true; do current_filestatus=`ls -lR grails-app lib scripts src test web-app/js web-app/css \ *GrailsPlugin.groovy | md5` if [ "$current_filestatus" != "$last_filestatus" ] then last_filestatus=$current_filestatus echo -n "Running tests..." grails test-app > $logfile tail -3 $logfile | grep -q 'Tests PASSED' if [ $? -eq 0 ] then echo "Tests PASSED - waiting for changes..." growlnotify -m "Grails AutoTests succeeded" -t "Test $project" \ -d "$project" --image $imagesDir/succeed.jpg else last_filestatus="failed" tail -3 $logfile | head -1 growlnotify -s -m "Grails AutoTests failed" -t "Test $project" \ -d "$project" --image $imagesDir/fail-icon.png fi fi sleep 2 done