本文整理汇总了Python中simulation.Simulation.traffic_load方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.traffic_load方法的具体用法?Python Simulation.traffic_load怎么用?Python Simulation.traffic_load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulation.Simulation
的用法示例。
在下文中一共展示了Simulation.traffic_load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import traffic_load [as 别名]
def __init__(self):
# get process info from mpi
communicator = MPI.COMM_WORLD
self.process_rank = communicator.Get_rank()
number_of_processes = communicator.Get_size()
self.log("Welcome to Streets4MPI!")
# set random seed based on process rank
random_seed = settings["random_seed"] + (37 * self.process_rank)
seed(random_seed)
self.log("Reading OpenStreetMap data...")
data = GraphBuilder(settings["osm_file"])
self.log("Building street network...")
street_network = data.build_street_network()
if self.process_rank == 0 and settings["persist_traffic_load"]:
self.log_indent("Saving street network to disk...")
persist_write("street_network_1.s4mpi", street_network)
self.log("Locating area types...")
data.find_node_categories()
self.log("Generating trips...")
trip_generator = TripGenerator()
# distribute residents over processes
number_of_residents = settings["number_of_residents"] / number_of_processes
if settings["use_residential_origins"]:
potential_origins = data.connected_residential_nodes
else:
potential_origins = street_network.get_nodes()
potential_goals = data.connected_commercial_nodes | data.connected_industrial_nodes
trips = trip_generator.generate_trips(number_of_residents, potential_origins, potential_goals)
# set traffic jam tolerance for this process and its trips
jam_tolerance = random()
self.log("Setting traffic jam tolerance to", str(round(jam_tolerance, 2)) + "...")
# run simulation
simulation = Simulation(street_network, trips, jam_tolerance, self.log_indent)
for step in range(settings["max_simulation_steps"]):
if step > 0 and step % settings["steps_between_street_construction"] == 0:
self.log_indent("Road construction taking place...")
simulation.road_construction()
if self.process_rank == 0 and settings["persist_traffic_load"]:
persist_write("street_network_" + str(step + 1) + ".s4mpi", simulation.street_network)
self.log("Running simulation step", step + 1, "of", str(settings["max_simulation_steps"]) + "...")
simulation.step()
# gather local traffic loads from all other processes
self.log("Exchanging traffic load data between nodes...")
total_traffic_load = array("I", repeat(0, len(simulation.traffic_load)))
communicator.Allreduce(simulation.traffic_load, total_traffic_load, MPI.SUM)
simulation.traffic_load = total_traffic_load
simulation.cumulative_traffic_load = merge_arrays((total_traffic_load, simulation.cumulative_traffic_load))
if self.process_rank == 0 and settings["persist_traffic_load"]:
self.log_indent("Saving traffic load to disk...")
persist_write("traffic_load_" + str(step + 1) + ".s4mpi", total_traffic_load, is_array = True)
del total_traffic_load
self.log("Done!")