VehicleRoutingProblem

Resumen

An ArcPy class for performing a vehicle routing problem analysis.

Debate

A vehicle routing problem analysis allows you to calculate the best routes for a fleet of vehicles.

Learn more about vehicle routing problem analysis

Learn more about how to perform a network analysis using arcpy.nax

Sintaxis

VehicleRoutingProblem (in_network, {version})
ParámetroExplicaciónTipo de datos
in_network

The network dataset or service that will be used for the network analysis. The argument can be specified using one of the following:

To use a network dataset, the network must have at least one travel mode.

To use a portal URL, you must be signed in to the portal with an account that has routing privileges.

Learn how to sign in to a portal in Python

When using ArcGIS Online or an ArcGIS Enterprise portal whose routing services are configured using ArcGIS Online as the in_network value, solving the analysis will consume credits and will be subject to certain limits, such as the number of allowed inputs.

Learn more about credit consumption and analysis limits in network analysis

String
version

The schema version to use in the analysis. The parameter should be specified using the VehicleRoutingProblemSchemaVersion enumeration.

An updated VehicleRoutingProblem object schema was introduced in ArcGIS Pro 2.7 to provide enhanced usability and to more closely match the schema of Vehicle Routing Problem layers introduced in ArcGIS Pro 2.6.

It is recommended that all new analyses use schema version Two when possible. However, the schema version Two is not currently supported for portal URL network data sources. If the analysis will use a portal URL for the network data source or the script needs to be compatible with software versions prior to ArcGIS Pro 2.7, use schema version One.

The default is schema version One.

Object

Propiedades

PropiedadExplicaciónTipo de datos
allowAutoRelocate
(Lectura y escritura)

Specifies whether inputs with existing network location fields can be automatically relocated at solve time to ensure valid, routable location fields for the analysis. If the value is True, points located on restricted network elements and points affected by barriers will be relocated to the closest routable location. If the value is False, network location fields will be used as is, even if the points are unreachable, and this may cause the solve to fail.

Even if the value is False, inputs with no location fields or incomplete location fields will be located at solve time.

The default is True.

This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method.

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

Setting this property returns an error if the network data source is ArcGIS Online, an ArcGIS Enterprise portal that does not support using network location fields, or a portal running a version of ArcGIS Enterprise earlier than 11.0.

Boolean
allowSaveLayerFile
(Lectura y escritura)

Specifies whether saving the analysis result as a layer file using the saveAsLayerFile method on the result object will be allowed. A value of True indicates that you can save a layer file. A value of False indicates that you cannot save a layer file. The default is True if the analysis references a network dataset and False if it references a portal service. Saving a layer file may slow down the analysis when the analysis references a portal service.

Boolean
allowSaveRouteData
(Lectura y escritura)

Specifies whether route data will be generated. A value of True indicates that route data will be generated when solving the analysis. A value of False indicates that route data will not be generated. Route data is saved as a .zip file using the saveRouteData method on the result object. Generating route data may slow down the analysis.

The default is True if the analysis references a network dataset and False if it references a portal service.

Precaución:
Even if the allowSaveRouteData property is set to True, the saveRouteData method may fail if returnDirections is False and the routeShapeType property is set to RouteShapeType.NoLine or RouteShapeType.StraightLine.

Boolean
defaultDate
(Lectura y escritura)

The default date for time field values that specify a time of day without including a date. The default is None, which indicates that all date time fields include date and time values.

DateTime
directionsDistanceUnits
(Lectura y escritura)

The units that will be used when reporting travel distance in the output turn-by-turn directions. The property is returned and set as a member of the DistanceUnits enumeration and is applicable only when the returnDirections property is True. The default is the units of the distance attribute in the travel mode used for the analysis.

This parameter does not apply and is ignored when the analysis uses the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
directionsLanguage
(Lectura y escritura)

The language in which the output turn-by-turn directions text will appear. The property is returned and set as a string using one of the two- or five-character language codes representing supported directions languages. The list of available directions languages can be obtained from the arcpy.nax.ListDirectionsLanguages function. The default value is either en (English) or the language of the currently activated language pack. The property is applicable only when the returnDirections property is True.

