Allow custom nogo weights
This should help taking into account road works for instance.
This commit is contained in:
parent
d95a200070
commit
910d6a0870
4 changed files with 27 additions and 15 deletions
|
@ -11,12 +11,13 @@ public class OsmNodeNamed extends OsmNode
|
|||
{
|
||||
public String name;
|
||||
public double radius; // radius of nogopoint (in meters)
|
||||
public double nogoWeight; // weight for nogopoint
|
||||
public boolean isNogo = false;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return ilon + "," + ilat + "," + name;
|
||||
return ilon + "," + ilat + "," + name + "," + nogoWeight;
|
||||
}
|
||||
|
||||
public static OsmNodeNamed decodeNogo( String s )
|
||||
|
@ -26,7 +27,14 @@ public class OsmNodeNamed extends OsmNode
|
|||
n.ilon = Integer.parseInt( s.substring( 0, idx1 ) );
|
||||
int idx2 = s.indexOf( ',', idx1+1 );
|
||||
n.ilat = Integer.parseInt( s.substring( idx1+1, idx2 ) );
|
||||
int idx3 = s.indexOf( ',', idx2+1 );
|
||||
if ( idx3 == -1) {
|
||||
n.name = s.substring( idx2 + 1 );
|
||||
n.nogoWeight = 100000;
|
||||
} else {
|
||||
n.name = s.substring( idx2+1, idx3 );
|
||||
n.nogoWeight = Double.parseDouble( s.substring( idx3 + 1 ) );
|
||||
}
|
||||
n.isNogo = true;
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ abstract class OsmPath implements OsmLinkHolder
|
|||
|
||||
boolean recordTransferNodes = detailMode || rc.countTraffic;
|
||||
|
||||
rc.nogomatch = false;
|
||||
rc.nogomatch = null;
|
||||
|
||||
// extract the 3 positions of the first section
|
||||
int lon0 = origin.originLon;
|
||||
|
@ -425,9 +425,9 @@ abstract class OsmPath implements OsmLinkHolder
|
|||
originElement.message = message;
|
||||
}
|
||||
}
|
||||
if ( rc.nogomatch )
|
||||
if ( rc.nogomatch != null )
|
||||
{
|
||||
cost = -1;
|
||||
cost += rc.nogomatch.nogoWeight;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -460,10 +460,9 @@ abstract class OsmPath implements OsmLinkHolder
|
|||
}
|
||||
|
||||
// check for nogo-matches (after the *actual* start of segment)
|
||||
if ( rc.nogomatch )
|
||||
if ( rc.nogomatch != null )
|
||||
{
|
||||
cost = -1;
|
||||
return;
|
||||
cost += rc.nogomatch.nogoWeight;
|
||||
}
|
||||
|
||||
// add target-node costs
|
||||
|
|
|
@ -194,7 +194,7 @@ public final class RoutingContext
|
|||
public boolean startDirectionValid;
|
||||
|
||||
private double cosangle;
|
||||
public boolean nogomatch = false;
|
||||
public OsmNodeNamed nogomatch = null;
|
||||
public boolean isEndpoint = false;
|
||||
|
||||
public boolean shortestmatch = false;
|
||||
|
@ -347,7 +347,7 @@ public final class RoutingContext
|
|||
if (!(nogo instanceof OsmNogoPolygon)
|
||||
|| ((OsmNogoPolygon)nogo).intersects(lon1, lat1, lon2, lat2))
|
||||
{
|
||||
nogomatch = true;
|
||||
nogomatch = nogo;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -388,7 +388,7 @@ public final class RoutingContext
|
|||
}
|
||||
else
|
||||
{
|
||||
nogomatch = false;
|
||||
nogomatch = null;
|
||||
lon1 = ilonshortest;
|
||||
lat1 = ilatshortest;
|
||||
}
|
||||
|
|
|
@ -222,24 +222,29 @@ public class ServerHandler extends RequestHandler {
|
|||
for (int i = 0; i < lonLatRadList.length; i++)
|
||||
{
|
||||
String[] lonLatRad = lonLatRadList[i].split(",");
|
||||
nogoList.add(readNogo(lonLatRad[0], lonLatRad[1], lonLatRad[2]));
|
||||
String nogoWeight = "100000";
|
||||
if (lonLatRad.length > 3) {
|
||||
nogoWeight = lonLatRad[3];
|
||||
}
|
||||
nogoList.add(readNogo(lonLatRad[0], lonLatRad[1], lonLatRad[2], nogoWeight));
|
||||
}
|
||||
|
||||
return nogoList;
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readNogo( String lon, String lat, String radius )
|
||||
private static OsmNodeNamed readNogo( String lon, String lat, String radius, String nogoWeight )
|
||||
{
|
||||
return readNogo(Double.parseDouble( lon ), Double.parseDouble( lat ), Integer.parseInt( radius ) );
|
||||
return readNogo(Double.parseDouble( lon ), Double.parseDouble( lat ), Integer.parseInt( radius ), Double.parseDouble( nogoWeight ));
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readNogo( double lon, double lat, int radius )
|
||||
private static OsmNodeNamed readNogo( double lon, double lat, int radius, double nogoWeight )
|
||||
{
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = "nogo" + radius;
|
||||
n.ilon = (int)( ( lon + 180. ) *1000000. + 0.5);
|
||||
n.ilat = (int)( ( lat + 90. ) *1000000. + 0.5);
|
||||
n.isNogo = true;
|
||||
n.nogoWeight = nogoWeight;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue