Beispiel #1
0
	PortalRoute * PathPlanner::getRoute( unsigned int startID, unsigned int endID, float minWidth ) {
		RouteKey key = makeRouteKey( startID, endID );

		PortalRoute * route = 0x0;
		_routeLock.lockRead();
		PRouteMapItr itr = _routes.find( key );
		if ( itr != _routes.end() ) {
			// test the routes to see if they are passable
			PRouteListItr rItr = itr->second.begin();
			for ( ; rItr != itr->second.end(); ++rItr ) {
				if ( (*rItr)->_maxWidth > minWidth ) {
					if ( (*rItr)->_bestSmallest <= minWidth * 1.05f ) {
						route = *rItr;
					}
				}
			}
		} 
		_routeLock.releaseRead();

		// Compute a new path
		if ( route == 0x0 ) {
			return computeRoute( startID, endID, minWidth );
		} else {
			return route;
		}
	}
Beispiel #2
0
SUMOTime
RONet::saveAndRemoveRoutesUntil(OptionsCont& options, SUMOAbstractRouter<ROEdge, ROVehicle>& router,
                                SUMOTime time) {
    checkFlows(time);
    SUMOTime lastTime = -1;
    // write all vehicles (and additional structures)
    while (myVehicles.size() != 0 || myPersons.size() != 0) {
        // get the next vehicle and person
        const ROVehicle* const veh = myVehicles.getTopVehicle();
        const SUMOTime vehicleTime = veh == 0 ? SUMOTime_MAX : veh->getDepartureTime();
        PersonMap::iterator person = myPersons.begin();
        const SUMOTime personTime = person == myPersons.end() ? SUMOTime_MAX : person->first;
        // check whether it shall not yet be computed
        if (vehicleTime > time && personTime > time) {
            lastTime = MIN2(vehicleTime, personTime);
            break;
        }
        if (vehicleTime < personTime) {
            // check whether to print the output
            if (lastTime != vehicleTime && lastTime != -1) {
                // report writing progress
                if (options.getInt("stats-period") >= 0 && ((int) vehicleTime % options.getInt("stats-period")) == 0) {
                    WRITE_MESSAGE("Read: " + toString(myReadRouteNo) + ",  Discarded: " + toString(myDiscardedRouteNo) + ",  Written: " + toString(myWrittenRouteNo));
                }
            }
            lastTime = vehicleTime;

            // ok, compute the route (try it)
            if (computeRoute(options, router, veh)) {
                // write the route
                veh->saveAllAsXML(*myRoutesOutput, myRouteAlternativesOutput, myTypesOutput, options.getBool("exit-times"));
                myWrittenRouteNo++;
            } else {
                myDiscardedRouteNo++;
            }
            // delete routes and the vehicle
            if (veh->getRouteDefinition()->getID()[0] == '!') {
                if (!myRoutes.erase(veh->getRouteDefinition()->getID())) {
                    delete veh->getRouteDefinition();
                }
            }
            myVehicles.erase(veh->getID());
        } else {
            myRoutesOutput->writePreformattedTag(person->second);
            if (myRouteAlternativesOutput != 0) {
                myRouteAlternativesOutput->writePreformattedTag(person->second);
            }
            myPersons.erase(person);
        }
    }
    return lastTime;
}
bool ContractionHierarchiesClient::GetRoute( double* distance, QVector< Node>* pathNodes, QVector< Edge >* pathEdges, const IGPSLookup::Result& source, const IGPSLookup::Result& target )
{
	assert( distance != NULL );
	m_heapForward->Clear();
	m_heapBackward->Clear();

	*distance = computeRoute( source, target, pathNodes, pathEdges );
	if ( *distance == std::numeric_limits< int >::max() )
		return false;

	// is it shorter to drive along the edge?
	if ( target.source == source.source && target.target == source.target && source.edgeID == target.edgeID ) {
		EdgeIterator targetEdge = m_graph.findEdge( target.source, target.target, target.edgeID );
		double onEdgeDistance = fabs( target.percentage - source.percentage ) * targetEdge.distance();
		if ( onEdgeDistance < *distance ) {
			if ( ( targetEdge.forward() && targetEdge.backward() ) || source.percentage < target.percentage ) {
				if ( pathNodes != NULL && pathEdges != NULL )
				{
					pathNodes->clear();
					pathEdges->clear();
					pathNodes->push_back( source.nearestPoint );

					QVector< Node > tempNodes;
					if ( targetEdge.unpacked() )
						m_graph.path( targetEdge, &tempNodes, pathEdges, target.target == targetEdge.target() );
					else
						pathEdges->push_back( targetEdge.description() );

					if ( target.previousWayCoordinates < source.previousWayCoordinates ) {
						for ( unsigned pathID = target.previousWayCoordinates; pathID < source.previousWayCoordinates; pathID++ )
							pathNodes->push_back( tempNodes[pathID - 1] );
						std::reverse( pathNodes->begin() + 1, pathNodes->end() );
					} else {
						for ( unsigned pathID = source.previousWayCoordinates; pathID < target.previousWayCoordinates; pathID++ )
							pathNodes->push_back( tempNodes[pathID - 1] );
					}

					pathNodes->push_back( target.nearestPoint );
					pathEdges->front().length = pathNodes->size() - 1;
				}

				*distance = onEdgeDistance;
			}
		}
	}

	*distance /= 10;
	return true;
}