minimum spanning tree lua HPPL
|
10-29-2021, 10:52 AM
Post: #10
|
|||
|
|||
RE: minimum spanning tree lua HPPL
(10-29-2021 05:53 AM)robmio Wrote: Thank you for having brilliantly solved the "multivariate" version as well. Are you a computer scientist? No. I had never heard of minimum spanning tree (10-28-2021 09:07 PM)Albert Chan Wrote: Version 3, extending to multi-dimensional points Instead of badEdges = [[p1,p2],[p2,p1], ...], we could simplify to [[1,2],[2,1], ...] Same for tree = [[p(j1),p(k1)], [p(j2),p(k2)], ...], simplified to [[j1,k1],[j2,k2], ...] But, this required pts not be shuffled (otherwise indexes meant nothing) Version 4 solve the problems with another level of indirection (*) Code: #cas Redo the same example, with this new version CAS> pts := [[15,17,24,14], [17,15,32,26], [15,14,29,23], [13,12,10,16], [20,17,26,28], [15,21,26,21]] CAS> tree := mstTree(pts, []) [[6,1],[3,6],[2,3],[5,2],[4,1]] CAS> norm2(x) := sqrt(dot(x,x)) CAS> map(tree, x -> norm2(pts[x[1]] - pts[x[2]])) → [√69,√62,√23,√53,√229] CAS> sum(float(Ans)) → 43.3893190999 What if points #2, #3 line segment not allowed ? CAS> tree := mstTree(pts, [[2,3],[3,2]]) [[6,1],[3,6],[5,3],[2,5],[4,1]] CAS> map(tree, x -> norm2(pts[x[1]] - pts[x[2]])) → [√69,√62,2*√17,√53,√229] CAS> sum(float(Ans)) → 46.8396988279 (*) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)