ODCM "solve did not find a solution" error with arcpy.nax.solve on valid origins/destinations

10-31-2022 03:44 PM
New Contributor III

I am trying to run an ODCM using arcpy.nax and I'm seeing this "Solve did not find a solution" error when running the example code below. 


# Solving OD Cost Matrix...
# OD Cost Matrix solve failed.
# [[-2147200956, 'No "Destinations" found for "Location 1" in "Origins".'], [30212, 'Solve did not find a solution.'], [-2147200971, 'No solution found.']]
import arcpy
import os

# Check out the NA license or alert error
class LicenseError(Exception):
if arcpy.CheckExtension("Network") == "Available":
  raise LicenseError("You need the ArcGIS Network Analyst extension license. Please contact your KP administrator.")

  arcpy.env.overwriteOutput = True

  # Set environment variables
  nds = r"path/to/StreetMapPremium/FGDB/StreetMap_Data/NorthAmerica.gdb/Routing/Routing_ND" # <path to your network dataset>
  gdb = r"path/to/scratch.gdb" # <path to your working geodatabase>
  in_origins = os.path.join(gdb, "in_org") #   nw block group weighted centroids
  in_destinations = os.path.join(gdb,"in_dest") # nw pc mob locations
  out_lines = os.path.join(gdb,"od_cost_matrix_lines")

  nd_travel_modes = arcpy.nax.GetTravelModes(nds)
  travel_mode = nd_travel_modes["Driving Time"]

  # Instantiate a solver object
  odcm = arcpy.nax.OriginDestinationCostMatrix(nds)
  # Set object properties
  odcm.travelMode = travel_mode
  odcm.timeUnits = arcpy.nax.TimeUnits.Minutes
  # odcm.defaultImpedanceCutoff = 20
  # odcm.defaultDestinationCount = 2
  odcm.lineShapeType = arcpy.nax.LineShapeType.StraightLine

  # Load inputs
    arcpy.nax.OriginDestinationCostMatrixInputDataType.Origins, in_origins)
    arcpy.nax.OriginDestinationCostMatrixInputDataType.Destinations, in_destinations)
  # Solve the analysis
  print("Solving OD Cost Matrix...")
  result = odcm.solve()
  # Export the results to a feature class
  if result.solveSucceeded:
    print("OD Cost Matrix solve succeeded.")
    print("OD Cost Matrix solve failed.")

except Exception as e:
  import sys
  tb = sys.exc_info()[2]
  print(f"An error occured on line {tb.tb_lineno}")
# Solving OD Cost Matrix...
# OD Cost Matrix solve failed.
# [[-2147200956, 'No "Destinations" found for "Location 1" in "Origins".'], [30212, 'Solve did not find a solution.'], [-2147200971, 'No solution found.']]


 The origin in question has the following coordinates: 33.492278, -117.247194

The destination in question has the following coordinates: 33.90478, -117.4693

The ODCM solve succeeds when running by hand within ArcGIS Pro, however, this approach is calling arcpy.na methods behind the scenes, instead of arcpy.nax.


arcpy.na.MakeODCostMatrixAnalysisLayer(r"/path/to/StreetMapPremium/FGDB/StreetMap_Data/NorthAmerica.gdb/Routing/Routing_ND", "OD Cost Matrix", "Driving Time", None, None, None, "LOCAL_TIME_AT_LOCATIONS", "STRAIGHT_LINES", None)

arcpy.na.AddLocations("OD Cost Matrix", "Origins", "in_org", "Name # #;TargetDestinationCount # #;CurbApproach # 0;Cutoff_Minutes # #;Cutoff_TravelTime # #;Cutoff_Miles # #;Cutoff_Kilometers # #;Cutoff_TimeAt1KPH # #;Cutoff_WalkTime # #;Cutoff_TruckMinutes # #;Cutoff_TruckTravelTime # #", "5000 Meters", None, "Routing_Streets SHAPE;Routing_Streets_Override NONE;Routing_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "EXCLUDE", None)

arcpy.na.AddLocations("OD Cost Matrix", "Destinations", "in_dest", "Name # #;CurbApproach # 0", "5000 Meters", None, "Routing_Streets SHAPE;Routing_Streets_Override NONE;Routing_ND_Junctions NONE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "EXCLUDE", None)

arcpy.na.Solve("OD Cost Matrix", "SKIP", "TERMINATE", None, '')
# Start Time: Monday, October 31, 2022 9:54:53 AM
# Succeeded at Monday, October 31, 2022 9:54:54 AM (Elapsed Time: 0.81 seconds)


Can someone from Esri help me understand why the same origins/destinations are returning different results depending on whether arcpy.na or arcpy.nax methods are used? Any insight is appreciated!

0 Kudos
2 Replies
New Contributor II

Hi Philip!

Could you provide me with a little more detail on what version of Pro you are using and the SMP data?

I did try it an in-house version of Pro 3.1 and it failed within Pro as well. Upon further inspection, I found that the street on which the origin is located does not allow automobile. Unchecking 'Driving an automobile' in the travel settings resolved the issue. 

I would still like to reproduce the issue in-house by replicating your settings and software version.

0 Kudos
New Contributor III

@AmlanR, thanks for the info! I'm using ArcGIS Pro 2.7.3 and SMP 2021.3. 

I did some more digging yesterday and discovered that the Rounting_ND data that comes with Business Analyst was being selected from within the GUI (instead of SMP). Pointing my ArcPy script to this Routing_ND resulted in a successful ODCM solve. 

Is there any other way to handle these points besides unchecking the "Driving an automobile" setting? Ideally, I would like this point to snap to the nearest edge where this is allowed instead of having to alter the travel mode. 

0 Kudos