NIVissimDistrictConnection Class Reference

#include <NIVissimDistrictConnection.h>


Detailed Description

Definition at line 45 of file NIVissimDistrictConnection.h.


Public Member Functions

Position2D geomPosition () const
 Returns the position The position yields from the edge geometry and the place the connection is plaed at.
int getID () const
 Returns the id of the connection.
SUMOReal getMeanSpeed () const
SUMOReal getPosition () const
 Returns the position of the connection at the edge.
 NIVissimDistrictConnection (int id, const std::string &name, const IntVector &districts, const DoubleVector &percentages, int edgeid, SUMOReal position, const std::vector< std::pair< int, int > > &assignedVehicles)
 Contructor.
 ~NIVissimDistrictConnection ()

Static Public Member Functions

static void clearDict ()
 Clears the dictionary.
static void dict_BuildDistrictConnections ()
static void dict_BuildDistrictNodes (NBDistrictCont &dc, NBNodeCont &nc)
 Builds the nodes that belong to a district.
static void dict_BuildDistricts (NBDistrictCont &dc, NBEdgeCont &ec, NBNodeCont &nc)
 Builds the districts.
static void dict_CheckEdgeEnds ()
static NIVissimDistrictConnectiondict_findForEdge (int edgeid)
 Returns the connection to a district placed at the given node Yep, there onyl should be one, there is no need to build a single edge as connection between two parking places.
static NIVissimDistrictConnectiondictionary (int id)
 Returns the named dictionary.
static bool dictionary (int id, NIVissimDistrictConnection *o)
 Inserts the build connection to the dictionary.
static bool dictionary (int id, const std::string &name, const IntVector &districts, const DoubleVector &percentages, int edgeid, SUMOReal position, const std::vector< std::pair< int, int > > &assignedVehicles)
 Inserts the connection into the dictionary after building it.

Private Types

typedef std::map< int,
NIVissimDistrictConnection * > 
DictType
 Definition of a dictionary of district connections.
typedef std::map< int, SUMOReal > DistrictPercentages
 Definition of a map of how many vehicles should leave to a certain district.

Private Member Functions

void checkEdgeEnd ()
SUMOReal getRealSpeed (int distNo) const

Private Attributes

std::vector< std::pair< int,
int > > 
myAssignedVehicles
 The vehicles using this connection.
IntVector myDistricts
 The connected districts.
int myEdgeID
 The id of the connected edge.
int myID
 The id of the connections.
std::string myName
 The name of the connections.
DistrictPercentages myPercentages
 A map how many vehicles (key, amount) should leave to a district (key).
SUMOReal myPosition
 The position on the edge.

Static Private Attributes

static DictType myDict
 District connection dictionary.
static std::map< int, IntVectormyDistrictsConnections
 Map from ditricts to connections.

Member Typedef Documentation

Definition of a dictionary of district connections.

Definition at line 136 of file NIVissimDistrictConnection.h.

typedef std::map<int, SUMOReal> NIVissimDistrictConnection::DistrictPercentages [private]

Definition of a map of how many vehicles should leave to a certain district.

Definition at line 120 of file NIVissimDistrictConnection.h.


Constructor & Destructor Documentation

NIVissimDistrictConnection::NIVissimDistrictConnection ( int  id,
const std::string &  name,
const IntVector districts,
const DoubleVector percentages,
int  edgeid,
SUMOReal  position,
const std::vector< std::pair< int, int > > &  assignedVehicles 
)

Contructor.

Definition at line 68 of file NIVissimDistrictConnection.cpp.

References myDistricts, and myPercentages.

Referenced by dictionary().

00073         : myID(id), myName(name), myDistricts(districts),
00074         myEdgeID(edgeid), myPosition(position),
00075         myAssignedVehicles(assignedVehicles) {
00076     IntVector::iterator i=myDistricts.begin();
00077     DoubleVector::const_iterator j=percentages.begin();
00078     while (i!=myDistricts.end()) {
00079         myPercentages[*i] = *j;
00080         i++;
00081         j++;
00082     }
00083 }