String
directionsStyle
(Lectura y escritura)

The style that will be used for the output turn-by-turn directions text. The property is returned and set as a member of the DirectionsStyle enumeration and is applicable only when the returnDirections property is True.

The default value is Desktop.

This parameter does not apply and is ignored when the analysis uses the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
distanceUnits
(Lectura y escritura)

The units that will be used when reporting the travel distance in the analysis output. Regardless of the units of the cost attributes in the network dataset, the output will be transformed to and reported in the units set in this property. The property is returned and set as a member of the DistanceUnits enumeration. The default is DistanceUnits.Kilometers.

Object
excessTransitFactor
(Lectura y escritura)

Rates the importance of reducing excess transit time of order pairs. Excess transit time is the amount of time exceeding the time required to travel directly between the paired orders. Excess time can be caused by driver breaks or travel to intermediate orders and depots.

The property is returned and set as a member of the Importance enumeration. The default is Importance.Medium.

When set to Importance.Low, the solver identifies a solution that minimizes overall solution cost, regardless of excess transit time. This setting is commonly used with courier services. Since couriers transport packages rather than people, they aren't concerned about ride time. Using this setting allows the couriers to service paired orders in the proper sequence and minimize the overall solution cost.

When set to Importance.Medium, the solver identifies a solution that is a balance between reducing excess transit time and reducing the overall solution cost.

When set to Importance.High, the solver identifies a solution with the least excess transit time between paired orders at the expense of increasing the overall travel costs. This setting allows you to shorten the ride time when you are transporting people between paired orders. This is characteristic of taxi services.

Object
ignoreInvalidLocations
(Lectura y escritura)

Specifies whether invalid input locations will be ignored. A value of True indicates that invalid input locations will be ignored so that the analysis will succeed using only valid locations. A value of False indicates that invalid locations will not be ignored and will cause the analysis to fail.

Boolean
networkDataSource
(Sólo lectura)

The full catalog path to the network dataset or the URL of the service being used for the analysis.

String
overrides
(Lectura y escritura)

Nota:

This property is for internal use only.

String
returnDirections
(Lectura y escritura)

Specifies whether turn-by-turn directions will be generated. A value of True indicates that turn-by-turn directions will be generated when solving the analysis. A value of False indicates that directions will not be generated. Generating directions may slow down the analysis. The default is False.

Boolean
returnStopShapes
(Lectura y escritura)

Specifies whether point shapes will be generated for the output stops. When set to True, point shapes will be generated for the output stops. When set to False, the output stops will be returned in table format. The default is False.

This parameter does not apply and is ignored when the analysis uses the VehicleRoutingProblemSchemaVersion.Two schema version.

Heredado:

Routing services based on portals running versions of ArcGIS Enterprise earlier than 10.8 do not support returning stop shapes. The method returns a ValueError exception if you set returnStopShapes to True, and the service does not support this option.

Boolean
routeShapeType
(Lectura y escritura)

The type of shape that will be generated to represent output routes. The routes are calculated along the network; however, you can represent them by shapes that do not reflect the network paths. The property is returned and set as a member of the RouteShapeType enumeration.

The default is RouteShapeType.TrueShapeWithMeasures.

Object
searchQuery
(Lectura y escritura)

Heredado:
This property has been superseded by the searchSources property, which was introduced at ArcGIS Pro 3.0. The searchQuery property continues to work to maintain backward compatibility with existing scripts, but it is recommended you use the searchSources property for new scripts instead.

When locating inputs on the network, this property specifies a query to restrict the search to a subset of the features within a source feature class. This is useful if you don't want to find features that may be unsuited for a network location. For example, if you don't want to locate on highway ramps, you can define a query to exclude them.

The parameter value is specified as a list with nested lists, with one entry per network source. Each inner list is composed of two values indicating the name of the network source and the SQL expression used as the query for that source. An empty string, "", indicates no query for a particular source.

