Just another Perl shrine | |
PerlMonks |
Re: Processing data with lot of math...by BrowserUk (Patriarch) |
on May 12, 2004 at 17:07 UTC ( [id://352838]=note: print w/replies, xml ) | Need Help?? |
I think that it is possible to do this with one loop, and almost no math! However, I could be missing something, so read, digest, cogitate and draw your own conclusions. For example, if you have an atom located at point ( 10, 10, 10 ), and the cut-off distance is 1 unit, then any atom that will be paired with this atom will have to be somewhere within an box defined by the points
So, instead of storing the x:y:z in separate arrays, or some other complex data structure, create a single array, indexed by the concatentations of x:y:z, (with leading zeros).
Once you have created this (sparse) array, it becomes very easy to pick out the limited set of possible pairings for any given point. It requires a final math check to exclude those point lying in the corners of the box, but the number of calculations should be significantly less than the brute force method. There are some problems with this.
At this point the solution becomes to process the files and create a single output file where each record is of the form
A single pass to create the file. Then sort the file (using your systems sort utility) and the a single pass to read the sorted output and do the final comparisons and write out the pairs in whatever format you need them. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail
In Section
Seekers of Perl Wisdom
|
|