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

Uranus3

by Chou Nay

Status: Passed
Results: 1235 (cyc: 7, node: 940)
CPU Time: 36.694
Score: 1271.26
Submitted at: 2012-11-07 07:15:59 UTC
Scored at: 2012-11-07 07:23:17 UTC

Current Rank: 83rd (Highest: 1st )
Based on: Uranus1 (diff)
Basis for: arguru (diff)

Comments
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)
diag(sum(a));
[V,~]=eig(ans-a,ans);
N = length(a);
[p1i,p2i] = find( triu(a,1));
[pickr,pickc] = find(tril(true(length(p1i)),-1));

for ss=1:3
    [xy{ss} xy{ss+3}] = solver_alfonsoz (a, ss+1, N, V+rand(size(V))/25);
end
xy{7} = solver_hannes(xyIn, N, V(:,2:3),0);

parfor ss=1:7
 NN(ss)=gradeIt(p1i,p2i,pickr,pickc,xy{ss})
end

[ZBest,best] = min(NN);
xyOut = xy{best};

xyOut = bsxfun(@minus,xyOut,round(wts*(xyOut-xyIn)./sum(wts)));

sprev = rng(0,'twister');

for ii=1:2
for jiggle=1:15
 xyOutZ=xyOut+randi([-ii ii],N,2);
 gradeIt(p1i,p2i,pickr,pickc,xyOutZ);
 if ans<ZBest && size(unique(xyOutZ,'rows'),1)==N
  xyOut=xyOutZ;
  ZBest=ans;
 end
end
end

rng(sprev);
end

function [xyOut xyOut1] = solver_alfonsoz(a, ss, N, V)
randn('seed',ss);
xyOut=V(:,2:3);
sN=sqrt(N);
for ncut=1:2
    Mbeta=((1-ss/15)*eye(N)+(ss/15)*bsxfun(@rdivide,a+eye(N),sum(a,2)+1))^10;
    for n1=1:117
        xyOut=Mbeta*xyOut;
        bsxfun(@minus,xyOut,sum(xyOut)/N);
        [c1,D]=svd(ans');
        xyOut=ans*c1*diag(sN./(.1+D([1 4])))*c1';
    end
    [i,j]=find(a>0.002+ss*5.1e-4);
    sum((xyOut(i,:)-xyOut(j,:)).^2,2);
    k=find(ans>(3.15 + ss*0.102)*mean(ans));
    if isempty(k), break; end
    a(i(k)+N*(j(k)-1))=0.002+ss*5.1e-4;
end

xyOutH=xyOut;
single_idx = find(sum(a)==1);
[singles_link, ~] = find(a(:,single_idx)==1);
xyOut(single_idx,:)=xyOut(singles_link,:);

for zsingle=1:2  
    xyOut0=sqrt(N)*detrend(xyOut,'constant')*diag(1./std(xyOut,1,1));
    k=5;
    [sxyOut0,idxequal]=sortrows(round(15*xyOut0));
    idxequal=idxequal(all(~diff(sxyOut0,1,1),2));
    xyOut=round(xyOut0);
    while size(unique(xyOut,'rows'),1)~=N
        k=k*(1.0+ss*0.055);
        xyOut=xyOut0*k;
        xyOut(idxequal,:)=(xyOut0(idxequal,:)+randn(numel(idxequal),2)/(9+ss))*k;
        xyOut=round(xyOut);
    end
    if zsingle==1
        xyOut1=xyOut;
        xyOut=xyOutH;
    end
end 
end

function xyOut = solver_hannes(xyIn, N, V,xyOut)
mult    = norm(max(xyIn)-min(xyIn))/norm(max(V)-min(V));
while size(unique(xyOut,'rows'),1)<N
    xyOut       = round(V*mult);
    [~,i]       = unique(xyOut,'rows');
    m           = setdiff(1:N,i);
    xyOut(m,:)  = xyOut(m,:) + randi([-1 1],length(m),2);
    mult        = mult*1.5;
end
end

function ans = gradeIt(p1i,p2i,pickr,pickc,XYnew)
  X = [XYnew(p1i,:) XYnew(p2i,:)];
  xa = X(pickr,:);
  xb = X(pickc,:);
  A13 = xa(:,1) - xa(:,3);
  A24 = xa(:,2) - xa(:,4);
  B13 = xb(:,1) - xb(:,3);
  B24 = xb(:,2) - xb(:,4);
  A = xb(:,1).*xb(:,4) - xb(:,2).*xb(:,3);
  B = xa(:,1).*xa(:,4) - xa(:,2).*xa(:,3);
  AA = (xa(:,1).*B24 - xa(:,2).*B13 + A) ...
     .*(xa(:,3).*B24 - xa(:,4).*B13 + A);
  BB = (xb(:,1).*A24 - xb(:,2).*A13 + B) ...
     .*(xb(:,3).*A24 - xb(:,4).*A13 + B);
 
  sum(abs(A13) .* AA <=0  & ...
            abs(A24) .* AA <=0  & ...
            abs(B13) .* BB <=0  & ...
            abs(B24) .* BB <=0 ...
         );
end