function [Prob] = Solver(Prob, Solver);

%
% Grab some sizes.
%

[tr,tc] = size(Prob.TumorDoseMatrix);
[gr,gc] = size(Prob.CriticalDoseMatrix);
[rr,rc] = size(Prob.RegularDoseMatrix);

%
% Build the data for the solver
%

if Prob.AnalysisType == 1

  U  = sparse([ Prob.TumorDoseMatrix,    zeros(tr, 1), zeros(tr, 1), zeros(tr, 1);
               -Prob.TumorDoseMatrix,     -ones(tr,1), zeros(tr, 1), zeros(tr, 1);
                Prob.CriticalDoseMatrix, zeros(gr, 1),  -ones(gr,1), zeros(gr, 1);
                Prob.RegularDoseMatrix,  zeros(rr, 1), zeros(rr, 1), -ones(rr,1)]);
  u  = sparse([Prob.TUB; -Prob.TLB; Prob.CUB; Prob.RUB]);
  lb = sparse([zeros(tc, 1); 0; -min(Prob.CUB); 0]);
  ub = sparse([inf * ones(tc, 1); min(Prob.TLB); inf; inf]);
  c  = sparse([zeros(tc,1); Prob.omega; 1; 1]);

else

 disp('RAD -> ERROR in Solver: Analysis Type is Not Selected')
 return

end

%
% Grab the the clock
%

StartTime = clock;

%
% Off to the Solver
%
% SolverTypes
%    0 - barrier
%    1 - primal simplex
%    2 - dual simplex
%
if strcmp(Solver, 'cplex')
   if Prob.SolverType == 0
      Soln = CplexLink(c, U, u, [], [], lb, ub, [], 'barrier');
   elseif Prob.SolverType == 1
      Soln = CplexLink(c, U, u, [], [], lb, ub, [], 'psimplex');
   elseif Prob.SolverType == 2
      Soln = CplexLink(c, U, u, [], [], lb, ub, [], 'dsimplex');
   else
      fprintf('\n\n RAD -> WARNING in Solver: Unknown SolverType \n\n');
   end
   Prob.x = Soln.variables;
   Prob.fval = Soln.objective;
else
   fprintf('\n\n RAD -> WARNING in Solver: Unknown Solver \n\n');
end

%
% Calculuate the time required by the solver.
%

TotalTime = etime(clock,StartTime);

%
% Partition the solution into the different types of
% decision variables.
%

if Prob.AnalysisType == 1

  Prob.alpha = Prob.x(tc+1);
  Prob.beta  = Prob.x(tc+2);
  Prob.gamma = Prob.x(tc+3);
  Prob.x     = Prob.x(1:tc);

else

  fprintf('RAD -> WARNING: Unknown Analysis Type, only absolute is allowed \n')

end

%
% Embedd the smaller plan, x, into a larger one and
% calculate the radiation levels over the image.
%

  [NumARows,NumACols] = size(Prob.DoseMatrix);
  Prob.ThePlan = zeros(NumACols,1);
  Prob.ThePlan(Prob.TumorColIndex) = Prob.x;
  Prob.RadLevel = Prob.DoseMatrix*Prob.ThePlan;

