function varargout = pwa_yalmip(varargin) %PWA_YALMIP Defines a piecewise function using data from MPT % %Only intended for internal use in YALMIP % % Three classes of PWA functions can be generated % % 1) Convexity aware epigraph version with a % convex domain and objective modelled as c'x 0)*ub + H.*(H<0)*lb+K; m2 = H.*(H>0)*lb + H.*(H<0)*ub+K; M = min([M M2],[],2); m = max([m m2],[],2); % Might be called with a convex function, % but wants the complete MILP description % Example : Someone tries to maximize value % function if length(d)~=length(costs) d = binvar(length(costs),1); F = (sum(d) == 1); end % t equals some of the costs F = F + ((m-max(M)).*(1-d) <= costs-t <= (M-min(m)).*(1-d)); for i = 1:length(pwa_struct{1}.Pn) [H,K] = double(pwa_struct{1}.Pn(i)); [M,m] = derivebounds(H*x - K); M2 = H.*(H>0)*ub + H.*(H<0)*lb-K; m2 = H.*(H>0)*lb + H.*(H<0)*ub-K; M = min([M M2],[],2); m = max([m m2],[],2); F = F + (H*x - K <= M*(1-d(i))); end otherwise varargout{1} = []; varargout{2} = struct('convexity','convex','monotonicity','none','definiteness','none','model','integer') varargout{3} = []; return end varargout{1} = F; varargout{2} = struct('convexity','none','monotonicity','none','definiteness','none','model','integer'); varargout{3} = x; otherwise error('PWA_YALMIP called with CHAR argument?'); end otherwise error('Strange type on first argument in SDPVAR/NORM'); end