-
Notifications
You must be signed in to change notification settings - Fork 3
/
ParseSolution.m
81 lines (66 loc) · 913 Bytes
/
ParseSolution.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
function sol=ParseSolution(xhat,model)
N=model.N;
P=model.P;
c=model.c;
alpha=model.alpha;
f=model.f;
r=model.r;
xii=diag(xhat)';
if any(xii>=0.5)
[~, so]=sort(xii,'descend');
nHub=0;
for i=so
if xii(i)<0.5 || nHub>=P
break;
end
xii(i)=1;
nHub=nHub+1;
end
xii(xii<1)=0;
else
[~, imax]=max(xii);
xii(:)=0;
xii(imax)=1;
end
Hubs=find(xii==1);
x=xhat;
for i=1:N
if xii(i)==0
x(i,:)=0;
else
x(:,i)=0;
x(i,i)=1;
end
end
h=zeros(1,N);
for i=1:N
XI=x(:,i);
XI(xii==0)=-inf;
[~, h(i)]=max(XI);
x(:,i)=0;
x(h(i),i)=1;
end
oc=zeros(N,N);
for i=1:N
for j=1:N
if i==j
oc(i,j)=0;
else
k=h(i);
l=h(j);
oc(i,j)=c(i,k)+alpha*c(k,l)+c(l,j);
end
end
end
ocr=oc.*r;
SumOCR=sum(ocr(:));
xiif=xii.*f;
SumXF=sum(xiif);
TotalCost=SumOCR+SumXF;
sol.x=x;
sol.h=h;
sol.Hubs=Hubs;
sol.SumOCR=SumOCR;
sol.SumXF=SumXF;
sol.TotalCost=TotalCost;
end