Commit 296736bc authored by Michael Zilske's avatar Michael Zilske

Somewhat clear up magic numbers

parent 25a16fe6
......@@ -102,11 +102,12 @@ public final class GraphHopperGtfs implements GraphHopperAPI {
private final Map<Integer, PathWrapper> walkPaths = new HashMap<>();
private final GHResponse response = new GHResponse();
private final QueryGraph queryGraph = new QueryGraph(new WrapperGraph(graphHopperStorage, extraEdges));
private final Graph graphWithExtraEdges = new WrapperGraph(graphHopperStorage, extraEdges);
private QueryGraph queryGraph = new QueryGraph(graphWithExtraEdges);
private GraphExplorer graphExplorer;
private int edgeId = 777777;
RequestHandler(GHRequest request) {
System.out.println(graphWithExtraEdges.getAllEdges().getMaxId());
maxVisitedNodesForRequest = request.getHints().getInt(Parameters.Routing.MAX_VISITED_NODES, 1_000_000);
profileQuery = request.getHints().getBool(PROFILE_QUERY, false);
ignoreTransfers = request.getHints().getBool(Parameters.PT.IGNORE_TRANSFERS, profileQuery);
......@@ -168,19 +169,20 @@ public final class GraphHopperGtfs implements GraphHopperAPI {
extraNodes.add(ghPoint);
int newNode = graphHopperStorage.getNodes() + 10000 + index;
int nextNodeId = graphHopperStorage.getNodes() + 10000 + index; // FIXME: A number bigger than the number of nodes QueryGraph adds
int nextEdgeId = graphWithExtraEdges.getAllEdges().getMaxId() + 100; // FIXME: A number bigger than the number of edges QueryGraph adds
final List<Label> stationNodes = findStationNodes(graphExplorer, allQueryResults.get(index).getClosestNode(), reverse);
for (Label stationNode : stationNodes) {
final PathWrapper pathWrapper = stationNode.parent.parent != null ?
tripFromLabel.parseSolutionIntoPath(reverse, flagEncoder, translation, graphExplorer, weighting, stationNode.parent, new PointList()) :
new PathWrapper();
final VirtualEdgeIteratorState newEdge = new VirtualEdgeIteratorState(stationNode.edge,
edgeId++, reverse ? stationNode.adjNode : newNode, reverse ? newNode : stationNode.adjNode, pathWrapper.getDistance(), 0, "", pathWrapper.getPoints());
nextEdgeId++, reverse ? stationNode.adjNode : nextNodeId, reverse ? nextNodeId : stationNode.adjNode, pathWrapper.getDistance(), 0, "", pathWrapper.getPoints());
final VirtualEdgeIteratorState reverseNewEdge = new VirtualEdgeIteratorState(stationNode.edge,
edgeId++, reverse ? newNode : stationNode.adjNode, reverse ? stationNode.adjNode : newNode, pathWrapper.getDistance(), 0, "", pathWrapper.getPoints());
nextEdgeId++, reverse ? nextNodeId : stationNode.adjNode, reverse ? stationNode.adjNode : nextNodeId, pathWrapper.getDistance(), 0, "", pathWrapper.getPoints());
newEdge.setFlags(((PtFlagEncoder) weighting.getFlagEncoder()).setEdgeType(newEdge.getFlags(), reverse ? GtfsStorage.EdgeType.EXIT_PT : GtfsStorage.EdgeType.ENTER_PT));
final long time = pathWrapper.getTime() / 1000;
System.out.println(time);
newEdge.setFlags(((PtFlagEncoder) weighting.getFlagEncoder()).setTime(newEdge.getFlags(), time));
reverseNewEdge.setFlags(newEdge.getFlags());
newEdge.setReverseEdge(reverseNewEdge);
......@@ -192,7 +194,7 @@ public final class GraphHopperGtfs implements GraphHopperAPI {
}
final QueryResult virtualNode = new QueryResult(ghPoint.getLat(), ghPoint.getLon());
virtualNode.setClosestNode(newNode);
virtualNode.setClosestNode(nextNodeId);
allQueryResults.set(index, virtualNode);
}
......@@ -202,7 +204,6 @@ public final class GraphHopperGtfs implements GraphHopperAPI {
final Stream<Label> labels = router.calcLabels(node, -1, initialTime);
return labels
.filter(current -> current.edge != -1 && flagEncoder.getEdgeType(graphExplorer.getEdgeIteratorState(current.edge, current.adjNode).getFlags()) == edgeType)
// .limit(limitSolutions)
.collect(Collectors.toList());
}
......
......@@ -21,11 +21,13 @@ package com.graphhopper.reader.gtfs;
import com.graphhopper.routing.VirtualEdgeIteratorState;
import com.graphhopper.routing.util.AllEdgesIterator;
import com.graphhopper.routing.util.EdgeFilter;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.storage.Graph;
import com.graphhopper.storage.GraphExtension;
import com.graphhopper.storage.NodeAccess;
import com.graphhopper.util.EdgeExplorer;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.PointList;
import com.graphhopper.util.shapes.BBox;
import java.util.List;
......@@ -81,7 +83,110 @@ public class WrapperGraph implements Graph {
@Override
public AllEdgesIterator getAllEdges() {
return baseGraph.getAllEdges();
return new AllEdgesIterator() {
@Override
public int getMaxId() {
return IntStream.concat(
IntStream.of(baseGraph.getAllEdges().getMaxId()),
extraEdges.stream().mapToInt(VirtualEdgeIteratorState::getEdge))
.max().getAsInt();
}
@Override
public boolean next() {
throw new UnsupportedOperationException();
}
@Override
public int getEdge() {
throw new UnsupportedOperationException();
}
@Override
public int getBaseNode() {
throw new UnsupportedOperationException();
}
@Override
public int getAdjNode() {
throw new UnsupportedOperationException();
}
@Override
public PointList fetchWayGeometry(int mode) {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState setWayGeometry(PointList list) {
throw new UnsupportedOperationException();
}
@Override
public double getDistance() {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState setDistance(double dist) {
throw new UnsupportedOperationException();
}
@Override
public long getFlags() {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState setFlags(long flags) {
throw new UnsupportedOperationException();
}
@Override
public int getAdditionalField() {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState setAdditionalField(int value) {
throw new UnsupportedOperationException();
}
@Override
public boolean isForward(FlagEncoder encoder) {
throw new UnsupportedOperationException();
}
@Override
public boolean isBackward(FlagEncoder encoder) {
throw new UnsupportedOperationException();
}
@Override
public boolean getBool(int key, boolean _default) {
throw new UnsupportedOperationException();
}
@Override
public String getName() {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState setName(String name) {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState detach(boolean reverse) {
throw new UnsupportedOperationException();
}
@Override
public EdgeIteratorState copyPropertiesTo(EdgeIteratorState e) {
throw new UnsupportedOperationException();
}
};
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment