AnsweredAssumed Answered

Solving OD Cost Matrix gets slower and slower in the iteration process

Question asked by darbari on Aug 14, 2015
Latest reply on Aug 15, 2015 by darbari

I have 7000 points, and for each point I want to create a OD cost matrix of that point to all other points and write the result in separate tables - that is 7000 tables with 6999 records each.


Solving the OD cost matrix is initially fast (takes about 3 seconds) for each origin (to 6999 destinations), but as the loop goes further, it gradually slows down. For example after 100 iterations solving OD matrix takes about a minute, and finally it gets so slow that it is not practical to continue -- for all 7000 points (it probably takes several days).  The solving time doesn't depend on where the origin point is located (in the center or periphery of the network).


Just to figure out what is wrong here, I modified the code such that for every 30 iterations, it redefined the OD Cost Matrix layer, and added the destinations again. This made the solving part as fast as it is in the beginning (about 3 second), but it is not a useful workaround as adding 7000 destination locations itself is a very slow process.


the memory usage doesn't change much, but CPU usages increase as the it loops further. 


should I del something after solving the OD matrix in the loop?


here is my code (i took out the part that redefined the OD Matrix for every 30 iteration, that was just for test):


import arcpy,datetime, sys



##print "start",






searchTolerance = "1000 Meters"


g = arcpy.Geometry()

geometryList = arcpy.CopyFeatures_management(inOrgins, g)

##print "object geometry created",,'OD_layer','Minutes','','','','','','','','No_Lines')

##print "OD matrix created",

outNALayer = outNALayer.getOutput(0)

subLayerNames =

originsLayerName = subLayerNames["Origins"]

destinationsLayerName = subLayerNames["Destinations"], destinationsLayerName, inDestinations,"", searchTolerance), destinationsLayerName, geometryList,"", searchTolerance)



##print "Destinations loaded",




for inOrgin in geometryList[start:end]:   

    print "myTable_{0}.dbf".format(i), originsLayerName, inOrgin, "",searchTolerance,"","","",'CLEAR')

    print "origin {0} added".format(i),

    print "solved for origin {0}".format(i),

    lines_lyr=arcpy.mapping.ListLayers(outNALayer, 'Lines')[0]


    print "dBase for origin {0} creatd".format(i),