LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
linkAndLog.m
1% this macro will need refactoring to decouple the observation from the Model class
2function [loggerBefore,loggerAfter] = linkAndLog(self, P, isNodeLogged, logPath)
3% [LOGGERBEFORE,LOGGERAFTER] = LINKANDLOG(P, ISNODELOGGED, LOGPATH)
4
5% Copyright (c) 2012-2026, Imperial College London
6% All rights reserved.
7
8self.resetStruct; % important to regenerate the sn with the loggers
9
10if self.hasState
11 line_warning(mfilename,'The network state cannot be initialized, or must be reset, before calling linkAndLog.');
12end
13
14if ~isempty(self.connections)
15 line_warning(mfilename,'Network topology already instantiated. Calling resetNetwork automatically before adding loggers.\n');
16 self.resetNetwork;
17end
18R = self.getNumberOfClasses;
19Mnodes = self.getNumberOfNodes;
20
21if Mnodes ~= numel(isNodeLogged)
22 line_error(mfilename,'The size of the isNodeLogged vector does not match the number of nodes.');
23end
24
25isNodeLogged = [isNodeLogged(:)'];
26if ~isempty(self.getSource)
27 sinkIndex = self.getIndexSinkNode;
28 if isNodeLogged(sinkIndex)
29 line_warning(mfilename,'Sink station cannot be logged, ignoring.\n');
30 isNodeLogged(sinkIndex) = false;
31 end
32end
33if ~isempty(self.getSource)
34 sourceIndex = self.getIndexSourceNode;
35 if isNodeLogged(sourceIndex)
36 line_warning(mfilename,'Source station cannot be logged, ignoring.\n');
37 isNodeLogged(sourceIndex) = false;
38 end
39end
40
41if nargin>=4 %exist('logPath','var')
42 self.setLogPath(logPath);
43else
44 logPath = getLogPath(self);
45end
46
47loggerBefore = cell(1,0);
48loggerAfter = cell(1,0);
49for ind=1:Mnodes
50 if isNodeLogged(ind)
51 if ispc
52 loggerBefore{end+1} = Logger(self,sprintf('Arv_%s',self.getNodeNames{ind}),[logPath,filesep,sprintf('%s-Arv.csv',self.getNodeNames{ind})]);
53 for r=1:R
54 loggerBefore{end}.setRouting(self.classes{r}, RoutingStrategy.RAND);
55 end
56 elseif isunix
57 loggerBefore{end+1} = Logger(self,sprintf('Arv_%s',self.getNodeNames{ind}),[logPath,filesep,sprintf('%s-Arv.csv',self.getNodeNames{ind})]);
58 for r=1:R
59 loggerBefore{end}.setRouting(self.classes{r}, RoutingStrategy.RAND);
60 end
61 end
62 end
63end
64for ind=1:Mnodes
65 if isNodeLogged(ind)
66 if ispc
67 loggerAfter{end+1} = Logger(self,sprintf('Dep_%s',self.getNodeNames{ind}),[logPath,filesep,sprintf('%s-Dep.csv',self.getNodeNames{ind})]);
68 for r=1:R
69 loggerAfter{end}.setRouting(self.classes{r}, RoutingStrategy.RAND);
70 end
71 elseif isunix
72 loggerAfter{end+1} = Logger(self,sprintf('Dep_%s',self.getNodeNames{ind}),[logPath,filesep,sprintf('%s-Dep.csv',self.getNodeNames{ind})]);
73 for r=1:R
74 loggerAfter{end}.setRouting(self.classes{r}, RoutingStrategy.RAND);
75 end
76 end
77 end
78end
79
80Mnodesnew = 3*Mnodes;
81newP = cellzeros(R,R,Mnodesnew,Mnodesnew);
82for r=1:R
83 for s=1:R
84 for ind=1:Mnodes
85 for jnd=1:Mnodes
86 if P{r,s}(ind,jnd)>0
87 if isNodeLogged(ind) && isNodeLogged(jnd)
88 % link loggerArvi to loggerDepj
89 newP{r,s}(2*Mnodes+ind,Mnodes+jnd) = P{r,s}(ind,jnd);
90 elseif isNodeLogged(ind) && ~isNodeLogged(jnd)
91 % link logAi to j
92 newP{r,s}(2*Mnodes+ind,jnd) = P{r,s}(ind,jnd);
93 elseif ~isNodeLogged(ind) && isNodeLogged(jnd)
94 % link i to logBj
95 newP{r,s}(ind,Mnodes+jnd) = P{r,s}(ind,jnd);
96 else
97 % link i to j
98 newP{r,s}(ind,jnd) = P{r,s}(ind,jnd);
99 end
100 end
101 end
102 end
103 for ind=1:Mnodes
104 if isNodeLogged(ind)
105 newP{r,r}(Mnodes+ind,ind) = 1.0; % logBi -> i
106 newP{r,r}(ind,2*Mnodes+ind) = 1.0; % i -> logAi
107 end
108 end
109 end
110end
111for r=1:R
112 for s=1:R
113 idx = find(isNodeLogged);
114 newP{r,s} = newP{r,s}([1:Mnodes,Mnodes+idx,2*Mnodes+idx],[1:Mnodes,Mnodes+idx,2*Mnodes+idx]);
115 end
116end
117self.link(newP);
118end
Definition mmt.m:92