加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
od_acc.py 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
xzhangcqjtu 提交于 2019-08-13 08:12 . 0
#%%
#coding:utf-8
# get od accessibility
import os,sys
sys.path.append(os.getcwd())
del os,sys
import pandas as pd
import numpy as np
from singue.bpr import bpr
from netop.epm_to_csr import epm_to_csr
#%% def cell
def od_acc(ueFlow,freeTime,capacity,epm,demand):
'''odAcc=od_acc(ueFlow,freeTime,capacity,epm,demand)
'''
if epm.shape[0]==1: # epm is []-like
odAcc=0
elif epm.shape[1]==0: # no path
odAcc=0
else:
cost=bpr(ueFlow,freeTime,capacity)
epmDense=epm.toarray()
pathCost=epmDense.T.dot(cost)
pathLn=np.log(pathCost)
pathProb=pathLn/np.sum(pathLn)
pathFlow=demand*pathProb
odAcc=demand/np.sum(pathFlow*pathCost)
return odAcc
#%% test cell
if __name__=='__main__':
# load data
ueflowfile=r'D:\Jobsplay\MyPython\netset\CQYuZhong\case8k\ueFlowRec_json.bz2'
ueFlowRec=pd.read_json(ueflowfile,orient='split')
edgefile=r'D:\Jobsplay\MyPython\netset\CQYuZhong\case8k\assi_edgesDf_json.bz2'
edgeDf=pd.read_json(edgefile,orient='split')
odfile=r'D:\Jobsplay\MyPython\netset\CQYuZhong\case8k\assi_odsDf8k_json.bz2'
odsDf=pd.read_json(odfile,orient='split')
# prep data
ueFlow=np.array(ueFlowRec['fineNet'])
freeTime=np.array(edgeDf['freeTime'])
capacity=np.array(edgeDf['capacity'])
epmDct=odsDf.loc[0,'epmDct']
epm=epm_to_csr(epmDct)
demand=odsDf.loc[0,'demand']
# def cell
odAcc=od_acc(ueFlow,freeTime,capacity,epm, demand)
# cost=bpr(ueFlow,freeTime,capacity)
# epmDense=epm.toarray()
# pathCost=epmDense.T.dot(cost)
# pathLn=np.log(pathCost)
# pathProb=pathLn/np.sum(pathLn)
# pathFlow=demand*pathProb
# odAcc=demand/np.sum(pathFlow*pathCost)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化