View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.agent.navigation.astar;
2   
3   import java.util.Collection;
4   
5   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
6   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
7   import cz.cuni.amis.utils.astar.AStarGoal;
8   
9   public abstract class UT2004AStarGoal implements AStarGoal<NavPoint> {
10  
11  	protected Collection<NavPoint> closeList;
12  	
13  	protected Collection<NavPoint> openList;
14  	
15  	@Override
16  	public void setCloseList(Collection<NavPoint> closeList) {
17  		this.closeList = closeList;
18  	}
19  
20  	@Override
21  	public void setOpenList(Collection<NavPoint> openList) {
22  		this.openList = openList;
23  	}
24  
25  	public Collection<NavPoint> getCloseList() {
26  		return closeList;
27  	}
28  
29  	public Collection<NavPoint> getOpenList() {
30  		return openList;
31  	}
32  
33  	/**
34  	 * Method defining extra-edge cost, see {@link AStarGoal#getExtraCost(Object, Object)}. You probably won't need to use that, thus
35  	 * it is not abstract.
36  	 * <p><p>
37  	 * Returns: always 0
38  	 */
39  	@Override
40  	public int getExtraCost(NavPoint nodeFrom, NavPoint nodeTo) {
41  		return 0;
42  	}
43  
44  	/**
45  	 * Method defining which nodes are allowed to be explored and which are forbidden, see {@link AStarGoal#isNodeOpened(Object)}. You probably
46  	 * won't need to use that, thus it is not abstract.
47  	 * <p><p>
48  	 * Returns: always 0
49  	 */
50  	@Override
51  	public boolean isNodeOpened(NavPoint node) {
52  		return true;
53  	}
54  
55  	/**
56  	 * Method defining "heuristic" for A*, see {@link AStarGoal#getEstimatedDistanceToGoal(Object)}. You will usually want to return
57  	 * Euclidian distance between 'node' and your goal using {@link NavPoint#getLocation()} and {@link Location#getDistance(Location)}.
58  	 * See also {@link UT2004AStarGoalNavPoint}. 
59  	 * 
60  	 * @param node
61  	 */
62  	@Override
63  	public abstract int getEstimatedDistanceToGoal(NavPoint node);
64  	
65  	/**
66  	 * This tests whether 'actualNode' matches your desired 'goalNode'. You will usually use "==" to do that as every NavPoint
67  	 * is "sort-of" singleton for single agent (note that every agent has different one, so you might want to equals their ids via  {@link NavPoint#getId()}).
68  	 * 
69  	 * @param actualNode
70  	 */
71  	@Override
72  	public abstract boolean isGoalReached(NavPoint actualNode);
73  	
74  }