Summary
Provides access to analysis properties from a vehicle routing problem Network Analyst layer. The GetSolverProperties function is used to obtain a VehicleRoutingProblemSolverProperties object from a vehicle routing problem Network Analyst layer.
Discussion
The VehicleRoutingProblemSolverProperties object provides read and write access to all the analysis properties of a vehicle routing problem Network Analyst layer. The object can be used to modify analysis properties of the vehicle routing problem layer, and the corresponding layer can be re-solved to determine the appropriate results. A new vehicle routing problem layer can be created using the Make Vehicle Routing Problem Layer geoprocessing tool. Obtaining the VehicleRoutingProblemSolverProperties object from a new vehicle routing problem layer allows you to reuse the existing layer for subsequent analyses rather than create a new layer for each analysis, which can be time consuming.
After modifying the properties of the VehicleRoutingProblemSolverProperties object, the corresponding layer can be immediately used with other functions and geoprocessing tools. There is no refresh or update of the layer required to honor the changes modified through the object.
Properties
Property | Explanation | Data Type |
attributeParameters (Read and Write) | 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. Do not attempt to modify the attributeParameters property in place; this coding method will not work.
Modify the attributeParameters property using a new dictionary object.
| Dictionary |
capacityCount (Read and Write) | Provides the ability to get or set the number of capacity constraint dimensions required to describe the relevant limits of the vehicles. | Integer |
defaultDate (Read and Write) | Provides the ability to get or set the implied date for time field values that don't have a date specified with the time. If a time field for an order object, such as TimeWindowStart1, has a time-only value, the date is assumed to be the defaultDate property value. For example, if an order has a TimeWindowStart1 value of 9:00 a.m. and the defaultDate is set to datetime.date(2012, 3, 6), the entire time value for the field is 9:00 a.m., March 6, 2012. The default date has no effect on time field values that already have a date. The day of the week can also be specified as the default date using the following dates:
For example, to specify that the implied date for time field values should be Tuesday, specify the property value as 1/2/1900. | DateTime |
distanceAttribute (Read and Write) | Provides the ability to get or set the distance cost attribute used to define the length along the elements of the network. | String |
distanceFieldUnits (Read and Write) | Provides the ability to get or set the distance units used by distance fields of the analysis layer's sublayers and tables (network analysis classes). The unit does not have to be the same as the unit of the network cost attribute specified as the timeAttribute property value.
| String |
excessTransitTimeImportance (Read and Write) | Provides the ability to get or set the importance of reducing excess transit time. Excess transit time is the amount of time exceeding the time required to travel directly between the paired orders. The excess time results from breaks or travel to other orders or depots between visits to the paired orders. This parameter is only relevant if using Order Pairs.
| String |
outputPathShape (Read and Write) | Provides the ability to get or set the shape type for the route features that are output by the solver.
| String |
restrictions (Read and Write) | 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 (Read Only) | Returns the name of the solver being referenced by the Network Analyst layer used to obtain the solver properties object. The property always returns the string value Vehicle Routing Problem Solver when accessed from a VehicleRoutingProblemSolverProperties object. | String |
streetDirectionsProperties (Read and Write) | Provides read and write access to StreetDirectionsProperties, allowing you to customize the directions output from your vehicle routing problem layer. | Object |
timeAttribute (Read and Write) | Provides the ability to get or set the time-based network cost attribute used to define the traversal time along the elements of the network. This cost attribute is minimized by the solver while finding the solution. | String |
timeFieldUnits (Read and Write) | Provides the ability to get or set the time unit used by the temporal fields of the analysis layer's sublayers and tables (network analysis classes). The unit does not have to be the same as the unit of the network cost attribute specified as the timeAttribute property value.
| String |
timeWindowViolationImportance (Read and Write) | Provides the ability to get or set the importance of honoring time windows without causing violations. A time window violation occurs when a route arrives at an order, depot, or break after a time window has closed. The violation is the interval between the end of the time window and the arrival time of a route. The following is a list of possible values:
| String |
timeZoneUsageForTimeFields (Read and Write) |
Specifies the time zone of datetime fields in the input data, such as the fields used for time windows.
| String |
spatialClustering (Read and Write) | Specifies whether to use spatial clustering.
| Boolean |
useHierarchy (Read and Write) | Controls the use of the hierarchy attribute while performing the analysis. The following is a list of possible values:
| String |
uTurns (Read and Write) | 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:
| String |
Method Overview
Method | Explanation |
applyTravelMode (travel_mode) | Updates the analysis properties of a network analyst layer based on a travel mode object. The updated network analyst layer can then be solved to complete the analysis. |
Methods
applyTravelMode (travel_mode)
Parameter | Explanation | Data Type |
travel_mode | A variable that references a travel mode object derived from a network dataset. A list of travel mode objects can be obtained by calling the arcpy.na.GetTravelModes function. | Object |
When a network analyst layer is created, it is assigned default values for all of its analysis properties. The individual analysis properties can be updated using a solver properties object obtained from the network analyst layer. A travel mode stores a predefined set of analysis settings that help to perform a particular analysis, such as a walking time travel mode that stores the analysis settings required to perform a time-based walking analysis.
Using the applyTravelMode method, all the analysis settings that are defined in a travel mode can be applied at once. After the analysis properties are updated, the network analyst layer can be solved to complete the analysis.
If there is an error when updating the solver properties, such as when the provided travel mode references properties that don't exist on the current network dataset or references properties that are no longer applicable to the network dataset that was used to create the network analyst layer corresponding to the solver properties object, no exceptions are raised. The method will execute successfully, but you will get errors when you try to solve such a network analyst layer.
If the travel_mode parameter does not reference a travel mode object or a string, a TypeError exception is raised. If the travel_mode parameter references a string and the string cannot be internally converted to a valid string representation of a travel mode object, a ValueError exception is raised.
Code sample
VehicleRoutingProblemSolverProperties example 1
The script shows how to update the Distance Attribute, Default Date, U-Turns at Junctions, and Output Shape Type properties for an existing vehicle routing problem layer in the ArcMap table of contents. It assumes that a vehicle routing problem layer called Store Delivery Routes has been created in a new map document based on the tutorial network dataset of the San Francisco region.
#Get the vehicle routing problem layer object from a layer named
#"Store Delivery Routes" in the table of contents
vrpLayer = arcpy.mapping.Layer("Store Delivery Routes")
#Get the solver properties object from the vehicle routing problem layer
solverProps = arcpy.na.GetSolverProperties(vrpLayer)
#Update the properties for the vehicle routing problem layer using the
#solver properties object
solverProps.distanceAttribute = "Meters"
#Set the default date to be Monday
solverProps.defaultDate = datetime.date(1900,1,1)
solverProps.uTurns = "NO_UTURNS"
solverProps.outputPathShape = "STRAIGHT_LINES"
ApplyTravelMode example 2 (workflow)
This script shows how to find routes for a fleet of trucks using the Trucking Time travel mode.
#Import modules
import os
import arcpy
#Define variables
workspace = "C:/data/SanDiego.gdb"
output_folder = "C:/data/output"
nds = os.path.join(workspace, "Transportation", "Streets_ND")
orders = os.path.join(workspace, "Orders")
depots = os.path.join(workspace, "TruckDepots")
routes = os.path.join(workspace, "Drivers")
analysis_layer_name = "TruckRoutes"
#Set environment variables
arcpy.env.overwriteOutput = True
#Check out the network analyst extension
arcpy.CheckOutExtension("network")
#Create a new closest facility analysis layer
make_layer_result = arcpy.na.MakeVehicleRoutingProblemLayer(nds, analysis_layer_name,
"TravelTime")
analysis_layer = make_layer_result.getOutput(0)
#Add orders, depots and routes to the analysis layer using default field mappings
sub_layer_names = arcpy.na.GetNAClassNames(analysis_layer)
order_layer_name = sub_layer_names["Orders"]
depot_layer_name = sub_layer_names["Depots"]
route_layer_name = sub_layer_names["Routes"]
arcpy.na.AddLocations(analysis_layer, order_layer_name, orders, "#", "#")
arcpy.na.AddLocations(analysis_layer, depot_layer_name, depots, "#", "#")
arcpy.na.AddLocations(analysis_layer, route_layer_name, routes, "#", "#")
#Get the Trucking Time travel mode from the network dataset
travel_modes = arcpy.na.GetTravelModes(nds)
trucking_mode = travel_modes["Trucking Time"]
#Apply the travel mode to the analysis layer
solver_properties = arcpy.na.GetSolverProperties(analysis_layer)
solver_properties.applyTravelMode(trucking_mode)
#Solve the analysis layer skipping any invalid orders and save the result as a layer file
arcpy.na.Solve(analysis_layer, "SKIP")
output_layer = os.path.join(output_folder, analysis_layer_name + ".lyr")
arcpy.management.SaveToLayerFile(analysis_layer, output_layer, "RELATIVE")
arcpy.AddMessage("Completed")