applyTravelMode
汇总
用于访问车辆配送 (VRP) 网络分析图层中的分析属性。 GetSolverProperties 函数用于从车辆配送 (VRP) 网络分析图层中获取 VehicleRoutingProblemSolverProperties 对象。
讨论
VehicleRoutingProblemSolverProperties 对象提供对车辆配送 (VRP) 网络分析图层中所有分析属性的读取和写入权限。该对象可用于修改车辆配送 (VRP) 图层的分析属性,并可重新求解相应图层以确定合适结果。使用 创建车辆配送分析图层 地理处理工具可创建新的车辆配送图层。通过从新的车辆配送图层获取 VehicleRoutingProblemSolverProperties 对象,可重新对现有图层进行后续分析,而无需每次分析都创建一个新图层,这将非常耗时。
修改 VehicleRoutingProblemSolverProperties 对象的属性后,相应的图层可立即与其他函数和地理处理工具配合使用。无需刷新或更新图层,通过上述对象进行的修改便可生效。
语法
applyTravelMode()
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
attributeParameters (读取和写入) |
用于获取或设置将在分析中使用的参数化属性。 该属性返回一个 Python 字典。 该字典关键字是由属性名称和参数名称这两个值组成的元组。 字典中每个项目的值均为参数值。 参数化的网络属性用于对属性值的某个动态方面进行建模。 例如,可使用某个参数对高度限制为 12 英尺的隧道进行建模。 在这种情况下,应将以英尺为单位的车辆高度指定为参数值。 如果车辆高度超过 12 英尺,此限制条件将评估为 尝试修改 请勿尝试修改
使用新的字典对象修改
如果网络分析图层没有参数化属性,则该属性将返回 |
Dictionary |
|
defaultDate (读取和写入) |
用于获取或设置指定了时间但未指定日期的时间字段值的隐式日期。 如果某个停靠点对象的时间字段(如 TimeWindowStart1)只有时间值,则假定该日期为 也可以使用以下日期将一周中的某天指定为默认日期:
例如,要将时间字段值的隐式日期指定为星期二,则将属性值指定为 |
DateTime |
|
distanceAttribute (读取和写入) |
用于获取或设置定义沿网络元素的长度所用的距离成本属性。 |
String |
|
distanceFieldUnits (读取和写入) |
用于获取或设置分析图层的子图层和表(网络分析类)的距离字段所用的距离单位。 单位不必与指定为
|
String |
|
excessTransitTimeImportance (读取和写入) |
用于获取或设置减少额外行驶时间的重要性。 额外行驶时间是指超出停靠点对间直线行驶所需时间的数量。 额外时间是由于在需求点对的访问期间进行休息或者行驶至其他停靠点或站点而导致的。 仅当使用停靠点对时,此参数才相关。
|
String |
|
ignoreInvalidLocations (读取和写入) |
指定是否忽略无效的输入位置。 通常,如果无法 在网络上定位 ,则位置无效。 当无效位置被忽略时,求解程序将跳过它们并尝试使用剩余位置执行分析。
|
String |
|
outputPathShape (读取和写入) |
用于获取或设置求解程序输出的路径要素的形状类型。
|
String |
|
restrictions (读取和写入) |
用于获取或设置适用于分析的约束属性的列表。 空列表 |
String |
|
solverName (只读) |
返回被用于获取求解程序属性对象的 Network Analyst 图层所引用的求解程序的名称。 从 |
String |
|
streetDirectionsProperties (读取和写入) |
为 |
Object |
|
timeAttribute (读取和写入) |
用于获取或设置基于时间的网络成本属性以用于定义通过网络元素时所需的时间。 查找解决方案时,利用求解程序使成本属性最小化。 |
String |
|
timeFieldUnits (读取和写入) |
用于获取或设置分析图层的子图层和表(网络分析类)的时态字段所用的时间单位。 单位不必与指定为
|
String |
|
timeWindowViolationImportance (读取和写入) |
用于获取或设置遵循时间窗且不引起冲突的重要性。 如果路径在时间窗关闭后才到达停靠点、站点或休息点,将会产生时间窗冲突。 该冲突是时间窗关闭与路径到达时间之间的时间间隔。 以下是可能值列表:
|
String |
|
timeZoneUsageForTimeFields (读取和写入) |
指定输入数据中日期时间字段的时区,例如用于时间窗的字段。
|
String |
|
spatialClustering (读取和写入) |
指定是否使用空间聚类。
|
Boolean |
|
travelMode (只读) |
访问网络分析图层上设置为 |
Object |
|
useHierarchy (读取和写入) |
当执行分析时控制等级属性的使用。 以下是可能值列表:
|
String |
|
uTurns (读取和写入) |
用于获取或设置策略,该策略指示求解程序如何管理停靠点之间的遍历网络期间所产生的交汇点处的 U 形转弯。 以下是可能值列表:
|
String |
方法
applyTravelMode(travel_mode)
根据出行模式对象更新网络分析图层的分析属性。随后可对更新的网络分析图层进行求解以完成分析。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
travel_mode |
该变量引用一个源自网络数据集的出行模式对象。可通过调用 VRP 将仅使用基于时间的阻抗进行求解,因此将仅允许基于时间的阻抗出行模式。 |
Object |
代码示例
该脚本显示了如何创建车辆配送图层图层、添加数据以及使用当前日期作为默认日期来解决该问题。然后,将默认日期更新为星期二并再次进行求解。其基于旧金山地区的教程网络数据集。
# Name: VehicleRoutingProblemSolverProperties_Workflow.py
# Description: Find the optimal VRP solution solving for today or a day of the
# week. Uses the SolverProperties to update the existing VRP layer
# before re-running the analysis.
# Requirements: Network Analyst extension
# Import system modules
import arcpy
from arcpy import env
import os
import datetime
try:
# Set environment settings
output_dir = r"C:\Data"
# The NA layer's data will be saved to the workspace specified here
env.workspace = os.path.join(output_dir, "Output.gdb")
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")
routes_today = os.path.join(output_dir, "Output.gdb", "Routes_Today")
routes_tuesday = os.path.join(output_dir, "Output.gdb", "Routes_Tuesday")
# 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["TimeWindowStart1"].mappedFieldName = "TimeStart1"
order_field_mappings["TimeWindowEnd1"].mappedFieldName = "TimeEnd1"
order_field_mappings["DeliveryQuantities"].mappedFieldName = "Demand"
order_field_mappings["MaxViolationTime1"].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["TimeWindowStart1"].defaultValue = "8 AM"
depot_field_mappings["TimeWindowEnd1"].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
arcpy.na.AddLocations(layer_object, routes_layer_name, in_routes, "", "")
# Solve the VRP layer
arcpy.na.Solve(layer_object)
# Save the resulting Routes sublayer
arcpy.management.CopyFeatures(routes_layer_name, routes_today)
# Get the solver properties object from the vehicle routing problem layer
solverProps = arcpy.na.GetSolverProperties(layer_object)
# Update the default date to tuesday using the specified day in the above
# doc (Tuesday - 1/2/1900) for the vehicle routing problem layer using the
#solver properties object
solverProps.defaultDate = datetime.date(1900, 1, 2)
# Solve the VRP layer
arcpy.na.Solve(layer_object)
# Save the resulting Routes sublayer
arcpy.management.CopyFeatures(routes_layer_name, routes_tuesday)
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))
此脚本显示如何使用“货运时间”出行模式查找货车车队的路径。
#Get the VRP layer object from a layer named "VRP" in the map
doc = arcpy.mp.ArcGISProject('current')
map_obj = doc.listMaps()[0]
vrp_layer = map_obj.listLayers('VRP')[0]
#Get the Trucking Time travel mode from the network dataset
desc = arcpy.Describe(vrp_layer)
travel_modes = arcpy.na.GetTravelModes(desc.network.catalogPath)
trucking_mode = travel_modes["Trucking Time"]
#Apply the travel mode to the analysis layer
solver_properties = arcpy.na.GetSolverProperties(vrp_layer)
solver_properties.applyTravelMode(trucking_mode)