VehicleRoutingProblem

摘要

此 ArcPy 类用于执行车辆配送问题分析。

说明

车辆配送问题分析可用于计算车队的最佳路径。

了解有关车辆配送问题分析的详细信息

语法

VehicleRoutingProblem (in_network, {version})
参数说明数据类型
in_network

将用于网络分析的网络数据集或服务。可以使用网络数据集的目录路径、网络数据集图层对象、网络数据集图层的字符串名称或网络分析服务的门户 URL 来指定参数。网络必须包含至少一个出行模式

要使用门户 URL,您必须使用具有路径选择权限的帐户登录门户。

当对象使用 ArcGIS Online 作为 in_network 时,求解分析将消耗配额。有关详细信息,请参阅服务配额概述

String
version

分析中要使用的方案版本。应使用 VehicleRoutingProblemSchemaVersion 枚举指定此参数。

ArcGIS Pro 2.7 中引入了更新的 VehicleRoutingProblem 对象方案,可提供增强的可用性以及更紧密地匹配 ArcGIS Pro 2.6 中引入的车辆配送图层方案。

如果可能,建议所有新分析均使用方案版本 Two。但是,门户 URL 网络数据源目前不支持方案版本 Two。如果分析将使用门户 URL 作为网络数据源,或者脚本需要与 ArcGIS Pro 2.7 之前的软件版本兼容,请使用方案版本 One

默认值为方案版本 One

Object

属性

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

指定是否允许在结果对象上使用 saveAsLayerFile 方法将分析结果另存为图层文件。 值为 True 表示可以保存图层文件。 值为 False 则表示无法保存图层文件。 如果分析引用网络数据集,则默认设置为 True;如果其引用门户服务,则为 False。 如果分析引用门户服务,则允许保存图层文件可能会降低分析速度。

Boolean
allowSaveRouteData
(可读写)

指定是否允许在结果对象上使用 saveRouteData 方法将分析结果保存为 ZIP 文件。 值为 True 表示可以保存路径数据。 值为 False 则表示无法保存路径数据。 如果分析引用网络数据集,则默认设置为 True;如果其引用门户服务,则为 False。 如果分析引用门户服务,则允许保存路径数据可能会降低分析速度。

Boolean
defaultDate
(可读写)

指定一天中的时间(不包含日期)的时间字段值的默认日期。 默认值为 None,其表示所有日期时间字段都包含日期和时间值。

DateTime
directionsDistanceUnits
(可读写)

报告输出转弯方向的行驶距离时使用的单位。 将返回该属性并将其设置为 DistanceUnits 枚举的成员,且仅在 returnDirections 属性为 True 时可用。 默认值是分析时使用的出行模式中距离属性的单位。

Object
directionsLanguage
(可读写)

将显示输出转弯方向文本的语言。 返回该属性并将表示受支持方向语言的两个或五个字符的语言代码之一设置为字符串。 可从 arcpy.nax.ListDirectionsLanguages 函数中获得可用的方向语言列表。 默认值为 en(英语)或当前激活的语言包的语言。 此属性仅在 returnDirections 属性为 True 时可用。

String
directionsStyle
(可读写)

用于输出转弯方向文本的样式。 将返回该属性并将其设置为 DirectionsStyle 枚举的成员,且仅在 returnDirections 属性为 True 时可用。

默认值为 Desktop

Object
distanceUnits
(可读写)

报告分析输出中的行驶距离时使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 DistanceUnits 枚举的成员。 默认为 DistanceUnits.Kilometers

Object
excessTransitFactor
(可读写)

对减少停靠点对的额外行驶时间的重要性作出评价。 额外行驶时间是指超出停靠点对间直线行驶所需时间的数量。 额外时间可能由司机休息或前往中间停靠点和站点造成。

将返回该属性并将其设置为 Importance 枚举的成员。 默认为 Importance.Medium

