import sys
sys.path.append(r'/run/media/pengfei/OTHERS/pythonlibs')
import numpy as np
from lib_time import MeasureT
from lib_timetable import Stations, Timetable
from lib_osm import queryRoute
from lib_plot import jointplotFromLists
######### 加载车站位置数据
fl = "/run/media/pengfei/OTHERS/Code/Data/ChinaRailway/China_Station_Location_City.xls"
stations_obj = Stations(fl)
dict_NameLoc = stations_obj.get_NameLoc_Index()

fs = "/run/media/pengfei/OTHERS/Code/Data/ChinaRailway/China_Railway_Schedule_20190701.csv"
timetable_obj = Timetable(fs)
df_timetable = timetable_obj.df
dict_pairT_timetable = timetable_obj.get_directTravelT()

tdd = MeasureT()  # 开始计时

dict_pairDis = {}  # 地理距离
dict_pairTrainT = {}  # 列车时刻表的真实旅行时间的中值
dict_pairDrivingT = {}  # OSRM路径规划的行车距离

for p in dict_pairT_timetable:
    s1, s2 = p[0], p[1]
    if not (s1 in dict_NameLoc and s2 in dict_NameLoc):
        continue
    loc1, loc2 = dict_NameLoc[s1], dict_NameLoc[s2]
    dict_pairDis[p] = stations_obj.get_distance(s1,s2)
    dict_pairTrainT[p] = np.median(dict_pairT_timetable[p]) 
    route,traveltime = queryRoute(loc1,loc2)
Beispiel #2
0
import geoplot.crs as gcrs
import numpy as np
import lib_time
import multiprocessing
import random
import matplotlib.pyplot as plt

import lib_time  ### 关于时间的相应操作在这个包里
from lib_time import get_deltaT, strT_to_floatT, floatT_to_strT

# 1 数据准备
##### 1.1 车站的位置
dict_HSRLocs = lib_file.pickle_load('E:/Code/需求与辐射模型-欧洲/dict_HSRLocs.pkl')

###### 1.1 列车时刻表,加载有向图
timetable = Timetable()
timetable.load_file('E:/Code/Data/EuropeRailway/Europe_Railway_Schedule.csv',
                    mode='ALL',
                    encoding='utf-8')  ### ALL 指的是全部车型, 还可以特指HSR,但是欧洲不支持

#list_names = ['London Euston', 'London Paddington', 'London St Pancras',
#             'London Kings Cross', 'London Liverpool Street', 'London Blackfriars',
#             'London Bridge', 'London Charing Cross', 'London Victoria']

##  dict_pairJS    应该也建成图
###### 识别一个互补车站群  #####################################
#G = nx.Graph()
#for pair in dict_pairJS:
#    JS = dict_pairJS[pair]
#    G.add_edge(pair[0],pair[1],weight=JS)
#
import multiprocessing
from haversine import haversine


def jaccard_similarity(list1, list2):
    s1 = set(list1)
    s2 = set(list2)
    return len(s1.intersection(s2)) / len(s1.union(s2))


# 1 数据准备
##### 1.1 车站的位置
dict_HSRLocs = lib_file.pickle_load('E:/Code/需求与辐射模型-欧洲/dict_HSRLocs.pkl')

###### 1.2 列车时刻表,加载有向图
timetable = Timetable()
timetable.load_file('E:/Code/Data/EuropeRailway/Europe_Railway_Schedule.csv',
                    mode='ALL',
                    encoding='utf-8')  ### ALL 指的是全部车型, 还可以特指HSR,但是欧洲不支持
#G_schedule = timetable.get_DiGraph(mode="all")
G_HSRTimetable = timetable.get_graph()

#### 2.3 去掉时刻表中没有位置的点
for n in list(G_HSRTimetable.nodes()):
    if n not in dict_HSRLocs:
        G_HSRTimetable.remove_node(n)

