Search in sources :

Example 21 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class EdgeBasedRoutingAlgorithmTest method testBlockANode.

@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testBlockANode(String algoStr) {
    GraphHopperStorage g = createStorage(createEncodingManager(true));
    initGraph(g, carEncoder);
    blockNode3(g);
    for (int i = 0; i <= 7; i++) {
        if (i == 3)
            continue;
        for (int j = 0; j <= 7; j++) {
            if (j == 3)
                continue;
            Path p = calcPath(g, i, j, algoStr);
            // We can go from everywhere to everywhere else without using node 3
            assertTrue(p.isFound());
            for (IntCursor node : p.calcNodes()) {
                assertNotEquals(3, node.value, p.calcNodes().toString());
            }
        }
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 22 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class Router method route.

public GHResponse route(GHRequest request) {
    try {
        checkNoLegacyParameters(request);
        checkAtLeastOnePoint(request);
        checkIfPointsAreInBounds(request.getPoints());
        checkHeadings(request);
        checkPointHints(request);
        checkCurbsides(request);
        checkNoBlockAreaWithCustomModel(request);
        Solver solver = createSolver(request);
        solver.checkRequest();
        solver.init();
        if (ROUND_TRIP.equalsIgnoreCase(request.getAlgorithm())) {
            if (!(solver instanceof FlexSolver))
                throw new IllegalArgumentException("algorithm=round_trip only works with a flexible algorithm");
            return routeRoundTrip(request, (FlexSolver) solver);
        } else if (ALT_ROUTE.equalsIgnoreCase(request.getAlgorithm())) {
            return routeAlt(request, solver);
        } else {
            return routeVia(request, solver);
        }
    } catch (MultiplePointsNotFoundException ex) {
        GHResponse ghRsp = new GHResponse();
        for (IntCursor p : ex.getPointsNotFound()) {
            ghRsp.addError(new PointNotFoundException("Cannot find point " + p.value + ": " + request.getPoints().get(p.value), p.value));
        }
        return ghRsp;
    } catch (IllegalArgumentException ex) {
        GHResponse ghRsp = new GHResponse();
        ghRsp.addError(ex);
        return ghRsp;
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) GHResponse(com.graphhopper.GHResponse)

Example 23 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class FlexiblePathCalculator method calcPaths.

private List<Path> calcPaths(int from, int to, EdgeRestrictions edgeRestrictions, RoutingAlgorithm algo) {
    StopWatch sw = new StopWatch().start();
    // edges directly without changing the graph
    for (IntCursor c : edgeRestrictions.getUnfavoredEdges()) queryGraph.unfavorVirtualEdge(c.value);
    List<Path> paths;
    if (edgeRestrictions.getSourceOutEdge() != ANY_EDGE || edgeRestrictions.getTargetInEdge() != ANY_EDGE) {
        if (!(algo instanceof BidirRoutingAlgorithm))
            throw new IllegalArgumentException("To make use of the " + Parameters.Routing.CURBSIDE + " parameter you need a bidirectional algorithm, got: " + algo.getName());
        paths = Collections.singletonList(((BidirRoutingAlgorithm) algo).calcPath(from, to, edgeRestrictions.getSourceOutEdge(), edgeRestrictions.getTargetInEdge()));
    } else {
        paths = algo.calcPaths(from, to);
    }
    // reset all direction enforcements in queryGraph to avoid influencing next path
    // todo: is this correct? aren't we taking a second look at these edges later when we calc times or
    // instructions etc.?
    queryGraph.clearUnfavoredStatus();
    if (paths.isEmpty())
        throw new IllegalStateException("Path list was empty for " + from + " -> " + to);
    if (algo.getVisitedNodes() >= algoOpts.getMaxVisitedNodes())
        throw new MaximumNodesExceededException("No path found due to maximum nodes exceeded " + algoOpts.getMaxVisitedNodes(), algoOpts.getMaxVisitedNodes());
    visitedNodes = algo.getVisitedNodes();
    debug += ", " + algo.getName() + "-routing:" + sw.stop().getMillis() + " ms";
    return paths;
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) StopWatch(com.graphhopper.util.StopWatch) MaximumNodesExceededException(com.graphhopper.util.exceptions.MaximumNodesExceededException)

Example 24 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class NodeBasedWitnessPathSearcher method reset.

private void reset() {
    for (IntCursor c : changedNodes) weights[c.value] = Double.POSITIVE_INFINITY;
    changedNodes.elementsCount = 0;
    heap.clear();
    ignoreNode = -1;
    settledNodes = 0;
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor)

Example 25 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class EdgeBasedTarjanSCCTest method smallGraphWithLoops.

@Test
public void smallGraphWithLoops() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 3<-0->2-1o
    // o
    // edge-keys 0,1
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 0).setDistance(1));
    // edge-keys 2,3
    GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 2).setDistance(1));
    // edge-keys 4,5
    GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 3).setDistance(1));
    // edge-keys 6,7
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 1).setDistance(1));
    // edge-keys 8,9
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 1).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(10, result.getEdgeKeys());
    assertEquals(6, result.getTotalComponents());
    assertEquals(2, result.getComponents().size());
    assertEquals(result.getComponents().get(0), result.getBiggestComponent());
    assertEquals(IntArrayList.from(7, 9, 8, 6), result.getComponents().get(0));
    assertEquals(IntArrayList.from(1, 0), result.getComponents().get(1));
    assertEquals(4, result.getSingleEdgeComponents().cardinality());
    for (IntCursor c : IntArrayList.from(2, 3, 4, 5)) {
        assertTrue(result.getSingleEdgeComponents().get(c.value));
    }
}
Also used : ConnectedComponents(com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

IntCursor (com.carrotsearch.hppc.cursors.IntCursor)37 Map (java.util.Map)11 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)8 ArrayList (java.util.ArrayList)7 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 HashMap (java.util.HashMap)5 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)5 Index (org.elasticsearch.index.Index)5 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 TreeMap (java.util.TreeMap)4 Metadata (org.elasticsearch.cluster.metadata.Metadata)4 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)3 ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)3 GraphBuilder (com.graphhopper.storage.GraphBuilder)3 ShardCollectorProvider (io.crate.execution.engine.collect.ShardCollectorProvider)3 RelationName (io.crate.metadata.RelationName)3 TransactionContext (io.crate.metadata.TransactionContext)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3