lifecycle-patch, first shot

This commit is contained in:
Arndt 2015-08-28 17:21:34 +02:00
parent 91c809e05c
commit 87fe904e7b
3 changed files with 47 additions and 118 deletions

View file

@ -535,13 +535,8 @@ public class RoutingEngine extends Thread
private OsmNode getStartNode( long startId )
{
// initialize the start-node
OsmNode start = nodesMap.get( startId );
if ( start == null )
{
start = new OsmNode( startId );
start.setHollow();
nodesMap.put( startId, start );
}
OsmNode start = new OsmNode( startId );
start.setHollow();
if ( !nodesCache.obtainNonHollowNode( start ) )
{
return null;
@ -678,14 +673,27 @@ public class RoutingEngine extends Thread
long startNodeId1 = startWp.node1.getIdFromPos();
long startNodeId2 = startWp.node2.getIdFromPos();
OsmNodeNamed startPos = startWp.crosspoint;
OsmNodeNamed endPos = endWp == null ? null : endWp.crosspoint;
boolean sameSegmentSearch = ( startNodeId1 == endNodeId1 && startNodeId2 == endNodeId2 )
|| ( startNodeId1 == endNodeId2 && startNodeId2 == endNodeId1 );
OsmNode start1 = getStartNode( startNodeId1 );
OsmNode start2 = getStartNode( startNodeId2 );
if ( start1 == null ) return null;
OsmNode start2 = null;
for( OsmLink link = start1.firstlink; link != null; link = link.next )
{
if ( link.targetNode.getIdFromPos() == startNodeId2 )
{
start2 = link.targetNode;
break;
}
}
if ( start2 == null ) return null;
if ( start1 == null || start2 == null ) return null;
OsmPath startPath1 = getStartPath( start1, start2, startWp, endPos, sameSegmentSearch );
@ -799,7 +807,6 @@ public class RoutingEngine extends Thread
if ( !currentNode.wasProcessed )
{
expandHollowLinkTargets( currentNode, true );
nodesMap.removeCompletedNodes();
}
if ( sourceNode != null )

View file

@ -75,9 +75,6 @@ public class OsmNode implements OsmPos
return selev / 4.;
}
/**
* Whether there's a traffic signal
*/
/**
* The links to other nodes
@ -86,11 +83,7 @@ public class OsmNode implements OsmPos
public OsmLink firstreverse = null;
// whether this node is completed and registerd for map-removal
public boolean completed;
public boolean wasProcessed;
public int maxcost; // maximum cost to consider for that node
public boolean wasProcessed; // whether this node has all it's links resolved
public void addLink( OsmLink link )
{
@ -120,6 +113,9 @@ public class OsmNode implements OsmPos
OsmLink lastlink = null;
OsmLink firstHollowLink = firstlink;
firstlink = null;
int lonIdx = ilon/62500;
int latIdx = ilat/62500;
@ -137,7 +133,6 @@ public class OsmNode implements OsmPos
for(;;)
{
int bitField = is.readByte();
// System.out.println( "parseNodeBody: var=" + readVarLength + " bitField=" + bitField );
if ( readVarLength )
{
int dlon = is.readVarLengthUnsigned();
@ -226,7 +221,7 @@ public class OsmNode implements OsmPos
{
if ( !dc.isWithinRadius( ilon, ilat, firstTransferNode, linklon, linklat ) )
{
continue;
// continue;
}
}
@ -245,23 +240,36 @@ public class OsmNode implements OsmPos
}
lastlink = link;
OsmNode tn = null;
long targetNodeId = ((long)linklon)<<32 | linklat;
OsmNode tn = hollowNodes.get( targetNodeId ); // target node
if ( tn == null )
// first check the hollow links for that target
for( OsmLink l = firstHollowLink; l != null; l = l.next )
{
// node not yet known, create a hollow proxy
tn = new OsmNode(linklon, linklat);
tn.setHollow();
hollowNodes.put( targetNodeId, tn );
OsmNode t = l.targetNode;
if ( t.ilon == linklon && t.ilat == linklat )
{
System.out.println( "found target in hollow links: " + t.getIdFromPos() );
tn = t;
break;
}
}
else
if ( tn == null ) // then check the hollow-nodes
{
if ( !( tn.isHollow() || tn.hasHollowLinks() ) )
long targetNodeId = ((long)linklon)<<32 | linklat;
tn = hollowNodes.get( targetNodeId ); // target node
if ( tn == null ) // node not yet known, create a new hollow proxy
{
hollowNodes.registerCompletedNode( tn );
tn = new OsmNode(linklon, linklat);
tn.setHollow();
hollowNodes.put( targetNodeId, tn );
}
System.out.println( "registering : " + getIdFromPos() + " at hollow " + tn.getIdFromPos() );
OsmLink hollowLink = new OsmLink();
hollowLink.targetNode = this;
tn.addLink( hollowLink ); // make us known at the hollow link
}
link.targetNode = tn;
@ -303,10 +311,7 @@ public class OsmNode implements OsmPos
}
if ( !hasHollowLinks() )
{
hollowNodes.registerCompletedNode( this );
}
hollowNodes.remove( getIdFromPos() );
}
public boolean isHollow()
@ -324,27 +329,6 @@ public class OsmNode implements OsmPos
return ((long)ilon)<<32 | ilat;
}
public boolean hasHollowLinks()
{
for( OsmLink link = firstlink; link != null; link = link.next )
{
if ( link.targetNode.isHollow() ) return true;
}
return false;
}
public int linkCnt()
{
int cnt = 0;
for( OsmLink link = firstlink; link != null; link = link.next )
{
cnt++;
}
return cnt;
}
public void unlinkLink( OsmLink link )
{
if ( link == firstlink )

View file

@ -20,8 +20,6 @@ public final class OsmNodesMap
return abUnifier;
}
private NodesList completedNodes = null;
/**
* Get a node from the map
* @return the node for the given id if exist, else null
@ -37,25 +35,6 @@ public final class OsmNodesMap
hmap.remove( new Long( id ) );
}
public void removeCompletedNodes()
{
for( NodesList le = completedNodes; le != null; le = le.next )
{
remove( le.node.getIdFromPos() );
}
completedNodes = null;
}
public void registerCompletedNode( OsmNode n )
{
if ( n.completed ) return;
n.completed = true;
NodesList le = new NodesList();
le.node = n;
if ( completedNodes != null ) le.next = completedNodes;
completedNodes = le;
}
/**
* Put a node into the map
* @return the previous node if that id existed, else null
@ -65,15 +44,6 @@ public final class OsmNodesMap
return hmap.put( new Long( id ), node );
}
/**
* Return the internal list.
* A reference is returned, not a copy-
* @return the nodes list
*/
public Collection<OsmNode> nodes()
{
return hmap.values();
}
/**
* @return the number of nodes in that map
@ -83,36 +53,4 @@ public final class OsmNodesMap
return hmap.size();
}
/**
* cleanup the map by removing the nodes
* with no hollow issues
*/
private int dontCareCount = 0;
public void removeCompleteNodes()
{
if ( ++dontCareCount < 5 ) return;
dontCareCount = 0;
ArrayList<OsmNode> delNodes = new ArrayList<OsmNode>();
for( OsmNode n : hmap.values() )
{
if ( n.isHollow() || n.hasHollowLinks() )
{
continue;
}
delNodes.add( n );
}
if ( delNodes.size() > 0 )
{
// System.out.println( "removing " + delNodes.size() + " nodes" );
for( OsmNode n : delNodes )
{
hmap.remove( new Long( n.getIdFromPos() ) );
}
}
}
}