Eclipse SUMO - Simulation of Urban MObility
MSAmitranTrajectories.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Realises dumping the complete network state
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
25 #include <microsim/MSEdge.h>
26 #include <microsim/MSLane.h>
27 #include <microsim/MSNet.h>
28 #include <microsim/MSVehicle.h>
29 #include <microsim/MSGlobals.h>
32 #include "MSAmitranTrajectories.h"
33 
34 // ===========================================================================
35 // static member definitions
36 // ===========================================================================
37 std::set<std::string> MSAmitranTrajectories::myWrittenTypes;
38 std::map<std::string, int> MSAmitranTrajectories::myWrittenVehicles;
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 void
47  for (MSVehicleControl::constVehIt v = vc.loadedVehBegin(); v != vc.loadedVehEnd(); ++v) {
48  writeVehicle(of, *v->second, timestep);
49  }
50 }
51 
52 
53 void
55  if (veh.isOnRoad()) {
56  const std::string& type = veh.getVehicleType().getID();
57  if (myWrittenTypes.count(type) == 0) {
60  if (c != 0) {
64  const double weight = PollutantsInterface::getWeight(c);
65  if (weight > 0.) {
66  of.writeAttr(SUMO_ATTR_WEIGHT, int(weight / 10. + 0.5));
67  }
68  }
69  of.writeAttr(SUMO_ATTR_REF, type).closeTag();
70  myWrittenTypes.insert(type);
71  }
72  if (myWrittenVehicles.count(veh.getID()) == 0) {
73  const int index = (int)myWrittenVehicles.size();
76  .writeAttr(SUMO_ATTR_STARTTIME, STEPS2MS(veh.getDeparture()));
77  of.writeAttr(SUMO_ATTR_REF, veh.getID()).closeTag();
78  myWrittenVehicles[veh.getID()] = index;
79  }
81  .writeAttr(SUMO_ATTR_SPEED, int(100.*veh.getSpeed() + 0.5))
82  .writeAttr(SUMO_ATTR_TIME, STEPS2MS(timestep))
83  .writeAttr(SUMO_ATTR_ACCELERATION, int(1000.*veh.getAcceleration() + 0.5));
84  of.closeTag();
85  }
86 }
87 
88 
89 /****************************************************************************/
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:194
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
SUMO_ATTR_ACCELERATION
Definition: SUMOXMLDefinitions.h:889
MSVehicleType::getNumericalID
int getNumericalID() const
Returns the running index of the vehicle type.
Definition: MSVehicleType.h:102
MSAmitranTrajectories::myWrittenVehicles
static std::map< std::string, int > myWrittenVehicles
Definition: MSAmitranTrajectories.h:78
MSNet.h
STEPS2MS
#define STEPS2MS(x)
Definition: SUMOTime.h:61
SUMOTrafficObject::getAcceleration
virtual double getAcceleration() const =0
Returns the vehicle's acceleration.
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
SUMO_ATTR_VEHICLE
Definition: SUMOXMLDefinitions.h:885
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
PollutantsInterface::getEuroClass
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
Definition: PollutantsInterface.cpp:137
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
SUMOEmissionClass
int SUMOEmissionClass
Definition: SUMOVehicleClass.h:232
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:385
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
MSEdge.h
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:75
MSVehicle.h
SUMO_ATTR_WEIGHT
Definition: SUMOXMLDefinitions.h:422
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
SUMOVehicle::getDeparture
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
PollutantsInterface.h
SUMO_TAG_ACTORCONFIG
Definition: SUMOXMLDefinitions.h:323
PollutantsInterface::getAmitranVehicleClass
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
Definition: PollutantsInterface.cpp:125
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:186
MSAmitranTrajectories.h
OutputDevice.h
SUMO_TAG_MOTIONSTATE
Definition: SUMOXMLDefinitions.h:324
MSGlobals.h
SUMO_TAG_VEHICLE
description of a vehicle
Definition: SUMOXMLDefinitions.h:120
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:673
SUMO_ATTR_STARTTIME
Definition: SUMOXMLDefinitions.h:886
PollutantsInterface::getWeight
static double getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7....
Definition: PollutantsInterface.cpp:143
PollutantsInterface::getFuel
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
Definition: PollutantsInterface.cpp:131
MSAmitranTrajectories::myWrittenTypes
static std::set< std::string > myWrittenTypes
Definition: MSAmitranTrajectories.h:77
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
MSAmitranTrajectories::writeVehicle
static void writeVehicle(OutputDevice &of, const SUMOVehicle &veh, const SUMOTime timestep)
Writes the dump of the given vehicle into the given device.
Definition: MSAmitranTrajectories.cpp:54
SUMO_ATTR_VEHICLECLASS
Definition: SUMOXMLDefinitions.h:887
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:72
SUMO_ATTR_REF
Definition: SUMOXMLDefinitions.h:818
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:178
MSLane.h
MSVehicleControl.h
MSAmitranTrajectories::write
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
Definition: MSAmitranTrajectories.cpp:45
SUMO_ATTR_EMISSIONCLASS
Definition: SUMOXMLDefinitions.h:792
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.
SUMO_ATTR_ACTORCONFIG
Definition: SUMOXMLDefinitions.h:884