当设置为 Importance.Low 时,求解程序尝试找到最小化总体解决方案成本的结果(不考虑额外行驶时间)。 此设置通常应用于快递服务。 由于快递运输的是包裹而不是人员,因此无需担心行驶时间。 使用此设置时,快递可以按照最适合的顺序为停靠点对提供服务,并且总体解决方案成本最低。

当设置为 Importance.Medium 时,求解程序在减少超出行驶时间和减少总体解决方案成本之间寻求一种平衡。

当设置为 Importance.High 时,求解程序尝试找到停靠点对之间额外行驶时间最少的解决方案(以增加总体行驶成本为代价)。 如果您正在停靠点对间运载乘客并且想缩短他们的乘车时间,则这种情况适合使用此设置。 这是出租车服务的特征。

Object
ignoreInvalidLocations
(可读写)

指定是否忽略无效的输入位置。 值为 True 表示将忽略无效的输入位置,仅使用有效位置即可成功进行分析。 值为 False 表示不会忽略无效位置,从而导致分析失败。

Boolean
networkDataSource
(只读)

分析时使用的网络数据集的完整目录路径。

String
overrides
(可读写)

求解网络分析问题时,指定可影响求解程序行为的其他设置。

必须在 JavaScript 对象表示法 (JSON) 中指定此参数的值。 例如,有效值的格式如下:{"overrideSetting1" : "value1", "overrideSetting2" : "value2"}。 覆盖设置名称始终以双引号括起。 该值可以是数字、布尔值或字符串。

此参数的默认值为无值,表示不覆盖任何求解程序设置。

覆盖是高级设置,应仅在谨慎分析应用设置前后得到的结果之后使用。 要获取每个求解程序支持的覆盖设置及其可接受值的列表,请联系 Esri 技术支持。

String
returnDirections
(可读写)

指定是否将生成转弯方向。 值为 True 表示在求解分析时将生成转弯方向。 值为 False 则表示不会生成转弯方向。 生成方向可能会降低分析速度。 默认值为 False

Boolean
returnStopShapes
(可读写)

当设置为 True 时,求解程序将为输出停靠点生成点状。 当设置为 False 时,输出停靠点将以表格格式返回。 默认为 False

当分析使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,该参数不适用并将忽略该参数。

旧版本:

基于运行 10.8 之前版本 ArcGIS Enterprise 的门户的路径服务不支持返回停靠点形状。 如果将 returnStopShapes 设置为 True 并且该服务不支持此选项,则此方法将返回 ValueError 异常。

Boolean
routeShapeType
(可读写)

要生成的表示输出路径的形状类型。 路径始终沿网络计算;但是,您可以选择使用不反映网络路径的形状来表示它们。 将返回该属性并将其设置为 RouteShapeType 枚举的成员。 默认为 RouteShapeType.TrueShapeWithMeasures

Object
searchQuery
(可读写)

当在网络中定位输入时,指定查询以将搜索范围限制在源要素类的要素子集内。 这在不想查找可能不适合网络位置的要素时很有用。 例如,如果正在加载面的质心,但不想定位在地方道路上,则可定义一个仅搜索主要道路的查询。

了解有关在网络中定位输入的详细信息

该参数值被指定为具有嵌套列表的列表。 嵌套列表由两个值组成,分别表示所有网络源的名称和 SQL 表达式。 对于不同的网络源要素类类型,SQL 表达式的语法略有不同。 例如,如果要查询存储在文件或企业级地理数据库中的源要素类、shapefile 或 SDC,则需将字段名用双引号括起:"CFCC"。 如果要查询存储在个人地理数据库中的源要素类,则需将字段用方括号括起:[CFCC]

如果您不想指定特定源的查询,请使用 "#" 作为 SQL 表达式的值,或者将源名称和 SQL 表达式从参数值中排除。 如果您不想指定所有网络源的查询,请使用 "#" 作为参数值。

例如,参数值 [["Streets","\"CFCC\" = 'A15'"], ["Streets_ND_Junctions",""]] 指定了 Streets 源要素类的 SQL 表达式,而没有指定 Streets_ND_Junctions 源要素类的表达式。 注意:用于括字段名 CFCC 的双引号通过反斜杠字符进行转义,以避免 Python 解释程序出现分析错误。

