Sign in to follow this  
Followers 0
Kapz

Very Complex Match/Search Function

16 posts in this topic

#1 ·  Posted (edited)

Hi,

I am working in a research lab and trying to determine the best way to write a function using autoit to match (or register) coordinates. I have two long lists of x,y,z coordinates each with a unique id (node) to represent that point. An example of a single point would be a point at 11.888 -100.189 -7.472 with a node representation of 1456. One of the two lists we'll call the master list and the other list we'll call the dependent list which contains roughly the same points as the master list, however, the unique ids (i.e. the nodes) are not the same. So the function would basically take the first point on the dependent list and search for the closest matching point in the master list, for example the closest point to 11.888 -100.189 -7.472 in the dependent list happens to be 11.001 -100.766 -7.987 in the master list but the unique ids are different for the two. The function would then append the correct id/node and x,y,z coordinates (based on what it found in the master list) to the end of the array for that first element (in the dependent list). By the time the function is done, it should have a modified version of the dependent list with the corresponding IDs and coordinates at the end of each array for each element.

I was thinking about loading each list (txt files) into 2 large arrays (master array = 5 x ~140000, dependnet array = 9 x ~140000) in autoit and then going through and searching for each point one at a time. While I know this can be done in autoit, the real trick is to determine the most efficient way to do this in the least amount of time as there are roughly 140,000 elements (points) in each of the two lists.

Below is a tiny example of the two lists:

Master list:

0  -10.946  -100.922  -12.331 0.000000
1  -11.392  -100.969  -12.217 0.000000
2  -12.448  -101.033  -12.040 0.000000
3  -13.395  -100.846  -11.726 0.000000
4  -14.301  -101.123  -12.033 0.000000
5  -15.035  -101.145  -12.032 0.000000
6  -15.684  -101.072  -12.033 0.000000
7  -16.533  -100.999  -12.050 0.000000
8  -9.286  -100.981  -12.650 0.000000
9  -9.811  -101.023  -12.742 0.000000
10  -10.749  -101.161  -12.752 0.000000
11  -11.909  -101.222  -12.717 0.000000
12  -12.602  -101.227  -12.616 0.000000
13  -13.341  -101.250  -12.504 0.000000
14  -14.204  -101.403  -12.819 0.000000
15  -15.153  -101.285  -12.824 0.000000
16  -16.215  -101.096  -12.789 0.000000
17  -17.091  -100.934  -12.622 0.000000
18  -9.229  -101.035  -13.133 0.000000
19  -9.913  -101.103  -13.472 0.000000
20  -10.631  -101.228  -13.930 0.000000
21  -11.610  -101.353  -13.661 0.000000
22  -12.760  -101.339  -13.371 0.000000
23  -13.708  -101.382  -13.295 0.000000
24  -14.482  -101.334  -13.576 0.000000
25  -15.211  -101.211  -13.778 0.000000
26  -15.929  -101.056  -13.645 0.000000
27  -16.784  -100.944  -13.449 0.000000
28  -9.252  -100.947  -13.954 0.000000
29  -9.872  -101.057  -14.440 0.000000
30  -10.478  -101.148  -14.664 0.000000
31  -11.221  -101.248  -14.648 0.000000
32  -12.442  -101.258  -14.643 0.000000
33  -13.713  -101.240  -14.226 0.000000
34  -14.751  -101.086  -14.402 0.000000
35  -15.549  -100.969  -14.219 0.000000
36  -16.000  -100.885  -14.070 0.000000
37  -16.379  -100.849  -13.969 0.000000
38  -10.096  -101.074  -14.975 0.000000
39  -10.575  -101.104  -15.267 0.000000
40  -11.594  -101.124  -15.609 0.000000
41  -12.641  -101.043  -15.569 0.000000
42  -13.460  -101.054  -15.129 0.000000
43  -14.217  -101.059  -14.856 0.000000
44  -15.082  -100.678  -18.606 0.000000
45  -15.559  -100.847  -18.684 0.000000
46  -16.104  -100.980  -18.872 0.000000
47  -16.605  -100.883  -18.904 0.000000
48  -12.860  -100.895  -19.867 0.000000
49  -13.577  -100.846  -19.526 0.000000
50  -14.740  -100.953  -19.157 0.000000

Dependent List:

