Line data Source code
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 : /****************************************************************************/
14 : /// @file MSAmitranTrajectories.cpp
15 : /// @author Michael Behrisch
16 : /// @date 13.03.2014
17 : ///
18 : // Realises dumping the complete network state
19 : /****************************************************************************/
20 : #include <config.h>
21 :
22 : #include <microsim/MSVehicleControl.h>
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>
28 : #include <utils/iodevices/OutputDevice.h>
29 : #include <utils/emissions/PollutantsInterface.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
43 1170 : MSAmitranTrajectories::write(OutputDevice& of, const SUMOTime timestep) {
44 1170 : MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
45 2781 : for (MSVehicleControl::constVehIt v = vc.loadedVehBegin(); v != vc.loadedVehEnd(); ++v) {
46 1611 : writeVehicle(of, *v->second, timestep);
47 : }
48 1170 : }
49 :
50 :
51 : void
52 1611 : MSAmitranTrajectories::writeVehicle(OutputDevice& of, const SUMOVehicle& veh, const SUMOTime timestep) {
53 1611 : if (veh.isOnRoad()) {
54 1572 : const std::string& type = veh.getVehicleType().getID();
55 : if (myWrittenTypes.count(type) == 0) {
56 9 : of.openTag(SUMO_TAG_ACTORCONFIG).writeAttr(SUMO_ATTR_ID, veh.getVehicleType().getNumericalID());
57 9 : const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
58 9 : if (c != 0) {
59 9 : of.writeAttr(SUMO_ATTR_VEHICLECLASS, PollutantsInterface::getAmitranVehicleClass(c));
60 18 : of.writeAttr("fuel", PollutantsInterface::getFuel(c));
61 9 : of.writeAttr(SUMO_ATTR_EMISSIONCLASS, "Euro" + toString(PollutantsInterface::getEuroClass(c)));
62 9 : const double weight = PollutantsInterface::getWeight(c);
63 9 : if (weight > 0.) {
64 0 : of.writeAttr(SUMO_ATTR_WEIGHT, int(weight / 10. + 0.5));
65 : }
66 : }
67 18 : of.writeAttr(SUMO_ATTR_REF, type).closeTag();
68 : myWrittenTypes.insert(type);
69 : }
70 : if (myWrittenVehicles.count(veh.getID()) == 0) {
71 54 : const int index = (int)myWrittenVehicles.size();
72 54 : of.openTag(SUMO_TAG_VEHICLE).writeAttr(SUMO_ATTR_ID, index)
73 54 : .writeAttr(SUMO_ATTR_ACTORCONFIG, veh.getVehicleType().getNumericalID())
74 108 : .writeAttr(SUMO_ATTR_STARTTIME, STEPS2MS(veh.getDeparture()));
75 54 : of.writeAttr(SUMO_ATTR_REF, veh.getID()).closeTag();
76 54 : myWrittenVehicles[veh.getID()] = index;
77 : }
78 1572 : of.openTag(SUMO_TAG_MOTIONSTATE).writeAttr(SUMO_ATTR_VEHICLE, myWrittenVehicles[veh.getID()])
79 1572 : .writeAttr(SUMO_ATTR_SPEED, int(100.*veh.getSpeed() + 0.5))
80 : .writeAttr(SUMO_ATTR_TIME, STEPS2MS(timestep))
81 1572 : .writeAttr(SUMO_ATTR_ACCELERATION, int(1000.*veh.getAcceleration() + 0.5));
82 3144 : of.closeTag();
83 : }
84 1611 : }
85 :
86 :
87 : /****************************************************************************/
|