默认情况下不使用查询。

List
searchTolerance
(可读写)

在网络上定位输入要素所需的最大搜索距离。 返回该属性并将其设置为双精度,然后通过 searchToleranceUnits 属性访问该值的单位。 默认值为 5000。

了解有关在网络中定位输入的详细信息

Double
searchToleranceUnits
(可读写)

searchTolerance 属性的单位。 将返回该属性并将其设置为 DistanceUnits 枚举的成员。 默认为 DistanceUnits.Meters

Object
spatiallyClusterRoutes
(可读写)

当设置为 True 时,分配给路径的停靠点将在空间上聚类。 对停靠点进行聚类往往在较小区域保持路径,并减小路径线彼此相交的频率;然而,聚类可能会增加总行程时间。 当设置为 False 时,求解程序不会对空间聚类停靠点进行优先排序,并且路径可能会相交。 如果指定了路径区,使用此选项。

默认为 True

Boolean
timeUnits
(可读写)

报告分析输出中的行驶时间时使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为使用在此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 TimeUnits 枚举的成员。 默认为 TimeUnits.Minutes

Object
timeWindowFactor
(可读写)

对支持时间窗的重要性作出评价。

将返回该属性并将其设置为 Importance 枚举的成员。 默认为 Importance.Medium

当设置为 Importance.Low 时,求解程序将提高减少驾驶时间的重要性,降低按时到达停靠点的重要性。 如果积压的服务请求逐渐增多,则可以使用此设置。 如果为了在当日内为更多的停靠点提供服务并减少积压的订单数,则可选择此设置,即使迟到可能会为客户带来不便。

当设置为 Importance.Medium 时,求解程序将平衡减少驾驶时间的重要性与在时间窗内到达的重要性。

当设置为 Importance.High 时,求解程序将提高按时到达停靠点的重要性,降低减少驾驶时间的重要性。 进行时间紧迫的配送或非常注重客户服务的组织将选择此设置。

Object
timeZoneForTimeFields
(可读写)

指示输入数据中的时间字段是否解释为输入位置的本地时间或协调世界时间 (UTC)。 将返回该属性并将其设置为 TimeZoneUsage 枚举的成员。 默认为 TimeZoneUsage.LocalTimeAtLocations

Object
travelMode
(可读写)

要用于分析的出行模式。

VRP 将仅使用基于时间的阻抗进行求解,因此仅基于时间的阻抗出行模式可用。

将返回该值并将其设置为 arcpy.nax.TravelMode 对象,但也可以使用出行模式的字符串名称或包含出行模式的有效 JSON 表示的字符串进行设置。 默认为用于分析的网络数据集上定义的默认出行模式。

了解有关出行模式的详细信息

Object

方法概述

方法说明
addFields (input_type, field_description)

将自定义字段添加到指定的输入类。 这些字段将包含在通过 fieldMappings 方法创建的字段映射字典中,也可与 insertCursor 方法配合使用。

count (input_type)

返回为输入类型添加的行数。

fieldMappings (input_type, {use_location_fields}, {list_candidate_fields})

生成将输入类型名称字段映射到 arcpy.nax.NAClassFieldMap 对象的 NAClassFieldMappings 字典,以允许您将字段从输入数据映射到求解程序属性。 字典可以用作 load 方法 field_mappings 参数的输入。

fieldNames (input_type, {use_location_fields})

获取指定输入类型支持的字段名称列表。

insertCursor (input_type, field_names)

在指定的输入类型上建立写入光标。此游标可用于将行直接添加到输入。

load (input_type, features, {field_mappings}, {append}, {max_features})

设置用于分析的输入要素。

solve ()

使用在 VehicleRoutingProblem 对象上设置的属性和已加载的输入执行车辆配送问题分析。

方法

addFields (input_type, field_description)
参数说明数据类型
input_type

The type of input to which the fields should be added.

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本时,应使用 VehicleRoutingProblemInputDataType 枚举设置此参数;在使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,应使用 VehicleRoutingProblemInputDataType2 枚举设置此参数。