NIVissimDistrictConnection::~NIVissimDistrictConnection (  ) 

Definition at line 86 of file NIVissimDistrictConnection.cpp.

00086 {}


Member Function Documentation

void NIVissimDistrictConnection::checkEdgeEnd (  )  [private]

void NIVissimDistrictConnection::clearDict (  )  [static]

Clears the dictionary.

Definition at line 360 of file NIVissimDistrictConnection.cpp.

References myDict.

Referenced by NIImporter_Vissim::~NIImporter_Vissim().

00360                                       {
00361     for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) {
00362         delete(*i).second;
00363     }
00364     myDict.clear();
00365 }

void NIVissimDistrictConnection::dict_BuildDistrictConnections (  )  [static]

Definition at line 127 of file NIVissimDistrictConnection.cpp.

References myDict, myDistricts, and myDistrictsConnections.

Referenced by NIImporter_Vissim::postLoadBuild().

00127                                                           {
00128     //  pre-assign connections to districts
00129     for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) {
00130         NIVissimDistrictConnection *c = (*i).second;
00131         const IntVector &districts = c->myDistricts;
00132         for (IntVector::const_iterator j=districts.begin(); j!=districts.end(); j++) {
00133             // assign connection to district
00134             myDistrictsConnections[*j].push_back((*i).first);
00135         }
00136     }
00137 }

void NIVissimDistrictConnection::dict_BuildDistrictNodes ( NBDistrictCont dc,
NBNodeCont nc 
) [static]

Builds the nodes that belong to a district.

Definition at line 161 of file NIVissimDistrictConnection.cpp.

References Position2D::add(), dictionary(), geomPosition(), Position2DVector::getPolygonCenter(), NBNodeCont::insert(), NBDistrictCont::insert(), myDistrictsConnections, and Position2DVector::push_back().

Referenced by NIImporter_Vissim::postLoadBuild().

00162                         {
00163     for (std::map<int, IntVector>::iterator k=myDistrictsConnections.begin(); k!=myDistrictsConnections.end(); k++) {
00164         // get the connections
00165         const IntVector &connections = (*k).second;
00166         // retrieve the current district
00167         std::string dsid = toString<int>((*k).first);
00168         NBDistrict *district = new NBDistrict(dsid);
00169         dc.insert(district);
00170         // compute the middle of the district
00171         Position2DVector pos;
00172         for (IntVector::const_iterator j=connections.begin(); j!=connections.end(); j++) {
00173             NIVissimDistrictConnection *c = dictionary(*j);
00174             pos.push_back(c->geomPosition());
00175         }
00176         Position2D distCenter = pos.getPolygonCenter();
00177         if (connections.size()==1) { // !!! ok, ok, maybe not the best way just to add an offset
00178             distCenter.add(10, 10);
00179         }
00180         district->setCenter(distCenter);
00181         // build the node
00182         std::string id = "District" + district->getID();
00183         NBNode *districtNode =
00184             new NBNode(id, district->getPosition(), district);
00185         if (!nc.insert(districtNode)) {
00186             throw 1;
00187         }
00188     }
00189 }

void NIVissimDistrictConnection::dict_BuildDistricts ( NBDistrictCont dc,
NBEdgeCont ec,
NBNodeCont nc 
) [static]

Builds the districts.

Definition at line 192 of file NIVissimDistrictConnection.cpp.

References dictionary(), NBEdge::getFromNode(), getMeanSpeed(), getPosition(), NBEdge::getToNode(), MsgHandler::getWarningInstance(), MsgHandler::inform(), NBEdgeCont::insert(), NBNode::invalidateIncomingConnections(), NBNode::invalidateOutgoingConnections(), NBEdge::LANESPREAD_RIGHT, myDistrictsConnections, myEdgeID, myID, myPercentages, myPosition, NBEdgeCont::retrieve(), NBNodeCont::retrieve(), NBDistrictCont::retrieve(), NBEdgeCont::retrievePossiblySplitted(), and SUMOReal.

