LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ImageFromMMAP.m
1% ImageFromMMAP(D, outFileName, prec)
2%
3% Depicts the given marked Markovian arrival process, and
4% either displays it or saves it to file.
5%
6% Parameters
7% ----------
8% D : list of matrices of shape(M,M), length(N)
9% The D0...DN matrices of the MMAP
10% outFileName : string, optional
11% If it is not provided, or equals to 'display', the
12% image is displayed on the screen, otherwise it is
13% written to the file. The file format is deduced
14% from the file name.
15% prec : double, optional
16% Transition rates less then prec are considered to
17% be zero and are left out from the image. The
18% default value is 1e-13.
19%
20% Notes
21% -----
22% The 'graphviz' software must be installed and available
23% in the path to use this feature.
24
25function ImageFromMMAP(D,outFileName,prec)
26
27 global BuToolsCheckInput;
28 if isempty(BuToolsCheckInput)
29 BuToolsCheckInput = true;
30 end
31
32 if BuToolsCheckInput && ~CheckMAPRepresentation(D)
33 error('ImageFromMMAP: Input isn''t a valid MMAP representation!');
34 end
35
36 if ~exist('prec','var')
37 prec = 1e-13;
38 end
39
40 if ~exist('outFileName','var') || strcmp(outFileName,'display')
41 outputFile = '.result.png';
42 displ = true;
43 else
44 outputFile = outFileName;
45 displ = false;
46 end
47
48 inputFile = '.temp.dot';
49
50 fid = fopen(inputFile,'w');
51 fprintf(fid, 'digraph G {\n');
52 fprintf(fid, '\trankdir=LR;\n');
53 fprintf(fid, '\tnode [shape=circle,width=0.3,height=0.3,label=""];\n');
54
55 N = size(D{1},1);
56
57 % transitions without arrivals
58 Dx=D{1};
59 for i=1:N
60 for j=1:N
61 if i~=j && abs(Dx(i,j))>prec
62 fprintf(fid, '\tn%d -> n%d [label="%g"];\n', i, j, Dx(i,j));
63 end
64 end
65 end
66
67 % transitions with arrivals
68 for k=2:length(D)
69 Dx=D{k};
70 for i=1:N
71 for j=1:N
72 if abs(Dx(i,j))>prec
73 if length(D)==2
74 fprintf(fid, '\tn%d -> n%d [style="dashed",label="%g"];\n', i, j, Dx(i,j));
75 else
76 fprintf(fid, '\tn%d -> n%d [style="solid",fontcolor="/dark28/%d",color="/dark28/%d",label="%g"];\n', i, j, min(k-1,8), min(k-1,8), Dx(i,j));
77 end
78 end
79 end
80 end
81 end
82 fprintf(fid,'}\n');
83 fclose(fid);
84
85 [~,~,ext] = fileparts(outputFile);
86 system(['dot -T', ext(2:end), ' ', inputFile, ' -o ', outputFile]);
87
88 delete (inputFile);
89
90 if displ
91 RGB = imread(outputFile);
92 figure('toolbar','none','units','pixel','position',[0,0,size(RGB,2)+100,size(RGB,1)+100]);
93 image(RGB);
94 axis image;
95 delete(outputFile);
96 end
97end
98