diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 13d7187..c271fff 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -432,7 +432,7 @@ public class RoutingEngine extends Thread private void resetCache() { nodesMap = new OsmNodesMap(); - nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay.lookupVersion, routingContext.carMode, nodesCache ); + nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay.lookupVersion,routingContext.expctxWay.lookupMinorVersion, routingContext.carMode, nodesCache ); } private OsmNode getStartNode( long startId ) diff --git a/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java b/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java index efca5bd..d600025 100644 --- a/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java +++ b/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java @@ -24,6 +24,7 @@ public final class BExpressionContext { private static final String CONTEXT_TAG = "---context:"; private static final String VERSION_TAG = "---lookupversion:"; + private static final String MINOR_VERSION_TAG = "---minorversion:"; private static final String VARLENGTH_TAG = "---readvarlength"; private String context; @@ -78,6 +79,7 @@ public final class BExpressionContext private int linenr; public short lookupVersion = -1; + public short lookupMinorVersion = -1; public boolean readVarLength = false; public BExpressionContext( String context ) @@ -104,7 +106,7 @@ public final class BExpressionContext /** - * encode lookup data to a byte array + * encode internal lookup data to a byte array */ public byte[] encode() { @@ -130,12 +132,15 @@ public final class BExpressionContext skippedTags++; continue; } - ctx.encodeDistance( skippedTags ); + ctx.encodeDistance( skippedTags+1 ); skippedTags = 0; - int n = lookupValues.get(inum).length - 2; - if ( n > 1 ) ctx.encode( n, d-1 ); // booleans are encoded just by presence... + + // 0 excluded already, 1 (=unknown) we rotate up to 8 + // to have the good code space for the popular values + int dd = d < 2 ? 7 : ( d < 9 ? d - 2 : d - 1); + ctx.encodeDistance( dd ); } - ctx.encodeDistance( skippedTags ); + ctx.encodeDistance( 0 ); int len = ctx.getEncodedLength(); byte[] ab = new byte[len]; System.arraycopy( abBuf, 0, ab, 0, len ); @@ -148,12 +153,20 @@ public final class BExpressionContext } + /** + * decode byte array to internal lookup data + */ + public void decode( byte[] ab ) + { + decode( lookupData, ab ); + } + /** * decode a byte-array into a lookup data array */ public void decode( int[] ld, byte[] ab ) { - if ( ab.length == 8 ) { decodeFix( ld, ab ); return; } + if ( !readVarLength ) { decodeFix( ld, ab ); return; } BitCoderContext ctx = new BitCoderContext(ab); @@ -161,21 +174,22 @@ public final class BExpressionContext ld[0] = ctx.decodeBit() ? 2 : 0; // all others are generic - for( int inum = 1; inum < lookupValues.size(); inum++ ) // loop over lookup names + int inum = 1; + for(;;) { - int skip = ctx.decodeDistance(); - while ( skip-- > 0 ) ld[inum++] = 0; - if ( inum >= lookupValues.size() ) break; - int n = lookupValues.get(inum).length - 2; - if ( n > 1 ) - { - ld[inum] = ctx.decode( n ) + 1; - } - else - { - ld[inum] = 2; // boolean - } + int delta = ctx.decodeDistance(); + if ( delta == 0) break; + if ( inum + delta > ld.length ) break; // higher minor version is o.k. + + while ( delta-- > 1 ) ld[inum++] = 0; + + // see encoder for value rotation + int dd = ctx.decodeDistance(); + int d = dd == 7 ? 1 : ( dd < 7 ? dd + 2 : dd + 1); + if ( d >= lookupValues.get(inum).length ) d = 1; // map out-of-range to unkown + ld[inum++] = d; } + while( inum < ld.length ) ld[inum++] = 0; } /** @@ -243,7 +257,10 @@ public final class BExpressionContext for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names { BExpressionLookupValue[] va = lookupValues.get(inum); - String value = va[lookupData[inum]].toString(); + int dataIdx = lookupData[inum]; + if ( dataIdx >= va.length ) + throw new RuntimeException( "ups, inum=" + inum + " dataIdx=" + dataIdx + " va.length=" + va.length + " sb=" + sb ); + String value = va[dataIdx].toString(); if ( value != null && value.length() > 0 ) { sb.append( " " + lookupNames.get( inum ) + "=" + value ); @@ -277,6 +294,11 @@ public final class BExpressionContext lookupVersion = Short.parseShort( line.substring( VERSION_TAG.length() ) ); continue; } + if ( line.startsWith( MINOR_VERSION_TAG ) ) + { + lookupMinorVersion = Short.parseShort( line.substring( MINOR_VERSION_TAG.length() ) ); + continue; + } if ( line.startsWith( VARLENGTH_TAG ) ) { readVarLength = true; diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java b/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java index f9c6c02..0d2085e 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java @@ -58,11 +58,11 @@ public class OsmCutter extends MapCreatorBase _expctxWay = new BExpressionContext("way"); _expctxWay.readMetaData( lookupFile ); - _expctxWayStat = new BExpressionContext("way"); +// _expctxWayStat = new BExpressionContext("way"); _expctxNode = new BExpressionContext("node"); _expctxNode.readMetaData( lookupFile ); - _expctxNodeStat = new BExpressionContext("node"); +// _expctxNodeStat = new BExpressionContext("node"); this.outTileDir = outTileDir; if ( !outTileDir.isDirectory() ) throw new RuntimeException( "out tile directory " + outTileDir + " does not exist" ); @@ -82,10 +82,10 @@ public class OsmCutter extends MapCreatorBase wayDos.close(); cyclewayDos.close(); - System.out.println( "-------- way-statistics -------- " ); - _expctxWayStat.dumpStatistics(); - System.out.println( "-------- node-statistics -------- " ); - _expctxNodeStat.dumpStatistics(); +// System.out.println( "-------- way-statistics -------- " ); +// _expctxWayStat.dumpStatistics(); +// System.out.println( "-------- node-statistics -------- " ); +// _expctxNodeStat.dumpStatistics(); System.out.println( statsLine() ); } @@ -114,7 +114,7 @@ public class OsmCutter extends MapCreatorBase { String value = n.getTag( key ); _expctxNode.addLookupValue( key, value, lookupData ); - _expctxNodeStat.addLookupValue( key, value, null ); +// _expctxNodeStat.addLookupValue( key, value, null ); } n.description = _expctxNode.encode(lookupData); } @@ -161,7 +161,7 @@ public class OsmCutter extends MapCreatorBase { String value = w.getTag( key ); _expctxWay.addLookupValue( key, value, lookupData ); - _expctxWayStat.addLookupValue( key, value, null ); +// _expctxWayStat.addLookupValue( key, value, null ); } w.description = _expctxWay.encode(lookupData); } diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/RelationMerger.java b/brouter-map-creator/src/main/java/btools/mapcreator/RelationMerger.java index 808fe64..601d195 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/RelationMerger.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/RelationMerger.java @@ -23,7 +23,7 @@ public class RelationMerger extends MapCreatorBase private CompactLongSet routesetall; private BExpressionContext expctxReport; private BExpressionContext expctxCheck; - private BExpressionContext expctxStat; + // private BExpressionContext expctxStat; private DataOutputStream wayOutStream; @@ -48,7 +48,7 @@ public class RelationMerger extends MapCreatorBase expctxCheck = new BExpressionContext("way"); expctxCheck.readMetaData( lookupFile ); expctxCheck.parseFile( checkProfile, "global" ); - expctxStat = new BExpressionContext("way"); + // expctxStat = new BExpressionContext("way"); // *** read the relation file into sets for each processed tag routesets = new HashMap(); @@ -78,7 +78,7 @@ public class RelationMerger extends MapCreatorBase { long wid = readId( dis ); if ( wid == -1 ) break; - expctxStat.addLookupValue( tagname, "yes", null ); + // expctxStat.addLookupValue( tagname, "yes", null ); if ( routeset != null && !routeset.contains( wid ) ) { routeset.add( wid ); @@ -103,8 +103,8 @@ public class RelationMerger extends MapCreatorBase new WayIterator( this, true ).processFile( wayFileIn ); wayOutStream.close(); - System.out.println( "-------- route-statistics -------- " ); - expctxStat.dumpStatistics(); +// System.out.println( "-------- route-statistics -------- " ); +// expctxStat.dumpStatistics(); } @Override diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java b/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java index 983915b..a667ed1 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java @@ -39,6 +39,7 @@ public class WayLinker extends MapCreatorBase private List nodesList; private CompactLongSet borderSet; private short lookupVersion; + private short lookupMinorVersion; private long creationTimeStamp; @@ -59,7 +60,7 @@ public class WayLinker extends MapCreatorBase public static void main(String[] args) throws Exception { - System.out.println("*** WayLinker: Format a regionof an OSM map for routing"); + System.out.println("*** WayLinker: Format a region of an OSM map for routing"); if (args.length != 7) { System.out.println("usage: java WayLinker "); @@ -79,6 +80,7 @@ public class WayLinker extends MapCreatorBase expctxWay = new BExpressionContext("way"); expctxWay.readMetaData( lookupFile ); lookupVersion = expctxWay.lookupVersion; + lookupMinorVersion = expctxWay.lookupMinorVersion; expctxWay.parseFile( profileFile, "global" ); creationTimeStamp = System.currentTimeMillis(); @@ -152,13 +154,13 @@ public class WayLinker extends MapCreatorBase boolean ok = expctxWay.getCostfactor() < 10000.; expctxWay.evaluate( true, description, null ); ok |= expctxWay.getCostfactor() < 10000.; + if ( !ok ) return; byte bridgeTunnel = 0; + expctxWay.decode( description ); if ( expctxWay.getBooleanLookupValue( "bridge" ) ) bridgeTunnel |= OsmNodeP.BRIDGE_AND_BIT; if ( expctxWay.getBooleanLookupValue( "tunnel" ) ) bridgeTunnel |= OsmNodeP.TUNNEL_AND_BIT; - if ( !ok ) return; - OsmNodeP n1 = null; OsmNodeP n2 = null; for (int i=0; i> 48); - if ( readVersion != lookupVersion && lookupVersion != -1 ) + if ( i == 0 && lookupVersion != -1 && readVersion != lookupVersion ) { throw new IllegalArgumentException( "lookup version mismatch (old rd5?) lookups.dat=" + lookupVersion + " " + f. getAbsolutePath() + "=" + readVersion ); } + if ( i == 1 && lookupMinorVersion != -1 && readVersion < lookupMinorVersion ) + { + throw new IllegalArgumentException( "lookup minor version mismatch (old rd5?) lookups.dat=" + + lookupMinorVersion + " " + f. getAbsolutePath() + "=" + readVersion ); + } fileIndex[i] = lv & 0xffffffffffffL; } diff --git a/brouter-server/src/main/java/btools/server/BRouter.java b/brouter-server/src/main/java/btools/server/BRouter.java index a178d10..c5dc022 100644 --- a/brouter-server/src/main/java/btools/server/BRouter.java +++ b/brouter-server/src/main/java/btools/server/BRouter.java @@ -84,7 +84,7 @@ public class BRouter } System.exit(0); } - System.out.println("BRouter 0.9.9 / 18042014 / abrensch"); + System.out.println("BRouter 1.0 / 01062014 / abrensch"); if ( args.length < 6 ) { System.out.println("Find routes in an OSM map");