Referenced by NIImporter_Vissim::postLoadBuild().

00195                                                                                                          {
00196     // add the sources and sinks
00197     //  their normalised probability is computed within NBDistrict
00198     //   to avoid SUMOReal code writing and more securty within the converter
00199     //  go through the district table
00200     for (std::map<int, IntVector>::iterator k=myDistrictsConnections.begin(); k!=myDistrictsConnections.end(); k++) {
00201         // get the connections
00202         const IntVector &connections = (*k).second;
00203         // retrieve the current district
00204         NBDistrict *district =
00205             dc.retrieve(toString<int>((*k).first));
00206         NBNode *districtNode = nc.retrieve("District" + district->getID());
00207         assert(district!=0&&districtNode!=0);
00208 
00209         for (IntVector::const_iterator l=connections.begin(); l!=connections.end(); l++) {
00210             NIVissimDistrictConnection *c = dictionary(*l);
00211             // get the edge to connect the parking place to
00212             NBEdge *e = ec.retrieve(toString<int>(c->myEdgeID));
00213             if (e==0) {
00214                 e = ec.retrievePossiblySplitted(toString<int>(c->myEdgeID), c->myPosition);
00215             }
00216             if (e==0) {
00217                 MsgHandler::getWarningInstance()->inform("Could not build district '" + toString<int>((*k).first) + "' - edge '" + toString<int>(c->myEdgeID) + "' is missing.");
00218                 continue;
00219             }
00220             std::string id = "ParkingPlace" + toString<int>(*l);
00221             NBNode *parkingPlace = nc.retrieve(id);
00222             if (parkingPlace==0) {
00223                 SUMOReal pos = c->getPosition();
00224                 if (pos<e->getLength()-pos) {
00225                     parkingPlace = e->getFromNode();
00226                     parkingPlace->invalidateIncomingConnections();
00227                 } else {
00228                     parkingPlace = e->getToNode();
00229                     parkingPlace->invalidateOutgoingConnections();
00230                 }
00231             }
00232             assert(
00233                 e->getToNode()==parkingPlace
00234                 ||
00235                 e->getFromNode()==parkingPlace);
00236 
00237             // build the connection to the source
00238             if (e->getFromNode()==parkingPlace) {
00239                 id = "VissimFromParkingplace" + toString<int>((*k).first) + "-" + toString<int>(c->myID);
00240                 NBEdge *source =
00241                     new NBEdge(id, districtNode, parkingPlace,
00242                                "Connection", c->getMeanSpeed(/*distc*/)/(SUMOReal) 3.6, 3, -1,
00243                                NBEdge::LANESPREAD_RIGHT);
00244                 if (!ec.insert(source)) { // !!! in den Konstruktor
00245                     throw 1; // !!!
00246                 }
00247                 SUMOReal percNormed =
00248                     c->myPercentages[(*k).first];
00249                 if (!district->addSource(source, percNormed)) {
00250                     throw 1;
00251                 }
00252             }
00253 
00254             // build the connection to the destination
00255             if (e->getToNode()==parkingPlace) {
00256                 id = "VissimToParkingplace"  + toString<int>((*k).first) + "-" + toString<int>(c->myID);
00257                 NBEdge *destination =
00258                     new NBEdge(id, parkingPlace, districtNode,
00259                                "Connection", (SUMOReal) 100/(SUMOReal) 3.6, 2, -1,
00260                                NBEdge::LANESPREAD_RIGHT);
00261                 if (!ec.insert(destination)) { // !!! (in den Konstruktor)
00262                     throw 1; // !!!
00263                 }
00264                 SUMOReal percNormed2 =
00265                     c->myPercentages[(*k).first];
00266                 if (!district->addSink(destination, percNormed2)) {
00267                     throw 1; // !!!
00268                 }
00269             }
00270 
00271             /*
00272             if(e->getToNode()==districtNode) {
00273             SUMOReal percNormed =
00274                 c->myPercentages[(*k).first];
00275             district->addSink(e, percNormed);
00276             }
00277             if(e->getFromNode()==districtNode) {
00278             SUMOReal percNormed =
00279                 c->myPercentages[(*k).first];
00280             district->addSource(e, percNormed);
00281             }
00282             */
00283         }
00284 
00285         /*
00286         // add them as sources and sinks to the current district
00287         for(IntVector::const_iterator l=connections.begin(); l!=connections.end(); l++) {
00288             // get the current connections
00289             NIVissimDistrictConnection *c = dictionary(*l);
00290             // get the edge to connect the parking place to
00291             NBEdge *e = NBEdgeCont::retrieve(toString<int>(c->myEdgeID));
00292             Position2D edgepos = c->geomPosition();
00293             NBNode *edgeend = e->tryGetNodeAtPosition(c->myPosition,
00294                 e->getLength()/4.0);
00295             if(edgeend==0) {
00296                 // Edge splitting omitted on build district connections by now
00297                 assert(false);
00298             }
00299 
00300             // build the district-node if not yet existing
00301             std::string id = "VissimParkingplace" + district->getID();
00302             NBNode *districtNode = nc.retrieve(id);
00303             assert(districtNode!=0);
00304 
00305             if(e->getToNode()==edgeend) {
00306                 // build the connection to the source
00307                 id = std::string("VissimFromParkingplace")
00308                     + toString<int>((*k).first) + "-"
00309                     + toString<int>(c->myID);
00310                 NBEdge *source =
00311                     new NBEdge(id, id, districtNode, edgeend,
00312                     "Connection", 100/3.6, 2, 100, 0,
00313                     NBEdge::EDGEFUNCTION_SOURCE);
00314                 NBEdgeCont::insert(source); // !!! (in den Konstruktor)
00315                 SUMOReal percNormed =
00316                     c->myPercentages[(*k).first];
00317                 district->addSource(source, percNormed);
00318             } else {
00319                 // build the connection to the destination
00320                 id = std::string("VissimToParkingplace")
00321                     + toString<int>((*k).first) + "-"
00322                     + toString<int>(c->myID);
00323                 NBEdge *destination =
00324                     new NBEdge(id, id, edgeend, districtNode,
00325                     "Connection", 100/3.6, 2, 100, 0,
00326                     NBEdge::EDGEFUNCTION_SINK);
00327                 NBEdgeCont::insert(destination); // !!! (in den Konstruktor)
00328 
00329                 // add both the source and the sink to the district
00330                 SUMOReal percNormed =
00331                     c->myPercentages[(*k).first];
00332                 district->addSink(destination, percNormed);
00333             }
00334         }
00335         */
00336     }
00337 }