0  -11.053  -100.651  -13.201 0.000000
1  -11.450  -100.861  -13.259 0.000000
2  -12.483  -100.930  -13.033 0.000000
3  -13.484  -100.897  -12.852 0.000000
4  -14.193  -101.098  -13.154 0.000000
5  -14.874  -100.978  -12.853 0.000000
6  -15.731  -100.913  -13.020 0.000000
7  -9.531  -100.650  -13.981 0.000000
8  -9.979  -100.693  -13.854 0.000000
9  -10.600  -100.818  -13.642 0.000000
10  -11.713  -101.061  -13.956 0.000000
11  -12.719  -101.120  -13.917 0.000000
12  -13.435  -101.130  -13.521 0.000000
13  -14.165  -101.246  -13.869 0.000000
14  -15.046  -101.148  -13.707 0.000000
15  -16.264  -100.862  -13.924 0.000000
16  -16.897  -100.460  -14.034 0.000000
17  -9.498  -100.730  -14.243 0.000000
18  -9.882  -100.828  -14.354 0.000000
19  -10.795  -101.088  -14.541 0.000000
20  -11.566  -101.136  -14.885 0.000000
21  -12.428  -101.133  -14.689 0.000000
22  -13.540  -101.207  -14.505 0.000000
23  -14.545  -101.174  -14.476 0.000000
24  -15.420  -101.045  -14.647 0.000000
25  -16.244  -100.772  -14.783 0.000000
26  -16.641  -100.547  -14.454 0.000000
27  -10.166  -100.966  -15.261 0.000000
28  -10.982  -101.123  -15.323 0.000000
29  -11.476  -101.097  -15.406 0.000000
30  -12.014  -101.074  -15.438 0.000000
31  -12.990  -101.056  -15.449 0.000000
32  -14.443  -100.964  -15.579 0.000000
33  -15.749  -100.737  -15.157 0.000000
34  -16.172  -100.647  -15.015 0.000000
35  -10.023  -100.875  -15.993 0.000000
36  -10.586  -101.009  -15.847 0.000000
37  -11.329  -101.034  -15.965 0.000000
38  -12.244  -100.926  -16.159 0.000000
39  -13.217  -100.768  -16.166 0.000000
40  -13.828  -100.626  -16.186 0.000000
41  -12.758  -99.670  -4.187 0.000000
42  -13.132  -99.505  -4.187 0.000000
43  -11.982  -99.611  -4.938 0.000000
44  -12.471  -99.578  -4.741 0.000000
45  -12.925  -99.449  -4.731 0.000000
46  -10.881  -99.758  -5.907 0.000000
47  -11.403  -99.687  -5.478 0.000000
48  -12.326  -99.507  -5.487 0.000000
49  -12.989  -99.236  -5.368 0.000000
50  -11.137  -99.883  -6.317 0.000000

(ignore the zeros at the end)

Any help would be much appreciated, thank you.

Edited by Kapz

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Oh damn i'm good:

#include <file.au3>
#include <array.au3>

Dim $array1, $array2
Dim $file1 = "list1.txt", $file2 = "list2.txt"

;Read file into 1 dimensional array
_FileReadToArray($file1, $array1)
If @ERROR Then
    MsgBox(0,"","Error opening " & $file1)
    Exit
EndIf

;Read file into 1 dimensional array
_FileReadToArray($file2, $array2)
If @ERROR Then
    MsgBox(0,"","Error opening " & $file2)
    Exit
EndIf

;Define new array with the same number of rows as lines in file
;[0] = id
;[1] = X
;[2] = Y
;[3] = Z
;[4] = Mysterious zeroes
;[5] = Id of closest point in master array (Slave array only)
;[6] = Distance from closest point (Slave array only)
Dim $newArray1[$array1[0]][5] ;Master
Dim $newArray2[$array2[0]][7] ;Slave

;Copy original arrays to new arrays
For $X = 1 to $array1[0]
    ;Reduce double spaces to single spaces
    $array1[$X] = StringStripWS($array1[$X], 4)
    
    ;Split line by SINGLE space
    $tempArray = StringSplit($array1[$X], " ", 1)
    
    ;Subtract 1 from $X since the new array will be zero indexed
    $newArray1[$X-1][0] = $tempArray[1] ;id
    $newArray1[$X-1][1] = $tempArray[2] ;X
    $newArray1[$X-1][2] = $tempArray[3] ;Y
    $newArray1[$X-1][3] = $tempArray[4] ;Z
    $newArray1[$X-1][4] = $tempArray[5] ;??
