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.dev/sumo
3 // Copyright (C) 2014-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Realises dumping the complete network state
19 /****************************************************************************/
20 #include <config.h>
21 
23 #include <microsim/MSEdge.h>
24 #include <microsim/MSLane.h>
25 #include <microsim/MSNet.h>
26 #include <microsim/MSVehicle.h>
27 #include <microsim/MSGlobals.h>
30 #include "MSAmitranTrajectories.h"
31 
32 // ===========================================================================
33 // static member definitions
34 // ===========================================================================
35 std::set<std::string> MSAmitranTrajectories::myWrittenTypes;
36 std::map<std::string, int> MSAmitranTrajectories::myWrittenVehicles;
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 void
45  for (MSVehicleControl::constVehIt v = vc.loadedVehBegin(); v != vc.loadedVehEnd(); ++v) {
46  writeVehicle(of, *v->second, timestep);
47  }
48 }
49 
50 
51 void
53  if (veh.isOnRoad()) {
54  const std::string& type = veh.getVehicleType().getID();
55  if (myWrittenTypes.count(type) == 0) {
58  if (c != 0) {
62  const double weight = PollutantsInterface::getWeight(c);
63  if (weight > 0.) {
64  of.writeAttr(SUMO_ATTR_WEIGHT, int(weight / 10. + 0.5));
65  }
66  }
67  of.writeAttr(SUMO_ATTR_REF, type).closeTag();
68  myWrittenTypes.insert(type);
69  }
70  if (myWrittenVehicles.count(veh.getID()) == 0) {
71  const int index = (int)myWrittenVehicles.size();
74  .writeAttr(SUMO_ATTR_STARTTIME, STEPS2MS(veh.getDeparture()));
75  of.writeAttr(SUMO_ATTR_REF, veh.getID()).closeTag();
76  myWrittenVehicles[veh.getID()] = index;
77  }
79  .writeAttr(SUMO_ATTR_SPEED, int(100.*veh.getSpeed() + 0.5))
80  .writeAttr(SUMO_ATTR_TIME, STEPS2MS(timestep))
81  .writeAttr(SUMO_ATTR_ACCELERATION, int(1000.*veh.getAcceleration() + 0.5));
82  of.closeTag();
83  }
84 }
85 
86 
87 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
#define STEPS2MS(x)
Definition: SUMOTime.h:59
int SUMOEmissionClass
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_MOTIONSTATE
@ SUMO_TAG_ACTORCONFIG
@ SUMO_ATTR_EMISSIONCLASS
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_WEIGHT
@ SUMO_ATTR_VEHICLECLASS
@ SUMO_ATTR_ACTORCONFIG
@ SUMO_ATTR_STARTTIME
@ SUMO_ATTR_REF
@ SUMO_ATTR_ACCELERATION
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_ID
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static std::map< std::string, int > myWrittenVehicles
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
static std::set< std::string > myWrittenTypes
static void writeVehicle(OutputDevice &of, const SUMOVehicle &veh, const SUMOTime timestep)
Writes the dump of the given vehicle into the given device.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
The class responsible for building and deletion of vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
int getNumericalID() const
Returns the running index of the vehicle type.
Definition: MSVehicleType.h:99
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
static double getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7....
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)