创建多路径配送(VRP)图层 (网络分析)
摘要
创建多路径配送 (VRP) 网络分析图层并设置其分析属性。多路径配送 (VRP) 分析图层可用于在使用一支车队时对一组路径进行优化。
用法
语法
| 参数 | 说明 | 数据类型 |
in_network_dataset |
将在其中执行多路径配送 (VRP) 分析的网络数据集。由于 VRP 求解程序要尽量缩短时间,因此网络数据集必须具有基于时间的成本属性。 | Network Dataset Layer |
out_network_analysis_layer |
要创建的多路径配送 (VRP) 网络分析图层的名称。 | String |
time_impedance |
用于定义沿网络元素的遍历时间的时间成本属性。时间成本属性是必选项,因为多路径配送 (VRP) 求解程序会将时间缩至最短。 | String |
distance_impedance (可选) |
用于定义沿网络元素的长度的距离成本属性。距离成本属性是可选的。 | String |
time_units (可选) |
分析图层的子图层和表(网络分析类)的时态字段所用的时间单位。此单位不必与时间成本属性的单位相同。 | String |
distance_units (可选) |
分析图层的子图层和表(网络分析类)的距离字段所用的距离单位。此单位不必与可选距离成本属性的单位相同。 | String |
default_date (可选) |
未用时间指定日期的时间字段值的隐式日期。如果某个停靠点对象的时间字段(如 TimeWindowStart1)只有时间值,则假定该日期为“默认日期”。例如,如果某个停靠点的 TimeWindowStart1 值为 9:00 AM 并且“默认日期”为 2011 年 3 月 6 日,那么其字段的整个时间值为 2011 年 3 月 6 日 9:00 A.M。默认日期对已具有日期的时间字段值没有影响。 使用以下日期也可以将一周中的某天指定为“默认日期”。
如果网络数据集包含历史流量数据,则分析结果可根据此处指定的日期发生相应的变化。例如,路径在星期日 8:00 a.m.(此时交通不太拥堵)开始与在星期一 8:00 a.m.(交通高峰时段)开始相比,星期一的路径会花费更长的时间。此外,最佳路径会根据交通状况发生相应的变化。 | Date |
capacity_count (可选) |
描述相关车辆限制所需的容量限制维度数。在订单配送实例中,根据物理限制和法律限制,每台车辆的可装载重量和体积可能同时受到限制。这种情况下,如果要追踪停靠点处的体积和重量,可以使用这两种容量来避免车辆超载。此时,容量计数为 2(体积和重量)。因问题而异,可能需要追踪不同类型或数目的容量。容量字段(“停靠点”类的 DeliveryQuantities 和 PickupQuantities 以及“路径”类的 Capacities)中输入的容量是以空格分隔的数字字符串,这些字符串最多可包含“容量计数”中指定的数值个数。每种容量维度都应以所有容量字段值在相同 VRP 分析图层中的相同位置顺序显示。容量本身没有名称,所以,为避免意外调换容量的维度,请确保始终按相同的顺序为所有容量字段值输入以空格分隔的容量列表。 | String |
time_window_factor (可选) |
此参数可用于评定遵循时间窗且不引起冲突的重要性。如果路径在时间窗关闭后才到达停靠点、站点或中断,将会产生时间窗冲突。该冲突是时间窗关闭与路径到达时间之间的时间间隔。 VRP 解决方案可根据您选择的时间窗冲突重要性参数值进行更改。下面的列表介绍了这些值的含义以及如何更改生成的 VRP 解决方案:
| String |
excess_transit_factor (可选) |
此参数可用于评定减少超出行驶时间的重要性。超出行驶时间是指超过配对停靠点间直接行驶所需时间的时间。超出时间是由于在配对停靠点的访问期间出现中断或者行驶至其他停靠点或站点而导致的。 VRP 解决方案可根据您选择的“超出行驶时间重要性”参数值进行更改。下面的列表介绍了这些值的含义以及如何更改生成的 VRP 解决方案:
| String |
UTurn_policy (可选) |
限制或允许停靠点间网络遍历过程中可能出现在交汇点处的 U 形转弯。
| String |
restriction_attribute_name [restriction_attribute_name,...] (可选) |
分析过程中要应用的约束属性的列表。 | String |
hierarchy (可选) |
如果未在用于执行分析的网络数据集中定义等级属性,该参数将不可用。在这种情况下,使用“#”作为参数值。 | Boolean |
hierarchy_settings (可选) |
旧版本:在版本 10 之前,可使用此参数将网络数据集中建立的默认等级范围更改为其他范围以用于分析。而版本 10 中不再支持此参数,并且应将其指定为空字符串。如果您要更改等级范围以进行分析,请更新网络数据集中的默认等级范围。 | Network Analyst Hierarchy Settings |
output_path_shape (可选) |
| String |
代码示例
仅使用必需参数执行此工具
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.MakeVehicleRoutingProblemLayer_na("Transportation/Streets_ND",
"DeliveryRoutes","Minutes")
使用所有参数执行此工具
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.MakeVehicleRoutingProblemLayer_na("Transportation/Streets_ND",
"FridayRoutes","Minutes","Meters",
"Minutes","Miles", "1/2/1900", "1",
"High","Medium","ALLOW_DEAD_ENDS_ONLY",
["Oneway"],"USE_HIERARCHY","",
"TRUE_LINES_WITHOUT_MEASURES")
以下独立 Python 脚本演示了如何使用 MakeVehicleRoutingProblemLayer 工具通过一支车队为一组停靠点提供服务。
# Name: MakeVehicleRoutingProblemLayer_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
from arcpy import env
try:
#Check out the Network Analyst extension license
arcpy.CheckOutExtension("Network")
#Set environment settings
env.workspace = "C:/data/SanFrancisco.gdb"
env.overwriteOutput = True
#Set local variables
inNetworkDataset = "Transportation/Streets_ND"
outNALayer = "StoreDeliveryRoute"
impedanceAttribute = "TravelTime"
distanceAttribute = "Meters"
timeUntis = "Minutes"
distanceUntis = "Miles"
inOrders = "Analysis/Stores"
inDepots = "Analysis/DistributionCenter"
inRoutes = "RoutesTable"
orderFieldMappings = "Name Name #; ServiceTime ServiceTime #; " + \
"TimeWindowStart1 TimeStart1 #; " + \
"TimeWindowEnd1 TimeEnd1 #; MaxViolationTime1 # 0; " + \
"DeliveryQuantities Demand #"
depotFieldMappings = "Name Name #; TimeWindowStart1 # 8 AM; " + \
"TimeWindowEnd1 # 5 PM"
outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
#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 unti distance in routes, we have to specify a
#distance attribute. The values for CostPerUnitDistance are in miles, so we
#specify miles for distance units parameter.
arcpy.MakeVehicleRoutingProblemLayer_na(inNetworkDataset,outNALayer,
impedanceAttribute,distanceAttribute,
timeUntis, distanceUntis, "", 1,
UTurn_policy="NO_UTURNS",
output_path_shape="STRAIGHT_LINES")
#Load the store locations as orders. Using field mappings we map the Name,
#ServiceTime, TimeWindowStart1, TimeWindowEnd1 and DeliveryQuantities
#properties for Orders from the fields of store features and assign a value
#of 0 to MaxViolationTime1 property
arcpy.AddLocations_na(outNALayer, "Orders", inOrders, orderFieldMappings,"")
#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 5PM for TimeWindowEnd2 properties
arcpy.AddLocations_na(outNALayer, "Depots", inDepots, depotFieldMappings,"")
#Load the routes from a table containing information about routes
#In this case, since the fields on the table and property names for Routes
#are same, we will just use the default field mappings
arcpy.AddLocations_na(outNALayer, "Routes", inRoutes, "", "")
#Solve the VRP layer
arcpy.Solve_na(outNALayer)
#Save the solved VRP layer as a layer file on disk with relative paths
arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE")
print "Script completed successfully"
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "An error occured on line %i" % tb.tb_lineno
print str(e)