I've written a piece of python code in ArcGIS 10.3 for applying VRP. pretty similar to sample code in Esri resource website.
But, it gives an error: ERROR 000192: Invalid value for Time Impedance
There was a similar question [here][1], but the answer doesn't fit to my problem as I'm using version 10.3
Meanwhile, when I'm using Network Analyst toolbox with the same layers, it works. So, problem is in my python code
import arcpy from arcpy import env try: arcpy.CheckOutExtension("Network") env.workspace = "C:\\Drivers\\Eli\\ArcGIS\\VRP\\" env.overwriteOutput = True inNetworkDataset = "C:\\Drivers\\Eli\\ArcGIS\\VRP\\Road_BNE_ND.nd\\Road_BNE_ND" outNALayerName = "results_MakeVRP" impedanceAttribute = "Travel_Tim" distanceAttribute = "Length" timeUntis = "Minutes" distanceUntis = "Meters" inOrdersClass= "orders.shp" inDepotClass = "POB.shp" inOrders = "orders" inDepots = "POB" inRoutes = "route" outLayerFile = "C:/Drivers/Eli/ArcGIS/VRP/" + outNALayerName + ".lyr" outNALayer = arcpy.na.MakeVehicleRoutingProblemLayer(inNetworkDataset, outNALayerName, impedanceAttribute, distanceAttribute, timeUntis, distanceUntis, "", 1, UTurn_policy = "NO_UTURNS", output_path_shape = "STRAIGHT_LINES") outNALayer = outNALayer.getOutput(0) subLayerNames = arcpy.na.GetNAClassNames(outNALayer) ordersLayerName = subLayerNames["Orders"] depotsLayerName = subLayerNames["Depots"] routesLayerName = subLayerNames["Routes"] candidateFields = arcpy.ListFields(inOrders) orderFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, ordersLayerName, False, candidateFields) orderFieldMappings["TimeWindowStart1"].defaultValue = "9 AM" orderFieldMappings["TimeWindowEnd1"].defaultValue = "5 PM" orderFieldMappings["DeliveryQuantities"].mappedFieldName = "Demand" orderFieldMappings["MaxViolationTime1"].defaultValue = 0 arcpy.na.AddLocations(outNALayer, ordersLayerName, inOrders, orderFieldMappings,"") depotFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, depotsLayerName) depotFieldMappings["Name"].mappedFieldName = "Name" depotFieldMappings["TimeWindowStart1"].defaultValue = "8 AM" depotFieldMappings["TimeWindowEnd1"].defaultValue = "5 PM" arcpy.na.AddLocations(outNALayer, depotsLayerName, inDepots, depotFieldMappings, "") arcpy.na.AddLocations(outNALayer, routesLayerName, inRoutes, "", "") arcpy.na.Solve(outNALayer) arcpy.management.SaveToLayerFile(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)
أكثر...
But, it gives an error: ERROR 000192: Invalid value for Time Impedance
There was a similar question [here][1], but the answer doesn't fit to my problem as I'm using version 10.3
Meanwhile, when I'm using Network Analyst toolbox with the same layers, it works. So, problem is in my python code
import arcpy from arcpy import env try: arcpy.CheckOutExtension("Network") env.workspace = "C:\\Drivers\\Eli\\ArcGIS\\VRP\\" env.overwriteOutput = True inNetworkDataset = "C:\\Drivers\\Eli\\ArcGIS\\VRP\\Road_BNE_ND.nd\\Road_BNE_ND" outNALayerName = "results_MakeVRP" impedanceAttribute = "Travel_Tim" distanceAttribute = "Length" timeUntis = "Minutes" distanceUntis = "Meters" inOrdersClass= "orders.shp" inDepotClass = "POB.shp" inOrders = "orders" inDepots = "POB" inRoutes = "route" outLayerFile = "C:/Drivers/Eli/ArcGIS/VRP/" + outNALayerName + ".lyr" outNALayer = arcpy.na.MakeVehicleRoutingProblemLayer(inNetworkDataset, outNALayerName, impedanceAttribute, distanceAttribute, timeUntis, distanceUntis, "", 1, UTurn_policy = "NO_UTURNS", output_path_shape = "STRAIGHT_LINES") outNALayer = outNALayer.getOutput(0) subLayerNames = arcpy.na.GetNAClassNames(outNALayer) ordersLayerName = subLayerNames["Orders"] depotsLayerName = subLayerNames["Depots"] routesLayerName = subLayerNames["Routes"] candidateFields = arcpy.ListFields(inOrders) orderFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, ordersLayerName, False, candidateFields) orderFieldMappings["TimeWindowStart1"].defaultValue = "9 AM" orderFieldMappings["TimeWindowEnd1"].defaultValue = "5 PM" orderFieldMappings["DeliveryQuantities"].mappedFieldName = "Demand" orderFieldMappings["MaxViolationTime1"].defaultValue = 0 arcpy.na.AddLocations(outNALayer, ordersLayerName, inOrders, orderFieldMappings,"") depotFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, depotsLayerName) depotFieldMappings["Name"].mappedFieldName = "Name" depotFieldMappings["TimeWindowStart1"].defaultValue = "8 AM" depotFieldMappings["TimeWindowEnd1"].defaultValue = "5 PM" arcpy.na.AddLocations(outNALayer, depotsLayerName, inDepots, depotFieldMappings, "") arcpy.na.AddLocations(outNALayer, routesLayerName, inRoutes, "", "") arcpy.na.Solve(outNALayer) arcpy.management.SaveToLayerFile(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)
أكثر...