Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed #282, issues with turn restrictions, also important refactoring…
…: using nodeVia always as second parameter
- Loading branch information
Peter
committed
Jan 14, 2015
1 parent
83705c2
commit 6fa2557
Showing
9 changed files
with
519 additions
and
389 deletions.
There are no files selected for viewing
417 changes: 58 additions & 359 deletions
417
core/src/main/java/com/graphhopper/routing/QueryGraph.java
Large diffs are not rendered by default.
Oops, something went wrong.
195 changes: 195 additions & 0 deletions
195
core/src/main/java/com/graphhopper/routing/VirtualEdgeIState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,195 @@ | |||
/* | |||
* Copyright 2015 Peter Karich. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package com.graphhopper.routing; | |||
|
|||
import com.graphhopper.util.EdgeIteratorState; | |||
import com.graphhopper.util.EdgeSkipIterState; | |||
import com.graphhopper.util.PointList; | |||
|
|||
/** | |||
* Creates an edge state decoupled from a graph where nodes, pointList, etc are kept in memory. | |||
*/ | |||
class VirtualEdgeIState implements EdgeIteratorState, EdgeSkipIterState { | |||
private final PointList pointList; | |||
private final int edgeId; | |||
private double distance; | |||
private long flags; | |||
private String name; | |||
private final int baseNode; | |||
private final int adjNode; | |||
|
|||
public VirtualEdgeIState( int edgeId, int baseNode, int adjNode, double distance, long flags, String name, PointList pointList ) | |||
{ | |||
this.edgeId = edgeId; | |||
this.baseNode = baseNode; | |||
this.adjNode = adjNode; | |||
this.distance = distance; | |||
this.flags = flags; | |||
this.name = name; | |||
this.pointList = pointList; | |||
} | |||
|
|||
@Override | |||
public int getEdge() | |||
{ | |||
return edgeId; | |||
} | |||
|
|||
@Override | |||
public int getBaseNode() | |||
{ | |||
return baseNode; | |||
} | |||
|
|||
@Override | |||
public int getAdjNode() | |||
{ | |||
return adjNode; | |||
} | |||
|
|||
@Override | |||
public PointList fetchWayGeometry( int mode ) | |||
{ | |||
if (pointList.getSize() == 0) | |||
return PointList.EMPTY; | |||
// due to API we need to create a new instance per call! | |||
if (mode == 3) | |||
return pointList.clone(false); | |||
else if (mode == 1) | |||
return pointList.copy(0, pointList.getSize() - 1); | |||
else if (mode == 2) | |||
return pointList.copy(1, pointList.getSize()); | |||
else if (mode == 0) | |||
{ | |||
if (pointList.getSize() == 1) | |||
return PointList.EMPTY; | |||
return pointList.copy(1, pointList.getSize() - 1); | |||
} | |||
throw new UnsupportedOperationException("Illegal mode:" + mode); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setWayGeometry( PointList list ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported for virtual edge. Set when creating it."); | |||
} | |||
|
|||
@Override | |||
public double getDistance() | |||
{ | |||
return distance; | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setDistance( double dist ) | |||
{ | |||
this.distance = dist; | |||
return this; | |||
} | |||
|
|||
@Override | |||
public long getFlags() | |||
{ | |||
return flags; | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setFlags( long flags ) | |||
{ | |||
this.flags = flags; | |||
return this; | |||
} | |||
|
|||
@Override | |||
public String getName() | |||
{ | |||
return name; | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setName( String name ) | |||
{ | |||
this.name = name; | |||
return this; | |||
} | |||
|
|||
@Override | |||
public String toString() | |||
{ | |||
return baseNode + "->" + adjNode; | |||
} | |||
|
|||
@Override | |||
public boolean isShortcut() | |||
{ | |||
return false; | |||
} | |||
|
|||
@Override | |||
public int getAdditionalField() | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public int getSkippedEdge1() | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public int getSkippedEdge2() | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public void setSkippedEdges( int edge1, int edge2 ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState detach( boolean reverse ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setAdditionalField( int value ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState copyPropertiesTo( EdgeIteratorState edge ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public EdgeSkipIterState setWeight( double weight ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public double getWeight() | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
} |
198 changes: 198 additions & 0 deletions
198
core/src/main/java/com/graphhopper/routing/VirtualEdgeIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,198 @@ | |||
/* | |||
* Copyright 2015 Peter Karich. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package com.graphhopper.routing; | |||
|
|||
import com.graphhopper.util.EdgeIterator; | |||
import com.graphhopper.util.EdgeIteratorState; | |||
import com.graphhopper.util.EdgeSkipIterState; | |||
import com.graphhopper.util.PointList; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
|
|||
/** | |||
* | |||
* @author Peter Karich | |||
*/ | |||
class VirtualEdgeIterator implements EdgeIterator, EdgeSkipIterState { | |||
private final List<EdgeIteratorState> edges; | |||
private int current; | |||
|
|||
public VirtualEdgeIterator( int edgeCount ) | |||
{ | |||
edges = new ArrayList<EdgeIteratorState>(edgeCount); | |||
reset(); | |||
} | |||
|
|||
void add( EdgeIteratorState edge ) | |||
{ | |||
edges.add(edge); | |||
} | |||
|
|||
EdgeIterator reset() | |||
{ | |||
current = -1; | |||
return this; | |||
} | |||
|
|||
int count() | |||
{ | |||
return edges.size(); | |||
} | |||
|
|||
@Override | |||
public boolean next() | |||
{ | |||
current++; | |||
return current < edges.size(); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState detach( boolean reverse ) | |||
{ | |||
if (reverse) | |||
throw new IllegalStateException("Not yet supported"); | |||
return edges.get(current); | |||
} | |||
|
|||
@Override | |||
public int getEdge() | |||
{ | |||
return edges.get(current).getEdge(); | |||
} | |||
|
|||
@Override | |||
public int getBaseNode() | |||
{ | |||
return edges.get(current).getBaseNode(); | |||
} | |||
|
|||
@Override | |||
public int getAdjNode() | |||
{ | |||
return edges.get(current).getAdjNode(); | |||
} | |||
|
|||
@Override | |||
public PointList fetchWayGeometry( int mode ) | |||
{ | |||
return edges.get(current).fetchWayGeometry(mode); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setWayGeometry( PointList list ) | |||
{ | |||
return edges.get(current).setWayGeometry(list); | |||
} | |||
|
|||
@Override | |||
public double getDistance() | |||
{ | |||
return edges.get(current).getDistance(); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setDistance( double dist ) | |||
{ | |||
return edges.get(current).setDistance(dist); | |||
} | |||
|
|||
@Override | |||
public long getFlags() | |||
{ | |||
return edges.get(current).getFlags(); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setFlags( long flags ) | |||
{ | |||
return edges.get(current).setFlags(flags); | |||
} | |||
|
|||
@Override | |||
public String getName() | |||
{ | |||
return edges.get(current).getName(); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setName( String name ) | |||
{ | |||
return edges.get(current).setName(name); | |||
} | |||
|
|||
@Override | |||
public String toString() | |||
{ | |||
return edges.toString(); | |||
} | |||
|
|||
@Override | |||
public int getAdditionalField() | |||
{ | |||
return edges.get(current).getAdditionalField(); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState setAdditionalField( int value ) | |||
{ | |||
return edges.get(current).setAdditionalField(value); | |||
} | |||
|
|||
@Override | |||
public EdgeIteratorState copyPropertiesTo( EdgeIteratorState edge ) | |||
{ | |||
return edges.get(current).copyPropertiesTo(edge); | |||
} | |||
|
|||
@Override | |||
public boolean isShortcut() | |||
{ | |||
EdgeIteratorState edge = edges.get(current); | |||
return edge instanceof EdgeSkipIterState && ((EdgeSkipIterState) edge).isShortcut(); | |||
} | |||
|
|||
@Override | |||
public double getWeight() | |||
{ | |||
// will be called only from PreparationWeighting and if isShortcut is true | |||
return ((EdgeSkipIterState) edges.get(current)).getWeight(); | |||
} | |||
|
|||
@Override | |||
public EdgeSkipIterState setWeight( double weight ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public int getSkippedEdge1() | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public int getSkippedEdge2() | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
@Override | |||
public void setSkippedEdges( int edge1, int edge2 ) | |||
{ | |||
throw new UnsupportedOperationException("Not supported."); | |||
} | |||
|
|||
} |
Oops, something went wrong.