Add first and last stop in Route Solver

01-19-2018 10:00 AM
New Contributor III

I m using ArcGIS 10.4.1 and NetworkAnalyst. The following part of code is used in order to solve a route layer. i am using the same starting and ending point. It works ok if i only have one route. But if i have more than one routes it doesn't work. 

fieldMappings =, stopsLayerName)

fieldMappings["RouteName"].mappedFieldName = "Group_ID"

#Add locations as Stops. T

#ADD FIRST STOP, stopsLayerName, inStops_1, fieldMappings1, "300 meters", "FID", [["roadNetwork_ND", "MIDDLE"], ["roadNetwork_ND_Junctions", "NONE"]], "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "", "", ""), stopsLayerName, inStops_2, fieldMappings, "300 meters", "FID", [["roadNetwork_ND", "SHAPE"], ["roadNetwork_ND_Junctions", "NONE"]], "", "APPEND", "SNAP", "", "", "")

#ADD LAST STOP, stopsLayerName, inStops_1, fieldMappings1, "300 meters", "FID", [["roadNetwork_ND", "MIDDLE"], ["roadNetwork_ND_Junctions", "NONE"]], "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "", "", "")

#Solve the route layer.

FYI The solved routes

the stops attribute table

the depots attribute table

Do you have any suggestions for what should i do to adapt my code so that all the routes start and finish at the same point, (a company's depot)?

0 Kudos
2 Replies
Esri Regular Contributor

What are your route analysis layer  optimization settings? That is, after you add the first stop, a second stop and then the first stop again, are you solving for best order? If yes, then it will redo the sequence and visit the first and last stop at the same time. You should set it to preserve first and last.

Generally for each unique route name, the stops are visited in sequence order. So each route for every unique routename can start and end at the same location not just one only.

Jay Sandhu

0 Kudos
New Contributor III

My route analysis layer optimization settings  are "FIND_BEST_ORDER", and "PRESERVE_BOTH". My goal is to assign the same starting and ending to point to many routes without having to use VRP solver.  inStops_2 refers to a table with which has different routenames (see the attached stops attribute table)

0 Kudos