-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSimpleDynamicSlice.m
166 lines (153 loc) · 5.75 KB
/
SimpleDynamicSlice.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
159
160
161
162
163
164
165
166
classdef SimpleDynamicSlice < DynamicSlice
%DynamicSlice Event-driven to dynamic configure slice.
% properties(Dependent)
% UnitReconfigureCost;
% end
%% Constructor
methods
function this = SimpleDynamicSlice(slice_data)
if nargin == 0
args = {};
else
args = {slice_data};
end
this@DynamicSlice(args{:});
end
end
%% Public Methods
methods
function op = getOptimizer(this, options)
if nargin == 1
this.op = SimpleDynamicSliceOptimizer(this);
else
this.op = SimpleDynamicSliceOptimizer(this, options);
end
op = this.op;
op.initializeState();
end
function finalize(this, prices)
finalize@DynamicSlice(this, prices);
end
%%%
% *Create new flows*
% Creating new flows in the slice could guarantee no extra node or link would be
% needed. If we enable new flows from new locations, we should create the flow
% in the network.
% function ft = createflow(this, slice)
% graph = slice.Topology;
% switch slice.options.FlowPattern
% case {FlowPattern.RandomSingleFlow, FlowPattern.RandomMultiFlow}
% ft = this.generateFlowTable(graph,
% case FlowPattern.RandomInterDataCenter
% case FlowPattern.RandomInterBaseStation
% case FlowPattern.RandomDataCenter2BaseStation
% otherwise
% error('error: cannot handle the flow pattern <%s>.', ...
% slice.options.FlowPattern.char);
% end
% end
%% Get link and node capacity
% <getLinkCapacity>
% <getNodeCapacity>
% Due to resource reservation or reconfiguration cost constraint, the link/node
% capcity might be larger than the demand.
function c = getLinkCapacity(this, isfinal)
if nargin == 1 || isfinal
c = this.Links.Capacity;
else
if this.op.invoke_method == 0
c = getLinkCapacity@SimpleSlice(this, isfinal);
else
c = this.op.temp_vars.c;
end
end
end
function c = getNodeCapacity(this, isfinal) % isfinal=true by default
if nargin == 1 || isfinal
c = this.ServiceNodes.Capacity;
else
if this.Optimizer.invoke_method == 0
c = getNodeCapacity@SimpleSlice(this, isfinal);
else
% since we do not reconfigure VNF capacity through fast slice reconfiguration,
% the sum of VNF capacity equals to the node capacity.
c = sum(reshape(this.op.temp_vars.v, ...
this.NumberServiceNodes,this.NumberVNFs),2);
end
end
end
%%%
% At present this method inherit the superclass. See also <Slice.checkFeasible>.
% function b = checkFeasible(this, vars, options)
% if nargin <= 1
% vars = [];
% else
% vars = vars(1:num_vars);
% end
% if nargin <= 2
% options = struct;
% end
% b = checkFeasible@Slice(this, vars, options);
% % if b
% % % TODO add other check conditions.
% % switch options.Action
% % case 'add'
% % case 'remove'
% % end
% % end
% end
end
methods (Access = protected)
function release_resource_description(this)
error('error: not implemented!');
%% Release Unused Resource Description
% release unused resource description: datacenters, nodes, links;
% A link is unused when its capcity is zero and no candidate paths use it;
% A node is unused only when all adjecent links are unused; If a node is unused
% and it is colocated with a DC, the DC must also be unused.
% A datacenter is unused when its capcacity is zero, and the co-located node is
% unused.
this.save_state;
b_removed_dcs = this.ServiceNodes.Capacity <= eps;
b_removed_links = this.Links.Capacity <= eps;
for i = 1:this.NumberFlows
pathlist = this.FlowTable{i, 'Paths'};
for j = 1:pathlist.Width
path = pathlist{j};
h = path.node_list(1:(end-1));
t = path.node_list(2:end);
eid = this.graph.IndexEdge(h,t);
b_removed_links(eid) = false;
end
end
b_removed_nodes = this.graph.Remove([], b_removed_links);
%% Update variables
% see also <OnRemoveFlow>.
% 'b_removed_nodes', 'b_removed_links', 'b_removed_dcs' helps to identify the
% variables that should be removed.
b_removed_dcs = b_removed_dcs & (b_removed_nodes(this.ServiceNodes.VirtualNode));
this.net_changes.NodeIndex = find(b_removed_nodes);
this.net_changes.DCIndex = find(b_removed_dcs);
this.net_changes.LinkIndex = find(b_removed_links);
this.op.identify_change(false(this.NumberPaths,1));
this.op.I_dc_path(b_removed_dcs, :) = [];
this.op.I_edge_path(b_removed_links, :) = [];
this.op.Variables.z(this.changed_index.z) = [];
this.op.Variables.v(this.changed_index.v) = [];
% this.vnf_reconfig_cost(this.changed_index.v) = [];
%% Update resources
% Should not change the relative indexing order.
this.Links(b_removed_links,:) = [];
this.Nodes(b_removed_nodes,:) = [];
this.ServiceNodes(b_removed_dcs, :) = [];
dc_node_index = find(this.Nodes.SeviceNode~=0);
this.Nodes{dc_node_index, 'ServiceNode'} = 1:this.NumberServiceNodes;
this.ServiceNodes.VirtualNode = dc_node_index;
% TO BE REMOVED: this.PhysicalNodeMap{:,'Node'} = 0;
% TO BE REMOVED: this.PhysicalNodeMap{this.Nodes.PhysicalNode,'Node'} = (1:this.NumberNodes)';
% TO BE REMOVED: this.PhysicalLinkMap{:,'Link'} = 0;
% TO BE REMOVED: this.PhysicalLinkMap{this.Links.PhysicalLink,'Link'} = (1:this.NumberLinks)';
warning('Debug Required!');
end
end
end