Winner Paulo Uribe (turbf1)

Finish 2002-05-23 00:00:00 UTC

freemov4

by freemov4

Status: Passed
Results: Average strain = 2087.702
CPU Time: 92.352
Score: 7914.56
Submitted at: 2002-05-23 16:18:16 UTC
Scored at: 2002-05-24 14:32:24 UTC

Current Rank: 587th

Comments
freemov4
23 May 2002
I will not be surprised if this wins. :)
Please login or create a profile.
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);
step = ceil(m/10);
for k = 3:step: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
[bestd,x]=freemov(x,m,I,J,td,100,bx);
fx = [real(x(p)) imag(x(p))];

function [fd,fc] = freemov(c,m,I,J,td,iter,bx)
fc = c; fd = sum(abs(abs(c(I)-c(J))-td)); 
for k = 0:iter
  e=0.8;oc=c;dc=c(I)-c(J);adc=abs(dc);dt=adc-td;adc=adc+(~adc);
  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