For example, the value [["Streets", "ROAD_CLASS <> 3"], ["Streets_ND_Junctions", ""]] specifies an SQL expression for the Streets source feature class and no expression for the Streets_ND_Junctions source feature class.

If a network source is not included in the list, it is interpreted to have no query. The value [["Streets", "ROAD_CLASS <> 3"]] is equivalent to [["Streets", "ROAD_CLASS <> 3"], ["Streets_ND_Junctions", ""]].

By default, no query is used for any source.

Learn more about locating inputs on the network

For more information about SQL syntax, see SQL reference for query expressions used in ArcGIS.

Setting this property returns an error if the network data source is ArcGIS Online or a portal running a version of ArcGIS Enterprise earlier than 11.0.

List
searchSources
(Lectura y escritura)

When locating inputs on the network, this property specifies the list of network sources that will be used, and, optionally, a query to restrict the search to a subset of the features within a source feature class.

The default value is to locate on all network sources except system junctions and override junctions created by running the Dissolve Network tool. By default, no query is used for any source.

The parameter value is specified as a list with nested lists, with at most one entry per network source. Each inner list is composed of two values indicating the name of the network source and the SQL expression used as the query for that source.

Possible values for the network source component are the string feature class names of edge and junction sources that participate in the network. Sources in the list will be used for locating, and sources not in the list will not.

Queries are useful if you don't want to find features that may be unsuited for a network location. For example, if you don't want to locate on highway ramps, you can define a query to exclude them. For the query component, see SQL reference for query expressions used in ArcGIS for correct syntax. An empty string, "", indicates no query for a particular source.

For example, the value [["Streets", "ROAD_CLASS <> 3"], ["Streets_ND_Junctions", ""]] specifies that inputs can be located on both the Streets and Streets_ND_Junctions sources. A SQL expression for the Streets source feature class prohibits inputs from locating on streets where the ROAD_CLASS field has a value of 3. No query is used for the Streets_ND_Junctions source feature class. A value of [["Streets", "ROAD_CLASS <> 3"]] indicates that only the Streets source feature class will be used for locating, and Streets_ND_Junctions will not. Additionally, a query is applied to Streets.

This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method.

Learn more about locating inputs on the network

Setting this property returns an error if the network data source is ArcGIS Online or a portal running a version of ArcGIS Enterprise earlier than 11.0.

String
searchTolerance
(Lectura y escritura)

The maximum search distance that will be used when locating the input features on the network. The property is returned and set as a double, and the units of this value are accessed through the searchToleranceUnits property. The default is 5000.

This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method.

Learn more about locating inputs on the network

Heredado:

Setting this property returns an error if the network data source is a portal running a version of ArcGIS Enterprise earlier than 11.0.

Double
searchToleranceUnits
(Lectura y escritura)

The units of the searchTolerance property. The property is returned and set as a member of the DistanceUnits enumeration. The default is DistanceUnits.Meters.

This property affects locating for all input types. To change this property for individual input types, use the setLocateSettingsOverrides method.

Heredado:

Setting this property returns an error if the network data source is a portal running a version of ArcGIS Enterprise earlier than 11.0.

Object
spatiallyClusterRoutes
(Lectura y escritura)

Specifies whether assigned orders will be spatially clustered. When set to True, the orders assigned to a route will be spatially clustered. Clustering orders tends to keep routes in smaller areas and reduce how often route lines intersect one another; however, clustering can increase overall travel times. When set to False, the solver will not prioritize spatially clustering orders, and the route lines may intersect. Use this option if route zones are specified.

The default is True.

Boolean
timeUnits
(Lectura y escritura)

The units that will be used when reporting the travel time in the analysis output. Regardless of the units of the cost attributes in the network dataset, the outputs will be transformed to and reported in the units set in this property. The property is returned and set as a member of the TimeUnits enumeration. The default is TimeUnits.Minutes.

Object
timeWindowFactor
(Lectura y escritura)

Rates the importance of honoring time windows.

The property is returned and set as a member of the Importance enumeration. The default is Importance.Medium.

