![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <sstream> 00029 00030 #include <RISE/scenario/mobility/roadmap/Street.hpp> 00031 00032 #include <WNS/Position.hpp> 00033 #include <WNS/Assure.hpp> 00034 00035 00036 using namespace rise::scenario::mobility::roadmap; 00037 using namespace std; 00038 00039 Street::Street(const wns::pyconfig::View& streetView, Map* _map) : 00040 MapObject(streetView.get<MapObject::ID>("ID"), _map), 00041 endPoints(), 00042 connections(), 00043 vMax(0.0), 00044 streetVector() 00045 { 00046 int nPoints = streetView.getSequence("endPoints").size(); 00047 assure(nPoints==2, "Street object should defined by exactly 2 Points!"); 00048 for (int i=0; i<nPoints; ++i) 00049 { 00050 std::stringstream index; 00051 index << i; 00052 endPoints.push_back(wns::Position(streetView.getView("endPoints["+index.str()+"]"))); 00053 } 00054 int nConnections = streetView.getSequence("connections").size(); 00055 assure(nConnections==2, "Street always has to be connected to 2 other MapObjects!"); 00056 for (int i=0; i<nConnections; ++i) 00057 connections.push_back(streetView.getSequence("connections").at<MapObject::ID>(i)); 00058 00059 // in m/s 00060 vMax = streetView.get<double>("vMax"); 00061 00062 streetVector = endPoints.at(1)-endPoints.at(0); 00063 } 00064 00065 wns::Position 00066 Street::getNextPosition(MapUser* user, simTimeType dt) const 00067 { 00068 // in case we just entered this street, we have to determine the 00069 // user's heading. If we come from the crossing at endPoint[0], we 00070 // call it "Forward", otherwise we'll call it "Reverse" 00071 if (user->currentObject!=this->id) 00072 { 00073 MapObject::ID from = user->currentObject; 00074 user->heading = ( ( from==connections.at(0)) 00075 ? int(Headings::Forward()) 00076 : int(Headings::Reverse()) ); 00077 user->currentObject=this->id; 00078 } 00079 00080 // how much of this road remains? 00081 double remaining = (1-user->percent)*streetVector.abs(); 00082 00083 // is user velocity on this street bounded by vMax? 00084 double currentVelocity = ( user->velocity < vMax ? user->velocity : vMax ); 00085 00086 if (currentVelocity*dt < remaining) 00087 { 00088 // we stay on this road and only advance by a certain 00089 // percentage (given through velocity and timestep) 00090 user->percent += (currentVelocity*dt)/streetVector.abs(); 00091 00092 MESSAGE_BEGIN(NORMAL, log, m, "MapUser advancing on street "); 00093 m << id << ", completed " << int(100.0*user->percent) 00094 << "%, velocity " << currentVelocity << "(desired: " << user->velocity << ") m/s"; 00095 MESSAGE_END(); 00096 00097 return this->getPosition(user); 00098 } 00099 else 00100 { 00101 // we reach the end of this street, how long does that take? 00102 double untilCrossing = remaining/currentVelocity; 00103 // determine the object we'll reach next 00104 MapObject* nextObject = map->getObject(( user->heading==Headings::Forward() 00105 ? connections.at(1) 00106 : connections.at(0) )); 00107 // and delegate the decision about the new final position 00108 return nextObject->getNextPosition(user,dt-untilCrossing); 00109 } 00110 } 00111 00112 wns::Position 00113 Street::getPosition(const MapUser* user) const 00114 { 00115 assure(user->currentObject==this->id, "User/Street mismatch."); 00116 00117 // where did we enter the road? 00118 wns::Position entryPoint = 00119 ( user->heading == Headings::Forward() ? endPoints.at(0) : endPoints.at(1) ); 00120 00121 // what distance have we traveled on the road 00122 wns::PositionOffset userTravelled = streetVector * 00123 user->percent * user->heading; 00124 00125 // this results in our current position 00126 wns::Position userPosition = entryPoint + userTravelled; 00127 00128 return userPosition; 00129 00130 } 00131 00132 std::vector<MapObject::ID> 00133 Street::getDependencies() const 00134 { 00135 return connections; 00136 }
1.5.5