-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstWeight.m
More file actions
86 lines (82 loc) · 2.23 KB
/
FirstWeight.m
File metadata and controls
86 lines (82 loc) · 2.23 KB
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
function [Weight,TargetCapacity,ObjDual] = FirstWeight(topo,beta,gamma)
format long e;
if nargin < 3, gamma =1e-2; end
numNode = topo.numNode;
numLink = topo.numLink;
newweight = ones(numLink,1);
for i=1:topo.numLink
newweight(i) =(1/ topo.Link(i).capacity);
end
numDestination = topo.numDestination;
Aeq = topo.B;
lb = zeros(numLink,1);
ub =[ topo.Link.capacity]';
% x0 = 0.1*ub;
opt = optimset;
opt.LargeScale = 'on';
opt.Display = 'off';
opt.MaxFunEvals = 20000;
opt.TolFun = 1e-4;
ObjDual = [];
maxiter =2000;
numIter=0;
for i=1:maxiter
%i,
weight = newweight;
f = [];
for i=1:numDestination
beq = topo.demanddestination((i-1)*numNode+1:i*numNode);
tmp = Aeq;
tmp(i,:) = [];
tmp1 = beq;
tmp1(i) = [];
% x = linprog(weight,[],[],Aeq,beq,lb,ub,[],opt);
x = linprog(weight,[],[],tmp,tmp1,lb,[],[],opt);
f = [f x];
x0 = x;
clear tmp tmp1;
end
obj_tmp=0;
for j=1:numLink
if (beta==0)
if (weight(j)<=1)
s(j)=topo.Link(j).capacity;
else
s(j)=0;
end
obj_tmp=obj_tmp+s(j);
elseif (beta==1)
if (1/ topo.Link(j).capacity > weight(j))
s(j) = topo.Link(j).capacity;
else
s(j) = 1/weight(j);
end
obj_tmp=obj_tmp+log(s(j));
else
if ((1/topo.Link(j).capacity)^beta >= weight(j))
s(j) = topo.Link(j).capacity;
else
s(j) = (weight(j))^(-1/beta);
end
obj_tmp=obj_tmp+(1-beta)^(-1)*(s(j))^(1-beta);
end
end
[weight(1) s(1)]
numIter=numIter+1;
for i=1:numLink
DeltaWeight=topo.Link(i).capacity-sum(f(i,:))-s(i);
newweight(i) = weight(i) - gamma*DeltaWeight;
if (newweight(i) < 1e-5)
newweight(i) = 0;
end
obj_tmp=obj_tmp+weight(i)*DeltaWeight;
end
ObjDual=[ObjDual obj_tmp];
end
TargetCapacity=zeros(numLink,1);
for i=1:numLink
TargetCapacity(i)=topo.Link(i).capacity-s(i);
end
Weight=weight;
%figure(1)
%plot(ObjDual)