Search in sources :

Example 1 with ShortestWeighting

use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.

the class InstructionListTest method testEmptyList.

@Test
public void testEmptyList() {
    Graph g = new GraphBuilder(carManager).create();
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 1);
    InstructionList il = p.calcInstructions(usTR);
    assertEquals(0, il.size());
    assertEquals(0, il.createStartPoints().size());
}
Also used : Path(com.graphhopper.routing.Path) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Dijkstra(com.graphhopper.routing.Dijkstra) Test(org.junit.Test)

Example 2 with ShortestWeighting

use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.

the class RoutingAlgorithmWithOSMIT method testMonacoParallel.

@Test
public void testMonacoParallel() throws IOException {
    System.out.println("testMonacoParallel takes a bit time...");
    String graphFile = "target/monaco-gh";
    Helper.removeDir(new File(graphFile));
    final EncodingManager encodingManager = new EncodingManager("car");
    final GraphHopper hopper = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(encodingManager).setCHEnabled(false).setWayPointMaxDistance(0).setDataReaderFile(DIR + "/monaco.osm.gz").setGraphHopperLocation(graphFile).importOrLoad();
    final Graph g = hopper.getGraphHopperStorage();
    final LocationIndex idx = hopper.getLocationIndex();
    final List<OneRun> instances = createMonacoCar();
    List<Thread> threads = new ArrayList<Thread>();
    final AtomicInteger integ = new AtomicInteger(0);
    int MAX = 100;
    final FlagEncoder carEncoder = encodingManager.getEncoder("car");
    // testing if algorithms are independent. should be. so test only two algorithms. 
    // also the preparing is too costly to be called for every thread
    int algosLength = 2;
    final Weighting weighting = new ShortestWeighting(encodingManager.getEncoder("car"));
    final EdgeFilter filter = new DefaultEdgeFilter(carEncoder);
    for (int no = 0; no < MAX; no++) {
        for (int instanceNo = 0; instanceNo < instances.size(); instanceNo++) {
            String[] algos = new String[] { ASTAR, DIJKSTRA_BI };
            for (final String algoStr : algos) {
                // an algorithm is not thread safe! reuse via clear() is ONLY appropriated if used from same thread!
                final int instanceIndex = instanceNo;
                Thread t = new Thread() {

                    @Override
                    public void run() {
                        OneRun oneRun = instances.get(instanceIndex);
                        AlgorithmOptions opts = AlgorithmOptions.start().weighting(weighting).algorithm(algoStr).build();
                        testCollector.assertDistance(new AlgoHelperEntry(g, opts, idx, algoStr + "|" + weighting), oneRun.getList(idx, filter), oneRun);
                        integ.addAndGet(1);
                    }
                };
                t.start();
                threads.add(t);
            }
        }
    }
    for (Thread t : threads) {
        try {
            t.join();
        } catch (InterruptedException ex) {
            throw new RuntimeException(ex);
        }
    }
    assertEquals(MAX * algosLength * instances.size(), integ.get());
    assertEquals(testCollector.toString(), 0, testCollector.errors.size());
    hopper.close();
}
Also used : AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) ArrayList(java.util.ArrayList) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) OneRun(com.graphhopper.routing.util.TestAlgoCollector.OneRun) GraphHopper(com.graphhopper.GraphHopper) LocationIndex(com.graphhopper.storage.index.LocationIndex) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Graph(com.graphhopper.storage.Graph) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Test(org.junit.Test)

Example 3 with ShortestWeighting

use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.

the class DijkstraBidirectionCHTest method testPathRecursiveUnpacking.