Next

;_ArrayDisplay($newArray1)

;Copy original arrays to new arrays
For $X = 1 to $array2[0]
    ;Reduce double spaces to single spaces
    $array2[$X] = StringStripWS($array2[$X], 4)    
    
    ;Split line by SINGLE space
    $tempArray = StringSplit($array2[$X], " ", 1)
    ;ConsoleWrite($array2[$X] & @CRLF)
    
    ;Subtract 1 from $X since the new array will be zero indexed
    $newArray2[$X-1][0] = $tempArray[1] ;id
    $newArray2[$X-1][1] = $tempArray[2] ;X
    $newArray2[$X-1][2] = $tempArray[3] ;Y
    $newArray2[$X-1][3] = $tempArray[4] ;Z
    $newArray2[$X-1][4] = $tempArray[5] ;??
    $newArray2[$X-1][5] = -1 ;Default id
    $newArray2[$X-1][6] = -1 ;Default distance
Next

;_ArrayDisplay($newArray2)

;For each row in slave array, find closest match from master array
For $X = 0 to $array2[0] - 1
    ;Define crazy high distance
    $shortestDistance = 10000
    $shortestId = -1
    
    ;Loop through master array
    For $K = 0 to $array1[0] - 1
        ;Retrieve distance - note that I use "X" for the outer loop and "K" for the inner loop
        $currentDistance = GetDistance($newArray2[$X][1], $newArray2[$X][2], $newArray2[$X][3], $newArray1[$K][1], $newArray1[$K][2], $newArray1[$K][3]) ;3D distance formula here        
        
        ;Self explanatory
        If $currentDistance < $shortestDistance Then
            ;ConsoleWrite("X: " & $X & @CRLF & "K: " & $K & @CRLF & "Id: " & $newArray1[$K][0] & @CRLF & "Distance: " & $currentDistance & @CRLF & @CRLF)

            ;Store Id of current closest point
            $shortestId = $newArray1[$K][0]            
            
            ;Store shortest distance
            $shortestDistance = $currentDistance
        EndIf
    Next

    ;Copy id from master array
    $newArray2[$X][5] = $shortestId
            
    ;Store distance
    $newArray2[$X][6] = $shortestDistance
            
    ;ConsoleWrite("X: " & $X & " Closest ID: " & $shortestId & @CRLF)
Next

_ArrayDisplay($newArray2)

;Pythagorean
Func GetDistance($X1, $Y1, $Z1, $X2, $Y2, $Z2)
    Local $distance = 0
    $distance = Sqrt(($X1 - $X2)^2 + ($Y1 - $Y2)^2 + ($Z1 - $Z2)^2)
    Return Abs($distance)
EndFunc

Edit: All fixed!

Edited by weaponx

Share this post


Link to post
Share on other sites

Hi,

I am working in a research lab and trying to determine the best way to write a function using autoit to match (or register) coordinates. I have two long lists of x,y,z coordinates each with a unique id (node) to represent that point. An example of a single point would be a point at 11.888 -100.189 -7.472 with a node representation of 1456. One of the two lists we'll call the master list and the other list we'll call the dependent list which contains roughly the same points as the master list, however, the unique ids (i.e. the nodes) are not the same. So the function would basically take the first point on the dependent list and search for the closest matching point in the master list, for example the closest point to 11.888 -100.189 -7.472 in the dependent list happens to be 11.001 -100.766 -7.987 in the master list but the unique ids are different for the two. The function would then append the correct id/node and x,y,z coordinates (based on what it found in the master list) to the end of the array for that first element (in the dependent list). By the time the function is done, it should have a modified version of the dependent list with the corresponding IDs and coordinates at the end of each array for each element.

I was thinking about loading each list (txt files) into 2 large arrays (master array = 5 x ~140000, dependnet array = 9 x ~140000) in autoit and then going through and searching for each point one at a time. While I know this can be done in autoit, the real trick is to determine the most efficient way to do this in the least amount of time as there are roughly 140,000 elements (points) in each of the two lists.

