I'm using ArcPy for a vehicle routing problem in ArcGIS Desktop. I'm using the Network Analyst tool to find the minimum number of routes needed to service all orders given some constraints. I can create and solve the routing problem in AcrPy, but I can't figure out how to return the number of unassigned orders.

Some things I've tried:

temp = arcpy.na.Solve("Vehicle Routing Problem")
solution = temp.getOutput(0)

###Now check what it can do###

'Solution' is a group layer. I had expected to see information about the routes, orders, etc. - but couldn't find any of it.

Then I thought that the information could be present in a different layer, so I checked a list of layers, but didn't find anything interesting:

document = arcpy.mapping.MapDocument("CURRENT")

This matched by Table of Contents, but not the contents of the Network Analyst window (which is what I really wanted).

Eventually I gave up op on the idea that the information I wanted was attached to a layer. I found this article on the ESRI website which references an "UnassignedOrders" table, but I have no idea how to access that.

  • 1
    Are you using ArcPy and Network Analyst with ArcGIS Desktop or ArcGIS Pro? For coding questions it is always best to include a code snippet that illustrates what you have tried and where you are stuck to encourage potential answerers to test if they do not just know.
    – PolyGeo
    Sep 8 '17 at 20:35
  • @PolyGeo - Thanks for the direction. I've edited to include that info. Sep 8 '17 at 20:58

The help link you refer to is for ArcGIS Pro. You are working in ArcMap, so you should be looking at this help page: Vehicle routing problem analysis.

To iterate through the unassigned orders, you have to look into the Status field of the Orders layer:

After a solve operation, the status can be modified using one of the following status values:

OK (0)—The network location was successfully evaluated.

Element not traversable (3)—The network element that the network location is on is not traversable. This can occur when the network element is restricted by a restriction attribute.

Invalid field values (4)—The field values of the network location fall outside the analysis layer's coded or range domains. For example, a negative number may exist where positive numbers are required.

Not reached (5)—The network location can't be arrived at by the solver.

If time windows are used and the route arrives early or late, the value changes to Time window violation (6).

Therefore run this code in your map document open with the VRP layer created and solved:

>>> mxd = arcpy.mapping.MapDocument('current')

>>> orders = arcpy.mapping.ListLayers(mxd, 'Orders')[0]
>>> orders
<map layer u'Orders'>

#to get all orders names and status
>>> [f for f in arcpy.da.SearchCursor(orders, 'Name Status'.split())]
[(u'Graphic Pick 1', 5), (u'Graphic Pick 2', 0), (u'Graphic Pick 3', 0), (u'Graphic Pick 4', 0), (u'Graphic Pick 5', 5), (u'Graphic Pick 7', 5)]

#to count only unassigned
>>> len([f for f in arcpy.da.SearchCursor(orders, 'Status') if f[0] == 5])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.