When set to Importance.Low, the solver places more importance on minimizing drive times and less on arriving at stops on time. You may want to use this setting if you have a growing backlog of service requests. For the purpose of servicing more orders in a day and reducing the backlog, you can choose this setting even though customers may be inconvenienced with your late arrivals.

When set to Importance.Medium, the solver balances the importance of minimizing drive times and arriving within time windows.

When set to Importance.High, the solver places more importance on arriving at stops on time than on minimizing drive times. Organizations that make time-critical deliveries or are concerned with customer service use this setting.

Object
timeZoneForTimeFields
(Lectura y escritura)

Indicates whether the time fields in the input data will be interpreted as local time at the input locations or as coordinated universal time (UTC). The property is returned and set as a member of the TimeZoneUsage enumeration. The default is TimeZoneUsage.LocalTimeAtLocations.

Object
travelMode
(Lectura y escritura)

The travel mode that will be used for the analysis.

Vehicle Routing Problem analysis must use a time-based impedance, so only time-based impedance travel modes are available.

The value is returned and set as an arcpy.nax.TravelMode object, but it can also be set using the string name of the travel mode or a string containing the valid JSON representation of a travel mode. The default is the default travel mode defined on the network dataset used for the analysis.

Learn more about travel modes

Object

Descripción general del método

MétodoExplicación
addFields (input_type, field_description)

Adds custom fields to the designated input class. These fields will be included in the field mapping dictionary created by the fieldMappings method and will also be available for use with the insertCursor method.

Learn more about using custom fields in analysis inputs

count (input_type)

Returns the number of rows added for an input type.

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

Generates an NAClassFieldMappings dictionary that maps the field names of the input type to arcpy.nax.NAClassFieldMap objects that allow you to map fields from the input data to the properties of the solver. The dictionary can be used as input to the field_mappings argument of the load method.

Learn more about how to use field mappings when loading inputs

fieldNames (input_type, {use_location_fields})

Get a list of field names supported by the specified input type.

insertCursor (input_type, field_names, {append})

Establishes a write cursor on the specified input type. This cursor can be used to add rows directly to the input.

Learn more about how to insert inputs

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

Sets input features to use for the analysis.

Learn more about how to load inputs

setLocateSettingsOverrides (input_type, {search_sources}, {allow_auto_relocate}, {search_tolerance}, {search_tolerance_units})

Set locate settings for a designated input class, overriding the default locate settings specified for the analysis. This is useful if you want to use different rules to locate different inputs. For example, in an OD cost matrix analysis, you can use a search query that applies to the input origins only, if that query should not apply to the input destinations and barriers.

Using this method, you can override the values of the searchSources, allowAutoRelocate, searchTolerance, and searchToleranceUnits properties for the designated input class.

Learn more about locating inputs on the network

solve ()

Perform the vehicle routing problem analysis using the properties set on the VehicleRoutingProblem object and the loaded inputs.

Métodos

addFields (input_type, field_description)
ParámetroExplicaciónTipo de datos
input_type

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

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
field_description
[field_description,...]

The fields and their properties that will be added to the input class. The value will 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 for 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.

Available field types are as follows:

Field typeDescription

TEXT

El tipo de campo será texto. Los campos de texto admiten una cadena de caracteres.

FLOAT

El tipo de campo será flotante. Los campos flotantes admiten números fraccionarios entre -3,4E38 y 1,2E38.

DOUBLE

El tipo de campo será doble. Los campos dobles admiten números fraccionarios entre -2,2E308 y 1,8E308.

SHORT

El tipo de campo será corto. Los campos cortos admiten números enteros entre -32.768 y 32.767.

LONG

El tipo de campo será largo. Los campos nuevos admiten número enteros entre -2.147.483.648 y 2.147.483.647.

DATE

El tipo de campo será fecha. Los campos de fecha admiten fecha y hora.

GUID

El tipo de campo será GUID. Los campos GUID almacenan cadenas de texto de estilo de registro que están compuestas por 36 caracteres encerrados entre paréntesis.

BIGINTEGER

