Path: blob/main/src/netimport/vissim/tempstructs/NIVissimTrafficDescription.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file NIVissimTrafficDescription.cpp14/// @author Daniel Krajzewicz15/// @date Sept 200216///17// -------------------18/****************************************************************************/19#include <config.h>2021#include <string>22#include <map>23#include <cassert>24#include "NIVissimVehicleClassVector.h"25#include "NIVissimTrafficDescription.h"262728// ===========================================================================29// member function definitions30// ===========================================================================31NIVissimTrafficDescription::DictType NIVissimTrafficDescription::myDict;323334// ===========================================================================35// member method definitions36// ===========================================================================37NIVissimTrafficDescription::NIVissimTrafficDescription(38const std::string& name,39const NIVissimVehicleClassVector& vehicleTypes)40: myName(name), myVehicleTypes(vehicleTypes) {}414243NIVissimTrafficDescription::~NIVissimTrafficDescription() {44for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {45delete *i;46}47myVehicleTypes.clear();48}495051bool52NIVissimTrafficDescription::dictionary(int id,53const std::string& name,54const NIVissimVehicleClassVector& vehicleTypes) {55NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);56if (!dictionary(id, o)) {57delete o;58return false;59}60return true;61}626364bool65NIVissimTrafficDescription::dictionary(int id, NIVissimTrafficDescription* o) {66DictType::iterator i = myDict.find(id);67if (i == myDict.end()) {68myDict[id] = o;69return true;70}71return false;72}737475NIVissimTrafficDescription*76NIVissimTrafficDescription::dictionary(int id) {77DictType::iterator i = myDict.find(id);78if (i == myDict.end()) {79return nullptr;80}81return (*i).second;82}838485void86NIVissimTrafficDescription::clearDict() {87for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {88delete (*i).second;89}90myDict.clear();91}9293949596double97NIVissimTrafficDescription::meanSpeed(int id) {98NIVissimTrafficDescription* i = dictionary(id);99assert(i != 0);100return i->meanSpeed();101}102103104double105NIVissimTrafficDescription::meanSpeed() const {106double speed = 0;107for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {108speed += (*i)->getSpeed();109}110return speed / (double) myVehicleTypes.size();111}112113114/****************************************************************************/115116117