void NIVissimDistrictConnection::dict_CheckEdgeEnds (  )  [static]

Definition at line 141 of file NIVissimDistrictConnection.cpp.

References checkEdgeEnd(), dictionary(), and myDistrictsConnections.

Referenced by NIImporter_Vissim::postLoadBuild().

00141                                                {
00142     for (std::map<int, IntVector>::iterator k=myDistrictsConnections.begin(); k!=myDistrictsConnections.end(); k++) {
00143         const IntVector &connections = (*k).second;
00144         for (IntVector::const_iterator j=connections.begin(); j!=connections.end(); j++) {
00145             NIVissimDistrictConnection *c = dictionary(*j);
00146             c->checkEdgeEnd();
00147         }
00148     }
00149 }

NIVissimDistrictConnection * NIVissimDistrictConnection::dict_findForEdge ( int  edgeid  )  [static]

Returns the connection to a district placed at the given node Yep, there onyl should be one, there is no need to build a single edge as connection between two parking places.

Definition at line 349 of file NIVissimDistrictConnection.cpp.

References myDict.

Referenced by NIVissimEdge::resolveSameNode(), and NIVissimEdge::setDistrictSpeed().

00349                                                        {
00350     for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) {
00351         if ((*i).second->myEdgeID==edgeid) {
00352             return (*i).second;
00353         }
00354     }
00355     return 0;
00356 }