El tipo de campo será entero grande. Los campos de números enteros grandes admiten números enteros entre -(253) y 253.

TIMEONLY

El tipo de campo será solo de tiempo. Los campos de solo hora admiten valores de hora sin valor de fecha.

DATEONLY

El tipo de campo será solo de fecha. Los campos de solo fecha admiten valores de fecha sin valores de hora.

TIMESTAMPOFFSET

El tipo de cambio será de desfase de marca de tiempo. Los campos de desplazamiento de fecha y hora admiten un valor de fecha, hora y desplazamiento con respecto a un valor UTC.

Only the field name and type are required. Use None as a place holder for any of the other parameters to accept the default or if the parameter does not apply to the specified field type.

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

Heredado:
The GUID, BIGINTEGER, TIMEONLY, DATEONLY, and TIMESTAMPOFFSET field types are not supported when the network data source is a portal running ArcGIS Enterprise 11.1.x or earlier.

List
count (input_type)
ParámetroExplicaciónTipo de datos
input_type

The type of input features to count.

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
Valor de retorno
Tipo de datosExplicación
Integer

The number of rows.

fieldMappings (input_type, {use_location_fields}, {list_candidate_fields})
ParámetroExplicaciónTipo de datos
input_type

The type of input for which the field mappings will be returned.

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

See descriptions of the fields available for each input type when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
use_location_fields

Specifies whether network location fields will 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 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 include network location fields. The default is False, which means the field mapping dictionary will not include network location fields.

(El valor predeterminado es False)

Boolean
list_candidate_fields
[list_candidate_fields,...]

Use this parameter to map additional, nondefault fields from the input data to the analysis inputs. For example, if the input feature class contains a field named MyField, and you want it to be included in the 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.

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

Learn more about best practices for setting up analysis inputs

Heredado:
If the network data source is an ArcGIS Enterprise portal, the method will return an error if any of the fields specified are of a type that is not supported by the portal version.

(El valor predeterminado es None)

Field
Valor de retorno
Tipo de datosExplicación
Dictionary

An NAClassFieldMappings dictionary in which the keys are the field names and the values are arcpy.nax.NAClassFieldMap objects.

fieldNames (input_type, {use_location_fields})
ParámetroExplicaciónTipo de datos
input_type

The type of input for which the supported field names are returned.

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

See descriptions of the fields available for each input type when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
use_location_fields

Indicates whether network location fields will be included in the returned list of field names. 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 list of field names will contain network location fields. The default is False; the list of field names will not include network location fields.

(El valor predeterminado es False)

Boolean
Valor de retorno
Tipo de datosExplicación
String

A list of field names supported by the specified input type.

insertCursor (input_type, field_names, {append})
ParámetroExplicaciónTipo de datos
input_type

The type of input into which the cursor can be used to insert rows.

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
field_names
[field_names,...]

A list of field names of the input type whose values you want to set when inserting rows using the cursor. You can get the names of the fields supported by an input type using the fieldNames method.

See descriptions of the fields available for each input type when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemSchemaVersion.Two schema version.

In addition to regular fields, you can also set the geometry of the input using one of the following geometry tokens:

  • 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.

The SHAPE@XY and SHAPE@XYZ tokens are only supported for point-based input types. When using the SHAPE@XY and SHAPE@XYZ tokens, specify the x-, y-, and z-values in the spatial reference of the network data source being used in the analysis.

String
append

Specifies whether the features being inserted will be appended to the existing set of features for the input type. A value of True indicates that the new features will be appended; the existing features will be preserved. This is the default. A value of False indicates that any existing features for the input type will be deleted and replaced with the features being inserted.

(El valor predeterminado es True)

Boolean
Valor de retorno
Tipo de datosExplicación
Object

A SolverInsertCursor object that can be used to write features.

load (input_type, features, {field_mappings}, {append}, {max_features})
ParámetroExplicaciónTipo de datos
input_type

The type of input feature that will be loaded.

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

Object
features

The input features that will be loaded. This parameter accepts the following input types:

  • The catalog path to a feature class or a table
  • A Layer object
  • The string representing the name of a layer
  • A 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 no field mappings are specified, all fields from the input features that have the same name as the supported fields for the input type will be mapped.