Below is a tiny example of the two lists:

Master list:

0  -10.946  -100.922  -12.331 0.000000
1  -11.392  -100.969  -12.217 0.000000
2  -12.448  -101.033  -12.040 0.000000
3  -13.395  -100.846  -11.726 0.000000
4  -14.301  -101.123  -12.033 0.000000
5  -15.035  -101.145  -12.032 0.000000
6  -15.684  -101.072  -12.033 0.000000
7  -16.533  -100.999  -12.050 0.000000
8  -9.286  -100.981  -12.650 0.000000
9  -9.811  -101.023  -12.742 0.000000

Dependent List:

0  -11.053  -100.651  -13.201 0.000000
1  -11.450  -100.861  -13.259 0.000000
2  -12.483  -100.930  -13.033 0.000000
3  -13.484  -100.897  -12.852 0.000000
4  -14.193  -101.098  -13.154 0.000000
5  -14.874  -100.978  -12.853 0.000000
6  -15.731  -100.913  -13.020 0.000000
7  -9.531  -100.650  -13.981 0.000000
8  -9.979  -100.693  -13.854 0.000000
9  -10.600  -100.818  -13.642 0.000000

(ignore the zeros at the end)

Any help would be much appreciated, thank you.

You are on your own interpreting the twisted explanation of what you wanted to do with the results, but simply finding a 3D distance and the nearest match is easy. This simply writes it to the a text string and then outputs it all to the console:
Global $avMaster[10][4] = [[-10.946, -100.922, -12.331, 0.000000], _
        [-11.392, -100.969, -12.217, 0.000000], _
        [-12.448, -101.033, -12.040, 0.000000], _
        [-13.395, -100.846, -11.726, 0.000000], _
        [-14.301, -101.123, -12.033, 0.000000], _
        [-15.035, -101.145, -12.032, 0.000000], _
        [-15.684, -101.072, -12.033, 0.000000], _
        [-16.533, -100.999, -12.050, 0.000000], _
        [-9.286, -100.981, -12.650, 0.000000], _
        [-9.811, -101.023, -12.742, 0.000000]]

Global $avDependent[10][4] = [[-11.053, -100.651, -13.201, 0.000000], _
        [-11.450, -100.861, -13.259, 0.000000], _
        [-12.483, -100.930, -13.033, 0.000000], _
        [-13.484, -100.897, -12.852, 0.000000], _
        [-14.193, -101.098, -13.154, 0.000000], _
        [-14.874, -100.978, -12.853, 0.000000], _
        [-15.731, -100.913, -13.020, 0.000000], _
        [-9.531, -100.650, -13.981, 0.000000], _
        [-9.979, -100.693, -13.854, 0.000000], _
        [-10.600, -100.818, -13.642, 0.000000]]

Global $iDist, $Index, $sAnswer = "", $iTimer = TimerInit()
For $d = 0 To UBound($avDependent) - 1
    $iDist = (2 ^ 31) - 1
    $Index = -1
    For $m = 0 To UBound($avMaster) - 1
        $iTestDist = _Distance3D($avDependent[$d][0], $avDependent[$d][1], _
                $avDependent[$d][2], $avMaster[$m][0], $avMaster[$m][1], $avMaster[$m][2])
        If $iTestDist < $iDist Then
            $iDist = $iTestDist
            $Index = $m
        EndIf
    Next
    $sAnswer &= "Data point " & $d & " (" & $avDependent[$d][0] & ", " & _
            $avDependent[$d][1] & ", " & $avDependent[$d][2] & _
            "):  Nearest master is index " & $Index & " (" & $avMaster[$Index][0] & _
            ", " & $avMaster[$Index][1] & ", " & $avMaster[$Index][2] & ") at distance = " & _
            $iDist & @LF
Next
$iTimer = Round(TimerDiff($iTimer), 3)
ConsoleWrite($sAnswer & @LF & "Results in " & $iTimer & "ms" & @LF)

Func _Distance3D($X1, $Y1, $Z1, $X2, $Y2, $Z2)
    Local $DeltaX = $X1 - $X2, $DeltaY = $Y1 - $Y2, $DeltaZ = $Z1 - $Z2
    Return Sqrt(($DeltaX ^ 2) + ($DeltaY ^ 2) + ($DeltaZ ^ 2))
