inline UpdateTrafficCostReplyPacket* RouteProcessor::processUpdateTrafficCostRequestPacket( const UpdateTrafficCostRequestPacket* updateCostsPacket) { mc2dbg2 << "RouteProcessor::processUpdateTrafficCostRequestPacket" << endl; // Temporary trick UpdateTrafficCostReplyPacket* reply = new UpdateTrafficCostReplyPacket( updateCostsPacket ); reply->setStatus(StringTable::OK); return reply; UpdateTrafficCostReplyPacket* replyPacket = NULL; if (updateCostsPacket != NULL) { uint32 mapID = updateCostsPacket->getMapID(); DEBUG8(updateCostsPacket->dump()); mc2dbg << "Updating map " << mapID << endl; // Get the CalcRoute for the map. CalcRoute* calcRoute = getCalcRoute(mapID); StringTable::stringCode status = StringTable::OK; if (calcRoute != NULL) { RoutingMap* mapToUpdate = calcRoute->getMap(); uint32 nbrNodesToUpdate = updateCostsPacket->getNbrCosts(); for (uint32 j = 0; j < nbrNodesToUpdate; j++) { uint32 nodeID = MAX_UINT32; uint32 cost = MAX_UINT32; if (updateCostsPacket->getCost(nodeID, cost, j)) { RoutingNode* node = mapToUpdate->getNodeFromTrueNodeNumber(nodeID); if (node != NULL) { RoutingConnection* connection = node->getFirstConnection(); while (connection != NULL) { RoutingConnectionData* connData = connection->getData(); // RoutingNode* toNode = // mapToUpdate->getNode(connection->getIndex()); RoutingNode* toNode = connection->getNode(); if ( toNode == NULL ) { mc2dbg << "Coulnd't find connection from " << hex << nodeID << " to node with index " << connection << endl; continue; } uint32 costC = connData->getCostB(0) + cost; mapToUpdate->changeConnectionCosts( node, connection, false, connData->getCostA(0), connData->getCostB(0), costC, connData->getVehicleRestriction(false)); connection = connection->getNext(); } } else { MC2WARNING("Node not found"); cerr << "map " << mapID << " nodeID: " << hex << nodeID << dec << " (" << nodeID << ")" << endl; status = StringTable::NOTFOUND; } } else { cerr << "Could not get cost " << j << endl; } } } else { handleMapNotFound(mapID, updateCostsPacket); status = StringTable::MAPNOTFOUND; } replyPacket = new UpdateTrafficCostReplyPacket(updateCostsPacket); replyPacket->setStatus(status); } // end if (calcRoute != NULL) return replyPacket; } // updateTrafficCostRequestPacket
int DisturbanceStorage::addDisturbances( const DisturbanceVector* distVect ) { int nbrDistAdded = 0; int nbrDist = distVect->size(); const bool isOverviewMap = MapBits::isOverviewMap( m_map->getMapID() ); for(int i=0; i < nbrDist; ++i ) { DisturbanceListElement* el = (*distVect)[i]; uint32 mapID = el->getMapID(); uint32 nodeID = el->getNodeID(); mc2dbg4 << "[DStor]: Element has ID " << IDPair_t(mapID, nodeID) << endl; if ( isOverviewMap && !MapBits::isOverviewMap( mapID ) ) { // We will have to translate the id uint32 higherID = m_map->translateToHigher( mapID, nodeID ); if ( higherID != MAX_UINT32 ) { mapID = m_map->getMapID(); nodeID = higherID; } else { // Not found - go another round continue; } } mc2dbg4 << "[DStor]: Dist-node has id = " << IDPair_t(mapID, nodeID) << endl; if ( mapID == m_map->getMapID() ) { RoutingNode* node = m_map->getNodeFromTrueNodeNumber(nodeID); if ( node == NULL ) { mc2dbg << "[DStor]: Coulnd't find node " << hex << nodeID << dec << endl; continue; } if ( el->getUseFactor() || el->getRawFactor() == MAX_UINT32 ) { mc2dbg8 << "[DStor]: Using factor when adding disturbance on node " << MC2HEX( nodeID ) << endl; mc2dbg8 << "RAW factor is " << el->getRawFactor() << endl; if ( el->getRawFactor() == MAX_UINT32 ) { mc2dbg8 << "[DStor]: Node " << MC2HEX( nodeID ) << " is blocked " << endl; avoidNode( node ); ++nbrDistAdded; } else { const float factor = el->getFactor(); mc2dbg8 << "[DStor]: Factor is " << factor << endl; bool added = false; for ( RoutingConnection* curConn = node->getFirstConnection(); curConn != NULL; curConn = curConn->getNext() ) { added = true; const RoutingConnectionData* connData = curConn->getData(); uint32 newCostC = uint32(connData->getCostB(0) * factor ); if(newCostC == connData->getCostB(0)){ mc2dbg8 << "newCostC same adding 1 **" << endl; newCostC++; } changeConnectionCosts( node, curConn, connData->getCostA(0), connData->getCostB(0), newCostC, connData->getVehicleRestriction(false)); } nbrDistAdded += added; } } else { mc2dbg4 << "Using time instead of factor" << endl; ++nbrDistAdded; uint32 cost = uint32(SEC_TO_TIME_COST(el->getTime())); RoutingConnection* curConn = node->getFirstConnection(); while ( curConn != NULL ) { RoutingConnectionData* connData = curConn->getData(); uint32 costC = connData->getCostB(0) + cost; changeConnectionCosts( node, curConn, connData->getCostA(0), connData->getCostB(0), costC, connData->getVehicleRestriction(false)); curConn = curConn->getNext(); } } } } return nbrDistAdded; }