One written would be great as a guide. I require rather rapid implementation of this.
Thanks
Main Topics
Browse All TopicsAnyone know any resources for implementing the A* search algorithm in Java? I'm also looking for resources that are good at explaining the algorithm in detail.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hey Jon, Sorry I am taking too long to write the code. Also it may not be so useful for you as I am implementing it for the Image Analysis thingy!
Hence, say thanx to Geert-Jan van Opdorp :)
And For the resources:
http://www.experts-exchang
http://www.policyalmanac.o
The Good One:
http://www.geocities.com/j
Java A* Algorithm
=================
// -*- mode: java; folded-file: t -*-
/*
* Author Geert-Jan van Opdorp
*
* Copyright (c) 1995 AI Engineering.
*
*/
package aie.astar;
// {{{ import
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.applet.*;
import java.lang.*;
import java.util.*;
// }}}
// {{{ final class node
final class node {
State state;
int costs;
int distance;
int total;
node parent;
node(State theState, node theParent, int theCosts, int theDistance) {
state = theState;
parent = theParent;
costs = theCosts;
distance = theDistance;
total = theCosts + theDistance;
};
}
// }}}
// {{{ public final class AStar
public final class AStar {
// {{{ Variables
private final Hashtable open = new Hashtable(500);
private final Hashtable closed = new Hashtable(500);
public int evaluated = 0;
public int expanded = 0;
public int bestTotal = 0;
public boolean ready = false;
private boolean newBest = false;
private final Vector nodes = new Vector(); //sorted open node
// }}}
private synchronized void setBest (int value) {
bestTotal = value;
newBest = true;
notify(); // All?
Thread.currentThread().yie
}
public synchronized int getNewBest() {
while(!newBest) {
try {
wait();
} catch (InterruptedException e) {
}
}
newBest = false;
return bestTotal;
}
// {{{ private node search()
private node search() {
node best;
Vector childStates;
int childCosts;
Vector children = new Vector();
while (!(nodes.isEmpty())) {
best = (node) nodes.firstElement();
if(closed.get(best.state) != null) { //to avoid having to remove
nodes.removeElementAt(0); // improved nodes from nodes
continue;
}
if (!(best.total == bestTotal)) {
setBest(best.total);
}
if ((best.state).goalp()) return best;
children.removeAllElements
childStates = (best.state).generateChild
childCosts = 1 + best.costs;
expanded++;
for (int i = 0; i < childStates.size(); i++) {
State childState = (State) childStates.elementAt(i);
node closedNode = null;
node openNode = null;
node theNode = null;
if ((closedNode = (node) closed.get(childState)) == null)
openNode = (node) open.get(childState);
theNode = (openNode != null) ? openNode : closedNode;
if (theNode != null) {
if (childCosts < theNode.costs) {
if (closedNode != null) {
open.put(childState, theNode);
closed.remove(childState);
} else {
int dist = theNode.distance;
theNode = new node(childState, best, childCosts, dist);
open.put(childState, theNode);
//nodes.removeElement(theN
}
theNode.costs = childCosts;
theNode.total = theNode.costs + theNode.distance;
theNode.parent = best;
children.addElement(theNod
}
} else {
int estimation;
node newNode;
estimation = childState.estimate();
newNode = new node(childState, best, childCosts, estimation);
open.put(childState, newNode);
evaluated++;
children.addElement(newNod
}
}
open.remove(best.state);
closed.put(best.state, best);
nodes.removeElementAt(0);
addToNodes(children); // update nodes
}
return null; //no open nodes and no solution
}
// }}}
private int rbsearch(int l, int h, int tot, int costs){
if(l>h) return l; //insert before l
int cur = (l+h)/2;
int ot = ((node) nodes.elementAt(cur)).tota
if((tot < ot) ||
(tot == ot && costs >= ((node) nodes.elementAt(cur)).cost
return rbsearch(l, cur-1, tot, costs);
return rbsearch(cur+1, h, tot, costs);
}
private int bsearch(int l, int h, int tot, int costs){
int lo = l;
int hi = h;
while(lo<=hi) {
int cur = (lo+hi)/2;
int ot = ((node) nodes.elementAt(cur)).tota
if((tot < ot) ||
(tot == ot && costs >= ((node) nodes.elementAt(cur)).cost
hi = cur - 1;
else
lo = cur + 1;
}
return lo; //insert before lo
}
// {{{ private void addToNodes(Vector children)
private void addToNodes(Vector children) {
for (int i = 0; i < children.size(); i++) {
node newNode = (node) children.elementAt(i);
int newTotal = newNode.total;
int newCosts = newNode.costs;
boolean done = false;
int idx = bsearch(0, nodes.size()-1, newTotal, newCosts);
nodes.insertElementAt(newN
// for (int j = 0; j < nodes.size(); j++) {
// int ot = ((node) nodes.elementAt(j)).total;
// if (newTotal < ot) {
// nodes.insertElementAt(newN
// done = true;
// break;
// }
// if (newTotal == ot) {
// if (newNode.costs >= ((node) nodes.elementAt(j)).costs)
// nodes.insertElementAt(newN
// done = true;
// break;
// }}
// }
// if (!done) nodes.addElement(newNode);
}
}
// }}}
// {{{ public final Vector solve (State initialState)
public final Vector solve (State initialState) {
node solution;
node firstNode;
int estimation;
expanded = 0;
evaluated = 1;
estimation = initialState.estimate();
firstNode = new node(initialState, null, 0, estimation);
open.put(initialState, firstNode);
nodes.addElement(firstNode
solution = search();
nodes.removeAllElements();
open.clear();
closed.clear();
ready = true;
setBest(bestTotal);
return getSequence(solution);
}
// }}}
// {{{ private Vector getSequence(node n)
private Vector getSequence(node n) {
Vector result;
if (n == null) {
result = new Vector();
} else {
result = getSequence (n.parent);
result.addElement(n.state)
}
return result;
}
// }}}
}
// }}}
State package
=============
// -*- mode: java; folded-file: t -*-
package aie.astar;
import java.util.Vector;
// {{{ abstract class state
public abstract class State {
public abstract Vector generateChildren();
public abstract boolean goalp();
public abstract int estimate();
}
// }}}
Business Accounts
Answer for Membership
by: vicky_vigiaPosted on 2002-12-18 at 21:55:09ID: 7605838
This might help: thread.jsp ?thread=31 7568&forum =31& messag e=1279328
http://forum.java.sun.com/
ELSE
Give me some time to write one (If you require)