Skip to content

Commit

Permalink
renamed directions to heading
Browse files Browse the repository at this point in the history
  • Loading branch information
jansoe committed Jun 5, 2015
1 parent af1f0c3 commit a514273
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/com/graphhopper/GraphHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,18 +1064,18 @@ protected List<Path> getPaths( GHRequest request, GHResponse rsp )
if (placeIndex == 1)
{
// enforce start direction
queryGraph.enforceDirection(fromQResult.getClosestNode(), request.getFavoredDirection(0), false);
queryGraph.enforceHeading(fromQResult.getClosestNode(), request.getFavoredDirection(0), false);
} else if (viaTurnPenalty)
{
// enforce straight start after via stop
EdgeIteratorState incomingVirtualEdge = paths.get(placeIndex - 2).getFinalEdge();
queryGraph.enforceDirectionByEdgeId(fromQResult.getClosestNode(), incomingVirtualEdge.getEdge(), false);
queryGraph.enforceHeadingByEdgeId(fromQResult.getClosestNode(), incomingVirtualEdge.getEdge(), false);
}

QueryResult toQResult = qResults.get(placeIndex);

// enforce end direction
queryGraph.enforceDirection(toQResult.getClosestNode(), request.getFavoredDirection(placeIndex), true);
queryGraph.enforceHeading(toQResult.getClosestNode(), request.getFavoredDirection(placeIndex), true);

sw = new StopWatch().start();
RoutingAlgorithm algo = tmpAlgoFactory.createAlgo(queryGraph, algoOpts);
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/com/graphhopper/routing/QueryGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,21 @@ private void createEdges( GHPoint3D prevSnapped, int prevWayIndex, GHPoint3D cur
}

/**
* set edges at virtual node unfavored which require at least a turn of 100° from favoredDirectionAz
* set edges at virtual node unfavored which require at least a turn of 100° from favoredHeadingAzi
*
* @param nodeId VirtualNode at which edges get unfavored
* @param favoredDirectionAz north based azimuth of favored direction
* @param favoredHeadingAzi north based azimuth of favored heading
* @param incoming if true, incoming edges are unfavored, else outgoing edges
*
* @return boolean indicating if enforcement took place
*/
public boolean enforceDirection( int nodeId, Double favoredDirectionAz, boolean incoming )
public boolean enforceHeading( int nodeId, Double favoredHeadingAzi, boolean incoming )
{
if (!isInitialized())
{
throw new IllegalStateException("QueryGraph.lookup has to be called in before direction enforcement");
throw new IllegalStateException("QueryGraph.lookup has to be called in before heading enforcement");
}
if (Double.isNaN(favoredDirectionAz))
if (Double.isNaN(favoredHeadingAzi))
{
return false;
}
Expand All @@ -406,7 +406,7 @@ public boolean enforceDirection( int nodeId, Double favoredDirectionAz, boolean
}

int virtNodeIDintern = nodeId - mainNodes;
double favoredDirection = ac.convertAzimuth2xaxisAngle(favoredDirectionAz);
double favoredHeading = ac.convertAzimuth2xaxisAngle(favoredHeadingAzi);

// either penalize incoming or outgoing edges
List<Integer> edgePositions = incoming ? Arrays.asList(VE_BASE, VE_ADJ_REV) : Arrays.asList(VE_BASE_REV, VE_ADJ);
Expand All @@ -428,8 +428,8 @@ public boolean enforceDirection( int nodeId, Double favoredDirectionAz, boolean
wayGeo.getLat(1), wayGeo.getLon(1));
}

edgeOrientation = ac.alignOrientation(favoredDirection, edgeOrientation);
double delta = (edgeOrientation - favoredDirection);
edgeOrientation = ac.alignOrientation(favoredHeading, edgeOrientation);
double delta = (edgeOrientation - favoredHeading);

