Skip to content

Commit

Permalink
Replace some more usages of GraphHopperStorage constructor with Graph…
Browse files Browse the repository at this point in the history
…Builder
  • Loading branch information
easbar committed Dec 13, 2019
1 parent 394869a commit 0f32226
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 41 deletions.
8 changes: 7 additions & 1 deletion core/src/main/java/com/graphhopper/util/GHUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,13 @@ static Directory guessDirectory(GraphStorage store) {
public static GraphHopperStorage newStorage(GraphHopperStorage store) {
Directory outdir = guessDirectory(store);
boolean is3D = store.getNodeAccess().is3D();
return new GraphHopperStorage(store.getCHProfiles(), outdir, store.getEncodingManager(), is3D, store.getTurnCostStorage() != null).create(store.getNodes());
return new GraphBuilder(store.getEncodingManager())
.withTurnCosts(store.getTurnCostStorage() != null)
.set3D(is3D)
.setDir(outdir)
.setCHProfiles(store.getCHProfiles())
.setBytes(store.getNodes())
.create();
}

public static int getAdjNode(Graph g, int edge, int adjNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.CHGraph;
import com.graphhopper.storage.CHProfile;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.RAMDirectory;
import com.graphhopper.util.Parameters;

import java.util.ArrayList;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected GraphHopperStorage createGHStorage(
for (Weighting w : weightings) {
chProfiles.add(CHProfile.edgeBased(w, INFINITE_U_TURN_COSTS));
}
return new GraphHopperStorage(chProfiles, new RAMDirectory(), em, is3D, true).create(1000);
return new GraphBuilder(em).setCHProfiles(chProfiles).set3D(is3D).withTurnCosts(true).create();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.CHGraph;
import com.graphhopper.storage.CHProfile;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.RAMDirectory;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.GHUtility;
import com.graphhopper.util.Parameters;
Expand All @@ -53,10 +53,8 @@ protected CHGraph getGraph(GraphHopperStorage ghStorage, Weighting weighting) {
}

@Override
protected GraphHopperStorage createGHStorage(EncodingManager em,
List<? extends Weighting> weightings, boolean is3D) {
return new GraphHopperStorage(CHProfile.createProfilesForWeightings(weightings), new RAMDirectory(), em, is3D).
create(1000);
protected GraphHopperStorage createGHStorage(EncodingManager em, List<? extends Weighting> weightings, boolean is3D) {
return new GraphBuilder(em).setCHProfiles(CHProfile.createProfilesForWeightings(weightings)).set3D(is3D).create();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.CHGraph;
import com.graphhopper.storage.CHProfile;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.RAMDirectory;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -43,7 +43,7 @@ protected GraphHopperStorage createGHStorage(
for (Weighting w : weightings) {
chProfiles.add(CHProfile.edgeBased(w, INFINITE_U_TURN_COSTS));
}
return new GraphHopperStorage(chProfiles, new RAMDirectory(), em, is3D, true).create(1000);
return new GraphBuilder(em).setCHProfiles(chProfiles).set3D(is3D).withTurnCosts(true).create();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
import com.graphhopper.routing.weighting.FastestWeighting;
import com.graphhopper.routing.weighting.ShortFastestWeighting;
import com.graphhopper.routing.weighting.ShortestWeighting;
import com.graphhopper.storage.CHProfile;
import com.graphhopper.storage.Directory;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.RAMDirectory;
import com.graphhopper.storage.*;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -60,9 +56,12 @@ public void setup() {
profileEdge1 = CHProfile.edgeBased(new FastestWeighting(encoder), 30);
profileEdge2 = CHProfile.edgeBased(new ShortestWeighting(encoder), 30);
profileEdge3 = CHProfile.edgeBased(new ShortFastestWeighting(encoder, 0.1), 30);
ghStorage = new GraphHopperStorage(
Arrays.asList(profileNode1, profileNode2, profileNode3, profileEdge1, profileEdge2, profileEdge3),
dir, encodingManager, false, true);
ghStorage = new GraphBuilder(encodingManager)
.setCHProfiles(profileNode1, profileNode2, profileNode3, profileEdge1, profileEdge2, profileEdge3)
.setDir(dir)
.set3D(false)
.withTurnCosts(true)
.create();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,7 @@ private List<String> comparePaths(Path refPath, Path path, int source, int targe
}

private GraphHopperStorage createGraph() {
GraphHopperStorage gh = new GraphHopperStorage(chProfiles, dir, encodingManager, false, true);
gh.create(1000);
return gh;
return new GraphBuilder(encodingManager).setCHProfiles(chProfiles).setDir(dir).withTurnCosts(true).create();
}

private int getRandom(Random rnd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ private List<String> comparePaths(Path refPath, Path path, int source, int targe
}

private GraphHopperStorage createGraph() {
GraphHopperStorage gh = new GraphHopperStorage(Collections.singletonList(chProfile), dir, encodingManager,
false, true);
gh.create(1000);
return gh;
return new GraphBuilder(encodingManager).setDir(dir).setCHProfiles(chProfile).withTurnCosts(true).create();
}

private int getTargetInEdge(Random rnd, int node, Graph graph) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private GraphHopperStorage newGHStorage(boolean is3D, boolean forEdgeBasedTraver

private GraphHopperStorage newGHStorage(Directory dir, boolean is3D, boolean forEdgeBasedTraversal, int segmentSize) {
CHProfile chProfile = new CHProfile(new FastestWeighting(carEncoder), forEdgeBasedTraversal, INFINITE_U_TURN_COSTS);
return new GraphHopperStorage(Collections.singletonList(chProfile), dir, encodingManager, is3D, false, segmentSize);
return new GraphBuilder(encodingManager).setCHProfiles(chProfile).setDir(dir).set3D(is3D).setSegmentSize(segmentSize).build();
}

@Test
Expand Down Expand Up @@ -472,7 +472,7 @@ public void testShortcutCreationAndAccessForManyVehicles() {
CHProfile.nodeBased(new FastestWeighting(tmpBike)));
BooleanEncodedValue tmpCarAccessEnc = tmpCar.getAccessEnc();

graph = new GraphHopperStorage(chProfiles, new RAMDirectory(), em, false).create(1000);
graph = new GraphBuilder(em).setCHProfiles(chProfiles).create();
IntsRef edgeFlags = GHUtility.setProperties(em.createEdgeFlags(), tmpCar, 100, true, false);
graph.edge(0, 1).setDistance(10).setFlags(GHUtility.setProperties(edgeFlags, tmpBike, 10, true, true));
graph.edge(1, 2).setDistance(10).setFlags(edgeFlags);
Expand Down Expand Up @@ -621,7 +621,6 @@ private GraphHopperStorage createStorageWithWeightings(List<Weighting> nodeBased
for (Weighting edgeBasedCHWeighting : edgeBasedCHWeightings) {
profiles.add(CHProfile.edgeBased(edgeBasedCHWeighting, INFINITE_U_TURN_COSTS));
}
return new GraphHopperStorage(profiles,
new GHDirectory(defaultGraphLoc, DAType.RAM_STORE), encodingManager, false);
return new GraphBuilder(encodingManager).setCHProfiles(profiles).setDir(new GHDirectory(defaultGraphLoc, DAType.RAM_STORE)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ protected GraphHopperStorage newGHStorage(Directory dir, boolean is3D) {

@Override
protected GraphHopperStorage newGHStorage(Directory dir, boolean enabled3D, int segmentSize) {
GraphHopperStorage g = GraphBuilder.start(encodingManager).setDir(dir).set3D(enabled3D).withTurnCosts(true).setSegmentSize(segmentSize).build();
return g;
return GraphBuilder.start(encodingManager).setDir(dir).set3D(enabled3D).withTurnCosts(true).setSegmentSize(segmentSize).build();
}

@Override
Expand Down Expand Up @@ -138,7 +137,7 @@ public void testEnsureCapacity() {
@Test(expected = IllegalArgumentException.class)
@Override
public void testClone() {
// todo: implement graph coyping in the presence of turn costs
// todo: implement graph copying in the presence of turn costs
super.testClone();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,7 @@ private GraphHopper createSquareGraphInstance(boolean withCH) {
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager encodingManager = EncodingManager.create(carEncoder);
Weighting weighting = new FastestWeighting(carEncoder);
GraphHopperStorage g = new GraphHopperStorage(Collections.singletonList(CHProfile.nodeBased(weighting)), new RAMDirectory(), encodingManager,
false).
create(20);
GraphHopperStorage g = new GraphBuilder(encodingManager).setCHProfiles(CHProfile.nodeBased(weighting)).setBytes(20).create();

// 2---3---4
// / | \
Expand Down Expand Up @@ -992,7 +990,7 @@ public void testGetWeightingForCH() {
Weighting fwSimpleTruck = new FastestWeighting(simpleTruck);
Weighting fwTruck = new FastestWeighting(truck);
RAMDirectory ramDir = new RAMDirectory();
GraphHopperStorage storage = new GraphHopperStorage(CHProfile.createProfilesForWeightings(Arrays.asList(fwSimpleTruck, fwTruck)), ramDir, em, false);
GraphHopperStorage storage = new GraphBuilder(em).setCHProfiles(CHProfile.createProfilesForWeightings(Arrays.asList(fwSimpleTruck, fwTruck))).setDir(ramDir).build();
decorator.addCHProfile(CHProfile.nodeBased(fwSimpleTruck));
decorator.addCHProfile(CHProfile.nodeBased(fwTruck));
decorator.addPreparation(PrepareContractionHierarchies.fromGraphHopperStorage(storage, CHProfile.nodeBased(fwSimpleTruck)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import com.graphhopper.routing.weighting.AbstractWeighting;
import com.graphhopper.routing.weighting.FastestWeighting;
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.*;
import com.graphhopper.storage.CHGraph;
import com.graphhopper.storage.CHProfile;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.util.CHEdgeIteratorState;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.MiniPerfTest;
Expand All @@ -22,7 +25,6 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;
import java.util.Random;

Expand Down Expand Up @@ -57,16 +59,15 @@ public TrafficChangeWithNodeOrderingReusingTest(int maxDeviationPercentage) {
EncodingManager em = EncodingManager.create(encoder);
baseProfile = CHProfile.nodeBased(new FastestWeighting(encoder));
trafficProfile = CHProfile.nodeBased(new RandomDeviationWeighting(baseProfile.getWeighting(), maxDeviationPercentage));
Directory dir = new RAMDirectory("traffic-change-test");
ghStorage = new GraphHopperStorage(Arrays.asList(baseProfile, trafficProfile), dir, em, false);
ghStorage = new GraphBuilder(em).setCHProfiles(baseProfile, trafficProfile).build();
}

@Test
public void testPerformanceForRandomTrafficChange() throws IOException {
final long seed = 2139960664L;
final int numQueries = 50_000;

LOGGER.info("Running performance test, max deviation percentage: " + this.maxDeviationPercentage);
LOGGER.info("Running performance test, max deviation percentage: " + maxDeviationPercentage);
// read osm
OSMReader reader = new OSMReader(ghStorage);
reader.setFile(new File(OSM_FILE));
Expand Down

0 comments on commit 0f32226

Please sign in to comment.