Select to view content in your preferred language

VRP - Looping

3160
1
Jump to solution
03-14-2012 01:38 PM
ScottBlankenbeckler
Deactivated User
Good Afternoon,

I am trying to make routes for a series of depots. My first pass thru the code works fine but the second pass always fails. Any help would be appreciated

selected_locs = (["Location 1","X1234"],["Location 2","Y1234"], etc) for x in selected_locs:     Cloc = x[0]     drpkey = str(x[1])     outDirectionsFile = "E:/Output" + "/" + Cloc + "_Directions.xml"     orders_out = "E:\\\Test.gdb\\Orders_"+ Czip      routes_out = "E:\\\Test.gdb\\Routes_" + Czip     arcpy.SelectLayerByAttribute_management(Geo_Orders_Layer, "NEW_SELECTION", "\"LOCATION\" = '"+ Cloc +"'")      if ordrs <1:         print Cloc + ": C R A S H ! ! ! ! ! ! No Deliveries Geocoded"     else:         print Cloc + " deliveries: " + str(ordrs)         arcpy.AddLocations_na(VRP_Setup, "Orders", Geo_Orders_Layer, "Name # #;Description Full_Add #;ServiceTime SRVTIME 0.34;TimeWindowStart1 # #;TimeWindowEnd1 # #;TimeWindowStart2 # #;TimeWindowEnd2 # #;MaxViolationTime1 # #;MaxViolationTime2 # #;DeliveryQuantities # #;PickupQuantities # #;Revenue # #;SpecialtyNames CRID #;AssignmentRule # 3;RouteName # #;Sequence # #;CurbApproach # 0", "5000 Meters", "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")          Expression = "\"Name\" = '"+drpkey+"'"         arcpy.SelectLayerByAttribute_management(Depots_All_Layer, "NEW_SELECTION", Expression)         if pos < 1:             writeLog( "\t"+drpkey + " not found. (C R A S H ! ! !)")         elif pos>1:             writeLog( "\t Too many Depot's found. (C R A S H ! ! !)")         else:             writeLog( "\t Depot found and loaded.")             arcpy.AddLocations_na(VRP_Setup, "Depots", Depots_All_Layer, "Name Name #;Description Description #;TimeWindowStart1 TimeWindowStart1 #;TimeWindowEnd1 TimeWindowEnd1 #;TimeWindowStart2 TimeWindowStart2 #;TimeWindowEnd2 TimeWindowEnd2 #;CurbApproach CurbApproach 0", "5000 Meters", "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")              arcpy.AddLocations_na(VRP_Setup, "Routes", Route_Template, "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 #;OvertimeStartTime OvertimeStartTime #;CostPerUnitOvertime CostPerUnitOvertime #;MaxOrderCount MaxOrderCount 30;MaxTotalTime MaxTotalTime #;MaxTotalTravelTime MaxTotalTravelTime #;MaxTotalDistance MaxTotalDistance #;SpecialtyNames SpecialtyNames #;AssignmentRule AssignmentRule 1", "5000 Meters", "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")              arcpy.CalculateField_management(Route_Template, "StartDepotName", "'"+drpkey+"'", "PYTHON", "")             arcpy.CalculateField_management(Route_Template, "EndDepotName", "'"+drpkey+"'", "PYTHON", "")              arcpy.AddLocations_na(VRP_Setup, "Breaks", Breaks_Template, "RouteName RouteName #;Precedence Precedence 1;ServiceTime ServiceTime 60;TimeWindowStart TimeWindowStart #;TimeWindowEnd TimeWindowEnd #;MaxViolationTime MaxViolationTime #;MaxTravelTimeBetweenBreaks MaxTravelTimeBetweenBreaks #;IsPaid IsPaid 1;Sequence # #;MaxCumulWorkTime # #", "5000 Meters", "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")             arcpy.AddLocations_na(VRP_Setup, "Specialties", Specialties_Template, "Name Name #;Description Description #", "5000 Meters", "", "'SDC Edge Source' SHAPE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "'SDC Edge Source' #")               arcpy.Directions_na(VRP_Setup, "XML", outDirectionsFile, "Miles", "REPORT_TIME", "")             arcpy.CopyFeatures_management(Orders, orders_out, "", "0", "0", "0")             arcpy.CopyFeatures_management(Routes, routes_out, "", "0", "0", "0") 


Everything works fine first time thru but when it starts the second pass everything up to the Directions command works but the solve/directions fails with an error

Traceback (most recent call last):
  File "test.py", line 191, in <module>
    arcpy.Directions_na(VRP_Setup, "XML", outDirectionsFile, "Miles", "REPORT_TIME", "")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\na.py", line 440, in Directions
    raise e
arcgisscripting.ExecuteError: ERROR 030092: VRP Solver failed due to invalid input.
Invalid input in the NA classes.
Failed to execute (Directions).
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NaAn
by
Deactivated User
Hi,

Your problem comes from the following two lines:

            arcpy.CalculateField_management(Route_Template, "StartDepotName", "'"+drpkey+"'", "PYTHON", "")
            arcpy.CalculateField_management(Route_Template, "EndDepotName", "'"+drpkey+"'", "PYTHON", "")

You should set the start and end depot on your Routes sublayer instead of the input route layer. For example, if your vrp nalayer has the internal name of "MyVRPlayer," those two lines should be modified as

            arcpy.CalculateField_management("MyVRPlayer\Routes", "StartDepotName", "'"+drpkey+"'", "PYTHON", "")
            arcpy.CalculateField_management(MyVRPlayer\Routes", "EndDepotName", "'"+drpkey+"'", "PYTHON", "")

Since the depot names were not set to the route, solver returns "Invalid input" error.

Thanks.

Anna

View solution in original post

0 Kudos
1 Reply
NaAn
by
Deactivated User
Hi,

Your problem comes from the following two lines:

            arcpy.CalculateField_management(Route_Template, "StartDepotName", "'"+drpkey+"'", "PYTHON", "")
            arcpy.CalculateField_management(Route_Template, "EndDepotName", "'"+drpkey+"'", "PYTHON", "")

You should set the start and end depot on your Routes sublayer instead of the input route layer. For example, if your vrp nalayer has the internal name of "MyVRPlayer," those two lines should be modified as

            arcpy.CalculateField_management("MyVRPlayer\Routes", "StartDepotName", "'"+drpkey+"'", "PYTHON", "")
            arcpy.CalculateField_management(MyVRPlayer\Routes", "EndDepotName", "'"+drpkey+"'", "PYTHON", "")

Since the depot names were not set to the route, solver returns "Invalid input" error.

Thanks.

Anna
0 Kudos