|
Mike,Chris You know what its like when you start something new - you need a meaty project to get your teeth into and accelarate the learning curve. I haven't gone anywhere near GDAL - I'm afraid - far too complex. I was toying with the idea of some R but then I realised I would have to learn R first - bit of a downer - so I decided to stick to things that I vaguely knew about such as Public Transport Models and Graph Theory. Just re-read that and it sounds pompous as hell. I have to do Travel Time 'Isochrones' for both private and public transport and I have to use some god-awful systems to accomplish this - Accession GIS - see - http://forum.manifold.net/forum/t67047.3 - I do NOT know graph theory!!! It's always been a bit of an ambition of mine to recreate the model in Manifold but routing esp Shortest Path Calculations were never upto the task so I gave up. However Python has renewed hope. So I've been doing a lot of work on SP. Now, the best standard I've heard from this forum and personal experience in Scripting and UIScripting is 2 seconds per Calculation - which is not great!!! especially when transport modelling is concerned - which revolves around Origin/Destination Pair Calculations - so 500x 500 matrices or 125,000 bidirectional SP calculations - which is a reasonable request. see:- http://forum.manifold.net/forum/t71988.5 http://forum.manifold.net/forum/t37404.4 http://forum.manifold.net/forum/t51990.4 http://forum.manifold.net/forum/t44201.5 Now by my [Excel] calculations, it would take roughly 3 Days for Manifold to perform this calculation [ 125K * 2sec / (24 * 60 * 60) ] whereas Accession - the dog of a system that it is - could accomplish this in 10 minutes / 600 seconds So my ultimate target is roughly the same as Accession - ie - 210 SP calculations a second Which equates to a whopping 42,000 % improvement in performance!!!! [CUDA - possible but lets let that one go for now and try and focus on scripting vs hardware/software improvements] I was looking at Python as a potential Black Box application which could be run in a separate process to Manifold - so the basic idea was to approach it from a Graph(Nodes/Edges] perspective My Process:- Manifold 1) I have a Network Drawing that is made up of Line Objects 2) I do a Node Points Transform 3) I do a merge of identical Points using a Select UnionAll Query based Upon [X (I)],[Y (I)] values 4) I now have two Drawings in my file - 'Network' and 'Nodes' Python Script A [Graph Preparation/Representation]:- 1) Open Above .map File 2) Run SQL that identifies FromNodeID and ToNodeID from Network,Nodes Drawings [as well as Distance] 3) Make this bi-directional by copying 2) above ie copy a,b,c to b,a,c 4) Create Python Dictionary of graph that takes the form:- '3021':{'3026':4059.77597904121,'3025':4132.92644502657,'3028':935.207463614358,'3030':1291.26062435126,'3022':1488.94358523082} which equate to all Nodes/distances around FromNode 3021 5) Use Python Pickle Library to save this Object to a file http://www.python.org/doc/2.5.2/lib/module-pickle.html Pickle's neat - you can save to file/read an object from file without having to recreate it programmatically 6) Graph saved To file - This takes a bit of time [depending on size on graph] but once done.............................. Script B [Calculations] 1) Load Map File 2) Generate 100 * 100 OD calculations from [Nodes] Drawing - potential 10,000 calculations 3) Create Results Table in .map 4) Create Comments to Hold Time Elapsed Data 5) If FromNode<>ToNode and SP calc has not already been performed [ ie A-B and B-A] 6) Perform dijkstra SP = FromNode - ToNode ( I found this code and verified it with Manifold) 7)From Results - FromNode,ToNode,Path eg 1,2, [1,3,7,9,2], Obtain cumulative distances to get Distance Result 8)Insert into Results Table, FromID,ToID,Distance,PathTaken [See Attached Image for Format] I ran the above code for 3 map files - see the results below:- See attached Excel Results Image File Network Count Node Count SP Calculations Time Seconds Calc/Second RN.map 37082 33559 5086 807 6.302 RN1.map 5438 4804 5229 120 43.575 RN2.map 1743 1547 5263 37.5 140.3467 You learn something new each and every day!!!! I never realised how linear the relationship was between graph size and speed of graph traversal/calculations So everytime Adam was saying split it up - he was making a lot of sense!!! By my calculations:- A graph that is 21.27481354 times smaller (RN2 vs, RN) will run 22.27017878 quicker (practically linear anyway) If my graph had a Network size of 1000, I think I would acheive my result of 210 SP calcs/sec!!!! So my code works on small graphs but not large ones - they take more creative thinking though I STRONGLY believe that my code could be somewhat "optimized" by someone who knows what they are doing Code will be uploaded when I am happy that others can use it - its pretty ugly in its present form and I have to find all the proper attributions for non-Manifold code. Manifold stuff - that blame lies squarely on my shoulders. [Edit] Results Table did not paste so have saved image Attachments:
 Excel_Results.PNG
 Results_Table.PNG
To err is human. To really foul things up requires a computer and a Very BIG Head |