LocationAllocationSolverProperties

摘要

用于访问位置分配网络分析图层中的分析属性。GetSolverProperties 函数用于从位置分配网络分析图层中获取 LocationAllocationSolverProperties 对象。

说明

LocationAllocationSolverProperties 对象提供对位置分配网络分析图层中所有分析属性的读取和写入权限。该对象可用于修改位置分配图层的所需分析属性,并可重新求解相应图层以确定合适结果。使用创建位置分配分析图层地理处理工具可创建新的位置分配图层。通过从新的位置分配图层获取 LocationAllocationSolverProperties 对象,可重新对现有图层进行后续分析,而无需每次分析都创建一个图层,以节省时间。

修改 LocationAllocationSolverProperties 对象的属性后,相应的图层可立即与其他函数和地理处理工具配合使用。无需刷新或更新图层,通过上述对象进行的修改便可生效。

属性

属性说明数据类型
accumulators
(可读写)

用于获取或设置累积为分析一部分的网络成本属性的列表。空列表 [] 表示没有累积成本属性。

String
attributeParameters
(可读写)

用于获取或设置将在分析中使用的参数化属性。该属性返回一个 Python 字典。该字典关键字是由属性名称和参数名称这两个值组成的元组。字典中每个项目的值均为参数值。

参数化的网络属性用于对属性值的某个动态方面进行建模。例如,可使用某个参数对高度限制为 12 英尺的隧道进行建模。在这种情况下,应将以英尺为单位的车辆高度指定为参数值。如果车辆高度超过 12 英尺,此限制条件将评估为 True,从而限制车辆穿越隧道。类似的,桥梁还可以具有一个用来指定重量限制的参数。

尝试修改 attributeParameters 属性不会导致值更新。相反,您应始终使用新的字典对象来设置属性值。以下两个代码块将演示这两种方法的差异。

请勿尝试修改 attributeParameters 属性,这种编码方法不起作用。

solverProps.attributeParameters[('HeightRestriction', 'RestrictionUsage')] = "PROHIBITED"

使用新的字典对象修改 attributeParameters 属性。

params = solverProps.attributeParameters params[('HeightRestriction', 'RestrictionUsage')] = "PROHIBITED"
solverProps.attributeParameters = params
如果网络分析图层没有参数化属性,则该属性将返回 None

Dictionary
defaultCapacity
(可读写)

用于获取或设置当位置分配 problemType 参数设置为 MAXIMIZE_CAPACITATED_COVERAGE 时默认的设施点容量。对于所有其他问题类型,可忽略此参数。

设施点有 Capacity 属性,如果此属性设置为非空值,将覆盖该设施点的 defaultCapacity 参数。

Double
facilitiesToFind
(可读写)

用于获取或设置求解程序应定位的设施点数量。如果 problemType 属性设置为 MINIMIZE_FACILITIES,则属性值将被忽略,因为求解程序将确定最小数量的设施点进行定位,以将覆盖范围最大化。如果 problemType 属性设置为 TARGET_MARKET_SHARE,属性值也会被忽略,因为求解程序将搜索要占有指定市场份额所需的最小数量的设施点。

Integer
impedance
(可读写)

用于获取或设置用作阻抗的网络成本属性。

String
impedanceCutoff
(可读写)

用于获取或设置请求点可分配给设施点时的最大阻抗。

Double
impedanceParameter
(可读写)

用于获取或设置在 impedanceTransformation 属性中指定的方程的参数值。当 impedanceTransformation 属性设置为 LINEAR 时,该属性值将被忽略。该属性值不应为零。

Double
impedanceTransformation
(可读写)

