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.

  • The tool will consume credits when the network analysis layer references ArcGIS Online as the network data source. For more information, see Credits .

Parameters

LabelExplanationData Type
Input Network Analysis Layer

The network analysis layer on which the analysis will be computed.

Network Analyst Layer
Ignore Invalid Locations
(Optional)

Specifies whether invalid input locations will be ignored. Typically, locations are invalid if they cannot be located on the network. When invalid locations are ignored, the solver will skip them and attempt to perform the analysis using the remaining locations.

  • Checked—Invalid input locations will be ignored and only valid locations will be used.
  • Unchecked—All input locations will be used. Any invalid locations will cause the solve to fail.

The default value will match the Ignore Invalid Locations at Solve Time setting on the designated Input Network Analysis Layer value.

Boolean
Terminate on Solve Error
(Optional)

Specifies whether tool execution will terminate if an error is encountered during the solve.

  • Checked—The tool will fail to execute when the solver encounters an error. This is the default.
  • Unchecked—The tool will not fail and will continue execution even when the solver encounters an error. All error messages returned by the solver will be converted to warning messages. Use this option when background processing is enabled in your application.
Boolean
Simplification Tolerance
(Optional)

The tolerance that determines the degree of simplification for the output geometry. If a tolerance is specified, it must be greater than zero. You can choose a preferred unit; the default unit is decimal degrees.

Specifying a simplification tolerance tends to reduce the time it takes to render routes or service areas. The drawback, however, is that simplifying geometry removes vertices, which may lessen the spatial accuracy of the output at larger scales.

Because a line with only two vertices cannot be simplified any further, this parameter has no effect on drawing times for single-segment output, such as straight-line routes, OD cost matrix lines, and location-allocation lines.

Linear Unit
Overrides
(Optional)

Additional settings that can influence the behavior of the solver when finding solutions for the network analysis problems.

The value for this parameter must be specified in JavaScript Object Notation (JSON). For example, a valid value is of the following form {"overrideSetting1" : "value1", "overrideSetting2" : "value2"}. The override setting name is always enclosed in double quotation marks. The values can be a number, a Boolean, or a string.

The default value for this parameter is no value, which indicates solver settings will not be overridden.

Overrides are advanced settings that should be used only after careful analysis of the results obtained before and after applying the settings. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support.

String

Derived Output

LabelExplanationData Type
Network Analyst Layer

The solved network analysis layer.

Network Analyst Layer
Solve Succeeded

A Boolean indicating whether the solve succeeded.

Boolean

arcpy.na.Solve(in_network_analysis_layer, {ignore_invalids}, {terminate_on_solve_error}, {simplification_tolerance}, {overrides})
NameExplanationData Type
in_network_analysis_layer

The network analysis layer on which the analysis will be computed.

Network Analyst Layer
ignore_invalids
(Optional)

Specifies whether invalid input locations will be ignored. Typically, locations are invalid if they cannot be located on the network. When invalid locations are ignored, the solver will skip them and attempt to perform the analysis using the remaining locations.

  • SKIPInvalid input locations will be ignored and only valid locations will be used.
  • HALTAll input locations will be used. Any invalid locations will cause the solve to fail.

The default value will match the ignoreInvalidLocations property of the designated in_network_analysis_layer value.

Boolean
terminate_on_solve_error
(Optional)

Specifies whether tool execution will terminate if an error is encountered during the solve.

  • TERMINATEThe tool will fail to execute when the solver encounters an error. This is the default. When you use this option, the Result object is not created when the tool fails to execute due to a solver error. Review the geoprocessing messages from the ArcPy object.
  • CONTINUEThe tool will not fail and will continue execution even when the solver encounters an error. All error messages returned by the solver will be converted to warning messages. When you use this option, the Result object is always created and the maxSeverity property of the Result object is set to 1 even when the solver encounters an error. Use the getOutput method of the Result object with an index value of 1 to determine if the solve was successful.
Boolean
simplification_tolerance
(Optional)

