Path: blob/main/tests/complex/scenario_generation/demand_models/runner.py
169685 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file runner.py15# @author Daniel Krajzewicz16# @date 2013-10-301718# import osm network192021import sys22import os23SUMO_HOME = os.environ.get('SUMO_HOME',24os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))25sys.path.append(os.path.join(SUMO_HOME, 'tools'))2627from sumolib.net.generator.network import Edge # noqa28from sumolib.net.generator.demand import Demand, Stream, LinearChange, WaveComposition # noqa2930demand = Demand()31demand.addStream(Stream(None, None, None, 800, "from", "to", "passenger"))32vehicles1 = []33for s in demand.streams:34vehicles1.extend(s.toVehicles(0, 86400))3536# demand.build(0, 3600, 3600, "net.net.xml", "linear.rou.xml")3738demand = Demand()39demand.addStream(Stream(None, 0, 39600, 400, "from", "to", "passenger"))40demand.addStream(Stream(None, 39600, 46800, LinearChange(41400, 1200, 39600, 46800), "from", "to", "passenger"))42demand.addStream(Stream(None, 46800, 86400, 1200, "from", "to", "passenger"))43vehicles2 = []44for s in demand.streams:45vehicles2.extend(s.toVehicles(0, 86400))46# demand.build(0, 3600, 3600, "net.net.xml", "linear.rou.xml")4748vehicles3 = [] # [600, 0, .000025, 14400]49demand = Demand()50demand.addStream(Stream(None, None, None, WaveComposition(51800, [[400, 0, .000025, 14400], [200, 0, .00001, 14400]]), "from", "to", "passenger"))52for s in demand.streams:53vehicles3.extend(s.toVehicles(0, 86400))54# demand.build(0, 3600, "net.net.xml", "linear.rou.xml")5556STEP = 30057d1 = [0] * (86400 // STEP)58for v in vehicles1:59d = v.depart / STEP60d1[int(d)] = d1[int(d)] + 161d2 = [0] * (86400 // STEP)62for v in vehicles2:63d = v.depart / STEP64d2[int(d)] = d2[int(d)] + 165d3 = [0] * (86400 // STEP)66for v in vehicles3:67d = v.depart / STEP68d3[int(d)] = d3[int(d)] + 16970fdo = open("t1.csv", "w")71for i in range(0, 86400 // STEP):72fdo.write("%s;%s;%s;%s\n" % (73i * STEP, d1[i] * 3600 / STEP, d2[i] * 3600 / STEP, d3[i] * 3600 / STEP))74fdo.close()757677