from
MATLAB Contest - blackbox
by The MATLAB Contest Team
All the files needed to develop and score an entry for this MATLABĀ® Programming Contest.
|
| runcontest(drawboard,solver_h)
|
function [message,results,timeElapsed] = runcontest(drawboard,solver_h)
% RUNCONTEST Test a Black Box contest entry.
%
% [MESSAGE,RESULTS,TIME] = RUNCONTEST runs the M-file solver.m against all
% the problems defined in testsuite_sample.mat. MESSAGE returns a summary
% of the testing. RESULTS measures how well the entry solved the problem
% and TIME measures the time the entry took to compute its answer.
%
% ... = RUNCONTEST(TRUE) shows each of the solutions in a figure window.
%
% ... = RUNCONTEST(T/F,FNC_HANDLE) uses the solver specified by
% FNC_HANDLE instead of the default solver (@solver).
% Copyright 2006 The MathWorks, Inc.
if (nargin<2)
% set default solver
solver_h = @solver;
end
% Set run mode.
if (nargin<1)
% by default do not draw the board
drawboard = 0;
end
% Load the testsuite
load testsuite_sample testsuite
% Run the submission for each problem in the suite.
n = numel(testsuite);
responses = cell(n,1);
numBeams = zeros(n,1);
score = zeros(n,1);
if ~drawboard
time0 = cputime;
for k = 1:n
% Clear the function and persistent variables.
clear beam
% Setup the persistent variables with the next puzzle.
beam(testsuite{k});
% Solve the puzzle.
responses{k} = solver_h(size(testsuite{k},1));
% Recover the number of used beams.
numBeams(k) = beam([]);
clear global
end
timeElapsed = cputime-time0;
else
for k = 1:n
% Call the seesolver function
responses{k} = seesolver(solver_h,testsuite{k},sprintf('Problem %d',k));
% Recover the number of used beams.
numBeams(k) = beam([]);
clear global
disp('Press any key for next puzzle...')
%pause
end
timeElapsed = NaN;
end
% Grade all answers.
for k = 1:n
score(k) = grade(responses{k}, testsuite{k}, numBeams(k));
end
% Report results.
results = sum(score);
message = sprintf('results: %.0f\ntime: %.4f',results,timeElapsed);
%======================================================================
function score = grade(solution, test, numBeams)
%GRADE Make sure the answer is valid and compute its score.
score = sum(sum(abs(test-solution))) + .1*numBeams;
|
|
Contact us at files@mathworks.com