Skip to content

Commit

Permalink
fix incorrect time unit for GenericWeighting.calcMillis, fixes graphh…
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Dec 6, 2016
1 parent 78d19a8 commit e3e027e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public DataFlagEncoder() {
"delivery",
"agricultural",
"no"
);
);


counter = 0;
Expand Down Expand Up @@ -210,9 +210,9 @@ int getHighwayValue(ReaderWay way) {
int getAccessValue(ReaderWay way) {
int accessValue = 0;
Integer tmpAccessValue = 0;
for (String restriction: restrictions) {
for (String restriction : restrictions) {
tmpAccessValue = accessMap.get(way.getTag(restriction, "yes"));
if(tmpAccessValue != null && tmpAccessValue > accessValue){
if (tmpAccessValue != null && tmpAccessValue > accessValue) {
accessValue = tmpAccessValue;
}
}
Expand All @@ -221,9 +221,9 @@ int getAccessValue(ReaderWay way) {
}

//TODO It is bad that it's a bit static right now. If anyone changes the accessMap this method won't work anymore...
public AccessValue getEdgeAccessValue(long flags){
public AccessValue getEdgeAccessValue(long flags) {
int accessValue = (int) accessEncoder.getValue(flags);
switch (accessValue){
switch (accessValue) {
case 0:
return AccessValue.ACCESSIBLE;
case 5:
Expand Down Expand Up @@ -355,6 +355,9 @@ public String getHighwayAsString(EdgeIteratorState edge) {
}

public double[] getHighwaySpeedMap(Map<String, Double> map) {
if (map == null)
throw new IllegalArgumentException("Map cannot be null when calling getHighwaySpeedMap");

double[] res = new double[highwayMap.size()];
for (Entry<String, Double> e : map.entrySet()) {
Integer integ = highwayMap.get(e.getKey());
Expand Down Expand Up @@ -575,7 +578,7 @@ public ConfigMap readStringMap(PMap weightingMap) {
return cMap;
}

public enum AccessValue{
public enum AccessValue {

ACCESSIBLE,
EVENTUALLY_ACCESSIBLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
*/
public class GenericWeighting extends AbstractWeighting {
/**
* Converting to seconds is not necessary but makes adding other penalties easier (e.g. turn
* costs or traffic light costs etc)
* Convert to milliseconds for correct calcMillis.
*/
protected final static double SPEED_CONV = 3.6;
private final static double SPEED_CONV = 3600;
private final double headingPenalty;
private final long headingPenaltyMillis;
private final double maxSpeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
* @author Peter Karich
*/
public class GenericWeightingTest {
private final EncodingManager em = new EncodingManager("generic");
private final DataFlagEncoder encoder = (DataFlagEncoder) em.getEncoder("generic");
private final DataFlagEncoder encoder = new DataFlagEncoder();
private final EncodingManager em = new EncodingManager(encoder);
private Graph graph;

private final double edgeWeight = 566;
private final double edgeWeight = 566111;

@Before
public void setup() {
public void setUp() {
ReaderWay way = new ReaderWay(27l);
way.setTag("highway", "primary");
way.setTag("maxspeed", "10");
Expand Down Expand Up @@ -98,4 +98,12 @@ public void testBlockedByShape() {
instance.setGraph(graph);
assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}

@Test
public void testCalcTime() {
ConfigMap cMap = encoder.readStringMap(new PMap());
GenericWeighting weighting = new GenericWeighting(encoder, cMap);
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1);
}
}

0 comments on commit e3e027e

Please sign in to comment.