The tolerance that determines the degree of simplification for the output geometry. If a tolerance is specified, it must be greater than zero. You can choose a preferred unit; the default unit is decimal degrees.

Specifying a simplification tolerance tends to reduce the time it takes to render routes or service areas. The drawback, however, is that simplifying geometry removes vertices, which may lessen the spatial accuracy of the output at larger scales.

Because a line with only two vertices cannot be simplified any further, this parameter has no effect on drawing times for single-segment output, such as straight-line routes, OD cost matrix lines, and location-allocation lines.

Linear Unit
overrides
(Optional)

Additional settings that can influence the behavior of the solver when finding solutions for the network analysis problems.

The value for this parameter must be specified in JavaScript Object Notation (JSON). For example, a valid value is of the following form {"overrideSetting1" : "value1", "overrideSetting2" : "value2"}. The override setting name is always enclosed in double quotation marks. The values can be a number, a Boolean, or a string.

The default value for this parameter is no value, which indicates solver settings will not be overridden.

Overrides are advanced settings that should be used only after careful analysis of the results obtained before and after applying the settings. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support.

String

Derived Output

NameExplanationData Type
output_layer

The solved network analysis layer.

Network Analyst Layer
solve_succeeded

A Boolean indicating whether the solve succeeded.

Boolean

Code sample

Solve example 1 (Python window)

Execute the tool using all the parameters.

arcpy.na.Solve("Route", "HALT", "TERMINATE", "10 Meters")
Solve example 2 (workflow)

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

#Import system modules
import arcpy
from arcpy import env
import os

try:
    #Check out Network Analyst license if available. Fail if the Network Analyst license is not available.
    if arcpy.CheckExtension("network") == "Available":
        arcpy.CheckOutExtension("network")
    else:
        raise arcpy.ExecuteError("Network Analyst Extension license is not available.")
    
    #Set environment settings
    output_dir = "C:/Data"
    #The NA layer's data will be saved to the workspace specified here
    env.workspace = os.path.join(output_dir, "Output.gdb")
    env.overwriteOutput = True

    #Set local variables
    input_gdb = "C:/Data/Paris.gdb"
    network = os.path.join(input_gdb, "Transportation", "ParisMultimodal_ND")
    layer_name = "ClosestWarehouse"
    travel_mode = "Driving Time"
    facilities = os.path.join(input_gdb, "Analysis", "Warehouses")
    incidents = os.path.join(input_gdb, "Analysis", "Stores")
    output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")

    #Create a new closest facility analysis layer.
    result_object = arcpy.na.MakeClosestFacilityAnalysisLayer(network,
                                            layer_name, travel_mode,
                                            "TO_FACILITIES",
                                            number_of_facilities_to_find=1)

    #Get the layer object from the result object. The closest facility layer can
    #now be referenced using the layer object.
    layer_object = result_object.getOutput(0)

    #Get the names of all the sublayers within the closest facility layer.
    sublayer_names = arcpy.na.GetNAClassNames(layer_object)
    #Stores the layer names that we will use later
    facilities_layer_name = sublayer_names["Facilities"]
    incidents_layer_name = sublayer_names["Incidents"]

    #Load the warehouses as Facilities using the default field mappings and
    #search tolerance
    arcpy.na.AddLocations(layer_object, facilities_layer_name,
                            facilities, "", "")

    #Load the stores as Incidents. Map the Name property from the NOM field
    #using field mappings
    field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
                                                    incidents_layer_name)
    field_mappings["Name"].mappedFieldName = "NOM"
    arcpy.na.AddLocations(layer_object, incidents_layer_name, incidents,
                          field_mappings, "")

    #Solve the closest facility layer
    arcpy.na.Solve(layer_object)

    #Save the solved closest facility layer as a layer file on disk
    layer_object.saveACopy(output_layer_file)

    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 occurred on line %i" % tb.tb_lineno)
    print(str(e))

Environments

Licensing information

  • Basic: Limited
  • Standard: Limited
  • Advanced: Limited

Related topics