### 2.4 车站间 car driving时间的数据   2019.09.27添加
G_stationPair = lib_graph.createG_fromFile(
    'E:/Code/Data/EuropeRailway/Europe_StationPairAccessibility_200km.csv',
    source='source',
            if (n in dict_accessed) and (info['travelT'] - dict_accessed[n] >=
                                         -0.1):  ## 就没快几分钟,不用换了
                continue
            if (n not in dict_ChildInfo) or (dict_ChildInfo[n]['travelT'] >
                                             info['travelT']):
                dict_ChildInfo[n] = info

    return dict_ChildInfo


###############################################################################
######################     Data prepare     ###################################
##### 1.1 高铁车站的位置
dict_HSRLocs = lib_file.pickle_load('dict_HSRLocs.pkl')
##### 2.2 高铁时刻表,加载有向图
timetable = Timetable()
timetable.load_file(
    '/run/media/pengfei/OTHERS/Code/Data/ChinaRailway/China_Railway_Schedule_20190701.csv'
)
###### 2.3 去掉时刻表中没有位置的点
G_schedule = timetable.get_TravelT(mode="all")
for n in list(G_schedule.nodes()):
    if n not in dict_HSRLocs:
        G_schedule.remove_node(n)

#### 3.1 加载 车站在三小时car driving 时间内可达的格点的图(graph)
f_HSRGrid = '/run/media/pengfei/OTHERS/Code/Data/ChinaRailway/CalculateGridTravelTTeacherGiveME/StationGridAccessibility_Adapt.csv'
G_HSRGrid = lib_graph.createG_fromFile(
    f_HSRGrid,
    source='station',
    target='grid',
Beispiel #5
0
                                        source='source',
                                        target='target',
                                        attr='')
#### 1.1 加载机场、车站位置数据
dict_AirportLocs = lib_file.pickle_load('dict_AirportLocs.pkl')
dict_HSRLocs = lib_file.pickle_load('dict_HSRLocs.pkl')

#### 2 由时刻表建图,获取联通关系 ## 属性上有车次
##### 2.1 飞机时刻表建图

air_timetable = FlightTimetable()
air_timetable.load_file('E:/Code/Data/ChinaAir/China_Air_Schedule_clean.csv')
G_airTimetable = air_timetable.get_graph()

##### 2.2 高铁时刻表  ### 建图,属性上有车次
timetable = Timetable()
timetable.load_file(
    'E:/Code/Data/ChinaRailway/China_Railway_Schedule_20190701.csv')
G_HSRTimetable = timetable.get_graph()

#### 2.3 去掉时刻表中没有位置的点
for n in list(G_airTimetable.nodes()):
    if n not in dict_AirportLocs:
        G_airTimetable.remove_node(n)

for n in list(G_HSRTimetable.nodes()):
    if n not in dict_HSRLocs:
        G_HSRTimetable.remove_node(n)

ttt = lib_time.MeasureT()
#G_HSRTimetable = G_airTimetable ####################
        for n in neighbors:
            info = get_scheme(s, n, G_schedule, dict_parents)
            if not 'train_code' in info:  ## 并没有产生有效的接续换乘策略
                continue
            if (n in dict_accessed) and (info['total_travelT'] - dict_accessed[n]>=-0.1): ## 现在是以分钟为单位,应该不需要后边这个条件了
                continue
            if (n not in dict_ChildInfo) or (dict_ChildInfo[n]['total_travelT'] > info['total_travelT']):
                dict_ChildInfo[n] = info              
    
    return dict_ChildInfo
                
    
    
# 1 数据准备
###### 1.1 列车时刻表,加载有向图
timetable = Timetable()
timetable.load_file(OS+'Code/Data/ChinaRailway/China_Railway_Schedule_20190701.csv',mode='HSR')
G_schedule = timetable.get_DiGraph(mode="all")
###### 1.2 保存有向图
#lib_file.pickle_save(G_schedule,OS+'Code/Data/ChinaRailway/G_schedule.pkl')
##### 1.3 直接加载有向图
#G_schedule = lib_file.pickle_load(OS+'Code/Data/ChinaRailway/G_schedule.pkl')

##### 1.1 车站的位置
df_railwayLocs = lib_file.read_file2df(OS+'Code/Data/ChinaRailway/China_Station_Locs_All.csv')
dict_HSRLocs = lib_file.get_LocIndex(df_railwayLocs)        

#### 3.1 加载 车站在一小时car driving 时间内可达的格点的图(graph)
f_HSRGrid = OS+'Code/Data/ChinaRailway/China_StationGridAccessibility_1h_correct.csv'
G_HSRGrid = lib_graph.createG_fromFile(f_HSRGrid, source='station', target='grid', attr=['distanceLBS_m','duration_s'])