Skip to content

Commit 229b8ac

Browse files
author
Peter
committed
MAJOR: removed getOutgoing and getIncoming - makes no sense for vehicle neutral Graph; other refactorings
1 parent 6b240b3 commit 229b8ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+461
-653
lines changed

src/main/java/com/graphhopper/GHRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package com.graphhopper;
2020

2121
import com.graphhopper.routing.util.CarFlagsEncoder;
22-
import com.graphhopper.routing.util.FlagsEncoder;
22+
import com.graphhopper.routing.util.VehicleType;
2323
import com.graphhopper.routing.util.ShortestCalc;
2424
import com.graphhopper.routing.util.WeightCalculation;
2525
import com.graphhopper.util.shapes.GHPoint;
@@ -35,7 +35,7 @@ public class GHRequest {
3535
private GHPoint from;
3636
private GHPoint to;
3737
private double precision = 1;
38-
private FlagsEncoder encoder = new CarFlagsEncoder();
38+
private VehicleType encoder = new CarFlagsEncoder();
3939
private WeightCalculation weightCalc = new ShortestCalc();
4040

4141
/**
@@ -112,12 +112,12 @@ public WeightCalculation type() {
112112
return weightCalc;
113113
}
114114

115-
public GHRequest vehicle(FlagsEncoder encoder) {
115+
public GHRequest vehicle(VehicleType encoder) {
116116
this.encoder = encoder;
117117
return this;
118118
}
119119

120-
public FlagsEncoder vehicle() {
120+
public VehicleType vehicle() {
121121
return encoder;
122122
}
123123
}

src/main/java/com/graphhopper/GraphHopper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.graphhopper.routing.util.AlgorithmPreparation;
2727
import com.graphhopper.routing.util.CarFlagsEncoder;
2828
import com.graphhopper.routing.util.FastestCalc;
29-
import com.graphhopper.routing.util.FlagsEncoder;
29+
import com.graphhopper.routing.util.VehicleType;
3030
import com.graphhopper.routing.util.FootFlagsEncoder;
3131
import com.graphhopper.routing.util.NoOpAlgorithmPreparation;
3232
import com.graphhopper.routing.util.ShortestCalc;
@@ -173,7 +173,7 @@ else if (new File(graphHopperFile + ".osm").exists())
173173
storage = new LevelGraphStorage(dir);
174174
PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies();
175175

176-
FlagsEncoder encoder;
176+
VehicleType encoder;
177177
if (acceptWay.acceptsCar())
178178
encoder = new CarFlagsEncoder();
179179
else

src/main/java/com/graphhopper/reader/OSMReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.graphhopper.routing.util.FastestCalc;
2424
import com.graphhopper.routing.ch.PrepareContractionHierarchies;
2525
import com.graphhopper.routing.util.CarFlagsEncoder;
26-
import com.graphhopper.routing.util.FlagsEncoder;
26+
import com.graphhopper.routing.util.VehicleType;
2727
import com.graphhopper.routing.util.NoOpAlgorithmPreparation;
2828
import com.graphhopper.routing.util.PrepareRoutingSubnetworks;
2929
import com.graphhopper.routing.util.RoutingAlgorithmSpecialAreaTests;
@@ -37,7 +37,7 @@
3737
import com.graphhopper.storage.Location2IDQuadtree;
3838
import com.graphhopper.storage.RAMDirectory;
3939
import com.graphhopper.util.CmdArgs;
40-
import com.graphhopper.util.GraphUtility;
40+
import com.graphhopper.util.GHUtility;
4141
import com.graphhopper.util.Helper;
4242
import static com.graphhopper.util.Helper.*;
4343
import com.graphhopper.util.Helper7;
@@ -218,8 +218,8 @@ void optimize() {
218218
// move this into the GraphStorage.optimize method?
219219
if (sortGraph) {
220220
logger.info("sorting ... (" + Helper.getMemInfo() + ")");
221-
GraphStorage newGraph = GraphUtility.newStorage(graphStorage);
222-
GraphUtility.sortDFS(graphStorage, newGraph);
221+
GraphStorage newGraph = GHUtility.newStorage(graphStorage);
222+
GHUtility.sortDFS(graphStorage, newGraph);
223223
graphStorage = newGraph;
224224
}
225225

@@ -376,7 +376,7 @@ public OSMReader setCHShortcuts(String chShortcuts) {
376376
if (chShortcuts.isEmpty() || "no".equals(chShortcuts) || "false".equals(chShortcuts))
377377
return this;
378378

379-
FlagsEncoder encoder = new CarFlagsEncoder();
379+
VehicleType encoder = new CarFlagsEncoder();
380380
int tmpIndex = chShortcuts.indexOf(",");
381381
if (tmpIndex >= 0)
382382
encoder = Helper.getEncoder(chShortcuts.substring(tmpIndex + 1).trim());

src/main/java/com/graphhopper/routing/AStarBidirection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.graphhopper.util.DistanceCalc;
2828
import com.graphhopper.util.DistancePlaneProjection;
2929
import com.graphhopper.util.EdgeIterator;
30-
import com.graphhopper.util.GraphUtility;
30+
import com.graphhopper.util.GHUtility;
3131
import com.graphhopper.util.shapes.CoordTrig;
3232
import gnu.trove.map.TIntObjectMap;
3333
import gnu.trove.map.hash.TIntObjectHashMap;

src/main/java/com/graphhopper/routing/AbstractRoutingAlgorithm.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.graphhopper.routing.util.CarFlagsEncoder;
2222
import com.graphhopper.routing.util.DefaultEdgeFilter;
2323
import com.graphhopper.routing.util.EdgeFilter;
24-
import com.graphhopper.routing.util.FlagsEncoder;
24+
import com.graphhopper.routing.util.VehicleType;
2525
import com.graphhopper.routing.util.ShortestCalc;
2626
import com.graphhopper.routing.util.WeightCalculation;
2727
import com.graphhopper.storage.EdgeEntry;
@@ -36,17 +36,17 @@ public abstract class AbstractRoutingAlgorithm implements RoutingAlgorithm {
3636
protected WeightCalculation weightCalc;
3737
protected EdgeFilter outEdgeFilter;
3838
protected EdgeFilter inEdgeFilter;
39-
protected FlagsEncoder flagsEncoder;
39+
protected VehicleType flagsEncoder;
4040

4141
public AbstractRoutingAlgorithm(Graph graph) {
4242
this.graph = graph;
4343
type(new ShortestCalc()).vehicle(new CarFlagsEncoder());
4444
}
4545

46-
@Override public RoutingAlgorithm vehicle(FlagsEncoder encoder) {
46+
@Override public RoutingAlgorithm vehicle(VehicleType encoder) {
4747
this.flagsEncoder = encoder;
48-
outEdgeFilter = new DefaultEdgeFilter(encoder).direction(false, true);
49-
inEdgeFilter = new DefaultEdgeFilter(encoder).direction(true, false);
48+
outEdgeFilter = new DefaultEdgeFilter(encoder, false, true);
49+
inEdgeFilter = new DefaultEdgeFilter(encoder, true, false);
5050
return this;
5151
}
5252

src/main/java/com/graphhopper/routing/Path.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package com.graphhopper.routing;
2020

21-
import com.graphhopper.routing.util.FlagsEncoder;
21+
import com.graphhopper.routing.util.VehicleType;
2222
import com.graphhopper.storage.EdgeEntry;
2323
import com.graphhopper.storage.Graph;
2424
import com.graphhopper.util.EdgeIterator;
@@ -41,7 +41,7 @@
4141
public class Path {
4242

4343
protected Graph graph;
44-
protected FlagsEncoder encoder;
44+
protected VehicleType encoder;
4545
protected double distance;
4646
// we go upwards (via EdgeEntry.parent) from the goal node to the origin node
4747
protected boolean reverseOrder = true;
@@ -54,7 +54,7 @@ public class Path {
5454
private PointList cachedPoints;
5555
private double weight;
5656

57-
public Path(Graph graph, FlagsEncoder encoder) {
57+
public Path(Graph graph, VehicleType encoder) {
5858
this.weight = Double.MAX_VALUE;
5959
this.graph = graph;
6060
this.encoder = encoder;

src/main/java/com/graphhopper/routing/PathBidir.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package com.graphhopper.routing;
2020

21-
import com.graphhopper.routing.util.FlagsEncoder;
21+
import com.graphhopper.routing.util.VehicleType;
2222
import com.graphhopper.storage.Graph;
2323
import com.graphhopper.util.EdgeWrapper;
2424

@@ -36,7 +36,7 @@ public class PathBidir extends Path {
3636
private EdgeWrapper edgeWFrom;
3737
private EdgeWrapper edgeWTo;
3838

39-
public PathBidir(Graph g, FlagsEncoder encoder,
39+
public PathBidir(Graph g, VehicleType encoder,
4040
EdgeWrapper edgesFrom, EdgeWrapper edgesTo) {
4141
super(g, encoder);
4242
this.edgeWFrom = edgesFrom;

src/main/java/com/graphhopper/routing/PathBidirRef.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
package com.graphhopper.routing;
2020

21-
import com.graphhopper.routing.util.FlagsEncoder;
21+
import com.graphhopper.routing.util.VehicleType;
2222
import com.graphhopper.storage.EdgeEntry;
2323
import com.graphhopper.storage.Graph;
2424
import com.graphhopper.util.EdgeIterator;
25-
import com.graphhopper.util.GraphUtility;
25+
import com.graphhopper.util.GHUtility;
2626

2727
/**
2828
* This class creates a DijkstraPath from two Edge's resulting from a
@@ -35,7 +35,7 @@ public class PathBidirRef extends Path {
3535
protected EdgeEntry edgeTo;
3636
private boolean switchWrapper = false;
3737

38-
public PathBidirRef(Graph g, FlagsEncoder encoder) {
38+
public PathBidirRef(Graph g, VehicleType encoder) {
3939
super(g, encoder);
4040
}
4141

@@ -63,8 +63,8 @@ public Path extract() {
6363
if (edgeEntry == null || edgeTo == null)
6464
return this;
6565

66-
int from = GraphUtility.getToNode(graph, edgeEntry.edge, edgeEntry.endNode);
67-
int to = GraphUtility.getToNode(graph, edgeTo.edge, edgeTo.endNode);
66+
int from = GHUtility.getToNode(graph, edgeEntry.edge, edgeEntry.endNode);
67+
int to = GHUtility.getToNode(graph, edgeTo.edge, edgeTo.endNode);
6868
if (from != to)
6969
throw new IllegalStateException("Locations of the 'to'- and 'from'-Edge has to be the same." + toString());
7070

src/main/java/com/graphhopper/routing/RoutingAlgorithm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package com.graphhopper.routing;
2020

21-
import com.graphhopper.routing.util.FlagsEncoder;
21+
import com.graphhopper.routing.util.VehicleType;
2222
import com.graphhopper.routing.util.WeightCalculation;
2323
import com.graphhopper.util.NotThreadSafe;
2424

@@ -49,7 +49,7 @@ public interface RoutingAlgorithm {
4949
* Specify which vehicle should be used to calculate the path. Default is
5050
* car.
5151
*/
52-
RoutingAlgorithm vehicle(FlagsEncoder encoder);
52+
RoutingAlgorithm vehicle(VehicleType encoder);
5353

5454
/**
5555
* @return name of this algorithm

src/main/java/com/graphhopper/routing/ch/Path4CH.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package com.graphhopper.routing.ch;
2020

2121
import com.graphhopper.routing.PathBidirRef;
22-
import com.graphhopper.routing.util.FlagsEncoder;
22+
import com.graphhopper.routing.util.VehicleType;
2323
import com.graphhopper.routing.util.WeightCalculation;
2424
import com.graphhopper.storage.Graph;
2525
import com.graphhopper.util.EdgeIterator;
@@ -35,7 +35,7 @@ public class Path4CH extends PathBidirRef {
3535

3636
private WeightCalculation calc;
3737

38-
public Path4CH(Graph g, FlagsEncoder encoder, WeightCalculation calc) {
38+
public Path4CH(Graph g, VehicleType encoder, WeightCalculation calc) {
3939
super(g, encoder);
4040
this.calc = calc;
4141
}

src/main/java/com/graphhopper/routing/ch/PrepareContractionHierarchies.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.graphhopper.routing.util.DefaultEdgeFilter;
3131
import com.graphhopper.routing.util.EdgeFilter;
3232
import com.graphhopper.routing.util.EdgeLevelFilterOld;
33-
import com.graphhopper.routing.util.FlagsEncoder;
33+
import com.graphhopper.routing.util.VehicleType;
3434
import com.graphhopper.routing.util.ShortestCalc;
3535
import com.graphhopper.routing.util.WeightCalculation;
3636
import com.graphhopper.storage.EdgeEntry;
@@ -39,7 +39,7 @@
3939
import com.graphhopper.storage.LevelGraphStorage;
4040
import com.graphhopper.util.EdgeIterator;
4141
import com.graphhopper.util.EdgeSkipIterator;
42-
import com.graphhopper.util.GraphUtility;
42+
import com.graphhopper.util.GHUtility;
4343
import com.graphhopper.util.Helper;
4444
import com.graphhopper.util.RawEdgeIterator;
4545
import com.graphhopper.util.StopWatch;
@@ -70,7 +70,7 @@ public class PrepareContractionHierarchies extends AbstractAlgoPreparation<Prepa
7070
private Logger logger = LoggerFactory.getLogger(getClass());
7171
private WeightCalculation shortestCalc;
7272
private WeightCalculation prepareWeightCalc;
73-
private FlagsEncoder prepareEncoder;
73+
private VehicleType prepareEncoder;
7474
private EdgeFilter inFilter;
7575
private EdgeFilter outFilter;
7676
private LevelGraph g;
@@ -115,10 +115,10 @@ public PrepareContractionHierarchies type(WeightCalculation weightCalc) {
115115
return this;
116116
}
117117

118-
public PrepareContractionHierarchies vehicle(FlagsEncoder encoder) {
118+
public PrepareContractionHierarchies vehicle(VehicleType encoder) {
119119
this.prepareEncoder = encoder;
120-
inFilter = new DefaultEdgeFilter(encoder).direction(true, false);
121-
outFilter = new DefaultEdgeFilter(encoder).direction(false, true);
120+
inFilter = new DefaultEdgeFilter(encoder, true, false);
121+
outFilter = new DefaultEdgeFilter(encoder, false, true);
122122
scOneDir = encoder.flags(0, false);
123123
scBothDir = encoder.flags(0, true);
124124
return this;
@@ -158,7 +158,7 @@ boolean prepareEdges() {
158158
// in CH the flags will be ignored (calculating the new flags for the shortcuts is impossible)
159159
// also several shortcuts would be necessary with the different modes (e.g. fastest and extractPath)
160160
// so calculate the weight and store this as distance, then use only distance instead of getWeight
161-
RawEdgeIterator iter = g.allEdges();
161+
RawEdgeIterator iter = g.getAllEdges();
162162
int c = 0;
163163
while (iter.next()) {
164164
c++;
@@ -289,7 +289,7 @@ int calculatePriority(int v) {
289289
// |shortcuts(v)| − |{(u, v) | v uncontracted}| − |{(v, w) | v uncontracted}|
290290
// meanDegree is used instead of outDegree+inDegree as if one endNode is in both directions
291291
// only one bucket memory is used. Additionally one shortcut could also stand for two directions.
292-
int degree = GraphUtility.count(g.getEdges(v));
292+
int degree = GHUtility.count(g.getEdges(v));
293293
int edgeDifference = tmpShortcuts.size() - degree;
294294

295295
// # huge influence: the bigger the less shortcuts gets created and the faster is the preparation

src/main/java/com/graphhopper/routing/rideshare/DijkstraWhichToOne.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.graphhopper.storage.EdgeEntry;
2828
import com.graphhopper.storage.Graph;
2929
import com.graphhopper.util.EdgeIterator;
30-
import com.graphhopper.util.GraphUtility;
30+
import com.graphhopper.util.GHUtility;
3131
import gnu.trove.list.array.TIntArrayList;
3232
import gnu.trove.map.TIntObjectMap;
3333
import gnu.trove.map.hash.TIntObjectHashMap;

src/main/java/com/graphhopper/routing/util/AbstractFlagEncoder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* @author Peter Karich
2323
*/
24-
public class AbstractFlagEncoder implements FlagsEncoder {
24+
public class AbstractFlagEncoder implements VehicleType {
2525

2626
/**
2727
* This variable converts the stored value to the speed in km/h or does the
@@ -68,7 +68,6 @@ public boolean canBeOverwritten(int flags1, int flags2) {
6868
return isBoth(flags2) || (flags1 & BOTH) == (flags2 & BOTH);
6969
}
7070

71-
@Override
7271
public int swapDirection(int flags) {
7372
int dir = flags & BOTH;
7473
if (dir == BOTH || dir == 0)
@@ -85,7 +84,6 @@ public int getSpeed(int flags) {
8584
return getSpeedPart(flags) * factor;
8685
}
8786

88-
@Override
8987
public int flagsDefault(boolean bothDirections) {
9088
if (bothDirections)
9189
return defaultSpeedPart << speedShift | BOTH;

src/main/java/com/graphhopper/routing/util/AcceptWay.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -239,29 +239,4 @@ public String toString() {
239239
str += "FOOT";
240240
return str;
241241
}
242-
243-
public CombinedEncoder createCombination() {
244-
return new CombinedEncoder() {
245-
@Override public int swapDirection(int flags) {
246-
if (foot)
247-
flags = footEncoder.swapDirection(flags);
248-
if (bike)
249-
flags = bikeEncoder.swapDirection(flags);
250-
if (car)
251-
flags = carEncoder.swapDirection(flags);
252-
return flags;
253-
}
254-
255-
@Override public int flagsDefault(boolean bothDirections) {
256-
int res = 0;
257-
if (foot)
258-
res |= footEncoder.flagsDefault(bothDirections);
259-
if (bike)
260-
res |= bikeEncoder.flagsDefault(bothDirections);
261-
if (car)
262-
res |= carEncoder.flagsDefault(bothDirections);
263-
return res;
264-
}
265-
};
266-
}
267242
}

0 commit comments

Comments
 (0)