Winner Paulo Uribe (turbf1)

2002-05-23 00:00:00 UTC

# freemove

by freemove

Status: Failed
Results: []

Based on: freemov (diff)
Basis for: freemov1 (diff)

freemove
23 May 2002
freemove
Code
```function fx = solver(d,bx)
if ~any(d(:)>0), fx = repmat(bx([1 3]),size(d,1),1); return; end
m = size(d,1); [p,id] = sort(-sum(d)); p(id)=1:m; d = d(id,id);
r1 = (bx(2)-bx(1)); r2 = (bx(4)-bx(3));
xc = (bx(2)+bx(1))/2+i*(bx(4)+bx(3))/2;
[I,J,v] = find(triu(d)>0); td = d((J-1)*m+I); % required distances.
x = repmat(xc,m,1)+0.1*(rand(m,1)-0.5); x(1:2) = bx(1:2)+i*bx(3:4);
for k = 3:min(40,m) % find good position for each point.
in = (I<=k)&(J<=k);
[bestd,x(1:k)]=freemov(x(1:k),k,I(in),J(in),td(in),100,bx);
end
if m > 40, [bestd,x]=freemov(x,k,I,J,td,100,bx); end
fx = [real(x(p)) imag(x(p))];

function [fd,fc] = freemov(c,m,I,J,td,iter,bx,flag)
fc = c; fd = sum(abs(abs(c(I)-c(J))-td));
for k = 0:iter
r = 0.5*dt.*dc./adc; qc = sparse([I J],1,[-r r],m,1);
while e > 1e-2
c = oc + e*qc;
x = real(c); x(x<bx(1))=bx(1); x(x>bx(2))=bx(2);
y = imag(c); y(y<bx(3))=bx(3); y(y>bx(4))=bx(4);
c = x+i*y;
dd = sum(abs(abs(c(I)-c(J))-td));
if dd < fd, fd = dd; fc = c; break; end
e = e/2;
end
if e < 1e-2, break; end
end
```