Object
field_description
[field_description,...]

The fields and their properties that will be added to the input class. The value should be constructed as a list of lists with each row containing the following items:

  • Field name—The name of the field that will be added to the input class.
  • Field type—The type of the new field.
  • Field alias—The alternate display name given to the field name.
  • Field length—The length of the field being added. This sets the maximum number of allowable characters for each record of the field. This option is only applicable to fields of type text; the default length is 255.
  • Default value—The default value of the field.
  • Field domain—The geodatabase domain that will be assigned to the field.

Available field types are as follows:

  • TEXT—Any string of characters.
  • FLOAT—Fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE—Fractional numbers between -2.2E308 and 1.8E308.
  • SHORT—Whole numbers between -32,768 and 32,767.
  • LONG—Whole numbers between -2,147,483,648 and 2,147,483,647.
  • DATE—Date or time.

The method will return an error if the field already exists in the table or if any of the field properties are invalid.

List
count (input_type)
参数说明数据类型
input_type

用于计数的输入要素类型。

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本时,应使用 VehicleRoutingProblemInputDataType 枚举设置此参数;在使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,应使用 VehicleRoutingProblemInputDataType2 枚举设置此参数。

Object
返回值
数据类型说明
Integer

行数。

fieldMappings (input_type, {use_location_fields}, {list_candidate_fields})
参数说明数据类型
input_type

The type of input for which the field mappings are returned.

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本时,应使用 VehicleRoutingProblemInputDataType 枚举设置此参数;在使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,应使用 VehicleRoutingProblemInputDataType2 枚举设置此参数。

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本VehicleRoutingProblemSchemaVersion.Two 方案版本时,请参阅适用于每种输入类型的字段的描述。

Object
use_location_fields

Indicates whether network location fields should be included in the returned field mappings dictionary. Network location fields describe the point on the network where an object is located. You can use network location fields to more precisely control how your analysis inputs locate on the network and to save time when calling the solve method because the solver will not have to calculate the location fields from the geometry of the inputs. You can calculate location fields for a feature class using the Calculate Locations tool.

Learn more about network location fields and how inputs are located on the network

When this argument is set to True, the returned field mappings dictionary will contain network location fields. The default is False; the field mapping dictionary will not include network location fields.

(默认值为 False)

Boolean
list_candidate_fields
[list_candidate_fields,...]

Use this parameter to map additional, non-default fields from your input data into your analysis inputs. For example, if your input feature class contains a field named MyField, and you want this field to be included in your analysis inputs, pass the MyField field object to the list_candidate_fields parameter. MyField will be included in the returned field mapping dictionary and automatically mapped. When you call the load method using these field mappings, MyField will be included in the analysis inputs along with all the default fields. In many cases, these extra fields will be passed to the analysis output as well.

The parameter should be specified as a list of arcpy.Field objects, which can be obtained from a given feature class or table using the arcpy.ListFields function.

Learn more about best practices for setting up analysis inputs

(默认值为 None)

Field
返回值
数据类型说明
Dictionary

如果 NAClassFieldMappings 字典中的键为字段名称和值,则其为 arcpy.nax.NAClassFieldMap 对象。

fieldNames (input_type, {use_location_fields})
参数说明数据类型
input_type

返回其支持的字段名称的输入类型。

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本时,应使用 VehicleRoutingProblemInputDataType 枚举设置此参数;在使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,应使用 VehicleRoutingProblemInputDataType2 枚举设置此参数。

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本VehicleRoutingProblemSchemaVersion.Two 方案版本时,请参阅适用于每种输入类型的字段的描述。

Object
use_location_fields

指示网络位置字段是否包含在返回的字段名称列表中。网络位置字段可描述网络中对象所在的点。您可以使用网络位置字段更精确地控制分析输入在网络上的定位方式,并且由于求解程序不必从输入的几何计算位置字段,因此在调用 solve 方法时可以节省时间。您可以使用计算位置工具计算要素类的位置字段。

