/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2016 Fraunhofer ESK * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Karsten Roscher <karsten.roscher@esk.fraunhofer.de> */ #include "sumo-config.h" #include "traci-util.h" namespace ns3 { SumoConfig::SumoConfig(std::string listDelimiter, std::string customNameDelimiter) : m_listDelimiter (listDelimiter), m_customNameDelimiter (customNameDelimiter) { } void SumoConfig::SetupCommandLine (CommandLine& cmd) { cmd.AddValue ("sumo-config", "SUMO configuration file", m_config); cmd.AddValue ("sumo-network", "SUMO network file", m_network); cmd.AddValue ("sumo-routes", "SUMO routes file", m_routes); cmd.AddValue ("sumo-add", "SUMO additional files, separated by comma", m_additional); cmd.AddValue ("sumo-seed", "SUMO seed for the random generator (must be an integer)", m_seed); cmd.AddValue ("sumo-step", "SUMO simulation step length in seconds (float)", m_step); cmd.AddValue ("sumo-begin", "SUMO begin time in seconds (must be a number)", m_begin); cmd.AddValue ("sumo-load-state", "Load SUMO state from this file", m_loadState); cmd.AddValue ("sumo-args", "SUMO custom command line options with ':' instead of spaces", m_args); cmd.AddValue ("sumo-copy", "List of files to copy to the SUMO launcher, separated by ':'", m_copy); cmd.AddValue ("sumo-fcd-output", "Filename for fcd output of the SUMO launcher", m_fcd_out); cmd.AddValue ("sumo-fcd-accel", "Log acceleration in fcd output", m_fcd_accel); cmd.AddValue ("sumo-lat-resolution", "Lateral resolution for the SUMO sub-lane model", m_lat_resolution); } bool SumoConfig::HasRunArguments () const { return !m_config.empty () || !m_network.empty () || !m_routes.empty () || !m_additional.empty () || !m_args.empty (); } SumoConfig::ArgumentList SumoConfig::GetRunArguments () const { ArgumentList list; if (!m_config.empty ()) { list.push_back ("-c"); list.push_back (m_config); } if (!m_network.empty ()) { list.push_back ("-n"); list.push_back (m_network); } if (!m_routes.empty ()) { list.push_back ("-r"); list.push_back (m_routes); } if (!m_additional.empty ()) { list.push_back ("-a"); list.push_back (m_additional); } if (!m_seed.empty ()) { list.push_back ("--seed"); list.push_back (m_seed); } if (!m_step.empty ()) { list.push_back ("--step-length"); list.push_back (m_step); } if (!m_begin.empty ()) { list.push_back ("--begin"); list.push_back (m_begin); } if (!m_loadState.empty ()) { list.push_back ("--load-state"); list.push_back (m_loadState); } if (!m_fcd_out.empty ()) { list.push_back ("--fcd-output"); list.push_back (m_fcd_out); if (m_fcd_accel) { list.push_back ("--fcd-output.acceleration"); } } if (!m_lat_resolution.empty ()) { list.push_back ("--lateral-resolution"); list.push_back (m_lat_resolution); } if (!m_args.empty ()) { traci::TokenizeString (m_args, list, m_listDelimiter); } return list; } SumoConfig::CopyFileList SumoConfig::GetFilesToCopy () const { CopyFileList list; if (m_copy.empty ()) { // return empty list return list; } traci::StringList files; traci::TokenizeString (m_copy, files, m_listDelimiter); for (traci::StringList::const_iterator it = files.begin (); it != files.end (); ++it) { std::size_t pos = it->rfind(m_customNameDelimiter); std::string srcName(*it); std::string dstName(""); if (pos != std::string::npos) { // found a delimiter, split string srcName = it->substr (0, pos); dstName = it->substr (pos + m_customNameDelimiter.size ()); } list.push_back(std::make_pair(srcName, dstName)); } return list; } void SumoConfig::SetConfiguration (std::string config) { m_config = config; } void SumoConfig::SetNetwork (std::string network) { m_network = network; } void SumoConfig::SetRoutes (std::string routes) { m_routes = routes; } void SumoConfig::SetAdditionalFiles (std::string add) { m_additional = add; } void SumoConfig::SetSeed (std::string seed) { m_seed = seed; } void SumoConfig::SetStep (std::string step) { m_step = step; } void SumoConfig::SetBegin (std::string begin) { m_begin = begin; } void SumoConfig::SetLoadState (std::string stateFile) { m_loadState = stateFile; } void SumoConfig::SetArguments (std::string arguments) { m_args = arguments; } void SumoConfig::SetFilesToCopy (std::string copy) { m_copy = copy; } void SumoConfig::SetFcdOutput (std::string fcd_file) { m_fcd_out = fcd_file; } void SumoConfig::SetFcdAccel (bool log_accel) { m_fcd_accel = log_accel; } void SumoConfig::SetLatResolution (std::string resolution) { m_lat_resolution = resolution; } } // namespace ns3