用于获取或设置对设施点与请求点间网络成本进行变换的方程。该属性值与 impedanceParameter 属性值结合使用可指定设施点与请求点间的网络阻抗对于求解程序选择设施点的影响的严重程度。以下是可能值列表:

  • LINEAR设施点和请求点之间变换的网络阻抗与它们之间的最短路径网络阻抗相同。设置该值后,impedanceParameter 属性值将始终设置为 one,并且为 impedanceParameter 属性设置的任何值都将被忽略。
  • POWER设施点和请求点之间变换的网络阻抗等于以最短路径网络阻抗为底,以 impedanceParameter 属性值所指定的数为指数的幂运算结果。使用此属性值以及正的 impedanceParameter 属性值可给予附近设施点更高的权重。
  • EXPONENTIAL设施点和请求点之间变换的网络阻抗等于以数学常量 e 为底,以最短路径网络阻抗所指定的数乘以 impedanceParameter 属性值为指数的幂运算结果。使用此属性值以及正的 impedanceParameter 属性值可给予附近设施点非常高的权重。
String
outputPathShape
(可读写)

控制是否用直线表示位置分配分析的结果。以下是可能值列表:

  • NO_LINES将不会为分析的输出生成任何形状。这在具有大量请求点或设施点,以及仅关注图表输出时非常有用。
  • STRAIGHT_LINES生成将设施点解连接到为其分配的请求点的直线。
String
problemType
(可读写)

用于获取或设置将求解的问题类型。问题类型的选择取决于要定位的设施点种类。不同种类的设施点具有不同的优先级和约束。以下是可能值列表:

  • MINIMIZE_IMPEDANCE此选项可解决仓库位置问题。它选择一组使加权阻抗(请求的位置乘以到最近设施点的阻抗)的总和最小的设施点。此问题类型通常称为 P 中位数问题。
  • MAXIMIZE_COVERAGE此选项可解决消防站位置问题。它选择了多个设施点以保证所有或最大数量的请求点处于指定的阻抗中断范围内。
  • MAXIMIZE_CAPACITATED_COVERAGE 此选项用于求解容量有限的设施点的位置问题。此选项将选择一组满足所有或最大数量的请求而不超出任何设施点容量的设施点。除了支持容量外,该选项还选择一组使加权阻抗(分配给某个设施点的请求点乘以到该设施点的阻抗)的总和最小的设施点。
  • MINIMIZE_FACILITIES此选项可解决消防站位置问题。它将选择当在指定的阻抗中断范围内覆盖了所有或最大数量的请求点时所需要的设施点的最小数量。
  • MAXIMIZE_ATTENDANCE此选项可解决邻域存储位置问题,其中分配给最近所选设施点的请求比例将随距离的增加而降低。已选择最大化总分配请求点的设施点集。大于指定的阻抗中断的请求点不会影响所选的设施点集。
  • MAXIMIZE_MARKET_SHARE此选项可解决竞争性设施点的位置问题。它选择当存在竞争性设施点时可最大化市场份额的设施点。重力模型概念用于确定分配给每个设施点的请求点比例。已选择最大化总分配请求点的设施点集。
  • TARGET_MARKET_SHARE此选项可解决竞争性设施点的位置问题。它选择当存在竞争性设施点时可达到指定目标市场份额的设施点。重力模型概念用于确定分配给每个设施点的请求点比例。已选择的最小设施点量需达到指定的目标市场份额。
String
restrictions
(可读写)

用于获取或设置适用于分析的约束属性的列表。空列表 [] 表示没有约束属性用于分析。

String
solverName
(只读)

返回被用于获取求解程序属性对象的 Network Analyst 图层所引用的求解程序的名称。从 LocationAllocationSolverProperties 对象访问时,该属性始终返回字符串值位置分配求解程序

String
targetMarketShare
(可读写)

用于获取或设置当 problemType 属性设置为 TARGET_MARKET_SHARE 时要求解的目标市场份额百分数。它是您希望设施点解占总请求权重的百分比。求解程序会求出为占有该值指定的目标市场份额所需的最小设施点数。为 facilitiesToFind 属性设置的任何值都将被忽略。

Double
timeOfDay
(可读写)

用于获取或设置离开的时间和日期。可以从设施点或请求点离开,取决于是从请求点向设施点行驶还是从设施点向请求点行驶。可以用值 None 指定不应使用任何日期和时间。