了解有关网络位置字段以及如何在网络中定位输入的详细信息

当此参数设置为 True 时,返回的字段名称列表将包含网络位置字段。默认为 False;字段名称列表不包括网络位置字段。

(默认值为 False)

Boolean
返回值
数据类型说明
String

指定输入类型支持的字段名称列表。

insertCursor (input_type, field_names)
参数说明数据类型
input_type

游标可用于插入行的输入类型。

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本时,应使用 VehicleRoutingProblemInputDataType 枚举设置此参数;在使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,应使用 VehicleRoutingProblemInputDataType2 枚举设置此参数。

Object
field_names
[field_names,...]

当使用游标插入行时要设置其值的输入类型的字段名称列表。您可以使用 fieldNames 方法获取输入类型支持的字段名称。

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本VehicleRoutingProblemSchemaVersion.Two 方案版本时,请参阅适用于每种输入类型的字段的描述。

除常规字段外,还可以使用以下几何令牌之一设置输入的几何:

  • SHAPE@XYA tuple of the feature's centroid x,y coordinates.
  • SHAPE@XYZ
  • SHAPE@JSON The esri JSON string representing the geometry.
  • SHAPE@WKBThe well-known binary (WKB) representation for OGC geometry. It provides a portable representation of a geometry value as a contiguous stream of bytes.
  • SHAPE@WKTThe well-known text (WKT) representation for OGC geometry. It provides a portable representation of a geometry value as a text string.
  • SHAPE@A geometry object for the feature.

基于点的输入类型仅支持 SHAPE@XYSHAPE@XYZ 令牌。在使用 SHAPE@XYSHAPE@XYZ 令牌时,应在分析中所使用的网络数据源的空间参考中指定 x、y 和 z 值。

String
返回值
数据类型说明
Object

可用于写入要素的 SolverInsertCursor 对象。

load (input_type, features, {field_mappings}, {append}, {max_features})
参数说明数据类型
input_type

The type of input feature to load.

在使用 VehicleRoutingProblemSchemaVersion.One 方案版本时,应使用 VehicleRoutingProblemInputDataType 枚举设置此参数;在使用 VehicleRoutingProblemSchemaVersion.Two 方案版本时,应使用 VehicleRoutingProblemInputDataType2 枚举设置此参数。

Object
features

The input features to load. This parameter accepts the following input types:

  • Catalog path to a feature class or a table
  • Layer object
  • String representing the name of a layer
  • FeatureSet or RecordSet object

For layer inputs, only selected features will be loaded. If a layer has a definition query, only the subset of features visible with the definition query will be loaded. The method also honors the Extent geoprocessing environment; only features in the specified extent will be loaded.

String
field_mappings

An NAClassFieldMappings dictionary that maps the field names of the input type to arcpy.nax.NAClassFieldMap objects representing the mapping of fields from the input features. Valid input for this parameter can be constructed using the fieldMappings method.

If field mappings are not specified, all fields from the input features that have the same name as the supported fields for the input type will be mapped.

(默认值为 None)

Dictionary
append

Indicates whether the features being loaded should be appended to the existing set of features for the input type. A value of True indicates that the new features should be appended; the existing features will be preserved. This is useful if you want to load inputs from multiple feature classes or tables to use in a single analysis. This is the default. A value of False indicates that any existing features for the input type should be deleted and replaced with the features currently being loaded.

(默认值为 True)

Boolean
max_features

The maximum number of features that can be loaded into the input type. This is useful if you are creating a tool or service and want an error returned if the size of the input exceeds the available resources. The load method will return an arcpy.nax.LimitError if the number of input features exceeds the max_features limit.

If a value is not specified, no limit is enforced for the count of the input features.

(默认值为 None)

Integer
solve ()
返回值
数据类型说明
Object

arcpy.nax.VehicleRoutingProblemResult 对象可用于访问输出和求解程序消息。

代码示例

VehicleRoutingProblem 示例 1

执行车辆配送问题分析。

