LocationAllocationSolverProperties (arcpy.na)

摘要

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

讨论

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

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

属性

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

Provides the ability to get or set a list of network cost attributes that are accumulated as part of the analysis. An empty list, [], indicates that no cost attributes are accumulated.

String
attributeParameters
(读写)

Provides the ability to get or set the parameterized attributes to be used in the analysis. The property returns a Python dictionary. The dictionary key is a two-value tuple consisting of the attribute name and the parameter name. The value for each item in the dictionary is the parameter value.

Parameterized network attributes are used to model some dynamic aspect of an attribute's value. For example, a tunnel with a height restriction of 12 feet can be modeled using a parameter. In this case, the vehicle's height in feet should be specified as the parameter value. If the vehicle is taller than 12 feet, this restriction will then evaluate to true, thereby restricting travel through the tunnel. Similarly, a bridge could have a parameter to specify a weight restriction.

Attempting to modify the attributeParameters property in place won't result in updated values. Instead, you should always use a new dictionary object to set values for the property. The following two code blocks demonstrate the difference between these two approaches.

#Don't attempt to modify the attributeParameters property in place.
#This coding method won't work.

solverProps.attributeParameters[('HeightRestriction', 'RestrictionUsage')] = "PROHIBITED"
#Modify the attributeParameters property using a new dictionary object.
#This coding method works. 

params = solverProps.attributeParameters
params[('HeightRestriction', 'RestrictionUsage')] = "PROHIBITED"
solverProps.attributeParameters = params
If the network analysis layer does not have parameterized attributes, this property returns None.

Dictionary
defaultCapacity
(读写)

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

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

Double
facilitiesToFind
(读写)

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

Integer
impedance
(读写)

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

String
impedanceCutoff
(读写)

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

Double
impedanceParameter
(读写)

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

Double
impedanceTransformation
(读写)

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

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

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

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

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

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

Provides the ability to get or set a list of restriction attributes that are applied for the analysis. An empty list, [], indicates that no restriction attributes are used for the analysis.

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
useHierarchy
(读写)

Controls the use of the hierarchy attribute while performing the analysis. The following is a list of possible values:

  • USE_HIERARCHY Use the hierarchy attribute for the analysis. Using a hierarchy results in the solver preferring higher-order edges to lower-order edges. Hierarchical solves are faster, and they can be used to simulate the preference of a driver who chooses to travel on freeways over local roads when possible—even if that means a longer trip. This option is applicable only if the network dataset referenced by the Network Analyst layer has a hierarchy attribute. A value of True can also be used to specify this option.
  • NO_HIERARCHYDo not use the hierarchy attribute for the analysis. Not using a hierarchy yields an exact route for the network dataset. A value of False can also be used to specify this option.
String
uTurns
(读写)

Provides the ability to get or set the policy that indicates how the U-turns at junctions that could occur during network traversal between stops are being handled by the solver. The following is a list of possible values:

  • ALLOW_UTURNSU-turns are permitted at junctions with any number of connected edges.
  • NO_UTURNSU-turns are prohibited at all junctions, regardless of junction valency. Note, however, that U-turns are still permitted at network locations even when this setting is chosen; however, you can set the individual network locations' CurbApproach property to prohibit U-turns there as well.
  • ALLOW_DEAD_ENDS_ONLYU-turns are prohibited at all junctions, except those that have only one adjacent edge (a dead end).
  • ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLYU-turns are prohibited at junctions where exactly two adjacent edges meet but are permitted at intersections (junctions with three or more adjacent edges) and dead ends (junctions with exactly one adjacent edge). Oftentimes, networks have extraneous junctions in the middle of road segments. This option prevents vehicles from making U-turns at these locations.
String

代码实例

LocationAllocationSolverProperties 示例 1(Python 窗口)

该脚本显示如何更新位置分配网络分析图层的问题类型,以“最小化设施点数”并将幂阻抗变换的阻抗参数设置为 2。它假设已经在新地图文档中根据旧金山地区的网络数据集创建名为 Stores Coverage 的位置分配图层。

#Get the location-allocation layer object from a layer named "Stores Coverage" in
#the table of contents
laLayer = arcpy.mapping.Layer("Stores Coverage")

#Get the solver properties object from the location-allocation layer
solverProps = arcpy.na.GetSolverProperties(laLayer)

#Update the properties for the location-allocation layer using the solver properties
#object
solverProps.problemType = "MINIMIZE_FACILITIES"
solverProps.impedanceTransformation = "POWER"
solverProps.impedanceParameter = 2
LocationAllocationSolverProperties 示例 2(工作流)