@Test
public void testPathRecursiveUnpacking() {
    // use an encoder where it is possible to store 2 weights per edge        
    FlagEncoder encoder = new Bike2WeightFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    GraphHopperStorage ghStorage = createGHStorage(em, Arrays.asList(weighting), false);
    CHGraphImpl g2 = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting);
    g2.edge(0, 1, 1, true);
    EdgeIteratorState iter1_1 = g2.edge(0, 2, 1.4, false);
    EdgeIteratorState iter1_2 = g2.edge(2, 5, 1.4, false);
    g2.edge(1, 2, 1, true);
    g2.edge(1, 3, 3, true);
    g2.edge(2, 3, 1, true);
    g2.edge(4, 3, 1, true);
    g2.edge(2, 5, 1.4, true);
    g2.edge(3, 5, 1, true);
    g2.edge(5, 6, 1, true);
    g2.edge(4, 6, 1, true);
    g2.edge(6, 7, 1, true);
    EdgeIteratorState iter2_2 = g2.edge(5, 7);
    iter2_2.setDistance(1.4).setFlags(encoder.setProperties(10, true, false));
    ghStorage.freeze();
    // simulate preparation
    CHEdgeIteratorState iter2_1 = g2.shortcut(0, 5);
    iter2_1.setDistance(2.8).setFlags(encoder.setProperties(10, true, false));
    iter2_1.setSkippedEdges(iter1_1.getEdge(), iter1_2.getEdge());
    CHEdgeIteratorState tmp = g2.shortcut(0, 7);
    tmp.setDistance(4.2).setFlags(encoder.setProperties(10, true, false));
    tmp.setSkippedEdges(iter2_1.getEdge(), iter2_2.getEdge());
    g2.setLevel(1, 0);
    g2.setLevel(3, 1);
    g2.setLevel(4, 2);
    g2.setLevel(6, 3);
    g2.setLevel(2, 4);
    g2.setLevel(5, 5);
    g2.setLevel(7, 6);
    g2.setLevel(0, 7);
    AlgorithmOptions opts = new AlgorithmOptions(Parameters.Algorithms.DIJKSTRA_BI, weighting);
    Path p = new PrepareContractionHierarchies(new GHDirectory("", DAType.RAM_INT), ghStorage, g2, weighting, TraversalMode.NODE_BASED).createAlgo(g2, opts).calcPath(0, 7);
    assertEquals(Helper.createTList(0, 2, 5, 7), p.calcNodes());
    assertEquals(1064, p.getTime());
    assertEquals(4.2, p.getDistance(), 1e-5);
}
Also used : ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) Test(org.junit.Test)

Example 4 with ShortestWeighting

use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.

the class PrepareContractionHierarchiesTest method testMultiplePreparationsIdenticalView.

@Test
public void testMultiplePreparationsIdenticalView() {
    CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
    BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
    EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
    // FastestWeighting would lead to different shortcuts due to different default speeds for bike and car
    Weighting carWeighting = new ShortestWeighting(tmpCarEncoder);
    Weighting bikeWeighting = new ShortestWeighting(tmpBikeEncoder);
    List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
    GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
    initShortcutsGraph(ghStorage);
    ghStorage.freeze();
    for (Weighting w : chWeightings) {
        checkPath(ghStorage, w, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Example 5 with ShortestWeighting

use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.

the class PathTest method testCalcInstructionsRoundabout.

/**
     * Test roundabout instructions for different profiles
     */
@Test
public void testCalcInstructionsRoundabout() {
    for (FlagEncoder encoder : mixedEncoders.fetchEdgeEncoders()) {
        Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 8);
        assertTrue(p.isFound());
        InstructionList wayList = p.calcInstructions(tr);
        // Test instructions
        List<String> tmpList = pick("text", wayList.createJson());
        assertEquals(Arrays.asList("Continue onto MainStreet 1 2", "At roundabout, take exit 3 onto 5-8", "Finish!"), tmpList);
        // Test Radian
        double delta = roundaboutGraph.getAngle(1, 2, 5, 8);
        RoundaboutInstruction instr = (RoundaboutInstruction) wayList.get(1);
        assertEquals(delta, instr.getTurnAngle(), 0.01);
        // case of continuing a street through a roundabout
        p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 7);
        wayList = p.calcInstructions(tr);
        tmpList = pick("text", wayList.createJson());
        assertEquals(Arrays.asList("Continue onto MainStreet 1 2", "At roundabout, take exit 2 onto MainStreet 4 7", "Finish!"), tmpList);
        // Test Radian
        delta = roundaboutGraph.getAngle(1, 2, 4, 7);
        instr = (RoundaboutInstruction) wayList.get(1);
        assertEquals(delta, instr.getTurnAngle(), 0.01);
    }
}
Also used : ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Aggregations

ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)14 Test (org.junit.Test)13 Graph (com.graphhopper.storage.Graph)8 Dijkstra (com.graphhopper.routing.Dijkstra)6 Path (com.graphhopper.routing.Path)6 GraphBuilder (com.graphhopper.storage.GraphBuilder)6 NodeAccess (com.graphhopper.storage.NodeAccess)5 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)1 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)1 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 RAMDirectory (com.graphhopper.storage.RAMDirectory)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1