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

Joe - run2

by Joe Wood

Status: Passed
Results: 364025 (cyc: 8, node: 144)
CPU Time: 0.118
Score: 364026.0
Submitted at: 2012-11-02 14:34:40 UTC
Scored at: 2012-11-02 14:36:46 UTC

Current Rank: 1765th (Highest: 141st )

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

%The goal is this routine is to find lines with only 1 connecting node, and
%then move them closer to their connector, then make sure that reduces the
%score

xyOut = xyIn;

move_table = [1,1;1,0;1,-1;0,-1;-1,-1;-1,0;-1,1;0,1];


for i = 1:length(a)
    
    connect_index = find(a(i,:));
    if(length(connect_index) == 1)
        
        %identify nodes in question
        open_node = xyOut(i,:);
        connector = xyOut(connect_index,:);
        
        %simulate move of open node.  attempt to move open node into open
        %spot around connector
        for k = 1:8
            new_open_node = connector + move_table(k,:);
            match = 0;
            for j = 1:length(a)
                if(xyOut(j,:) == new_open_node)
                    match = 1;
                    break
                end
            end
            if(~match)
                break
            end
        end
        
        if(~match)
        
%             %calculate weight penalty
%             new_distance = sqrt(((open_node(1,1)-new_open_node(1,1))^2) + ((open_node(1,2)-new_open_node(1,2))^2));
%             weight_penalty = new_distance * wts(i);
%             
%             %calculate knots
%             tempxyIn = xyOut;
%             tempxyIn(i,:) = new_open_node;
%             initial_num_knots = count_knots(xyOut,a);
%             new_num_knots = count_knots(tempxyIn,a);
% 
%             fudge = 0.5;
%             %if score is better, keep move.  if not, put it back and move on
%             if((initial_num_knots - new_num_knots) > (weight_penalty * fudge))
                
                xyOut(i,:) = new_open_node;
%             end
        end
    end
end