Skip to content

Commit 0c189f2

Browse files
committed
v0.3
1 parent 9285f8e commit 0c189f2

File tree

7 files changed

+340
-248
lines changed

7 files changed

+340
-248
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name = "DesignStructureMatrix"
22
uuid = "19401b82-8c43-11e9-36fe-e7e08b9911f1"
33
authors = ["Otepipi"]
4-
version = "0.2.0"
4+
version = "0.3.0"
55

66
[deps]
7-
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
87
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8+
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
99

1010
[compat]
11+
Luxor = "3.0.0"
1112
julia = "1.7"
12-
Gadfly = "1.3.4"
1313

1414
[extras]
1515
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ plotDSM(A,label)
7373
```
7474
then
7575

76-
![](https://user-images.githubusercontent.com/35882132/59391598-bf501300-8daf-11e9-923b-72509125d567.png)
76+
![](https://user-images.githubusercontent.com/35882132/150766189-c486a062-8723-4654-8a30-1aaa2455fdad.svg)
7777

7878

7979
## Clustering DSM
@@ -97,7 +97,7 @@ plotDSM(original_DSM,original_label)
9797
```
9898
original_DSM
9999

100-
![ClusteroriginalDSM](https://user-images.githubusercontent.com/35882132/59392360-54eca200-8db2-11e9-8fa3-6062f31045e5.png)
100+
![ClusteroriginalDSM](https://user-images.githubusercontent.com/35882132/150766202-73f94b96-cef5-46df-a8f9-20ecf4175b44.svg)
101101

102102

103103

@@ -111,7 +111,7 @@ plotDSM(clustered_DSM,clustered_label)
111111
```
112112
then, you get clustered DSM
113113

114-
![Clustered_DSM](https://user-images.githubusercontent.com/35882132/59392602-2cb17300-8db3-11e9-8ea3-3c3367ffc18d.png)
114+
![Clustered_DSM](https://user-images.githubusercontent.com/35882132/150766197-5260e5c0-3063-4709-97a9-3a4b3415671a.svg)
115115

116116
## Sequencing DSM
117117

@@ -142,7 +142,7 @@ plotDSM(original_DSM,original_label)
142142
```
143143
original DSM
144144

145-
![SequencingoriginalDSM](https://user-images.githubusercontent.com/35882132/59393683-9cc1f800-8db7-11e9-9bb5-f2af79c7f7e9.png)
145+
![SequencingoriginalDSM](https://user-images.githubusercontent.com/35882132/150766204-9d85760c-98b4-4b59-ae11-f75ec4d199d8.svg)
146146

147147
To get Sequenced DSM, please type
148148

@@ -154,19 +154,18 @@ plotDSM(sequenced_DSM, sequenced_label)
154154

155155
then, you get sequenced DSM
156156

157-
![SequencedDSM](https://user-images.githubusercontent.com/35882132/59393832-2d003d00-8db8-11e9-9147-cad34b77a2c7.png)
157+
![SequencedDSM](https://user-images.githubusercontent.com/35882132/150766200-cb57710a-509d-48e5-acf3-450445198ca2.svg)
158158

159159

160160

161161
## Future
162162

163-
* Improve plotting DSM
164163
* Implement Other algorithm for clustering DSM
165164
* Implement Other algorithm for sequencing DSM
166165
* Display **D**omain **M**apping **M**atrices (**DMMs**), and **M**ulti**D**omain **M**atrices (**MDMs**)
167166

168167
## Dependency packages
169-
* Gadfly.jl
168+
* Luxor.jl
170169
* LinearAlgebra.jl
171170

172171

src/DesignStructureMatrix.jl

Lines changed: 4 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module DesignStructureMatrix
22

3-
using Gadfly
3+
using Luxor
44
using LinearAlgebra
55

66
export plotDSM
@@ -9,242 +9,8 @@ export OrderReachable
99
export Sequencing
1010
export Clustering
1111

12-
## plot DSM by using Gadfly
13-
function plotDSM(DSM,label)
12+
include("plotDSM.jl")
13+
include("sequencing.jl")
14+
include("clustering.jl")
1415

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=16pt, key_position=:none, bar_spacing= 0.5mm, 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
5016
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

Comments
 (0)