View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.agent.navigation.astar;
2   
3   import cz.cuni.amis.pathfinding.alg.astar.AStar;
4   import cz.cuni.amis.pathfinding.alg.astar.AStarResult;
5   import cz.cuni.amis.pathfinding.map.IPFMapView;
6   import cz.cuni.amis.pathfinding.map.IPFMapView.DefaultView;
7   import cz.cuni.amis.pogamut.base.agent.navigation.IPathFuture;
8   import cz.cuni.amis.pogamut.base.agent.navigation.IPathPlanner;
9   import cz.cuni.amis.pogamut.base.agent.navigation.impl.PrecomputedPathFuture;
10  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavigationGraphBuilder;
11  import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathAutoFixer;
12  import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
14  import cz.cuni.amis.utils.collections.MyCollections;
15  
16  public class UT2004AStar extends AStar<NavPoint> implements IPathPlanner<NavPoint>  {
17  
18  	/**
19  	 * AStar configured with {@link UT2004PFMap} with no agent-specific view on the map, {@link DefaultView} is used. 
20  	 * @param map
21  	 */
22  	public UT2004AStar(UT2004Bot bot) {
23  		this(new UT2004PFMap(bot.getWorldView()));
24  	}
25  	
26  	/**
27  	 * AStar configured with {@link UT2004PFMap} with no agent-specific view on the map, {@link DefaultView} is used. 
28  	 * @param map
29  	 */
30  	public UT2004AStar(UT2004Bot bot, IPFMapView<NavPoint> view) {
31  		this(new UT2004PFMap(bot.getWorldView()), view);
32  	}
33  	
34  	/**
35  	 * AStar configured with "map" with no agent-specific view on the map, {@link DefaultView} is used. 
36  	 * @param map
37  	 */
38  	public UT2004AStar(UT2004PFMap map) {
39  		this(map, new IPFMapView.DefaultView());
40  	}
41  	
42  	/**
43  	 * AStar configured with "map" and agent-specific view on the map, if "view" is null, {@link DefaultView} is going to be used. 
44  	 * @param map
45  	 * @param view may be null
46  	 */
47  	public UT2004AStar(UT2004PFMap map, IPFMapView<NavPoint> view) {
48  		super(map, view);
49  	}	
50  	
51  	@Override
52  	public UT2004PFMap getMap() {
53  		return (UT2004PFMap) super.getMap();
54  	}
55  	
56  	/**
57  	 * Uses {@link UT2004PFGoal} to define START-NODE (from) and TARGET-NODE (to) for the A-Star, using
58  	 * standard 3D-Euclidian heuristic and customized 'mapView'.
59  	 * @param from
60  	 * @param to
61  	 * @return
62  	 */
63  	public synchronized AStarResult<NavPoint> findPath(NavPoint from, NavPoint to, IPFMapView<NavPoint> mapView) {		
64  		return findPath(new UT2004PFGoal(from, to), mapView);
65  	}
66  	
67  	/**
68  	 * Using {@link #findPath(NavPoint, NavPoint)} to implement {@link IPathPlanner#computePath(Object, Object)} interface.
69  	 */
70  	@Override
71  	public IPathFuture<NavPoint> computePath(NavPoint from, NavPoint to) {
72  		if (from == null || to == null) return new PrecomputedPathFuture<NavPoint>(from, to, null);
73  		if (from == to) return new PrecomputedPathFuture<NavPoint>(from, to, MyCollections.toList(from));
74  		AStarResult<NavPoint> result = findPath(from, to);
75  		if (result == null) return new PrecomputedPathFuture<NavPoint>(from, to, null);
76  		return new PrecomputedPathFuture<NavPoint>(from, to, result.getPath());		
77  	}
78  	
79  	/**
80  	 * Uses {@link UT2004PFGoal} to define START-NODE (from) and TARGET-NODE (to) for the A-Star, using
81  	 * standard 3D-Euclidian heuristic.
82  	 * @param from
83  	 * @param to
84  	 * @return
85  	 */
86  	public synchronized AStarResult<NavPoint> findPath(NavPoint from, NavPoint to) {		
87  		return findPath(new UT2004PFGoal(from, to));
88  	}
89  	
90  	/**
91  	 * Call to wipe cached info about the map, e.g., whenever {@link UT2004PathAutoFixer} bans some navpoint or you use {@link NavigationGraphBuilder}, etc.
92  	 */
93  	public void mapChanged() {
94  		getMap().mapChanged();
95  	}
96  
97  }