function robust_feas = rob_feas(varargin)
%ROB_FEAS find a feasible solution in probabilistic sense for robust problem
%
% robust_feas = rob_feas(hFunc, hGrad, x0)
% robust_feas = rob_feas(hFunc, hGrad, x0, param1, param2, ...)
% robust_feas = rob_feas(hFunc, hGrad, x0, options)
%
% find a vector solution x for common function in form
% f(x, Delta) <= 0 forall Delta \in Delta
% where Q0, Q1, ... are symmetric matrices or handles to
% user-defined functions with uncertain matrices
% $Id$
if nargin == 3 % (hFunc, hGrad, x0)
hFunc = varargin{1};
hGrad = varargin{2};
x0 = varargin{3};
options = [];
elseif nargin == 4 % (hFunc, hGrad, x0, options)
hFunc = varargin{1};
hGrad = varargin{2};
x0 = varargin{3};
options = varargin{4};
else
error(['RACT:rob_feas:InputSize', ['Incorrect number of arguments: ' num2str(nargin)]]);
end
% validate options
options = valfeasopt(options);
if ~isa(hFunc, 'function_handle')
error(['RACT:rob_feas:InputType', 'First parameter hFunc should be function handle!']);
end
if ~isa(hGrad, 'function_handle')
error(['RACT:rob_feas:InputType', 'Second parameter hGrad should be function handle!']);
end
% initial point
x = x0;
Nin = ceil(log(1/options.delta)/log(1/(1 - options.eps)));
FEAS = 0; % constant for feasibility
for k=1:options.Nout
% cast probabilistic oracle
if ~(k==1)
[feasible, Ninter, Delta_viol] = poracle(hFunc, x, Nin, 'cont');
else
[feasible, Ninter, Delta_viol] = poracle(hFunc, x, Nin, 'init');
end
disp([num2str(k), '-th oracle casted, interrupted on ' num2str(Ninter) ' iteration (max ', num2str(Nin),').']);
if feasible
% solution considered to be found with some epsilon and delta
robust_feas = x;
return;
else
% violation sample found
% TODO can be speeded up by prefetching type of algorithm
switch options.method
case 'grad'
x = updgrad(hFunc, hGrad, x, Delta_viol, options);
case 'ell'
x = updell(hFunc, hGrad, x, Delta_viol, options);
case 'cutplane'
x = updcp(hFunc, hGrad, x, Delta_viol, options);
end
% [x.', 0, feval(hFunc, 0, Delta_viol, x, 1)]
end
end
robust_feas = x;
%warning('RACT:rob_feas:NoSolution', 'No feasible solution found.');
warning('No feasible solution found.');