function prob=estrel1(pv,p,K);
% This file estimates reliability of a system with purchase vector x
% using crude monte carlo method.
%
% Inputs: x - purchase vector
%         p - link reliabilities
%         K - samples used in estimation
% Output: prob - estimated reliability

N=size(pv,1); m=size(pv,2);
prob=zeros(N,1);
for i=1:N
    if feval('structure',pv(i,:)) == 0
        prob(i)=0;
    else
        pind=find(pv(i,:)); % find all links that are purchased
        np = size(pind,2); % number of links bought
        z=zeros(K,np);
        for j=1:K
            z(j,:)=p(pind);
        end
        y=(rand(K,np)<=z);
        y1=zeros(K,m);
        y1(:,pind)=y;
        phi=feval('structure',y1);
        prob(i)=mean(phi);
    end
end
