%
%  This generates N-beam treatments with a simple scoring technique
%

%
% Prob --------- Origninal Problem Statement
% N ------------ vector of angles to generate planes for -i.e. N = [10, 5]
%                means find a 10 and 5 beam treatment
% ScoreType ---- List of different scores (pdf's) that are used.
% prescription - Original problem prescription.
%

function Scoring(Prob, N, ScoreType, prescription, SaveType)

NumScores = length(fieldnames(ScoreType));

for t = 1:NumScores
   % Grab the scores
   Scores = eval(['Prob.', eval(sprintf('ScoreType.t%d',t)) ] );
   % Make sure Scores are meaningful
   if max(Scores) > .01
      for n = 1:length(N)
         % Grab the system clock
         t0 = clock;
         % Make sure NOT to count zero scores
         NumPracticalScores = min([length(find(Scores >= 0.01)), N(n)]);
         % Find where the Highscores are
         [HighScores, ScoreIndex] = sort(-Scores);
         % Grab the best angles
         Angles = ScoreIndex(1:NumPracticalScores);
         % Solve with Resticted Angles
         TmpProb = RestrictedSolver(Prob, prescription, Angles);
         % Try to make a pic or two
         Figure(TmpProb, prescription, sprintf('%s_NumBeams%d', ...
            eval(sprintf('ScoreType.t%d',t)), N(n)),'Scoring', SaveType)
         % Write to the LaTex File
         LaTex('AddRow', 'Scoring', eval(sprintf('ScoreType.t%d',t)), ...
            Angles, etime(clock, t0)/60);
      end
   else
      fprintf('    -> PDF is zero, skipping Scoring \n')
   end
end
