基于蒙特卡洛模拟求解城市货运配送路径(python+arcgis)

该环节需要基于python的networkx库进行。实验中所用到的excel文件内容如图8所示。Python中的部分操作内容可以参考如下链接:

[4] https://zhuanlan.zhihu.com/p/164470586

图8

通过以下代码可以构建复杂网络,节点为道路端点,连边为道路。

#节点经纬度字典
dict_loc=dict(zip(df_node['节点ID'],list(zip(df_node['经度'],df_node['纬度']))))
# 创建空的交通网络
G = nx.Graph()

# 添加节点到交通网络
for index, row in df_node.iterrows():
    node_id = row['节点ID']
    longitude = row['经度']
    latitude = row['纬度']
    G.add_node(node_id, pos=(longitude, latitude))

# 添加边到交通网络
for index, row in df_edge.iterrows():
    road_id = row['道路ID']
    start_node = row['节点1']
    end_node = row['节点2']
    road_length = row['长度']
    G.add_edge(start_node, end_node, road_id=road_id, length=road_length)

4**、最短路径计算**


以下代码以节点“19814”与节点“30073”为例展示了最短路径的计算方式,批量计算可以通过For循环实现。另外,由于实际计算中所需的POI(如配送中心)并不一定是道路的端点,此时可以通过一些判断准则,选取合适的道路端点代表POI(如选取距离POI最近的端点)。

# 计算最短路径
start_node = 19814
end_node = 30073
shortest_path = nx.shortest_path(G, source=start_node, target=end_node, weight='length')
shortest_distance = nx.shortest_path_length(G, source=start_node, target=end_node, weight='length')
# 打印最短路径和最短距离
print(f"最短路径: {shortest_path}")
print(f"最短距离: {shortest_distance}")

CREATE TABLE IF NOT EXISTS `mk_international_location` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `pid` int(10) unsigned DEFAULT '0' COMMENT '父id/上级id', `path` varchar(255) DEFAULT '' COMMENT '路径', `level` int(10) unsigned DEFAULT '0' COMMENT '层级', `name` varchar(255) DEFAULT '' COMMENT '中文名称', `name_en` varchar(255) DEFAULT '' COMMENT '英文名称', `name_pinyin` varchar(255) DEFAULT '' COMMENT '中文拼音', `code` varchar(50) DEFAULT '' COMMENT '地区代码', `zip_code` varchar(50) DEFAULT '' COMMENT '邮政编码', `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态值 0无效 1有效', `manager_id` int(10) unsigned DEFAULT '0' COMMENT '操作管理员id', `manager_username` varchar(30) DEFAULT '' COMMENT '操作员账户名', `deleted_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `lat` varchar(255) DEFAULT NULL COMMENT '百度.纬度', `lng` varchar(255) DEFAULT NULL COMMENT '百度.经度', PRIMARY KEY (`id`), KEY `international_location_pid_index` (`pid`), KEY `international_location_manager_id_index` (`manager_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=4170 ; -- -- 转存表中的数据 `mk_international_location` -- INSERT INTO `mk_international_location` (`id`, `pid`, `path`, `level`, `name`, `name_en`, `name_pinyin`, `code`, `zip_code`, `status`, `manager_id`, `manager_username`, `deleted_at`, `created_at`, `updated_at`, `lat`, `lng`) VALUES (1, 0, ',1,', 1, '亚洲', 'Asia', 'yazhou', '', '', 1, 0, '', NULL, '2019-01-25 02:51:17', NULL, NULL, NULL), (2, 0, ',2,', 1, '欧洲', 'Europe', 'ouzhou', '', '', 1, 0, '', NULL, '2019-01-25 02:51:17', NULL, NULL, NULL);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值