arcpy.na.MakeVehicleRoutingProblemAnalysisLayer(network_data_source, {layer_name}, {travel_mode}, {time_units}, {distance_units}, {default_date}, {time_zone_for_time_fields}, {line_shape}, {time_window_factor}, {excess_transit_factor}, {generate_directions_on_solve}, {spatial_clustering}, {ignore_invalid_locations}, {analysis_geodatabase}, {analysis_feature_dataset_name})
|
名称
|
说明
|
数据类型
|
|
network_data_source
|
将对其执行网络分析的网络数据集或服务。
可以使用以下值之一来指定该参数:
要使用门户 URL,您必须使用具有路径选择权限的账户登录门户。
了解如何在 Python 中登录门户
了解有关使用路径服务的网络分析详细信息
当使用 ArcGIS Online 或使用 ArcGIS Online 配置路径服务的 ArcGIS Enterprise 门户作为输入网络时,解决分析将消耗配额并受到某些限制,例如允许的输入数量。
了解关于网络分析中配额消耗和分析限制的详细信息
网络必须至少包含一个其阻抗属性具有时间单位的出行模式。
|
Network Dataset Layer; String
|
|
layer_name
(可选)
|
要创建的 VRP 网络分析图层的名称。
|
String
|
|
travel_mode
(可选)
|
分析中使用的出行模式名称。 出行模式为一组网络设置(例如行驶限制和 U 形转弯),用于确定行人、车辆、卡车或其他交通媒介在网络中的移动方式。 出行模式在网络数据源中进行定义。 arcpy.na.TravelMode 对象和包含出行模式有效 JSON 表示的字符串也可用作参数的输入。
出行模式必须具有单位为时间的阻抗属性。
|
String
|
|
time_units
(可选)
|
指定分析图层的子图层和表(网络分析类)的时态字段所用的时间单位。 该值不需要与时间成本属性的单位匹配。
了解有关成本属性的详细信息
|
String
|
|
distance_units
(可选)
|
指定分析图层的子图层和表(网络分析类)的距离字段所用的距离单位。 该值不需要与可选距离成本属性的单位匹配。
了解有关成本属性的详细信息
Miles—距离单位将为英里。 这是默认设置。
Kilometers—距离单位将为千米。
Feet—距离单位将为英尺。
Yards—距离单位将为码。
Meters—距离单位将为米。
Inches—距离单位为英寸。
Centimeters—距离单位为厘米。
Millimeters—距离单位为毫米。
Decimeters—距离单位为分米。
NauticalMiles—距离单位将为海里。
|
String
|
|
default_date
(可选)
|
未用时间指定日期的时间字段值的隐式日期。 如果某个停靠点对象的时间字段(如 TimeWindowStart)只有时间值,则假定该日期为默认日期。 默认日期不影响已具有日期的时间字段值。
将分析配置为使用以下特殊日期之一以针对一周中的某天或当前日期建模(而非使用特定静态日期):
Today—12/30/1899
Sunday—12/31/1899
Monday—1/1/1900
Tuesday—1/2/1900
Wednesday—1/3/1900
Thursday—1/4/1900
Friday—1/5/1900
Saturday—1/6/1900
了解有关如何在网络分析中使用和解释日期和时间的详细信息
|
Date
|
|
time_zone_for_time_fields
(可选)
|
指定工具支持的输入日期时间字段所用的时区。
如果不知道停靠点或站点所在的时区,或者停靠点或站点处在多个时区内并且您想要所有的日期时间值同时启动,那么在 UTC 中指定日期时间值非常有用。 UTC 选项仅在您的网络数据集定义了时区属性时才可用。 否则,所有日期时间值将被视为与该位置相对应的时区。
|
String
|
|
line_shape
(可选)
|
指定将用于分析所输出的路径要素的形状类型。
无论指定的输出形状类型为何,最佳路径始终由网络阻抗(而非欧氏距离)决定。 这表示只是路径形状不同,而对网络进行的基础遍历则相同。
|
String
|
|
time_window_factor
(可选)
|
用于指定支持时间窗且不引起冲突的重要性。 如果路径在时间窗关闭后才到达停靠点、站点或休息点,将会产生时间窗冲突。 该冲突是时间窗关闭与路径到达时间之间的时间间隔。
High—求解程序需要寻求最小化时间窗冲突的解决方案(以增加总体行驶时间为代价)。 如果对您而言按时到达停靠点要比最小化总体解决方案成本更加重要,请选择此设置。 您可能会在以下情况下选择此设置:您要在自己的停靠点会见客户,且不想因为迟到给客户带来不便(另一种方法是使用根本不会出现冲突的硬性时间窗)。假设还要考虑车辆配送 (VRP) 的其他约束,可能无法在它们的时间窗内访问所有停靠点。 在这种情况下,即使选择高设置也可能会产生冲突。
Medium—求解程序在满足时间窗和减少总体解决方案成本之间寻求一种平衡。 这是默认设置。
Low—求解程序需要寻求最小化总体行驶时间的解决方案(不考虑时间窗)。 如果减少您的总体解决方案成本要比满足时间窗更重要,请选择此设置。 如果积压的服务请求逐渐增多,则可以使用此设置。 如果为了在当日内为更多的停靠点提供服务并减少积压的订单,则可选择此设置,即使车队迟到会为客户带来不便。
|
String
|
|
excess_transit_factor
(可选)
|
指定减少额外行驶时间的重要性。 额外行驶时间是指超出停靠点对间直线行驶所需时间的数量。 额外时间是由于在需求点对的访问期间进行休息或者行驶至其他停靠点或站点而导致的。 仅当您使用停靠点对时,此参数才相关。
了解有关停靠点对的详细信息
High—求解程序需要寻求需求点对之间超出行驶时间较短的解决方案(以增加总体行驶成本为代价)。 如果您正在停靠点对间运载乘客并且想缩短他们的乘车时间,请使用此设置。 这是出租车服务的特征。
Medium—求解程序在减少超出行驶时间和减少总体解决方案成本之间寻求一种平衡。 这是默认设置。
Low—求解程序需要寻求最小化总体解决方案成本的结果(不考虑额外行驶时间)。 此设置通常应用于快递服务。 由于快递运输的是包裹而不是人员,因此行驶时间并不十分重要。 使用此设置时,快递可以按照最适合的顺序为停靠点对提供服务,并且总体解决方案成本最低。
|
String
|
|
generate_directions_on_solve
(可选)
|
指定运行分析时是否生成方向。
对于不需要生成转向指示的分析,关闭方向生成可以减少求解分析的时间。
|
Boolean
|
|
spatial_clustering
(可选)
|
指定是否使用空间聚类。
|
Boolean
|
|
ignore_invalid_locations
(可选)
|
指定是否忽略无效的输入位置。
|
Boolean
|
|
analysis_geodatabase
(可选)
|
存储新网络分析图层的子图层的文件地理数据库工作空间。 当未指定此参数时,将在当前工作空间地理处理环境(通常为工程地理数据库)中创建子图层的数据。
了解有关网络分析图层的分析数据源的详细信息
|
Workspace
|
|
analysis_feature_dataset_name
(可选)
|
用于命名该工具将在分析地理数据库中创建的新要素数据集的名称,该数据集将用于存储网络分析图层的子图层数据。 如未指定,要素数据集将以随机唯一名称创建。
了解有关网络分析图层的分析数据源的详细信息
|
String
|
派生输出
|
名称
|
说明
|
数据类型
|
|
out_network_analysis_layer
|
新网络分析图层。
|
Network Analyst Layer
|
代码示例
MakeVehicleRoutingProblemAnalysisLayer 示例 1(Python 窗口)
仅使用必需参数运行该工具。
import arcpy
arcpy.env.workspace = "C:/Data/SanFrancisco.gdb"
arcpy.na.MakeVehicleRoutingProblemAnalysisLayer("Transportation/Streets_ND")
MakeVehicleRoutingProblemAnalysisLayer 示例 2(Python 窗口)
使用所有参数运行该工具。
import arcpy
arcpy.env.workspace = "C:/Data/SanFrancisco.gdb"
arcpy.na.MakeVehicleRoutingProblemAnalysisLayer('Streets_ND', 'FridayRoutes',
'Driving Time', 'Minutes',
'Miles', '1/2/2020',
'LOCAL_TIME_AT_LOCATIONS',
'TRUE_LINES_WITHOUT_MEASURES',
'High', 'Medium', 'DIRECTIONS')
MakeVehicleRoutingProblemAnalysisLayer 示例 3(工作流)
以下独立 Python 脚本演示了如何使用 MakeVehicleRoutingProblemAnalysisLayer 函数通过一支车队为一组停靠点提供服务。
# Name: MakeVRPAnalysisLayer_Ex3_Workflow.py
# Description: Find the best routes for a fleet of vehicles, which is operated
# by a distribution company, to deliver goods from a main
# distribution center to a set of grocery stores.
# Requirements: Network Analyst extension
# Import system modules
import arcpy
import os
try:
# Set environment settings
output_dir = r"C:\Data"
# The NA layer's data will be saved to the workspace specified here
arcpy.env.workspace = os.path.join(output_dir, "Output.gdb")
arcpy.env.overwriteOutput = True
# Set local variables
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
layer_name = "StoreDeliveryRoute"
travel_mode = "Driving Time"
time_units = "Minutes"
distance_units = "Miles"
in_orders = os.path.join(input_gdb, "Analysis", "Stores")
in_depots = os.path.join(input_gdb, "Analysis", "DistributionCenter")
in_routes = os.path.join(input_gdb, "Analysis", "Routes")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
# Create a new Vehicle Routing Problem (VRP) layer. Since the time-based
# attributes such as ServiceTime on orders and CostPerUnitTime on routes is
# recorded in minutes, we use minutes for time_units parameter. As we are
# using cost per unit distance in routes, we have to specify a distance
# attribute. The values for CosterPerUnitDistance are in miles, so we
# specify miles for distance units parameter
result_object = arcpy.na.MakeVehicleRoutingProblemAnalysisLayer(
network, layer_name, travel_mode, time_units, distance_units,
line_shape="STRAIGHT_LINES")
# Get the layer object form the result object. The route layer can now be
# referenced using the layer object.
layer_object = result_object.getOutput(0)
# Get the names of all the sublayers within the VRP layer.
sub_layer_names = arcpy.na.GetNAClassNames(layer_object)
# Store the layer names that we will use later
orders_layer_name = sub_layer_names["Orders"]
depots_layer_name = sub_layer_names["Depots"]
routes_layer_name = sub_layer_names["Routes"]
# Load the store locations as orders. Using field mappings we map the
# TimeWindowStart1, TimeWindowEnd1, and DeliveryQuantities properties
# for Orders from the fields of store features and assign a value of
# 0 to MaxViolationTime1 property. The Name and ServiceTime properties
# have the correct mapped field names when using the candidate fields
# from store locations feature class.
candidate_fields = arcpy.ListFields(in_orders)
order_field_mappings = arcpy.na.NAClassFieldMappings(layer_object, orders_layer_name, False, candidate_fields)
order_field_mappings["TimeWindowStart"].mappedFieldName = "TimeStart1"
order_field_mappings["TimeWindowEnd"].mappedFieldName = "TimeEnd1"
order_field_mappings["DeliveryQuantity_1"].mappedFieldName = "Demand"
order_field_mappings["MaxViolationTime"].defaultValue = 0
arcpy.na.AddLocations(layer_object, orders_layer_name, in_orders, order_field_mappings, "")
# Load the depots from the distribution center features. Using field mappings
# we map the Name properties for Depots from the fields of distribution
# center features and assign a value of 8 AM for TimeWindowStart1 and a
# value of 5 PM for TimeWindowEnd1 properties
depot_field_mappings = arcpy.na.NAClassFieldMappings(layer_object, depots_layer_name)
depot_field_mappings["Name"].mappedFieldName = "Name"
depot_field_mappings["TimeWindowStart"].defaultValue = "8 AM"
depot_field_mappings["TimeWindowEnd"].defaultValue = "5 PM"
arcpy.na.AddLocations(layer_object, depots_layer_name, in_depots, depot_field_mappings, "")
# Load the routes from a table containing information about routes. In this
# case, since the fields on the routes table and property names for Routes
# are the same, we will just use the default field mappings
routes_field_mappings = arcpy.na.NAClassFieldMappings(layer_object, routes_layer_name)
routes_field_mappings["Name"].mappedFieldName = "Name"
routes_field_mappings["StartDepotName"].mappedFieldName = "StartDepotName"
routes_field_mappings["EndDepotName"].mappedFieldName = "EndDepotName"
routes_field_mappings["StartDepotServiceTime"].mappedFieldName = "StartDepotServiceTime"
routes_field_mappings["Capacity_1"].mappedFieldName = "Capacities"
routes_field_mappings["CostPerUnitTime"].mappedFieldName = "CostPerUnitTime"
routes_field_mappings["CostPerUnitDistance"].mappedFieldName = "CostPerUnitDistance"
routes_field_mappings["MaxOrderCount"].mappedFieldName = "MaxOrderCount"
routes_field_mappings["MaxTotalTime"].mappedFieldName = "MaxTotalTime"
routes_field_mappings["MaxTotalTravelTime"].mappedFieldName = "MaxTotalTravelTime"
routes_field_mappings["MaxTotalDistance"].mappedFieldName = "MaxTotalDistance"
arcpy.na.AddLocations(layer_object, routes_layer_name, in_routes, routes_field_mappings, "")
# Solve the VRP layer
arcpy.na.Solve(layer_object)
# Save the solved VRP layer as a layer file on disk with relative paths
arcpy.management.SaveToLayerFile(layer_object, output_layer_file, "RELATIVE")
print("Script Completed Successfully")
except Exception as e:
# If an error occurred, print line number and error message
import traceback
import sys
tb = sys.exc_info()[2]
print("An error occurred on line %i" % tb.tb_lineno)
print(str(e))