function y = custimp(x1,x2)
%CUSTIMP Customized implication function for CUSTTIP.FIS.
%   OUT = CUSTIMP(IN1,IN2) calculates the implication output.
%   The implication operator must be able to support either one
%   or two inputs, such that CUSTIMP(X1,X2) == CUSTIMP([X1 X2]).

% Copyright 1994 - 2018 The MathWorks, Inc.

% Lukasiewicz t-norm: T(a,b) = max(0, a+b-1)

if nargin == 1
    minVal = zeros(1,size(x1,2),'like',x1);
    y = ones(1,size(x1,2),'like',x1);
    
    for i = 1:size(x1,1)
        y = max(minVal,sum([y;x1(i,:)])-1);
    end
else
    minVal = zeros(1,size(x1,2),'like',x1);
    y = zeros(size(x1),'like',x1);
    
    for i = 1:size(x1,1)
        y(i,:) = max(minVal,sum([x1(i,:);x2(i,:)])-1);
    end    
end
end