Solve (Network Analyst)
Summary
Solves the network analysis layer problem based on its network locations and properties.
Usage
-
When the solve fails, the warning and error messages provide useful information about the reasons for the failure.
-
Be sure to specify all the parameters on the network analysis layer that are necessary to solve the problem before running this tool.
Syntax
| Parameter | Explanation | Data Type |
in_network_analysis_layer |
The network analysis layer on which the analysis will be computed. | Network Analyst Layer |
ignore_invalids (Optional) |
For vehicle routing problem network analysis layer, use HALT as the parameter value since the vehicle routing problem solver requires all the network locations to be valid. | Boolean |
terminate_on_solve_error (Optional) |
| Boolean |
Code Sample
Execute the tool using all the parameters.
import arcpy
arcpy.Solve_na("Route","HALT","TERMINATE")
The following stand-alone Python script demonstrates how the Solve tool can be used to perform a closest facility analysis and save results to a layer file.
# Name: Solve_Workflow.py
# Description: Solve a closest facility analysis to find the closest warehouse
# from the store locations and save the results to a layer file on
# disk.
# Requirements: Network Analyst Extension
# Author: ESRI
#Import system modules
import arcpy
from arcpy import env
try:
#Check out the Network Analyst extension license
arcpy.CheckOutExtension("Network")
#Set environment settings
env.workspace = "C:/data/Paris.gdb"
env.overwriteOutput = True
#Set local variables
inNetworkDataset = "Transportation/ParisMultimodal_ND"
outNALayer = "ClosestWarehouse"
impedanceAttribute = "Drivetime"
accumulateAttributeName = ["Meters"]
inFacilities = "Analysis/Warehouses"
inIncidents = "Analysis/Stores"
fieldMappings = "Name NOM #"
outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
#Create a new closest facility analysis layer. Apart from finding the drive
#time to the closest warehouse, we also want to find the total distance. So
#we will accumulate the "Meters" impedance attribute.
arcpy.MakeClosestFacilityLayer_na(inNetworkDataset,outNALayer,
impedanceAttribute,"TRAVEL_TO","",1,
accumulateAttributeName,"NO_UTURNS")
#Load the warehouses as Facilities using the default field mappings and
#search tolerance
arcpy.AddLocations_na(outNALayer,"Facilities",inFacilities,"","")
#Load the Stores as Incidents. Map the Name property from the NOM field
arcpy.AddLocations_na(outNALayer,"Incidents",inIncidents,fieldMappings,"")
#Solve the closest facility layer
arcpy.Solve_na(outNALayer)
#Save the solved closest facility layer as a layer file on disk using
#relative paths
arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE")
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)