Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Hello GIS Stack Exchange,

I am finding it difficult to load locations to sublayers using python in ArcGIS 10.0 network analyst Vehicle routing problem.

I'm also having some trouble debugging my code. Basically i keep getting the following error from the Solve_na function

"An error occured on line 72 ERROR 030092: VRP Solver failed due to invalid input. Invalid input in the NA classes. Failed to execute (Solve)."

It strikes me that even though there is an error, the depot and orders network analyst sublayers are well loaded with values from the input feature classes, while the routes network analyst sublayer does not load the values from its corresponding feature class. This implies that there must be a problem adding locations to the route from the corresponding route feature class that i created.

Here is the code below

import arcpy
from arcpy import env

try:
    arcpy.CheckOutExtension("Network")

    env.workspace = arcpy.GetParameterAsText(0)
    env.overwriteOutput = True

    inNetworkDataset = arcpy.GetParameterAsText(1)
    outNALayer = arcpy.GetParameterAsText(2)

    impedanceAttribute = "CABLE_COST"
    distanceAttribute = "Cable_Length"
    timeUntis = "Minutes"
    distanceUnits = arcpy.GetParameterAsText(3)
    inTurbines = arcpy.GetParameterAsText(4)
    inDepots = arcpy.GetParameterAsText(5)
    inRoutes = arcpy.GetParameterAsText(6)

    depotFieldMappings = "Name Name #;"
    routeFieldMappings = "Name Name #; StartDepotName StartDepotName #; EndDepotName EndDepotName #; StartDepotServiceTime StartDepotServiceTime #; EndDepotServiceTime EndDepotServiceTime #; EarliestStartTime EarliestStartTime #; LatestStartTime LatestStartTime #; Capacities Capacities #; FixedCost FixedCost #; CostPerUnitTime CostPerUnitTime #; CostPerUnitDistance CostPerUnitDistance #; OvertimeStartTime OvertimeStartTime #; CostPerUnitOvertime CostPerUnitOvertime #; MaxOrderCount MaxOrderCount #; MaxTotalTime MaxTotalTime #; MaxTotalTravelTime MaxTotalTravelTime #; MaxTotalDistance MaxTotalDistance #; SpecialtyNames SpecialtyNames #; AssignmentRule AssignmentRule #;"
    turbineFieldMappings = "Name NAME #; TimeWindowStart1 TimeWindowStart1 #; TimeWindowEnd1 TimeWindowEnd1 #; MaxViolationTime1 # 0"

    outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"

    arcpy.MakeVehicleRoutingProblemLayer_na(inNetworkDataset,outNALayer,
                                            timeUntis,distanceAttribute,
                                            "Minutes", distanceUnits, "1/1/1900", "#", "Low","#",
                                            "NO_UTURNS", "#", "TRUE","","STRAIGHT_LINES")

    arcpy.AddLocations_na(outNALayer, "Depots", inDepots, depotFieldMappings,"")

    arcpy.AddLocations_na(outNALayer, "Routes", inRoutes, , "")

    arcpy.AddLocations_na(outNALayer, "Orders", inTurbines, turbineFieldMappings,"")  

    arcpy.Solve_na(outNALayer)

    arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE")

    arcpy.AddMessage("Script completed successfully")

except Exception as e:

    import traceback, sys
    tb = sys.exc_info()[2]
    arcpy.AddMessage("An error occured on line %i" % tb.tb_lineno)
    arcpy.AddMessage(str(e))
share|improve this question
add comment

1 Answer

I originally created the routes feature class without any geometry since it was not going to play any part in the network. For this reason arcpy.AddLocation_na could not locate the table where the attribute values were stored.

Once i created a new route from the streets line feature class that i had and included only the number of rows i needed (each row representing a route) i was able to use this feature class in my script successfully.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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