可使用以下日期来指定一周中的每一天,而无需使用特定的日期:

  • 今天 - 12/30/1899
  • 星期日 - 12/31/1899
  • 星期一 - 1/1/1900
  • 星期二 - 1/2/1900
  • 星期三 - 1/3/1900
  • 星期四 - 1/4/1900
  • 星期五 - 1/5/1900
  • 星期六 - 1/6/1900

例如,要指定应该在星期五 8:00 a.m. 离开,则将值指定为 datetime.datetime(1900, 1, 5, 8,0,0)

timeZoneUsage 参数指定该日期和时间是 UTC 还是设施点或请求点所在时区。

DateTime
timeZoneUsage
(可读写)

指定 timeOfDay 参数的时区。

  • GEO_LOCALtimeOfDay 参数是指设施点或请求点所在的时区。如果已在 timeOfDay 中指定时间和日期,并且 travelDirection 已设置为 FACILITY_TO_DEMAND,则这是设施点的时区。如果其他条件相同,但 travelDirection 设置为 DEMAND_TO_FACILITY,则这也是设施点的时区。
  • UTCtimeOfDay 参数采用协调世界时间 (UTC)。如果您想要在指定时间内(如现在)求解分析问题,但不确定设施点或请求点所在的时区,请选择此选项。

在求解跨多个时区的位置分配分析问题时,以下规则适用:

  • 当已设置起始时间并且驾驶方向是从设施点到请求点时,所有设施点都必须位于同一个时区内。
  • 当已设置起始时间并且驾驶方向是从请求点到设施点时,所有请求点都必须位于同一个时区内。

String
travelDirection
(可读写)

控制计算网络成本时设施点与请求点之间的行驶方向。以下是可能值列表:

  • FACILITY_TO_DEMAND行驶方向是从请求点指向设施点。
  • DEMAND_TO_FACILITY行驶方向从请求点到设施点。
String
travelMode
(只读)

访问网络分析图层上设置为 arcpy.na.TravelMode 对象的出行模式。

Object
useHierarchy
(可读写)

当执行分析时控制等级属性的使用。以下是可能值列表:

  • USE_HIERARCHY 使用等级属性进行分析。使用等级的结果是,求解程序更偏好高等级的边而不是低等级的边。分等级求解的速度更快,并且可用于模拟驾驶员在可能的情况下选择在高速公路而非地方道路上行驶(即使行程可能更远)的偏好。仅当 Network Analyst 图层引用的网络数据集具有等级属性时,此选项才适用。值 True 也可用于指定此选项。
  • NO_HIERARCHY不使用等级属性进行分析。如果不使用等级属性,则会为网络数据集生成精确的路径。值 False 也可用于指定此选项。
String
uTurns
(可读写)

用于获取或设置策略,该策略指示交汇点处的 U 形转弯在求解程序处理停靠点之间的遍历期间可如何出现。以下是可能值列表:

  • ALLOW_UTURNS无论在交汇点处有几条连接的边,均允许 U 形转弯。
  • NO_UTURNS在所有交汇点处均禁止 U 形转弯,不管交汇点原子价如何。不过请注意,即使已选择该设置,在网络位置仍允许 U 形转弯;但是也可以通过设置个别网络位置的 CurbApproach 属性来禁止 U 形转弯。
  • ALLOW_DEAD_ENDS_ONLY除仅有一条相邻边的交汇点(死角)外,其他交汇点均禁止 U 形转弯。
  • ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLY在恰好有两条相邻边相遇的交汇点处禁止 U 形转弯,但是交叉点(三条或三条以上相邻边的交汇点)和死角(仅有一条相邻边的交汇点)处允许。通常,网络在路段中间有多余的交汇点。此选项可防止车辆在这些位置出现 U 形转弯。
String

方法概述

方法说明
applyTravelMode (travel_mode)

根据出行模式对象更新网络分析图层的分析属性。随后可对更新的网络分析图层进行求解以完成分析。

方法

applyTravelMode (travel_mode)
参数说明数据类型
travel_mode