if (Math.abs(delta) > 1.74) // penalize if a turn of more than 100° is necessary
{
Expand All @@ -455,7 +455,7 @@ public boolean enforceDirection( int nodeId, Double favoredDirectionAz, boolean
*
* @return boolean indicating if enforcement took place
*/
public boolean enforceDirectionByEdgeId( int nodeId, int edgeId, boolean incoming )
public boolean enforceHeadingByEdgeId( int nodeId, int edgeId, boolean incoming )
{
if (!isVirtualNode(nodeId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class FastestWeighting implements Weighting
* costs or traffic light costs etc)
*/
protected final static double SPEED_CONV = 3.6;
final static double DEFAULT_DIRECTION_PENALTY = 300; //[s]
final static double DEFAULT_HEADING_PENALTY = 300; //[s]
protected final FlagEncoder encoder;
private final double maxSpeed;
private final PMap pMap;
Expand Down Expand Up @@ -68,7 +68,7 @@ public double calcWeight( EdgeIteratorState edge, boolean reverse, int prevOrNex
boolean penalizeEdge = edge.getBoolean(EdgeIteratorState.K_UNFAVORED_EDGE, reverse, false);
if (penalizeEdge)
{
time += pMap.getDouble("directionpenalty", DEFAULT_DIRECTION_PENALTY);
time += pMap.getDouble("headingpenalty", DEFAULT_HEADING_PENALTY);
}

return time;
Expand Down
14 changes: 7 additions & 7 deletions core/src/test/java/com/graphhopper/routing/QueryGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ private boolean getEdgePreference( QueryGraph queryGraph, int virtualEdgeTypeId,
}

@Test
public void testEnforceDirection()
public void testEnforceHeading()
{

initHorseshoeGraph(g);
Expand All @@ -591,7 +591,7 @@ public void testEnforceDirection()
queryGraph.lookup(Arrays.asList(qr));

// enforce going out north
queryGraph.enforceDirection(qr.getClosestNode(), 0., false);
queryGraph.enforceHeading(qr.getClosestNode(), 0., false);
// test penalized south
boolean expect = true;
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_BASE_REV, false, !expect));
Expand All @@ -604,7 +604,7 @@ public void testEnforceDirection()
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_BASE, true, !expect));

// enforce coming in north
queryGraph.enforceDirection(qr.getClosestNode(), 3.14, true);
queryGraph.enforceHeading(qr.getClosestNode(), 3.14, true);
// test penalized south
expect = true;
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_BASE_REV, true, !expect));
Expand All @@ -617,23 +617,23 @@ public void testEnforceDirection()
queryGraph.lookup(Arrays.asList(qr));

// enforce going north
queryGraph.enforceDirection(qr.getClosestNode(), 0., false);
queryGraph.enforceHeading(qr.getClosestNode(), 0., false);
// test penalized south
expect = true;
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_ADJ, false, !expect));
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_ADJ_REV, true, !expect));

queryGraph.clearUnfavoredStatus();
// enforce coming in north
queryGraph.enforceDirection(qr.getClosestNode(), 3.14, true);
queryGraph.enforceHeading(qr.getClosestNode(), 3.14, true);
// test penalized south
expect = true;
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_ADJ, true, !expect));
assertEquals(expect, getEdgePreference(queryGraph, QueryGraph.VE_ADJ_REV, false, !expect));
}