NIVissimDistrictConnection * NIVissimDistrictConnection::dictionary ( int  id  )  [static]

Returns the named dictionary.

Definition at line 118 of file NIVissimDistrictConnection.cpp.

References myDict.

00118                                              {
00119     DictType::iterator i=myDict.find(id);
00120     if (i==myDict.end()) {
00121         return 0;
00122     }
00123     return (*i).second;
00124 }

bool NIVissimDistrictConnection::dictionary ( int  id,
NIVissimDistrictConnection o 
) [static]

Inserts the build connection to the dictionary.

Definition at line 107 of file NIVissimDistrictConnection.cpp.

References myDict.

00107                                                                             {
00108     DictType::iterator i=myDict.find(id);
00109     if (i==myDict.end()) {
00110         myDict[id] = o;
00111         return true;
00112     }
00113     return false;
00114 }

bool NIVissimDistrictConnection::dictionary ( int  id,
const std::string &  name,
const IntVector districts,
const DoubleVector percentages,
int  edgeid,
SUMOReal  position,
const std::vector< std::pair< int, int > > &  assignedVehicles 
) [static]

Inserts the connection into the dictionary after building it.

Definition at line 91 of file NIVissimDistrictConnection.cpp.

References NIVissimDistrictConnection().

Referenced by dict_BuildDistrictNodes(), dict_BuildDistricts(), dict_CheckEdgeEnds(), and NIVissimSingleTypeParser_Parkplatzdefinition::parse().

00094                                                                                               {
00095     NIVissimDistrictConnection *o =
00096         new NIVissimDistrictConnection(id, name, districts, percentages,
00097                                        edgeid, position, assignedVehicles);
00098     if (!dictionary(id, o)) {
00099         delete o;
00100         return false;
00101     }
00102     return true;
00103 }

Position2D NIVissimDistrictConnection::geomPosition (  )  const

Returns the position The position yields from the edge geometry and the place the connection is plaed at.

Definition at line 342 of file NIVissimDistrictConnection.cpp.

References NIVissimEdge::dictionary(), NIVissimAbstractEdge::getGeomPosition(), myEdgeID, and myPosition.

Referenced by dict_BuildDistrictNodes(), NIVissimEdge::remapOneOfNodes(), and NIVissimEdge::resolveSameNode().

00342                                                {
00343     NIVissimAbstractEdge *e = NIVissimEdge::dictionary(myEdgeID);
00344     return e->getGeomPosition(myPosition);
00345 }

int NIVissimDistrictConnection::getID (  )  const [inline]

Returns the id of the connection.

Definition at line 61 of file NIVissimDistrictConnection.h.

References myID.

Referenced by NIVissimEdge::remapOneOfNodes(), and NIVissimEdge::resolveSameNode().

00061                       {
00062         return myID;
00063     }

SUMOReal NIVissimDistrictConnection::getMeanSpeed (  )  const

Definition at line 369 of file NIVissimDistrictConnection.cpp.

References getRealSpeed(), MsgHandler::getWarningInstance(), MsgHandler::inform(), myAssignedVehicles, myID, SUMOReal, and toString().

Referenced by dict_BuildDistricts(), and NIVissimEdge::setDistrictSpeed().