该变量引用一个源自网络数据集的出行模式对象。可通过调用 arcpy.na.GetTravelModes 函数获得出行模式对象的列表。

Object

创建网络分析图层后,将为其分配所有分析属性的默认值。可使用从网络分析图层获得的求解程序属性对象更新各个分析属性。出行模式存储了一组预定义的分析设置,用于帮助执行特定分析,例如,步行时间出行模式存储了执行基于时间的步行分析所需的分析设置。

使用 applyTravelMode 方法,可一次性应用在一个出行模式中定义的所有分析设置。在分析属性完成更新后,可对网络分析图层进行求解以完成分析。

如果在更新求解程序属性时出错,例如,当提供的出行模式所引用的属性在当前网络数据集中不存在,或不再适用于创建求解程序属性对象的相应网络分析图层所使用的网络数据集时,不会产生任何异常。此方法将成功执行,但当您尝试求解此类网络分析图层时会出现错误。

如果 travel_mode 参数不引用出行模式对象或字符串,则将产生 TypeError 异常。如果 travel_mode 参数引用字符串并且该字符串无法在内部转换成出行模式对象的有效字符串表示,将产生 ValueError 异常。

代码示例

LocationAllocationSolverProperties 示例 1(工作流)

该脚本显示如何使用位置分配分析为连锁零售店选择可以获得最大业务量的商店位置。该脚本首先使用相应的分析设置创建一个位置分配图层。接下来,将候选商店位置和区块组中心分别加载为设施点和需求点。对分析进行求解并保存至图层文件。使用 LocationAllocationSolverProperties 对象修改分析属性以执行两个后续分析。每次求解之后,图层均以文件格式储存。该脚本使用旧金山地区的数据。

旧版本:

GetNASublayer 功能可用于检索网络分析图层的子图层。它是在 ArcGIS Pro 2.7 中引入的。在以前的软件版本中,检索网络分析图层的子图层对象的最佳方法是使用网络分析 Layer 对象的 listLayers 方法,该方法将子图层名称用作通配符。

# Name: LocationAllocationSolverProperties_workflow_01.py
# Description: Test three different scenarios for optimizing the locations of
#              new stores based on customer and competitor locations. Use the
#              LocationAllocationSolverProperties object to update an existing
#              Location-Allocation layer before re-running the analysis.
# Requirements: Network Analyst Extension

# Import system modules
import arcpy
from arcpy import env
import os

