Реализация n-арных расстояний

Я наткнулся на некоторые проблемы с поиском расстояний в моем районе между узлами.

Дан список местоположений пулов, инструкция алгоритма в псевдокоде выглядит так;

Build a tree
o Sort the pools from West to East.
o Store the most Western pool as the root node
o Connect the closest pool with an edge as the child of the root.
o For each pool from West to East connect the node for the pool with an edge as the child
of the closest node in the tree.
o This will result in an n-ary tree.
• Search for a route
o Given the above tree, perform a pre-order traversal to find a route that visits all nodes.
o Make sure to calculate the distance travelled in kilometers.

Я не совсем понимаю, зачем нам нужно это делать n-ary и как бы я построил тот, который добавляет детей в соответствии с расстоянием между бассейнами.

location('58 Fieldrow St.',-75.73795670904249,45.344387632924054). 
location('1520 Caldwell Ave.',-75.73886856878032,45.37223315413918). 
location('154 Mann Ave.',-75.66809864107668,45.420784695340274). 
location('145 Cathcart St',-75.69570714265845,45.43364510779131). 
location('349 Claremont Dr.',-75.65100870365318,45.45147956435529). 
location('1640 Devon Rd.',-75.64341396386098,45.40505998694386). 
location('2149 Berwick Ave.',-75.76237762310991,45.35750853073128). 
location('1500 Larose Ave.',-75.74042790502267,45.376538041017916). 
location('2844 Ahern Ave.',-75.79935158132524,45.36063791083469). 
location('68 Elm St.',-75.71353870063207,45.40984992554796). 
location('366 Parkdale Ave.',-75.73023035094172,45.40138661908912). 
location('1309 Randall Ave.',-75.6663971454287,45.383081724040146). 
location('1332 Avenue N.',-75.64599611564647,45.417175891787146). 
location('999 Heron Rd.',-75.67726553077785,45.37955540833377). 
location('120 Clegg St.',-75.67162178567759,45.406132203975446). 
location('6 Lisa Ave.',-75.78888493568607,45.344203611634356). 
location('539 Wavell Ave.',-75.7663355603181,45.383356299319395). 
location('33 Quill St.',-75.65712102762836,45.42506341603979). 
location('215 Owl Dr.',-75.66479650124089,45.35438810082107). 
location('1270 Pebble Rd.',-75.64825277394819,45.35958959542747). 
location('250 Somerset St. E.',-75.67679178631916,45.421628374955425). 
location('411 Dovercourt Ave.',-75.75301290567192,45.38390614815524). 
location('1B Windsor Ave.',-75.67593721799336,45.394532186176534). 
location('950 Alpine Ave.',-75.78913776510414,45.35618157210449). 
location('25 Range Rd.',-75.67270686637411,45.42814320884978). 
location('363 Lorry Greenberg Dr.',-75.63644623282283,45.363297932669155). 
location('10 Fifth Ave.',-75.68218644953257,45.40257049489391). 
location('395 Levis St.',-75.65314626399277,45.43665037776025). 
location('2 Eaton St.',-75.81675609520583,45.32631894820216). 
location('107 Chesterton Dr.',-75.72068192228832,45.3517223372365). 
location('61 Corkstown Rd.',-75.82733278768433,45.34609228122724). 
location('1015 Harkness Ave.',-75.676559014967,45.366710168887366). 
location('166 Frank St.',-75.68696475924723,45.41513265659813). 
location('2185 Arch St.',-75.62883265479898,45.389521642267944). 
location('1816 ST Laurent Blvd.',-75.62566700143215,45.402733068354976). 
location('2139 Tawney Rd.',-75.615926705023,45.39368089918365). 
location('955 Pleasant Park Rd.',-75.62613467769313,45.39596271646451). 
location('2955 Michéle Dr.',-75.8020190093133,45.3548865821927). 
location('2095 Kingsley Rd.',-75.77593080375445,45.35631278392867). 
location('1099 Grenon Ave.',-75.7957485439787,45.35143574971178). 
location('1269 Albany Dr.',-75.75360944568821,45.35959223124413). 
location('1161 Blohm Dr.',-75.61936964815708,45.36999070895657). 
location('400 Clarence St. E.',-75.68154277234615,45.433497486473115). 
location('2074 Benjamin Ave.',-75.7625479468355,45.36492415895533). 
location('1665 Apeldoorn Ave.',-75.70254191613397,45.35963576001747). 
location('960 Eiffel Ave.',-75.70673708550083,45.367907282835596). 
location('1990 Cochrane St.',-75.65708630346525,45.36886086041407). 
location('43 Ste-Cécile St.',-75.66850786065743,45.442237661390195). 
location('50 Castlefrank Rd.',-75.88504321403646,45.29552398823589). 
location('2679 Innes Rd.',-75.56367146417631,45.43415859594989). 
location('223 Iona St.',-75.74247203669871,45.392425824249926). 
location('1205 Trenton Ave.',-75.72477696260978,45.37828145083384). 
location('40 Reid Ave.',-75.72389983475932,45.39809949308152). 
location('645 Parkview Rd.',-75.73836344415304,45.38742953063268). 
location('525 Côté St.',-75.64849014424264,45.436351255364265). 
location('469 Donald St.',-75.64813126103986,45.43004145660221). 
location('180 Lockhart Ave.',-75.77225704729584,45.37607987330218). 
location('294 Elmgrove Ave.',-75.75232047849263,45.39427770813794). 
location('435 Bronson Ave.',-75.70274498043973,45.40897618041744). 
location('960 Silver St.',-75.73163858599659,45.380330193754176). 
location('140 Carleton Ave.',-75.74496450985441,45.40431589991452). 
location('108 Beech St.',-75.71148292845268,45.39934611083154). 

Расчет расстояния между двумя пулами можно найти по формуле Hypersine, которую я уже получил. Мне нужно понять реализацию Java n-арного дерева и то, как оно применяется к расстояниям.

0 ответов

Другие вопросы по тегам