Right now I am just trying to get a simple route created using VRP. Eventually, I have 180 files or "orders" that I would like to run routes for too, but right now I just want my code to work for one route. Below is my code. When I try to run it, I get an error at line 44: class 'Queue.Empty'. Any help on this is greatly appreciated as I am pretty new to both python and network analyst. Also, any input on repeating the VRP by looping through and changing the input order & depot files is greatly appreciated.
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# RouteCreation.py
# Created on: 2015-01-06
# Created by: L.M. Blackburn and ArcGIS/ModelBuilder
# ArcGIS 10.1
# Usage: RouteCreation for all grid center layers
# Description:
# solves routing problem for all point layers in a folder
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy, os, sys, traceback
from arcpy import env
# Check out any necessary licenses
arcpy.CheckOutExtension("Network")
# Set environment settings
env.workspace = 'F:\\Workspace\\Sandy\\GM_costAnalysis\\analysis2\\'
env.overwriteOutput = True
# Set Local variables:
inNetworkDataset = "F:\\Workspace\\Sandy\\GM_costAnalysis\\streets" # it seems that this value is empty
outNALayerName = "TrapRoute_MO1_6K" # may want this name to change with each run thru
impedanceAttribue = "Time"
distanceAttribute = "Length"
timeUnits = "Minutes"
distanceUnits = "Miles"
inOrder = "Grids/Block_MO1_6000_label.shp" #This value will change with each run - may want to define this via a loop
inDepots = "Depots/Depot_MO1.shp" # This value will change with each run - may want to define this via a loop
inRoutes = "RoutesTable"
outLayerFile = "F:/Workspace/Sandy/GM_costAnalysis/analysis2/Routes/" + outNALayerName + ".lyr" # may want to change w/ each run
searchTolerance = "4243 Meters" # This value will change based on the inOrder number of features
try:
#Test out paths and layer locations
print 'Starting the VRP'
# orderList = arcpy.ListWorkspaces("analysis2", "Folder")
# print ("network: {}".format(inNetworkDataset))
# print outNALayerName
# Process: Make Vehicle Routing Problem Layer
outNALayer = arcpy.MakeVehicleRoutingProblemLayer_na(inNetworkDataset, outNALayerName, impedanceAttribute, distanceAttribute, timeUnits, distanceUnits, "USE_HIERARCHY", "TRUE_LINES_WITH_MEASURES")
# outNALayer = arcpy.MakeVehicleRoutingProblemLayer_na(str(inNetworkDataset), outNALayerName, impedanceAttribute, distanceAttribute, timeUnits, distanceUnits, "", "", "Medium", "Medium", "ALLOW_UTURNS", "'4WD Road';'Pedestrian Walkway';'Pedestrian Ferry';TurnRestriction;OneWay", "USE_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES")
# Get the layer object from the result object to reference the VRP layer
outNALayer = outNALayer.getOutput(0)
# Get the names of all the sublayers within the VRP layer
subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
#Stores the layer names that we'll use later
ordersLayerName = subLayerNames["Orders"]
depotsLayerName = subLayerNames["Depots"]
routesLayerName = subLayerNames["Routes"]
# Process: Add Trap Locations - Order - will want to alter the search_tolerance to match the
arcpy.AddLocations_na(outNALayer, ordersLayerName, inOrders, "Name FID #", searchTolerance, "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")
# Process: Add Locations - Depot
arcpy.AddLocations_na(outNALayer, depotsLayerName, inDepots, "Name Name #", searchTolerance, "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")
# Process: Add Locations - Route
arcpy.AddLocations_na(outNALayer, routesLayerName, inRoutes, "Name Name #;Description Description #;StartDepotName StartDepotName #;EndDepotName EndDepotName #;StartDepotServiceTime StartDepotServiceTime #;EndDepotServiceTime EndDepotServiceTime #;EarliestStartTime EarliestStartTime '8:00:00 AM';LatestStartTime LatestStartTime '10:00:00 AM';ArriveDepartDelay ArriveDepartDelay #;Capacities Capacities #;FixedCost FixedCost #;CostPerUnitTime CostPerUnitTime 1;CostPerUnitDistance CostPerUnitDistance 1;OvertimeStartTime OvertimeStartTime #;CostPerUnitOvertime CostPerUnitOvertime #;MaxOrderCount MaxOrderCount 30;MaxTotalTime MaxTotalTime #;MaxTotalTravelTime MaxTotalTravelTime #;MaxTotalDistance MaxTotalDistance #;SpecialtyNames SpecialtyNames #;AssignmentRule AssignmentRule 1", searchTolerance, "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")
# Process: Solve
arcpy.Solve_na(outNALayer, "HALT", "TERMINATE", "")
print 'VRP complete'
except:
print 'Program failed.'
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n"
msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(msgs)
arcpy.AddError(pymsg)
print msgs
print pymsg
arcpy.AddMessage(arcpy.GetMessages(1))
print arcpy.GetMessages(1)