try:
    # Check out Network Analyst license if available. Fail if the Network Analyst license is not available.
    if arcpy.CheckExtension("network") == "Available":
        arcpy.CheckOutExtension("network")
    else:
        raise arcpy.ExecuteError("Network Analyst Extension license is not available.")

    # Set environment settings
    output_dir = "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 = "Location_Allocation"
    scenario1_output = "NewStoreLocations"
    scenario2_output = "StoreExpansionScenario"
    scenario3_output = "MaximizedMarketShareStoreLocations"
    facilities = os.path.join(input_gdb, "Analysis", "CandidateStores")
    required_facility = os.path.join(input_gdb, "Analysis", "ExistingStore")
    competitor_facility = os.path.join(input_gdb, "Analysis", "CompetitorStores")
    demand_points = os.path.join(input_gdb, "Analysis", "TractCentroids")

    # --- Scenario 1: Select the best three locations for stores

    # Create a new Location-Allocation layer. In this case, the demand travels to
    # the facility. We wish to find 3 potential store locations out of all the
    # candidate store locations using the maximize attendance model.
    result_object = arcpy.na.MakeLocationAllocationAnalysisLayer(network,
                                            layer_name, "Driving Time",
                                            "TO_FACILITIES",
                                            "MAXIMIZE_ATTENDANCE", cutoff=5,
                                            number_of_facilities_to_find=3,
                                            decay_function_type="LINEAR")
    
    # Get the layer object from the result object. The Location-Allocation layer
    # can now be referenced using the layer object.
    layer_object = result_object.getOutput(0)
    
    # Get the names of all the sublayers within the location-allocation layer.
    sublayer_names = arcpy.na.GetNAClassNames(layer_object)
    # Store the layer names that we will use later
    facilities_layer_name = sublayer_names["Facilities"]
    demand_points_layer_name = sublayer_names["DemandPoints"]
    # Get the facilities sublayer object to use later
    facilities_sublayer = arcpy.na.GetNASublayer(layer_object, "Facilities")
    
    # Load the candidate store locations as facilities using default search
    # tolerance and field mappings.
    arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities, "",
                                                                            "")
    
    # Load the tract centroids as demand points using default search tolerance.
    # Use the field mappings to map the Weight property from POP2000 field.
    demand_field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
                                                    demand_points_layer_name)
    demand_field_mappings["Weight"].mappedFieldName = "POP2000"
    arcpy.na.AddLocations(layer_object, demand_points_layer_name, demand_points,
                          demand_field_mappings, "")
    
    # Solve the location-allocation layer
    arcpy.na.Solve(layer_object)
        
    # Save the facilities sublayer of the solved Location-Allocation layer as a 
    # feature class
    arcpy.management.CopyFeatures(facilities_sublayer, scenario1_output)
    
    # --- Scenario 2: Assuming the three stores selected previously have already
    # been built, select the best locations for two more stores
    
    # We need to re-solve the previous scenario as a store-expansion scenario, in
    # which we will start with an existing store and optimally locate two
    # additional stores.
    # Load the existing store location as the required facility. Use the field
    # mappings to set the facility type to requried. We need to append this
    # required facility to existing facilities.
    field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
                                                    facilities_layer_name)
    field_mappings["FacilityType"].defaultValue = 1
    field_mappings["Name"].mappedFieldName = "Name"
    arcpy.na.AddLocations(layer_object, facilities_layer_name, required_facility,
                          field_mappings, "", append="APPEND")
    
    # Solve the location-allocation layer
    arcpy.na.Solve(layer_object)
        
    # Save the facilities sublayer of the solved Location-Allocation layer as a 
    # feature class
    arcpy.management.CopyFeatures(facilities_sublayer, scenario2_output)
    
    # --- Scenario 3: Re-run the previous scenario with additional information:
    # the locations of competing stores.
    
    # Load the competitor store locations as the competitor facilities. Use the
    # field mappings to set the facility type to Competitor. We need to append
    # these competitor facilities to existing facilities.
    field_mappings["FacilityType"].defaultValue = 2
    arcpy.na.AddLocations(layer_object, facilities_layer_name,
                          competitor_facility, field_mappings, "",
                          append="APPEND")
    
    # Get the LocationAllocationSolverProperties object from the 
    # Location-Allocation layer to modify the analysis settings for the layer.
    solver_props = arcpy.na.GetSolverProperties(layer_object)
    
    # Set the problem type to Maximize Market Share, and impedance transformation
    # to Power with an impedance parameter value of 2.
    solver_props.problemType = "MAXIMIZE_MARKET_SHARE"
    solver_props.impedanceTransformation = "POWER"
    solver_props.impedanceParameter = 2
    
    # Solve the location-allocation layer
    arcpy.na.Solve(layer_object)
    
    # print the market share that was obtained
    print(arcpy.GetMessage(0))
    
    # Save the facilities sublayer of the solved Location-Allocation layer as a 
    # feature class
    arcpy.management.CopyFeatures(facilities_sublayer, scenario3_output)
    
    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))
ApplyTravelMode 示例 2(Python 窗口)

此脚本显示如何将 TruckingTime 出行模式应用到现有图层。

#Get the location-allocation layer object from a layer named
#"Location-Allocation" in the map
doc = arcpy.mp.ArcGISProject('current')
map_obj = doc.listMaps()[0]
la_layer = map_obj.listLayers('Location-Allocation')[0]

#Get the Trucking Time travel mode from the network dataset
desc = arcpy.Describe(la_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(la_layer)
solver_properties.applyTravelMode(trucking_mode)