LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
map_isfeasible.m
1function ISFEAS=map_isfeasible(MAP, TOL)
2% ISFEAS=map_isfeasible(MAP) - Evaluate feasibility of a MAP process
3%
4% Input:
5% MAP: a MAP in the form of {D0,D1}
6%
7% Output:
8% ISFEAS: boolean 1=feasible, 0=infeasible. Numerical tolerance is based
9% on the standard toolbox value in map_feastol.m
10%
11% Examples:
12% - map_isfeasible({[0,0;0,0],[1,2;3,4]}) is an infeasible MAP
13%
14
15ISFEAS=0;
16if nargin==2
17 ISFEAS=map_checkfeasible(MAP,TOL);
18elseif nargin==1
19 TOLMAGNITUDE=15;
20 for k=TOLMAGNITUDE:-1:1
21 check=map_checkfeasible(MAP,10^-k);
22 if check
23 ISFEAS=k;
24 ISFEAS=ISFEAS>map_feastol;
25 return
26 end
27 end
28 if nargout>0
29 ISFEAS=0;
30 end
31end
32end
33
34function isfeas=map_checkfeasible(MAP,TOL)
35w=warning;
36warning off;
37n=length(MAP{1});
38D0=MAP{1};
39D1=MAP{2};
40if sum(isnan(D0(:)))>0
41 warning(w);
42 isfeas=0;
43 return
44end
45
46if any(isinf(D0), 'all') || any(isinf(D1), 'all') || any(isnan(D0), 'all') || any(isnan(D1), 'all')
47 isfeas=0;
48 return
49end
50if any(imag(D0)>10^-4, 'all') || any(imag(D1)>10^-4, 'all')
51 isfeas=0;
52 return
53end
54
55
56P=inv(-D0)*D1;
57Q=D0+D1;
58
59% set very small values to zero
60D0(find(abs(D0)<TOL))=0;
61D1(find(abs(D1)<TOL))=0;
62P(find(abs(P)<TOL))=0;
63Q(find(abs(Q)<TOL))=0;
64
65% assume initially the MAP is feasible
66isfeas=1;
67for i=1:n
68 for j=1:n
69 %% validate signs
70 if i~=j && D0(i,j)<0
71 isfeas=0;
72 end
73 if i==j && D0(i,j)>0
74 isfeas=0;
75 end
76 if D1(i,j)<0
77 isfeas=0;
78 end
79 if i~=j && Q(i,j)<0
80 isfeas=0;
81 end
82 if i==j && Q(i,j)>0
83 isfeas=0;
84 end
85 if P(i,j)<0
86 isfeas=0;
87 end
88 end
89 %% validate stochasticity
90 if abs(sum(P(i,:)))<1-n*TOL
91 isfeas=0;
92 end
93 if abs(sum(P(i,:)))>1+n*TOL
94 isfeas=0;
95 end
96 if abs(sum(Q(i,:)))<0-n*TOL
97 isfeas=0;
98 end
99 if abs(sum(Q(i,:)))>0+n*TOL
100 isfeas=0;
101 end
102end
103if isfeas==0
104 warning(w);
105 return;
106end
107%% validate irreducibility
108if n<map_largemap % compute eigenvalues only if the MAP is not too large
109 eigQ=eig(Q);
110 if length(find(eigQ>0-TOL))>1
111 isfeas=0;
112 end
113 eigP=eig(P);
114 if length(find(eigP>1-TOL))>1
115 isfeas=0;
116 end
117end
118end