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

Test entry

by Victoria

Status: Passed
Results: 371212 (cyc: 9, node: 217)
CPU Time: 0.149
Score: 371217.0
Submitted at: 2012-11-01 13:11:25 UTC
Scored at: 2012-11-01 18:58:32 UTC

Current Rank: 1766th (Highest: 47th )

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

% Solver by Victoria

% Copyright 2012 The MathWorks, Inc.

xyOut = xyIn;
xyPrevious = xyIn;
xyNext = xyIn;

NodesNum = length(wts);

if NodesNum <= 100
%     scorePrevious = scoreSolution(xyOut, a, xyIn, wts);
    for I = 1:7
        Node = floor(rand*NodesNum) + 1;
        DRand = floor(rand*4) + 1;
        if (DRand == 1)
            Direction = [1 0];
        end
        if (DRand == 2)
            Direction = [0 1];
        end
        if (DRand == 3)
            Direction = [-1 0];
        end
        if (DRand == 4)
            Direction = [0 -1];
        end
        xyNext(Node,:) = xyPrevious(Node,:) + Direction;
        if validateSolution(xyIn,xyNext)
%             scoreNext = scoreSolution(xyNext, a, xyIn, wts);
            if true %scoreNext < scorePrevious
                xyPrevious = xyNext;
            end
        end
    end
end

xyOut = xyPrevious;


    function pass = validateSolution(XYold,XYnew)
        pass = true;
        
        % Check that points are integers
        if ~isequal(XYnew,round(XYnew))
            %             error('XY coordinates must be at integer locations')
            pass = false;
        end
        
        % Check that number of points is correct
        nPoints = size(XYold,1);
        nNewPoints = size(XYnew,1);
        if ~isequal(nPoints,nNewPoints)
            %     error('Number of points is not the same as original number of points')
            pass = false;
        end
        
        % Check that point coordinates are unique
        nUniquePoints = size(unique(XYnew,'rows'),1);
        if ~isequal(nPoints,nUniquePoints)
            %     error('Each point must have a unique location')
            pass = false;
        end
    end

end