1.0 preparations
This commit is contained in:
parent
e13d1ad468
commit
fb4bf8e0cd
9 changed files with 169 additions and 27 deletions
|
@ -11,6 +11,7 @@ import java.io.BufferedReader;
|
|||
import java.io.BufferedWriter;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -25,6 +26,7 @@ import btools.util.FrozenLongMap;
|
|||
public final class OsmTrack
|
||||
{
|
||||
public MatchedWaypoint endPoint;
|
||||
public long[] nogoChecksums;
|
||||
|
||||
private class OsmPathElementHolder
|
||||
{
|
||||
|
@ -86,10 +88,13 @@ public final class OsmTrack
|
|||
{
|
||||
node.writeToStream( dos );
|
||||
}
|
||||
dos.writeLong( nogoChecksums[0] );
|
||||
dos.writeLong( nogoChecksums[1] );
|
||||
dos.writeLong( nogoChecksums[2] );
|
||||
dos.close();
|
||||
}
|
||||
|
||||
public static OsmTrack readBinary( String filename, OsmNodeNamed newEp )
|
||||
public static OsmTrack readBinary( String filename, OsmNodeNamed newEp, long[] nogoChecksums )
|
||||
{
|
||||
OsmTrack t = null;
|
||||
if ( filename != null )
|
||||
|
@ -119,7 +124,18 @@ public final class OsmTrack
|
|||
t.cost = last_pe.cost;
|
||||
t.buildMap();
|
||||
}
|
||||
long[] al = new long[3];
|
||||
try
|
||||
{
|
||||
al[0] = dis.readLong();
|
||||
al[1] = dis.readLong();
|
||||
al[2] = dis.readLong();
|
||||
} catch( EOFException eof ) { /* kind of expected */ }
|
||||
dis.close();
|
||||
boolean nogoCheckOk = Math.abs( al[0] - nogoChecksums[0] ) <= 20
|
||||
&& Math.abs( al[1] - nogoChecksums[1] ) <= 20
|
||||
&& Math.abs( al[2] - nogoChecksums[2] ) <= 20;
|
||||
if ( !nogoCheckOk ) return null;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
|
|
|
@ -92,6 +92,20 @@ public final class RoutingContext implements DistanceChecker
|
|||
}
|
||||
}
|
||||
|
||||
public long[] getNogoChecksums()
|
||||
{
|
||||
long[] cs = new long[3];
|
||||
int n = nogopoints == null ? 0 : nogopoints.size();
|
||||
for( int i=0; i<n; i++ )
|
||||
{
|
||||
OsmNodeNamed nogo = nogopoints.get(i);
|
||||
cs[0] += nogo.ilon;
|
||||
cs[1] += nogo.ilat;
|
||||
cs[2] += (long) ( nogo.radius*111894.*10.);
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
public void setWaypoint( OsmNodeNamed wp, boolean endpoint )
|
||||
{
|
||||
keepnogopoints = nogopoints;
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package btools.router;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import btools.expressions.BExpressionContext;
|
||||
|
@ -30,10 +34,12 @@ public class RoutingEngine extends Thread
|
|||
|
||||
private volatile boolean terminated;
|
||||
|
||||
private File profileDir;
|
||||
private String segmentDir;
|
||||
private String outfileBase;
|
||||
private String logfileBase;
|
||||
private boolean infoLogEnabled;
|
||||
private Writer infoLogWriter;
|
||||
private RoutingContext routingContext;
|
||||
|
||||
private double airDistanceCostFactor;
|
||||
|
@ -59,7 +65,6 @@ public class RoutingEngine extends Thread
|
|||
if ( rc.localFunction != null )
|
||||
{
|
||||
String profileBaseDir = System.getProperty( "profileBaseDir" );
|
||||
File profileDir;
|
||||
File profileFile;
|
||||
if ( profileBaseDir == null )
|
||||
{
|
||||
|
@ -95,6 +100,18 @@ public class RoutingEngine extends Thread
|
|||
{
|
||||
System.out.println( s );
|
||||
}
|
||||
if ( infoLogWriter != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
infoLogWriter.write( s );
|
||||
infoLogWriter.write( '\n' );
|
||||
}
|
||||
catch( IOException io )
|
||||
{
|
||||
infoLogWriter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
|
@ -106,6 +123,13 @@ public class RoutingEngine extends Thread
|
|||
{
|
||||
try
|
||||
{
|
||||
File debugLog = new File( profileDir, "../debug.txt" );
|
||||
if ( debugLog.exists() )
|
||||
{
|
||||
infoLogWriter = new FileWriter( debugLog, true );
|
||||
logInfo( "start request at " + new Date() );
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
this.maxRunningTime = maxRunningTime;
|
||||
OsmTrack sum = null;
|
||||
|
@ -196,6 +220,12 @@ public class RoutingEngine extends Thread
|
|||
}
|
||||
openSet.clear();
|
||||
finished = true; // this signals termination to outside
|
||||
|
||||
if ( infoLogWriter != null )
|
||||
{
|
||||
try { infoLogWriter.close(); } catch( Exception e ) {}
|
||||
infoLogWriter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +248,7 @@ public class RoutingEngine extends Thread
|
|||
OsmTrack nearbyTrack = null;
|
||||
if ( refTrack == null )
|
||||
{
|
||||
nearbyTrack = OsmTrack.readBinary( routingContext.rawTrackPath, waypoints.get( waypoints.size()-1) );
|
||||
nearbyTrack = OsmTrack.readBinary( routingContext.rawTrackPath, waypoints.get( waypoints.size()-1), routingContext.getNogoChecksums() );
|
||||
if ( nearbyTrack != null )
|
||||
{
|
||||
wayointIds[waypoints.size()-1] = nearbyTrack.endPoint;
|
||||
|
@ -375,6 +405,8 @@ public class RoutingEngine extends Thread
|
|||
if ( matchPath != null )
|
||||
{
|
||||
track = mergeTrack( matchPath, nearbyTrack );
|
||||
isDirty = true;
|
||||
logInfo( "using fast partial recalc" );
|
||||
}
|
||||
maxRunningTime += System.currentTimeMillis() - startTime; // reset timeout...
|
||||
}
|
||||
|
@ -396,6 +428,7 @@ public class RoutingEngine extends Thread
|
|||
{
|
||||
// ups, didn't find it, use a merge
|
||||
t = mergeTrack( matchPath, track );
|
||||
logInfo( "using sloppy merge cause pass1 didn't reach destination" );
|
||||
}
|
||||
if ( t != null )
|
||||
{
|
||||
|
@ -411,7 +444,9 @@ public class RoutingEngine extends Thread
|
|||
|
||||
if ( refTrack == null && !isDirty )
|
||||
{
|
||||
logInfo( "supplying new reference track" );
|
||||
track.endPoint = endWp;
|
||||
track.nogoChecksums = routingContext.getNogoChecksums();
|
||||
foundRawTrack = track;
|
||||
}
|
||||
|
||||
|
@ -577,7 +612,8 @@ public class RoutingEngine extends Thread
|
|||
int firstMatchCost = 1000000000;
|
||||
int firstEstimate = 1000000000;
|
||||
|
||||
logInfo( "findtrack with maxTotalCost=" + maxTotalCost + " airDistanceCostFactor=" + airDistanceCostFactor );
|
||||
logInfo( "findtrack with airDistanceCostFactor=" + airDistanceCostFactor );
|
||||
if (costCuttingTrack != null ) logInfo( "costCuttingTrack.cost=" + costCuttingTrack.cost );
|
||||
|
||||
matchPath = null;
|
||||
int nodesVisited = 0;
|
||||
|
@ -602,6 +638,20 @@ public class RoutingEngine extends Thread
|
|||
|
||||
int maxAdjCostFromQueue = 0;
|
||||
|
||||
// check for an INITIAL match with the cost-cutting-track
|
||||
if ( costCuttingTrack != null )
|
||||
{
|
||||
OsmPathElement pe1 = costCuttingTrack.getLink( startNodeId1, startNodeId2 );
|
||||
if ( pe1 != null ) { logInfo( "initialMatch pe1.cost=" + pe1.cost );
|
||||
int c = startPath1.cost - pe1.cost; if ( c < 0 ) c = 0; if ( c < firstMatchCost ) firstMatchCost = c; }
|
||||
|
||||
OsmPathElement pe2 = costCuttingTrack.getLink( startNodeId2, startNodeId1 );
|
||||
if ( pe2 != null ) { logInfo( "initialMatch pe2.cost=" + pe2.cost );
|
||||
int c = startPath2.cost - pe2.cost; if ( c < 0 ) c = 0; if ( c < firstMatchCost ) firstMatchCost = c; }
|
||||
|
||||
if ( firstMatchCost < 1000000000 ) logInfo( "firstMatchCost from initial match=" + firstMatchCost );
|
||||
}
|
||||
|
||||
synchronized( openSet )
|
||||
{
|
||||
openSet.clear();
|
||||
|
@ -634,6 +684,7 @@ public class RoutingEngine extends Thread
|
|||
|
||||
if ( matchPath != null && fastPartialRecalc && firstMatchCost < 500 && path.cost > 30L*firstMatchCost )
|
||||
{
|
||||
logInfo( "early exit: firstMatchCost=" + firstMatchCost + " path.cost=" + path.cost );
|
||||
throw new IllegalArgumentException( "early exit for a close recalc" );
|
||||
}
|
||||
|
||||
|
@ -664,6 +715,11 @@ public class RoutingEngine extends Thread
|
|||
{
|
||||
// remember first match cost for fast termination of partial recalcs
|
||||
int parentcost = path.originElement == null ? 0 : path.originElement.cost;
|
||||
|
||||
// hitting start-element of costCuttingTrack?
|
||||
int c = path.cost - parentcost - pe.cost;
|
||||
if ( c > 0 ) parentcost += c;
|
||||
|
||||
if ( parentcost < firstMatchCost ) firstMatchCost = parentcost;
|
||||
|
||||
int costEstimate = path.cost
|
||||
|
|
Binary file not shown.
|
@ -3,7 +3,13 @@ package btools.routingapp;
|
|||
|
||||
public class BInstallerSizes {
|
||||
|
||||
public static int[] rd5_sizes = {
|
||||
public static int getRd5Size( int idx )
|
||||
{
|
||||
int i = rd5_sizes[idx];
|
||||
return (3*i)/4;
|
||||
}
|
||||
|
||||
private static int[] rd5_sizes = {
|
||||
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,73999,0,0,
|
||||
|
@ -223,6 +229,12 @@ public class BInstallerSizes {
|
|||
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
};
|
||||
|
||||
public static int getCd5Size( int idx )
|
||||
{
|
||||
int i = cd5_sizes[idx];
|
||||
return (3*i)/4;
|
||||
}
|
||||
|
||||
public static int[] cd5_sizes = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,70091,0,0,
|
||||
|
|
|
@ -39,6 +39,10 @@ public class BInstallerView extends View
|
|||
9, 8, 9, 8,
|
||||
12, 12, 12, 12 };
|
||||
|
||||
private int imgwOrig;
|
||||
private int imghOrig;
|
||||
private float scaleOrig;
|
||||
|
||||
private int imgw;
|
||||
private int imgh;
|
||||
|
||||
|
@ -132,7 +136,7 @@ public class BInstallerView extends View
|
|||
boolean isCd5 = (mask == 2);
|
||||
if ( ( s & mask ) != 0 && ( s & (mask*4)) == 0 )
|
||||
{
|
||||
int tilesize = isCd5 ? BInstallerSizes.cd5_sizes[tidx] : BInstallerSizes.rd5_sizes[tidx];
|
||||
int tilesize = isCd5 ? BInstallerSizes.getCd5Size(tidx) : BInstallerSizes.getRd5Size(tidx);
|
||||
if ( tilesize > 0 && tilesize < min_size )
|
||||
{
|
||||
tidx_min = tidx;
|
||||
|
@ -229,6 +233,7 @@ public class BInstallerView extends View
|
|||
}
|
||||
|
||||
private Matrix mat;
|
||||
private Matrix matText;
|
||||
|
||||
public void startInstaller() {
|
||||
|
||||
|
@ -249,8 +254,8 @@ public class BInstallerView extends View
|
|||
tileStatus = new int[72*36];
|
||||
scanExistingFiles();
|
||||
|
||||
float scaleX = imgw / ((float)bmp.getWidth());
|
||||
float scaley = imgh / ((float)bmp.getHeight());
|
||||
float scaleX = imgwOrig / ((float)bmp.getWidth());
|
||||
float scaley = imghOrig / ((float)bmp.getHeight());
|
||||
|
||||
viewscale = scaleX < scaley ? scaleX : scaley;
|
||||
|
||||
|
@ -270,8 +275,17 @@ public class BInstallerView extends View
|
|||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
imgw = metrics.widthPixels;
|
||||
imgh = metrics.heightPixels;
|
||||
imgwOrig = metrics.widthPixels;
|
||||
imghOrig = metrics.heightPixels;
|
||||
int im = imgwOrig > imghOrig ? imgwOrig : imghOrig;
|
||||
|
||||
scaleOrig = im / 480.f;
|
||||
|
||||
matText = new Matrix();
|
||||
matText.preScale( scaleOrig, scaleOrig );
|
||||
|
||||
imgw = (int)(imgwOrig / scaleOrig);
|
||||
imgh = (int)(imghOrig / scaleOrig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -328,7 +342,7 @@ public class BInstallerView extends View
|
|||
pnt_2.setStrokeWidth(2);
|
||||
drawSelectedTiles( canvas, pnt_2, fw, fh, MASK_SELECTED_RD5, MASK_SELECTED_CD5, true, drawGrid );
|
||||
|
||||
canvas.setMatrix( null );
|
||||
canvas.setMatrix( matText );
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(Color.RED);
|
||||
|
@ -388,13 +402,13 @@ float tx, ty;
|
|||
boolean isCd5 = (tileStatus[tidx] & maskCd5) != 0;
|
||||
if ( isRd5 || isCd5 )
|
||||
{
|
||||
int tilesize = BInstallerSizes.rd5_sizes[tidx];
|
||||
int tilesize = BInstallerSizes.getRd5Size(tidx);
|
||||
if ( tilesize > 0 )
|
||||
{
|
||||
if ( doCount )
|
||||
{
|
||||
if ( isRd5) { rd5Tiles++; totalSize += BInstallerSizes.rd5_sizes[tidx]; };
|
||||
if ( isCd5) { cd5Tiles++; totalSize += BInstallerSizes.cd5_sizes[tidx]; };
|
||||
if ( isRd5) { rd5Tiles++; totalSize += BInstallerSizes.getRd5Size(tidx); };
|
||||
if ( isCd5) { cd5Tiles++; totalSize += BInstallerSizes.getCd5Size(tidx); };
|
||||
}
|
||||
if ( !doDraw ) continue;
|
||||
if ( isRd5 ) canvas.drawLine( fw*ix, fh*iy, fw*(ix+1), fh*(iy+1), pnt);
|
||||
|
@ -499,7 +513,7 @@ float tx, ty;
|
|||
}
|
||||
|
||||
// download button?
|
||||
if ( rd5Tiles + cd5Tiles > 0 && event.getX() > imgh - btnh && event.getY() > imgh-btnh )
|
||||
if ( rd5Tiles + cd5Tiles > 0 && event.getX() > imgwOrig - btnw*scaleOrig && event.getY() > imghOrig-btnh*scaleOrig )
|
||||
{
|
||||
toggleDownload();
|
||||
invalidate();
|
||||
|
|
|
@ -35,6 +35,7 @@ public class BRouterActivity extends Activity implements OnInitListener {
|
|||
private static final int DIALOG_PICKWAYPOINT_ID = 10;
|
||||
private static final int DIALOG_SELECTBASEDIR_ID = 11;
|
||||
private static final int DIALOG_MAINACTION_ID = 12;
|
||||
private static final int DIALOG_OLDDATAHINT_ID = 13;
|
||||
|
||||
private BRouterView mBRouterView;
|
||||
private PowerManager mPowerManager;
|
||||
|
@ -106,6 +107,21 @@ public class BRouterActivity extends Activity implements OnInitListener {
|
|||
}
|
||||
});
|
||||
return builder.create();
|
||||
case DIALOG_OLDDATAHINT_ID:
|
||||
builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle( "Local setup needs reset" )
|
||||
.setMessage( "You are currently using an old version of the lookup-table "
|
||||
+ "together with routing data made for this old table. "
|
||||
+ "Before downloading new datafiles made for the new table, "
|
||||
+ "you have to reset your local setup by 'moving away' (or deleting) "
|
||||
+ "your <basedir>/brouter directory and start a new setup by calling the "
|
||||
+ "BRouter App again." )
|
||||
.setPositiveButton( "OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
case DIALOG_ROUTINGMODES_ID:
|
||||
builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle( message );
|
||||
|
@ -318,9 +334,16 @@ public class BRouterActivity extends Activity implements OnInitListener {
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void startDownloadManager()
|
||||
{
|
||||
if ( !mBRouterView.hasUpToDateLookups() )
|
||||
{
|
||||
showDialog( DIALOG_OLDDATAHINT_ID );
|
||||
}
|
||||
else
|
||||
{
|
||||
showDialog( DIALOG_SHOW_DM_INFO_ID );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void selectBasedir( List<String> items, String defaultBasedir, String message )
|
||||
|
|
|
@ -191,12 +191,6 @@ public class BRouterView extends View
|
|||
if ( fileName.endsWith( ".cd5" ) ) segmentFound = true;
|
||||
}
|
||||
}
|
||||
if ( !segmentFound )
|
||||
{
|
||||
((BRouterActivity)getContext()).startDownloadManager();
|
||||
waitingForSelection = true;
|
||||
return;
|
||||
}
|
||||
|
||||
fileNames = new File( profileDir ).list();
|
||||
ArrayList<String> profiles = new ArrayList<String>();
|
||||
|
@ -222,6 +216,12 @@ public class BRouterView extends View
|
|||
+ " contains no routing profiles (*.brf)."
|
||||
+ " see www.dr-brenschede.de/brouter for setup instructions." );
|
||||
}
|
||||
if ( !segmentFound )
|
||||
{
|
||||
((BRouterActivity)getContext()).startDownloadManager();
|
||||
waitingForSelection = true;
|
||||
return;
|
||||
}
|
||||
((BRouterActivity)getContext()).selectProfile( profiles.toArray( new String[0]) );
|
||||
}
|
||||
catch( Exception e )
|
||||
|
@ -234,6 +234,13 @@ public class BRouterView extends View
|
|||
waitingForSelection = true;
|
||||
}
|
||||
|
||||
public boolean hasUpToDateLookups()
|
||||
{
|
||||
BExpressionMetaData meta = new BExpressionMetaData();
|
||||
meta.readMetaData( new File( profileDir, "lookups.dat" ) );
|
||||
return meta.lookupVersion == 10;
|
||||
}
|
||||
|
||||
public void continueProcessing()
|
||||
{
|
||||
waitingForSelection = false;
|
||||
|
|
|
@ -14,15 +14,15 @@ rm -rf /var/www/brouter/segments2_lastrun
|
|||
mkdir tmp
|
||||
cd tmp
|
||||
mkdir nodetiles
|
||||
/java/bin/java -Xmx256m -Xms256m -Xmn32m -cp ../pbfparser.jar:../brouter.jar btools.mapcreator.OsmCutter ../lookups.dat nodetiles ways.dat relations.dat ../planet-latest.osm.pbf
|
||||
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.RelationMerger ways.dat ways2.dat relations.dat ../lookups.dat ../trekking.brf ../softaccess.brf
|
||||
/java/bin/java -Xmx256m -Xms256m -Xmn32m -cp ../pbfparser.jar:../brouter.jar btools.mapcreator.OsmCutter ../lookups.dat nodetiles ways.dat relations.dat ../all.brf ../planet-latest.osm.pbf
|
||||
|
||||
mkdir ftiles
|
||||
/java/bin/java -Xmx512M -Xms512M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.NodeFilter nodetiles ways.dat ftiles
|
||||
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.RelationMerger ways.dat ways2.dat relations.dat ../lookups.dat ../trekking.brf ../softaccess.brf
|
||||
|
||||
mkdir waytiles
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.WayCutter ftiles ways.dat waytiles
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.WayCutter ftiles ways2.dat waytiles
|
||||
|
||||
mkdir waytiles55
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.WayCutter5 ftiles waytiles waytiles55 bordernids.dat
|
||||
|
|
Loading…
Reference in a new issue