Finish 2012-11-07 16:00:00 UTC

422b4b45c7108725779f700b10661e422383b8b8

by William Wu

Status: Passed
Results: 3588 (cyc: 4, node: 387)
CPU Time: 53.17
Score: 3628.14
Submitted at: 2012-11-02 15:59:17 UTC
Scored at: 2012-11-02 16:08:00 UTC

Current Rank: 1533rd (Highest: 17th )

Comments
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)

% Comment: Ken is my hero.

p = (xyIn(:,1)+1j*xyIn(:,2))'; 
[u,v]=find(triu(a,1)); 
pairs=[u v];
k1=0.1;	
k2_relax=100;	
iters_relax=300;

npoints=length(p);
allpairs=nchoosek(1:npoints,2);	
ix1=sub2ind([npoints npoints],allpairs(:,1),allpairs(:,2));
ix2=sub2ind([npoints npoints],allpairs(:,2),allpairs(:,1));
f2=zeros(npoints);

w0=max(xyIn(:,1))-min(xyIn(:,1));
h0=max(xyIn(:,2))-min(xyIn(:,2));

for i=1:iters_relax
	forces=k1*(p(pairs(:,1))-p(pairs(:,2)));
	f1=sparse([pairs(:,1);pairs(:,2)],[pairs(:,2);pairs(:,1)],[forces -forces]);
	v=p(allpairs(:,1))-p(allpairs(:,2)); 
	forces=v*k2_relax./abs(v);
	f2([ix1;ix2])=[-forces forces];	
	p=p+sum(f1)+sum(f2)+((rand(1,npoints)-1/2)+1j*(rand(1,npoints)-1/2))*(1-i/iters_relax);
end
xyReal = [real(p)' imag(p)'];

r = 1;
w1=max(xyReal(:,1))-min(xyReal(:,1));
h1=max(xyReal(:,2))-min(xyReal(:,2));
while 1
    xyOut(:,1) = round((r*w0/w1)*xyReal(:,1));
    xyOut(:,2) = round((r*h0/h1)*xyReal(:,2));
    if (npoints == length(unique(xyOut,'rows')))
        break
    end
    r=r+1;
end

end