00369                                                                      {
00370     //assert(myAssignedVehicles.size()!=0);
00371     if (myAssignedVehicles.size()==0) {
00372         MsgHandler::getWarningInstance()->inform("No streams assigned at district'" + toString(myID) + "'.\n Using default speed 200km/h");
00373         return (SUMOReal) 200/(SUMOReal) 3.6;
00374     }
00375     SUMOReal speed = 0;
00376     std::vector<std::pair<int, int> >::const_iterator i;
00377     for (i=myAssignedVehicles.begin(); i!=myAssignedVehicles.end(); i++) {
00378         speed += getRealSpeed(/*dc, */(*i).second);
00379     }
00380     return speed / (SUMOReal) myAssignedVehicles.size();
00381 }

SUMOReal NIVissimDistrictConnection::getPosition (  )  const [inline]

Returns the position of the connection at the edge.

Definition at line 66 of file NIVissimDistrictConnection.h.

References myPosition.

Referenced by dict_BuildDistricts(), and NIVissimEdge::resolveSameNode().

00066                                  {
00067         return myPosition;
00068     }

SUMOReal NIVissimDistrictConnection::getRealSpeed ( int  distNo  )  const [private]

Definition at line 385 of file NIVissimDistrictConnection.cpp.

References NBDistribution::dictionary(), OptionsCont::getFloat(), OptionsCont::getOptions(), SUMOReal, and WRITE_WARNING.

Referenced by getMeanSpeed().

00385                                                                                  {
00386     std::string id = toString<int>(distNo);
00387     Distribution *dist = NBDistribution::dictionary("speed", id);
00388     if (dist==0) {
00389         WRITE_WARNING("The referenced speed distribution '" + id + "' is not known.");
00390         WRITE_WARNING(". Using default.");
00391         return OptionsCont::getOptions().getFloat("vissim.default-speed");
00392     }
00393     assert(dist!=0);
00394     SUMOReal speed = dist->getMax();
00395     if (speed<0||speed>1000) {
00396         WRITE_WARNING(" False speed at district '" + id);
00397         WRITE_WARNING(". Using default.");
00398         speed = OptionsCont::getOptions().getFloat("vissim.default-speed");
00399     }
00400     return speed;
00401 }


Field Documentation

std::vector<std::pair<int, int> > NIVissimDistrictConnection::myAssignedVehicles [private]

The vehicles using this connection.

Definition at line 132 of file NIVissimDistrictConnection.h.

Referenced by getMeanSpeed().

District connection dictionary.

Definition at line 139 of file NIVissimDistrictConnection.h.

Referenced by clearDict(), dict_BuildDistrictConnections(), dict_findForEdge(), and dictionary().

The connected districts.

Definition at line 117 of file NIVissimDistrictConnection.h.

Referenced by dict_BuildDistrictConnections(), and NIVissimDistrictConnection().

Map from ditricts to connections.

Definition at line 142 of file NIVissimDistrictConnection.h.

Referenced by dict_BuildDistrictConnections(), dict_BuildDistrictNodes(), dict_BuildDistricts(), and dict_CheckEdgeEnds().

The id of the connected edge.

Definition at line 126 of file NIVissimDistrictConnection.h.

Referenced by checkEdgeEnd(), dict_BuildDistricts(), and geomPosition().

The id of the connections.

Definition at line 111 of file NIVissimDistrictConnection.h.

Referenced by dict_BuildDistricts(), getID(), and getMeanSpeed().

std::string NIVissimDistrictConnection::myName [private]

The name of the connections.

Definition at line 114 of file NIVissimDistrictConnection.h.

A map how many vehicles (key, amount) should leave to a district (key).

Definition at line 123 of file NIVissimDistrictConnection.h.

Referenced by dict_BuildDistricts(), and NIVissimDistrictConnection().

The position on the edge.

Definition at line 129 of file NIVissimDistrictConnection.h.

Referenced by checkEdgeEnd(), dict_BuildDistricts(), geomPosition(), and getPosition().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:53 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6