Search in sources :

Example 1 with MapWayFilter

use of aimax.osm.data.MapWayFilter in project aima-java by aimacode.

the class RouteCalculator method calculateRoute.

/**
	 * Template method, responsible for shortest path generation between two map
	 * nodes. It searches for way nodes in the vicinity of the given nodes which
	 * comply with the specified way selection, searches for a suitable paths,
	 * and adds the paths as tracks to the provided <code>map</code>. Various
	 * factory methods can be used to override aspects of the default behavior
	 * in subclasses if needed.
	 * 
	 * @param markers
	 *            Nodes, not necessarily way nodes. The first node is used as
	 *            start, last node as finish, all others as via nodes.
	 * @param map
	 *            The information source.
	 * @param taskSelection
	 *            Number, indicating which kinds of ways are relevant.
	 */
public List<Position> calculateRoute(List<MapNode> markers, OsmMap map, int taskSelection) {
    List<Position> result = new ArrayList<>();
    try {
        MapWayFilter wayFilter = createMapWayFilter(map, taskSelection);
        boolean ignoreOneways = (taskSelection == 0);
        List<MapNode[]> pNodeList = subdivideProblem(markers, map, wayFilter);
        MapNode prevNode = null;
        for (int i = 0; i < pNodeList.size() && !CancelableThread.currIsCanceled(); i++) {
            Problem<MapNode, OsmMoveAction> problem = createProblem(pNodeList.get(i), map, wayFilter, ignoreOneways, taskSelection);
            ToDoubleFunction<Node<MapNode, OsmMoveAction>> h = createHeuristicFunction(pNodeList.get(i), taskSelection);
            SearchForActions<MapNode, OsmMoveAction> search = createSearch(h, taskSelection);
            List<OsmMoveAction> actions = search.findActions(problem);
            if (actions.isEmpty())
                break;
            for (Object action : actions) {
                if (action instanceof OsmMoveAction) {
                    OsmMoveAction a = (OsmMoveAction) action;
                    for (MapNode node : a.getNodes()) {
                        if (prevNode != node) {
                            result.add(new Position(node.getLat(), node.getLon()));
                            prevNode = node;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : MapWayFilter(aimax.osm.data.MapWayFilter) Position(aimax.osm.data.Position) Node(aima.core.search.framework.Node) MapNode(aimax.osm.data.entities.MapNode) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

Aggregations

Node (aima.core.search.framework.Node)1 MapWayFilter (aimax.osm.data.MapWayFilter)1 Position (aimax.osm.data.Position)1 MapNode (aimax.osm.data.entities.MapNode)1 ArrayList (java.util.ArrayList)1