1
1
module DesignStructureMatrix
2
2
3
- using Gadfly
3
+ using Luxor
4
4
using LinearAlgebra
5
5
6
6
export plotDSM
@@ -9,242 +9,8 @@ export OrderReachable
9
9
export Sequencing
10
10
export Clustering
11
11
12
- # # plot DSM by using Gadfly
13
- function plotDSM (DSM,label)
12
+ include (" plotDSM.jl" )
13
+ include (" sequencing.jl" )
14
+ include (" clustering.jl" )
14
15
15
- cDSM = copy (DSM);
16
- cDSM[diagind (cDSM)] .= - 1
17
-
18
- spy (cDSM, Scale. y_discrete (labels = i-> label[i]), Scale. x_discrete (labels = i-> label[i]),
19
- Guide. ylabel (nothing ), Guide. xlabel (nothing , orientation= :vertical ), Guide. xticks (orientation= :vertical ),
20
- Scale. color_continuous (colormap= Scale. lab_gradient ( " darkgrey" ," aliceblue" , " navy" )),
21
- Theme (minor_label_font_size= 16 pt, key_position= :none , bar_spacing= 0.5 mm, panel_fill= " darkgrey" ))
22
-
23
- end
24
-
25
- # # convert DSM to ReachableMatrix
26
- function toReachableMatrix (DSM)
27
-
28
- I = zeros (Int64,size (DSM)) + Diagonal (ones (Int64,size (DSM))); # identity matrix
29
- R1 = zeros (Int64,size (DSM))
30
- calcmax = 1000
31
-
32
- for i = 1 : calcmax
33
-
34
-
35
- R1 = (DSM+ I)^ i
36
- (Rindex) = findall (x-> 1 < x , R1);
37
- R1[Rindex] = ones (size (Rindex));
38
-
39
- R2 = (DSM+ I)^ (i+ 1 )
40
- (Rindex) = findall (x-> 1 < x , R2);
41
- R2[Rindex] = ones (size (Rindex));
42
-
43
- if R1 == R2
44
- break
45
- end
46
-
47
- end
48
-
49
- return R1
50
16
end
51
-
52
-
53
- # #order Reachable matrix for seaqencing
54
- function OrderReachable (Reachable)
55
-
56
- original = copy (Reachable);
57
- (DSMsize,) = size (Reachable);
58
- valuesDSM = collect (1 : DSMsize);
59
- count = 0 ;
60
- level = zeros (Int,DSMsize);
61
-
62
- while count < DSMsize
63
-
64
- R = Reachable;
65
- A = Reachable' ;
66
- RA = R .* A;
67
- (RAsize,) = size (RA);
68
- elements = collect (1 : RAsize);
69
-
70
- for i = 1 : RAsize
71
-
72
- if RA[i,:] == R[i,:];
73
- count += 1 ;
74
- level[count] = valuesDSM[i];
75
- elements[i] = 0 ;
76
- end
77
- end
78
-
79
- elements = filter (x-> x > 0 , elements);
80
- Reachable = Reachable[elements , elements];
81
- valuesDSM = valuesDSM[elements];
82
-
83
- end
84
-
85
- orderedReachable = original[level,level]
86
-
87
- return orderedReachable , level
88
-
89
- end
90
-
91
-
92
- # # Sequencing DSM
93
- function Sequencing (DSM,label)
94
- cDSM = copy (DSM);
95
- clabel = copy (label);
96
-
97
- Reachable = toReachableMatrix (cDSM);
98
-
99
- (OrderedReachable,level) = OrderReachable (Reachable);
100
-
101
- SequencedDSM = cDSM[level,level];
102
- Sequencedlabel = clabel[level];
103
-
104
- return SequencedDSM, Sequencedlabel
105
-
106
- end
107
-
108
- # #Clustering DSM
109
- function Clustering (DSM,label)
110
-
111
- powcc = 1 ;
112
- powbid = 0 ;
113
- powdep = 1 ;
114
- rand_accept = 30 ;
115
- rand_bid = 30 ;
116
- times = 5 ;
117
- stable_limit = 2 ;
118
-
119
- original_DSM = copy (DSM);
120
- original_label = copy (label);
121
- (DSMsize,) = size (original_DSM);
122
-
123
- Clustermatrix = zeros (Int64,DSMsize,DSMsize) + Diagonal (ones (Int64,DSMsize,DSMsize)) ;
124
-
125
- cDSM = copy (original_DSM);
126
-
127
-
128
- function ClusterBid (Clustermatrix,cDSM,DSMsize,powdep,powbid,element)
129
-
130
- bestCluster = 0 ;
131
- bestBid = - 1 ;
132
-
133
- for i = 1 : DSMsize
134
-
135
- Clusterlist= findall (x-> x == 1 , Clustermatrix[i,:]);
136
- (Clustersize,) = size (Clusterlist);
137
- bid = 0 ;
138
-
139
- for j = 1 : Clustersize
140
-
141
- bid += cDSM[element,Clusterlist[j]];
142
-
143
- end
144
-
145
- bid = bid ^ powdep / Clustersize ^ powbid;
146
-
147
- if bid > bestBid
148
-
149
- bestBid = bid;
150
- bestCluster = i;
151
- end
152
-
153
- end
154
-
155
-
156
- return bestCluster
157
-
158
- end
159
-
160
- function TCC (cDSM,DSMsize,Clustermatrix,powcc)
161
-
162
- intraCost= 0 ;
163
- extraCost= 0 ;
164
-
165
-
166
- for i = 1 : DSMsize
167
-
168
- for j = 1 : DSMsize
169
-
170
- Clusterofi = findall (x-> x == 1 , Clustermatrix[:,i]);
171
- Clusterofj = findall (x-> x == 1 , Clustermatrix[:,j]);
172
- (Clustersizeofi,) = size (Clustermatrix[Clusterofi,:]);
173
-
174
- cost = cDSM[i,j] + cDSM[j,i];
175
-
176
- if Clusterofi == Clusterofj
177
-
178
- intraCost += cost* Clustersizeofi^ powcc;
179
-
180
- else
181
-
182
- extraCost += cost* DSMsize^ powcc;
183
- end
184
-
185
-
186
- end
187
-
188
- end
189
-
190
- totalCost = intraCost + extraCost;
191
-
192
- return totalCost
193
- end
194
-
195
-
196
- TCCost = TCC (cDSM,DSMsize,Clustermatrix,powcc)
197
-
198
- costlist = zeros (DSMsize* times,1 );
199
-
200
- for i = 1 : DSMsize * times;
201
-
202
- preClustermatrix = Clustermatrix;
203
- element = rand (1 : DSMsize);
204
- bestCluster = ClusterBid (Clustermatrix,cDSM,DSMsize,powdep,powbid,element);
205
- Clustermatrix[:,element] = zeros (DSMsize,1 );
206
- Clustermatrix[bestCluster,element] = 1 ;
207
- newCost = TCC (cDSM,DSMsize,Clustermatrix,powcc);
208
- if newCost <= maximum ([TCCost,rand_accept])
209
- TCCost = newCost;
210
- else
211
- Clustermatrix = preClustermatrix;
212
- end
213
-
214
- costlist[i] = newCost
215
- end
216
-
217
-
218
- orderCluster = [sum (Clustermatrix,dims= 2 ) Clustermatrix]
219
- orderedCluster = sortslices (orderCluster,dims = 1 , rev= true )
220
- reorderedCluster = orderedCluster[:,2 : DSMsize+ 1 ]
221
-
222
- Order = [];
223
-
224
- for i = 1 : DSMsize
225
- Order = [Order ; findall (x-> x == 1 , reorderedCluster[i,:])]
226
- end
227
-
228
- # # reorder DSM
229
- I = zeros (DSMsize,DSMsize) + Diagonal (ones (DSMsize,DSMsize))
230
- P = zeros (DSMsize,DSMsize) + Diagonal (ones (DSMsize,DSMsize))
231
- Clusteredlabel = copy (original_label)
232
- copylabel= copy (original_label)
233
-
234
- # # Permutation matrix
235
- for i = 1 : DSMsize
236
- P[i,:] = I[Order[i],:]
237
- Clusteredlabel[i] = copylabel[Order[i]]
238
- end
239
-
240
- # # order DSM
241
- ClusteredDSM = P* original_DSM* P'
242
-
243
- return ClusteredDSM, Clusteredlabel;
244
-
245
-
246
- end
247
-
248
-
249
-
250
- end # module
0 commit comments