首页 > 解决方案 > osmnx 如何在 HPC 集群中使用?

问题描述

osmnx 如何在 HPC 集群中使用?

我想在 Ubuntu Server 的 HPC 类型的集群中运行一个 python 这个脚本来加快它的执行时间

(目前在没有集群的服务器上完成该过程大约需要 4 分钟)

附上Python代码:

import sys
import networkx as nx
import osmnx as ox
import geopandas as gpd
import math
from shapely.geometry import Point
import json


ox.config(use_cache=False)


origlatTmp = float(sys.argv[1])
origlngTmp = float(sys.argv[2])
destlatTmp = float(sys.argv[3]) 
destlngTmp = float(sys.argv[4])


def fromAtoBpoints(origlat, origlng, destlat, destlng):
   
    G = ox.load_graphml('/var/www/html/jalisco.graphml')

    #This .graphml file was generated with:

    #import osmnx as ox

    #ox.config(use_cache=True, log_console=True)

    #G = ox.graph_from_place('Jalisco,Mexico', network_type = 'drive', simplify=False)
    #G = ox.add_edge_speeds(G)
    #G = ox.add_edge_travel_times(G)
    #ox.save_graphml(G, '/var/www/html/jalisco.graphml')
    #print("Done!")

    #Jalisco is a state of Mexico and the territorial extension of Jalisco is 78,588 km²

    lats = []
    lngs = []
    
    lats.insert(0, origlat)
    lats.insert(1, destlat)
    
    lngs.insert(0, origlng)
    lngs.insert(1, destlng)

    points_list = [Point((lng, lat)) for lat, lng in zip(lats, lngs)]

    points = gpd.GeoSeries(points_list, crs='epsg:4326')

    points_proj = points.to_crs(G.graph['crs'])

    nearest_nodes = [ox.distance.nearest_nodes(G, pt.x, pt.y) for pt in points_proj]

    route = nx.shortest_path (G, nearest_nodes[0], nearest_nodes[1], weight='length')

    time = nx.shortest_path_length(G, nearest_nodes[0], nearest_nodes[1], weight='travel_time')
    #print("Tiempo:",time/60,"min")

    distance = nx.shortest_path_length(G, nearest_nodes[0], nearest_nodes[1], weight='length')
    #print("Distancia:",distance/1000,"km")

    resultArray = []
    resultArray2 = []

    for a in route:
        resultArray.append("{lat:"+ str(G.nodes[a]['y'])+",lng:"+ str(G.nodes[a]['x'])+"}")

    return (distance/1000),"@@@",resultArray

print(fromAtoBpoints(origlatTmp,origlngTmp,destlatTmp,destlngTmp))
 

这段代码执行时间长(我上面提到的4分钟),但是我们想到的是它可以离线工作,并且提出的解决响应时间的解决方案是使用HPC集群

标签: pythoncluster-computingnetworkxopenstreetmaposmnx

解决方案


推荐阅读