/****************************************************************************/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 NWWriter_MATSim.cpp14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Tue, 04.05.201117///18// Exporter writing networks using the MATSim format19/****************************************************************************/20#include <config.h>21#include "NWWriter_MATSim.h"22#include <utils/common/MsgHandler.h>23#include <netbuild/NBEdge.h>24#include <netbuild/NBEdgeCont.h>25#include <netbuild/NBNode.h>26#include <netbuild/NBNodeCont.h>27#include <netbuild/NBNetBuilder.h>28#include <utils/options/OptionsCont.h>29#include <utils/iodevices/OutputDevice.h>30313233// ===========================================================================34// method definitions35// ===========================================================================36// ---------------------------------------------------------------------------37// static methods38// ---------------------------------------------------------------------------39void40NWWriter_MATSim::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {41// check whether a matsim-file shall be generated42if (!oc.isSet("matsim-output")) {43return;44}45OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));46device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";47device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";48device << "<network name=\"NAME\">\n"; // !!! name49// write nodes50device << " <nodes>\n";51NBNodeCont& nc = nb.getNodeCont();52for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {53device << " <node id=\"" << (*i).first54<< "\" x=\"" << (*i).second->getPosition().x()55<< "\" y=\"" << (*i).second->getPosition().y()56<< "\"/>\n";57}58device << " </nodes>\n";59// write edges60device << " <links capperiod=\"01:00:00\">\n";61NBEdgeCont& ec = nb.getEdgeCont();62for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {63device << " <link id=\"" << (*i).first64<< "\" from=\"" << (*i).second->getFromNode()->getID()65<< "\" to=\"" << (*i).second->getToNode()->getID()66<< "\" length=\"" << (*i).second->getLoadedLength()67<< "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())68<< "\" freespeed=\"" << (*i).second->getSpeed()69<< "\" permlanes=\"" << (*i).second->getNumLanes()70<< "\"/>\n";71}72device << " </links>\n";73//74device << "</network>\n"; // !!! name75device.close();76}777879/****************************************************************************/808182