SUMO - Simulation of Urban MObility
MSAmitranTrajectories.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Realises dumping the complete network state
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2014-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSNet.h>
35 #include <microsim/MSVehicle.h>
36 #include <microsim/MSGlobals.h>
39 #include "MSAmitranTrajectories.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 // ===========================================================================
46 // static member definitions
47 // ===========================================================================
48 std::set<std::string> MSAmitranTrajectories::myWrittenTypes;
49 std::map<std::string, int> MSAmitranTrajectories::myWrittenVehicles;
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 void
58  for (MSVehicleControl::constVehIt v = vc.loadedVehBegin(); v != vc.loadedVehEnd(); ++v) {
59  writeVehicle(of, *v->second, timestep);
60  }
61 }
62 
63 
64 void
66  if (veh.isOnRoad()) {
67  const std::string& type = veh.getVehicleType().getID();
68  if (myWrittenTypes.count(type) == 0) {
71  if (c != 0) {
75  const SUMOReal weight = PollutantsInterface::getWeight(c);
76  if (weight > 0.) {
77  of.writeAttr(SUMO_ATTR_WEIGHT, int(weight / 10. + 0.5));
78  }
79  }
80  of.writeAttr(SUMO_ATTR_REF, type).closeTag();
81  myWrittenTypes.insert(type);
82  }
83  if (myWrittenVehicles.count(veh.getID()) == 0) {
84  const int index = (int)myWrittenVehicles.size();
87  .writeAttr(SUMO_ATTR_STARTTIME, STEPS2MS(veh.getDeparture()));
88  of.writeAttr(SUMO_ATTR_REF, veh.getID()).closeTag();
89  myWrittenVehicles[veh.getID()] = index;
90  }
92  .writeAttr(SUMO_ATTR_SPEED, int(100.*veh.getSpeed() + 0.5))
93  .writeAttr(SUMO_ATTR_TIME, STEPS2MS(timestep))
94  .writeAttr(SUMO_ATTR_ACCELERATION, int(1000.*veh.getAcceleration() + 0.5));
95  of.closeTag();
96  }
97 }
98 
99 
100 /****************************************************************************/
static SUMOReal getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7.eu/deliverables/COLOMBO_D4.2_ExtendedPHEMSUMO_v1.7.pdf.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
long long int SUMOTime
Definition: SUMOTime.h:43
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
static std::map< std::string, int > myWrittenVehicles
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
the weight of a district&#39;s source or sink
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
int SUMOEmissionClass
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
static std::set< std::string > myWrittenTypes
int getNumericalID() const
Returns the running index of the vehicle type.
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
virtual SUMOTime getDeparture() const =0
Returns this vehicle&#39;s real departure time.
static void writeVehicle(OutputDevice &of, const SUMOVehicle &veh, const SUMOTime timestep)
Writes the dump of the given vehicle into the given device.
virtual SUMOReal getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
const std::string & getID() const
Returns the name of the vehicle type.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
The class responsible for building and deletion of vehicles.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
#define STEPS2MS(x)
Definition: SUMOTime.h:68
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.