-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathINetwork.m
158 lines (138 loc) · 3.92 KB
/
INetwork.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
%% Virtual Network
% Define resource information in a network.
classdef (Abstract) INetwork < BaseCopyable & HeteroObject
properties
Identifier uint64;
graph DirectedGraph; % <DirectedGraph> topology information
Links = table; % <table> information of links
Nodes = table; % <table> information of nodes
options Dictionary;
end
%%%
% |Nodes|: the fields in node table include _Name_, _Location_.
%
% |Edges|: the fields in the edge table include _EndNodes_, _Weight_, _Capacity_,
% _Index_, _Load_, _Price_.
properties (Dependent)
Optimizer;
NumberNodes; % Number of nodes in the network
NumberLinks; % Number of edges in the network
end
properties (Access = protected)
op;
end
methods (Abstract)
op = getOptimizer(this, options);
end
methods
%
% netdata: <struct>
function this = INetwork(netdata)
if nargin == 0 % default constructor
return;
end
if nargin >= 1
this.graph = DirectedGraph(netdata);
end
if isfield(netdata, 'Identifier')
this.Identifier = netdata.Identifier;
end
this.options = Dictionary();
end
function delete(this)
if ~isempty(this.graph) && isvalid(this.graph)
delete(this.graph);
end
end
end
methods (Access = protected)
function newobj = copyElement(this)
% Make a shallow copy of all properties
if this.isShallowCopyable
newobj = copyElement@BaseCopyable(this);
else
newobj = this;
end
% Deep Copy
% [graph]
if newobj.graph == this.graph
newobj.graph = this.graph.copy();
end
end
end
%% Property Get Methods
methods
function n = get.NumberNodes(this)
n = height(this.Nodes);% n = this.graph.NumberNodes;
end
function m = get.NumberLinks(this)
m = height(this.Links); % m = this.graph.NumberEdges;
end
function op = get.Optimizer(this)
op = this.op;
end
end
%% Public Methods
methods
function value = readNode(this, name, node_id)
value = this.Nodes{node_id, {name}};
end
function value = readLink(this, name, link_id)
value = this.Links{link_id, {name}};
end
end
methods
%% Resource Utilization
% Calculate the average and overall resource utilization ratio.
% Also, calculate the resource utilization of links and nodes separately.
%
% NOTE: Exclude the resource with no capacity.
%
% Subclasses might override this method to provide different measure of
% resource utilization.
function [theta, t_link, t_node] = utilizationRatio(this)
[cap,load] = this.readCapacityLoad();
capacities = [cap.node; cap.link];
loads = [load.node; load.link];
idx = capacities>eps;
if isempty(idx)
error('error:[%s] this network has no capacity.', calledby);
end
theta.Mean = mean(loads(idx)./capacities(idx));
theta.Overall = sum(loads)/sum(capacities);
if nargout >= 2
eidx = cap.link>eps;
if isempty(eidx)
error('error: no link capacity.');
end
t_link.Mean = mean(load.link(eidx)./cap.link(eidx));
t_link.Overall = sum(load.link(eidx))/sum(cap.link(eidx));
end
if nargout >= 3
nidx = cap.node>eps;
if isempty(nidx)
t_link = struct([]);
warning('no node capacity.');
end
t_node.Mean = mean(load.node(nidx)./cap.node(nidx));
t_node.Overall = sum(load.node(nidx))/sum(cap.node(nidx));
end
end
end
methods (Abstract,Access = protected)
% Get the link and node's capacity and load.
[cap, load] = readCapacityLoad(this);
end
end
%% Properties
% * *graph*: Normally, the network slice will not run shrtest path algorithm, so the
% absolute value of the adjacent matrix of graph does not matter. On the other hand,
% the link and node capacity of the slice is also not determined until the substrate
% network allocate the resource to the slice.
% * *Links* : fields include _PhysicalLink_, _Price_, _Load_.
% * *Nodes* : fields include _PhysicalNode_, _Price_, _Load_.
%
% * *NumberNodes* |get|
%
% * *NumberLinks* |get|
%