该脚本显示如何使用位置分配分析为连锁零售店选择可以获得最大业务量的商店位置。该脚本首先使用相应的分析设置创建一个新位置分配图层。接下来,将候选商店位置和区块组中心分别加载为设施点和需求点。对分析进行求解并保存至图层文件。使用 LocationAllocationSolverProperties 对象修改分析属性以执行两个后续分析。每次求解之后,图层均以文件格式储存。该脚本使用旧金山地区的数据。示例详细描述参照“网络分析教程”的练习 9。在帮助您在 ArcMap 用户界面下演练此流程的同时,该教程提供了使用 Python 脚本自动处理类似场景的示例。

import arcpy

#Set up the environment
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/data/SanFrancisco.gdb"
arcpy.CheckOutExtension("network")

#Set up variables
networkDataset = "Transportation/Streets_ND"
outNALayerName = "NewStoreLocations"
inFacilities = "Analysis/CandidateStores"
requiredFacility = "Analysis/ExistingStore"
competitorFacility = "Analysis/CompetitorStores"
inDemandPoints = "Analysis/TractCentroids"
outputFolder = "C:/data/output/"

#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.
outNALayer = arcpy.na.MakeLocationAllocationLayer(networkDataset, outNALayerName,
                                                  "TravelTime","DEMAND_TO_FACILITY",
                                                  "MAXIMIZE_ATTENDANCE",3,5,
                                                  "LINEAR")
#Get the layer object from the result object. The location-allocation layer
#can now be referenced using the layer object.
outNALayer = outNALayer.getOutput(0)

#Get the names of all the sublayers within the location-allocation layer.
subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
#Stores the layer names that we will use later
facilitiesLayerName = subLayerNames["Facilities"]
demandPointsLayerName = subLayerNames["DemandPoints"]

#Load the candidate store locations as facilities using default search
#tolerance and field mappings.
arcpy.na.AddLocations(outNALayer, facilitiesLayerName, inFacilities, "", "",
                      exclude_restricted_elements = "EXCLUDE")

#Load the tract centroids as demand points using default search tolerance. Use 
#the field mappings to map the Weight property from POP2000 field.
demandFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer,
                                                    demandPointsLayerName)
demandFieldMappings["Weight"].mappedFieldName = "POP2000"
arcpy.na.AddLocations(outNALayer,demandPointsLayerName ,inDemandPoints,
                      demandFieldMappings, "",
                      exclude_restricted_elements = "EXCLUDE")

#Solve the location-allocation layer
arcpy.na.Solve(outNALayer)
    
#Save the solved location-allocation layer as a layer file on disk with 
#relative paths
outLayerFile = outputFolder + outNALayerName + ".lyr"
arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"RELATIVE")

#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.
fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, facilitiesLayerName)
fieldMappings["FacilityType"].defaultValue = 1
fieldMappings["Name"].mappedFieldName = "Name"
arcpy.na.AddLocations(outNALayer, facilitiesLayerName, requiredFacility,
                      fieldMappings, "", append = "APPEND",
                      exclude_restricted_elements = "EXCLUDE")

#Solve the location-allocation layer
arcpy.na.Solve(outNALayer)
    
#Save the solved location-allocation layer as a layer file on disk with 
#relative paths
updatedNALayerName = "StoreExpansionScenario"
outNALayer.name = updatedNALayerName
outLayerFile = outputFolder + updatedNALayerName + ".lyr"
arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"RELATIVE")

#We need to resolve the previous scenario and locate new stores to 
#maximize market share in light 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.
fieldMappings["FacilityType"].defaultValue = 2
arcpy.na.AddLocations(outNALayer, facilitiesLayerName, competitorFacility,
                      fieldMappings, "", append = "APPEND",
                      exclude_restricted_elements = "EXCLUDE")

#Get the LocationAllocationSolverProperties object from the location-allocation 
#layer to modify the analysis settings for the layer.
solverProps = arcpy.na.GetSolverProperties(outNALayer)

#Set the problem type to Maximize Market Share, and impedance transformation to
#Power with an impedance parameter value of 2.
solverProps.problemType = "MAXIMIZE_MARKET_SHARE"
solverProps.impedanceTransformation = "POWER"
solverProps.impedanceParameter = 2

#Solve the location-allocation layer
arcpy.na.Solve(outNALayer)

#print the market share that was obtained
arcpy.AddMessage(arcpy.GetMessage(0))

#Change the name of the NA Layer
updatedNALayerName = "MaximizedMarketShareStoreLocations"
outNALayer.name = updatedNALayerName

#Save the solved location-allocation layer as a layer file on disk with 
#relative paths
outLayerFile = outputFolder + updatedNALayerName + ".lyr"
arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"RELATIVE")
    
arcpy.AddMessage("Completed")

相关主题

5/10/2014