# An example showing how to perform vehicle routing problem analysis using inputs from feature classes and tables.
import arcpy
arcpy.CheckOutExtension("network")

nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_orders = "C:/data/io.gdb/Orders"
input_depots = "C:/data/io.gdb/Depots"
input_routes = "C:/data/io.gdb/Vehicles"
output_stops = "C:/data/io.gdb/AssignedStops"
output_routes = "C:/data/io.gdb/Routes"
output_directions = "C:/data/io.gdb/Directions"
unassigned_stops = "C:/data/io.gdb/UnassignedStops"

# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]

# Instantiate a VehicleRoutingProblem solver object
vrp = arcpy.nax.VehicleRoutingProblem(nds)
# Set properties
vrp.travelMode = travel_mode
vrp.distanceUnits = arcpy.nax.DistanceUnits.Miles
vrp.routeShapeType = arcpy.nax.RouteShapeType.TrueShape
vrp.returnDirections = True
vrp.returnStopShapes = True
# Load inputs
vrp.load(arcpy.nax.VehicleRoutingProblemInputDataType.Orders, input_orders)
vrp.load(arcpy.nax.VehicleRoutingProblemInputDataType.Depots, input_depots)
vrp.load(arcpy.nax.VehicleRoutingProblemInputDataType.Routes, input_routes)
# Solve the analysis
result = vrp.solve()

# Export the results to feature classes
if result.solveSucceeded:
    result.export(arcpy.nax.VehicleRoutingProblemOutputDataType.Stops, output_stops)
    result.export(arcpy.nax.VehicleRoutingProblemOutputDataType.Routes, output_routes)
    result.export(arcpy.nax.VehicleRoutingProblemOutputDataType.Directions, output_directions)
    if result.isPartialSolution:
        print("Some of the orders were not assigned.")
        result.export(arcpy.nax.VehicleRoutingProblemOutputDataType.UnassignedStops, unassigned_stops)
else:
    print("Solved failed")
    print(result.solverMessages(arcpy.nax.MessageSeverity.All))
VehicleRoutingProblem 示例 2

可以使用 VehicleRoutingProblemSchemaVersion.Two 方案版本执行车辆配送问题分析。

# An example showing how to perform vehicle routing problem analysis using inputs from feature classes and tables.
import arcpy
arcpy.CheckOutExtension("network")

nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_orders = "C:/data/io.gdb/Orders"
input_depots = "C:/data/io.gdb/Depots"
input_routes = "C:/data/io.gdb/Vehicles"
output_orders = "C:/data/io.gdb/VisitedOrders"
output_routes = "C:/data/io.gdb/Routes"
output_depots_visits = "C:/data/io.gdb/DepotVisits"

# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]

# Instantiate a VehicleRoutingProblem solver object using schema version Two
vrp = arcpy.nax.VehicleRoutingProblem(nds, arcpy.nax.VehicleRoutingProblemSchemaVersion.Two)
# Set properties
vrp.travelMode = travel_mode
vrp.distanceUnits = arcpy.nax.DistanceUnits.Miles
vrp.routeShapeType = arcpy.nax.RouteShapeType.TrueShape
vrp.returnDirections = True
# Load inputs
vrp.load(arcpy.nax.VehicleRoutingProblemInputDataType2.Orders, input_orders)
vrp.load(arcpy.nax.VehicleRoutingProblemInputDataType2.Depots, input_depots)
vrp.load(arcpy.nax.VehicleRoutingProblemInputDataType2.Routes, input_routes)
# Solve the analysis
result = vrp.solve()

# Export the results to feature classes
if result.solveSucceeded:
    result.export(arcpy.nax.VehicleRoutingProblemOutputDataType2.Orders, output_orders)
    result.export(arcpy.nax.VehicleRoutingProblemOutputDataType2.Routes, output_routes)
    result.export(arcpy.nax.VehicleRoutingProblemOutputDataType2.DepotVisits, output_depots_visits)
else:
    print("Solve failed")
    print(result.solverMessages(arcpy.nax.MessageSeverity.All))