See descriptions of the fields available for each input type when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemSchemaVersion.Two schema version.

(El valor predeterminado es None)

Dictionary
append

Specifies whether the features being loaded will be appended to the existing set of features for the input type. A value of True indicates that the new features will be appended, and existing features will be preserved. This is useful when loading 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 will be deleted and replaced with the features currently being loaded.

(El valor predeterminado es 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 no value is provided, no limit will be enforced for the count of the input features.

(El valor predeterminado es None)

Integer
setLocateSettingsOverrides (input_type, {search_sources}, {allow_auto_relocate}, {search_tolerance}, {search_tolerance_units})
ParámetroExplicaciónTipo de datos
input_type

The type of input for which to override default locate settings.

Set this parameter using the VehicleRoutingProblemInputDataType enumeration when using the VehicleRoutingProblemSchemaVersion.One schema version or the VehicleRoutingProblemInputDataType2 enumeration when using the VehicleRoutingProblemSchemaVersion.Two schema version.

Locate settings do not apply to table-based inputs and inputs that do not locate on the network. For the vehicle routing problem solver, only orders, depots, and barriers locate on the network and are valid input types for this method. The method returns an error if an inapplicable input type is specified.

Object
search_sources
[[Source, Expression],...]

The list of network sources to be used when locating inputs of the designated type on the network, and, optionally, a query to restrict the search to a subset of the features within a source feature class.

See the documentation for the searchSources property for examples of proper syntax for this parameter.

Specifying a value for this parameter overrides the default searchSources property value for the designated input type.

If this parameter is not specified or is set to None, the searchSources value will be used for this input type.

The method returns an error if this parameter is used and the network data source is ArcGIS Online.

String
allow_auto_relocate

Specifies whether inputs of the designated type with existing network location fields can be automatically relocated at solve time to ensure valid, routable location fields for the analysis. If the value is True, points located on restricted network elements and points affected by barriers will be relocated to the closest routable location. If the value is False, network location fields will be used as is, even if the points are unreachable, and this may cause the solve to fail.

Even if the value is False, inputs with no location fields or incomplete location fields will be located at solve time.

Specifying a value for this parameter overrides the default allowAutoRelocate property value for the designated input type.

If this parameter is not specified or is set to None, the allowAutoRelocate value will be used for this input type.

The method returns an error if the network data source is ArcGIS Online.

The method returns an error if the network data source is an ArcGIS Enterprise portal that does not support using network location fields.

Boolean
search_tolerance

The maximum search distance to use when locating inputs of the designated type on the network.

Specifying a value for this parameter overrides the default searchTolerance property value for the designated input type.

If this parameter is not specified or is set to None, the searchTolerance value will be used for this input type.

The units of this parameter value are set using the search_tolerance_units parameter; however, if no value is set for that parameter, the search_tolerance value will be interpreted in the units specified in the searchToleranceUnits property.

This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the input_type value is one of these barrier types.

Double
search_tolerance_units

The units of the maximum search distance when locating inputs of the designated type of the network. The parameter is specified using a member of the DistanceUnits enumeration.

Specifying a value for this parameter overrides the default searchToleranceUnits property value for the designated input type.

If this parameter is not specified or is set to None, the searchToleranceUnits will be used for this input type.

The value specified using the search_tolerance parameter is interpreted using these units. If that parameter is not specified, the value of the searchTolerance property will be interpreted using these units for the designated input type only.

This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the input_type value is one of these barrier types.

Double
solve ()
Valor de retorno
Tipo de datosExplicación
Object

An arcpy.nax.VehicleRoutingProblemResult object that can be used to access outputs and solver messages.

Muestra de código

VehicleRoutingProblem example 1

Perform a vehicle routing problem analysis.

# 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(nd_layer_name)
# 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 example 2

Perform a vehicle routing problem analysis using the VehicleRoutingProblemSchemaVersion.Two schema version.

# 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(nd_layer_name, 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))