EndFunc   ;==>_Distance3D

If speed is really an issue, then I question the wisdom of using AutoIt or any other scripting language over a compiled language like C++.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I was thinking about loading each list (txt files) into 2 large arrays (master array = 5 x ~140000, dependnet array = 9 x ~140000) in autoit and then going through and searching for each point one at a time. While I know this can be done in autoit, the real trick is to determine the most efficient way to do this in the least amount of time as there are roughly 140,000 elements (points) in each of the two lists.

hm.. sounds like you are looking for clusters of data points in 3D. There are some very fast algorithms available for cluster "detection". Search google for: data mining cluster algorithm.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Both of those look awesome, I will test them out. I will also search for cluster detection. Thank you very much for your help!

Share this post


Link to post
Share on other sites

The actual lists of coordinates that I am using has many more than the 50 lines that I posted as an example. There are close to 140,000 but it looks like there is a limit for how long an array can be in autoit and I get an error when I try to run the script with large lists. Are there any workarounds for this?

Thanks!

Share this post


Link to post
Share on other sites

And the error is??? Copy the output from SciTe if you can.

Share this post


Link to post
Share on other sites

And the error is??? Copy the output from SciTe if you can.

I apologize, it looks like an array can actually be 2^24 in length in Autoit. I checked and there was an empty space in the txt file. It took approximately 370 seconds when list1 was 123,000 lines and list2 was 50 lines. The actual data that I will be working with will be ~130,000 lines in list1 and ~1600 lines in list2. It should take about 3.5 hours to complete. I can batch this process and allow it to run over a weekend for all 30 different cases. I was just curious if there was any way to speed up the processing without having to use C++ or another language. Btw, I am using weaponx's code. Thanks!

Share this post


Link to post
Share on other sites

I don't think it can be more optimized in AutoIt. Maybe you can perform a seperate benchmark just on the FileReadToArray() portions just to see how long that takes.

I don't think this would be difficult in C++. If you want further help, PM me and maybe you can send me the entire files for testing. Or I guess you could just give me the min and max limits for the XYZ coordinates and I will generate some sample files myself.

Share this post


Link to post
Share on other sites

I apologize, it looks like an array can actually be 2^24 in length in Autoit. I checked and there was an empty space in the txt file. It took approximately 370 seconds when list1 was 123,000 lines and list2 was 50 lines. The actual data that I will be working with will be ~130,000 lines in list1 and ~1600 lines in list2. It should take about 3.5 hours to complete. I can batch this process and allow it to run over a weekend for all 30 different cases. I was just curious if there was any way to speed up the processing without having to use C++ or another language. Btw, I am using weaponx's code. Thanks!

Let's see... 3.5Hrs x 30 cases = 105Hrs = 4 days 9 hours of run time.

You either need longer weekends, or to give up on doing this with a scripting language.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Wow I just found some interesting results. I wrote this script to generate two example files which I ran my original script against (be sure to delete whitespace at end):

$fileHandle = FileOpen("test_list1.txt",2)
For $V = 0 to 999
    $XX = Random(-100, 100)
    $YY = Random(-100, 100)
    $ZZ = Random(-100, 100)
    $MM = 0.000000
    $line = StringFormat("%i %.3f %.3f %.3f %.3f", $V, $XX, $YY, $ZZ, $MM)
    FileWriteLine($fileHandle,$line)
Next
FileClose($fileHandle)
MsgBox(0,"","File write complete")

Here are the results on my quad core Q6600 machine with 4gb of ram:

1000x1000 with function call for Pythagorean = 40.072 seconds

1000x1000 with Pythagorean integrated into loop = 25.323 seconds (36% faster)

5000x5000 with function call for Pythagorean = 1002.875 seconds (16.714 minutes)

5000x5000 with Pythagorean integrated into loop = 633.794 seconds (10.563 minutes) (36% faster)

Edited by weaponx

Share this post


Link to post
Share on other sites

Wow I just found some interesting results. I wrote this script to generate two example files which I ran my original script against (be sure to delete whitespace at end):

Here are the results on my quad core Q6600 machine with 4gb of ram:

1000x1000 with function call for Pythagorean = 40.072 seconds

1000x1000 with Pythagorean integrated into loop = 25.323 seconds (36% faster)