@Test
public void testEnforceDirectionByEdgeId()
public void testEnforceHeadingByEdgeId()
{

initHorseshoeGraph(g);
Expand All @@ -645,7 +645,7 @@ public void testEnforceDirectionByEdgeId()
queryGraph.lookup(Arrays.asList(qr));

// enforce coming in north
queryGraph.enforceDirectionByEdgeId(2, 1, false);
queryGraph.enforceHeadingByEdgeId(2, 1, false);
// test penalized south
boolean expect = true;
VirtualEdgeIteratorState incomingEdge = (VirtualEdgeIteratorState) queryGraph.getEdgeProps(1, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public void testMinWeightHasSameUnitAs_getWeight()
}

@Test
public void testWeightWrongDirection()
public void testWeightWrongHeading()
{
FastestWeighting instance = new FastestWeighting(encoder, new PMap().put("directionpenalty", "100"));
FastestWeighting instance = new FastestWeighting(encoder, new PMap().put("headingpenalty", "100"));

VirtualEdgeIteratorState virtEdge = new VirtualEdgeIteratorState(0, 1, 1, 2, 10,
encoder.setProperties(10, true, true), "test", Helper.createPointList(51, 0, 51, 1));
double time = instance.calcWeight(virtEdge, false, 0);

virtEdge.setVirtualEdgePreference(true, false);
// direction penalty on edge
// heading penalty on edge
assertEquals(time + 100, instance.calcWeight(virtEdge, false, 0), 1e-8);
// but not in reverse direction
// but not in reverse heading
assertEquals(time, instance.calcWeight(virtEdge, true, 0), 1e-8);
// only after setting it
virtEdge.setVirtualEdgePreference(true, true);
Expand All @@ -64,7 +64,7 @@ public void testWeightWrongDirection()

// test default penalty
instance = new FastestWeighting(encoder);
assertEquals(time + FastestWeighting.DEFAULT_DIRECTION_PENALTY, instance.calcWeight(virtEdge, false, 0), 1e-8);
assertEquals(time + FastestWeighting.DEFAULT_HEADING_PENALTY, instance.calcWeight(virtEdge, false, 0), 1e-8);
}

@Test
Expand Down
22 changes: 11 additions & 11 deletions web/src/main/java/com/graphhopper/http/GraphHopperServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public void doGet( HttpServletRequest httpReq, HttpServletResponse httpRes ) thr
String weighting = getParam(httpReq, "weighting", "fastest");
String algoStr = getParam(httpReq, "algorithm", "");
String localeStr = getParam(httpReq, "locale", "en");
List<Double> favoredDirections = Collections.EMPTY_LIST;
List<Double> favoredHeadings = Collections.EMPTY_LIST;
try
{
favoredDirections = getDoubleParamList(httpReq, "direction");
favoredHeadings = getDoubleParamList(httpReq, "heading");

} catch (java.lang.NumberFormatException e)
{
Expand All @@ -96,27 +96,27 @@ public void doGet( HttpServletRequest httpReq, HttpServletResponse httpRes ) thr
} else if (enableElevation && !hopper.hasElevation())
{
ghRsp.addError(new IllegalArgumentException("Elevation not supported!"));
} else if (favoredDirections.size()>1 && favoredDirections.size() != infoPoints.size())
} else if (favoredHeadings.size()>1 && favoredHeadings.size() != infoPoints.size())
{
ghRsp.addError(new IllegalArgumentException("#directions must be <=1 or equal #points"));
ghRsp.addError(new IllegalArgumentException("#heading must be <=1 or equal #points"));
}
if (!ghRsp.hasErrors())
{
FlagEncoder algoVehicle = hopper.getEncodingManager().getEncoder(vehicleStr);

GHRequest request;
if (favoredDirections.size()>0)
if (favoredHeadings.size()>0)
{
// if only one preferred directions is specified take as start direction
if (favoredDirections.size() == 1)
// if only one favored heading is specified take as start heading
if (favoredHeadings.size() == 1)
{
List<Double> paddedDirections = new ArrayList<Double>(Collections.nCopies(infoPoints.size(),
List<Double> paddedHeadings = new ArrayList<Double>(Collections.nCopies(infoPoints.size(),
Double.NaN));
paddedDirections.set(0, favoredDirections.get(0));
request = new GHRequest(infoPoints, paddedDirections);
paddedHeadings.set(0, favoredHeadings.get(0));
request = new GHRequest(infoPoints, paddedHeadings);
} else
{
request = new GHRequest(infoPoints, favoredDirections);
request = new GHRequest(infoPoints, favoredHeadings);
}
} else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testBasicQuery() throws Exception
public void testQuerywithDirections() throws Exception
{
// Note, in general specifying directions does not work with CH, but this is an example where it works
JSONObject json = query("point=42.496696,1.499323&point=42.497257,1.501501&direction=4&direction=4", 200);
JSONObject json = query("point=42.496696,1.499323&point=42.497257,1.501501&heading=4&heading=4", 200);
JSONObject infoJson = json.getJSONObject("info");
assertFalse(infoJson.has("errors"));
JSONObject path = json.getJSONArray("paths").getJSONObject(0);
Expand Down

0 comments on commit a514273

Please sign in to comment.