function [] = LocalSearch(Prob, N, prescription, SaveType)

%
% Make the Dir. for images
%
if ~isdir('../images/LocalSearch')
   !mkdir ../images/LocalSearch
end

%
% Cycle through the different angle numbers
%
for n = 1:length(N)

%
% SearchType 1 - Ehgot and Johnson with ties broken by least index
% SearchType 2 - Das, Cullip, Tracton, Chang, Marks, Anscher, Rosenman
%

for SearchType = 1:2

if SearchType == 1

%Grap System Clock
t0 = clock;

%Initiate the starting angles as evenly spaced, rooted at 0
Angles = round(1:Prob.NumAngles/N(n):Prob.NumAngles)

% Get an initial evaluation of the judgment function
TmpProb = RestrictedSolver(Prob, prescription, Angles);
LowestCurrentValue = TmpProb.fval;

% Enter loop that updates angles
Improved = 1;
while Improved
   % Assume no improvement will be made
   Improved = 0;

   % Embed the angles
   Shift = (Prob.NumAngles - Angles(length(Angles))) + (Angles(1) - 1);
   EmAngles = [Angles(1) - Shift, Angles, Angles(length(Angles)) + Shift];
   for a = 2:(length(EmAngles) - 1)
      % Find the angles for replacement
      ReplacementAngles = ...
         (EmAngles(a) + 1) : (EmAngles(a+1) - 1);

      % Make sure the angles are in range
      ReplacementAngles = mod(ReplacementAngles, Prob.NumAngles);
      ReplacementAngles(find(ReplacementAngles == 0)) = Prob.NumAngles;

      %Check which neighbors are better angles
      BestSoln = zeros(length(ReplacementAngles), 2);
      for i = 1:length(ReplacementAngles)
         TmpAngles = Angles;
         TmpAngles(a-1) = ReplacementAngles(i);
         CandidateProb = RestrictedSolver(Prob, prescription, TmpAngles);
         BestSoln(i, :) = [CandidateProb.fval , ReplacementAngles(i)];
      end
      
      % Grab the Best Angles to reassing a better score.
      BestValue = min(BestSoln(:,1));
      if BestValue < LowestCurrentValue
         BestIndex = find(BestSoln(:,1) == BestValue );
         Angles(a-1) = BestSoln(BestIndex(1),2);
         LowestCurrentValue = BestValue;
         Improved = 1;
      end
   end

   % Update the Problem statement
   TmpProb = RestrictedSolver(Prob, prescription, Angles);

end

% Make some figures
Figure(TmpProb, prescription, sprintf('LocalSearch1_NumBeams%d', N(n)),'LocalSearch', ...
       SaveType)

% Write to the table
LaTex('AddRow', 'Scoring (Local Search 1)', 'N/A', Angles, etime(clock, t0)/60 )

elseif SearchType == 2

%Grab System Clock
t0 = clock;

%Initiate the starting angles as evenly spaced, rooted at 0
Angles = round(1:Prob.NumAngles/N(n):Prob.NumAngles)

% Get an initial evaluation of the judgment function
TmpProb = RestrictedSolver(Prob, prescription, Angles);
LowestCurrentValue = TmpProb.fval;

% Enter loop that updates angles
Improved = 1;
while Improved
   % Assume no improvement will be made
   Improved = 0;

   for a = 1:length(Angles)
      % Find the angles for replacement
      ReplacementAngles = ...
         ceil(Angles(a) - (Prob.NumAngles / (2*N(n)) )) : ...
              floor(Angles(a) + (Prob.NumAngles / (2*N(n)) ));

      % Remove angle Angles(a)
      ReplacementAngles = setdiff(ReplacementAngles, ...
                                     Angles(a)-2:Angles(a)+2);

      % Make sure the angles are in range
      ReplacementAngles = mod(ReplacementAngles, Prob.NumAngles);
      ReplacementAngles(find(ReplacementAngles == 0)) = Prob.NumAngles;

      %Check which neighbors are better angles
      BestSoln = zeros(length(ReplacementAngles), 2);
      for i = 1:length(ReplacementAngles)
         TmpAngles = Angles;
         TmpAngles(a) = ReplacementAngles(i);
         CandidateProb = RestrictedSolver(Prob, prescription, TmpAngles);
         BestSoln(i, :) = [CandidateProb.fval , ReplacementAngles(i)];
      end
      
      % Grab the Best Angles to reassing a better score.
      BestValue = min(BestSoln(:,1));
      if BestValue < LowestCurrentValue
         BestIndex = find(BestSoln(:,1) == BestValue );
         Angles(a) = BestSoln(BestIndex(1),2);
         LowestCurrentValue = BestValue;
         Improved = 1;
      end
   end

   % Update the Problem statement
   TmpProb = RestrictedSolver(Prob, prescription, Angles);

end

% Make some figures
Figure(TmpProb, prescription, sprintf('LocalSearch2_NumBeams%d', N(n)),'LocalSearch', ...
       SaveType)

% Write to the table
LaTex('AddRow', 'Scoring (Local Search 2)', 'N/A', Angles, etime(clock, t0)/60 )

else
   fprintf('RAD -> Confused SearchType \n')
end

% End Search Type loop
end 

% End N(n) loop
end