5000x5000 with function call for Pythagorean = 1002.875 seconds (16.714 minutes)

5000x5000 with Pythagorean integrated into loop = 633.794 seconds (10.563 minutes) (36% faster)

I wouldn't have thought the overhead for calling a UDF was that high.

BTW, you can drop the ABS() in your Pythagorean function. The squaring of the delta values guarantees they are positvie numbers before they are summed. That might bring it down a tiny bit more.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Dropping Abs() took 23.268 seconds vs. 25.323 seconds for 1000x1000.

I am going to start the big test when I leave work, 130000 x 1600 and will post the results in the morning.

Share this post


Link to post
Share on other sites

Dropping Abs() took 23.268 seconds vs. 25.323 seconds for 1000x1000.

I am going to start the big test when I leave work, 130000 x 1600 and will post the results in the morning.

That's awesome! Doing some research of your own--looks great!!

Share this post


Link to post
Share on other sites

Here are the final results:

Master list: 130,000 elements

Slave list: 1,600 elements

4817.579 seconds (80.29 minutes)

Still seems like C++ would be a lot faster.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I attempted a trial run in C++. This works extremely fast, like only a few seconds. Unfortunately it crashes when I try to use ifstream with the larger 100,000 element test files:

#include <cstdlib>
 #include <iostream>
 #include <iomanip>
 #include <fstream>
 #include <math.h>
 
 using namespace std;
 
 struct row 
 {
         int id;
         double X;
         double Y;
         double Z;
         double M;
         int masterid;
         double distance;
 };
 
 int main(int argc, char *argv[])
 {
     //Column types
     int id;
     double X;
     double Y;
     double Z;
     double M;
     int masterid;
     double distance;
     
     int array1size = 10000;
     int array2size = 10000;
     
     
     //Array to hold rows (structs)
     row array1[array1size];
     row array2[array2size];
     
     //Open input file 1
     ifstream list1Handle;
     list1Handle.open("test_list1.txt");
     
     if(!list1Handle){
         cout << "Error reading file 1" << endl;
         exit(1);
     };
     
     //Open input file 2
     ifstream list2Handle;
     list2Handle.open("test_list2.txt");
 
     if(!list2Handle){
         cout << "Error reading file 2" << endl;
         exit(1);
     };
 
     int element = 0;
 
     //Read in file 1
     while (list1Handle >> id >> X >> Y >> Z >> M) {
         array1[element].id = id;
         array1[element].X = X;
         array1[element].Y = Y;
         array1[element].Z = Z;
         array1[element].M = M;
         cout << id << " " << X << " " << Y << " " << Z << " " << M << endl;
         element += 1;
     }
     
     element = 0;
 
     //Read in file 2
     while (list2Handle >> id >> X >> Y >> Z >> M) {
         array2[element].id = id;
         array2[element].X = X;
         array2[element].Y = Y;
         array2[element].Z = Z;
         array2[element].M = M;
         array2[element].masterid = -1;
         array2[element].distance = -1;
         //cout << id << " " << X << " " << Y << " " << Z << " " << M << endl;
         element += 1;
     }
 
     
     //Close opened files
     list1Handle.close();
     list2Handle.close();
     
     exit(1);
     
     double currentDistance = -1;
     double shortestDistance;
     int shortestid;
     
     //Loop through slave list
     for (int V=0; V < array2size; V++){
         
         shortestDistance = 1000000;
         shortestid = -1;
         
         
         //Loop through master list
         for (int K = 0; K < array1size; K++){
             currentDistance = sqrt(pow(array2[V].X - array1[K].X, 2) + pow(array2[V].Y - array1[K].Y,2) + pow(array2[V].Z - array1[K].Z, 2));
             
             if (currentDistance < shortestDistance){
                shortestDistance = currentDistance;
                shortestid = K;
             };
         };
         
         //cout << shortestDistance << endl;
         
         array2[V].masterid = shortestid;
         array2[V].distance = shortestDistance;
         
         cout << array2[V].id << " " << array2[V].X << " " <<array2[V].id << " " << array2[V].Z << " " << array2[V].M << " " << array2[V].masterid << " " << array2[V].distance <<endl;
     };
         
     system("PAUSE");
     return EXIT_SUCCESS;
 }
Edited by weaponx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0