ISM 可达矩阵 分层 算法
VB的可达矩阵源于对C的移植:
For i = 1 To temp
For j = 1 To temp
If shuzu(i, j) = 1 Then
For n = 1 To temp
shuzu(i, n) = shuzu(j, n) Or shuzu(i, n)
Next n
End If
Next j
Next i
For i = 1 To temp
For j = 1 To temp
If i = j Then
shuzu(i, j) = shuzu(i, j) Or 1
End If
Next j
Next i
这里
Dim shuzu() As Long
temp = Text1.Text '这里的Text1.text是需要用户输入的矩阵的维数
ReDim shuzu(temp, temp)
VB的分层:
Dim count() As Long
ReDim count(temp * temp)
For i = 1 To temp
For j = 1 To temp
If shuzu(i, j) = 1 Then
count(i) = count(i) + 1
End If
Next j
Next i '这里计算每一行中 1 的个数
For s = 1 To temp
mini = temp
For i = 1 To temp
If count(i) < mini And count(i) > 0 Then
mini = count(i)
End If
Next i '这里mini是计算第几行 1 最少
For i = 1 To temp
If count(i) = mini Then
Text5.Text = Text5.Text & i & " " '1 最少意味着最上层
For m = 1 To temp
For n = i To i
shuzu(m, n) = 0 '最上层 1 这一列清 0
Next n
Next m
End If
Next i
Text5.Text = Text5.Text & vbCrLf
For i = 1 To temp
count(i) = 0
Next i
For i = 1 To temp
For j = 1 To temp
If shuzu(i, j) = 1 Then
count(i) = count(i) + 1 '重新计算每一行 1 的个数
End If
Next j
Next i
Next s
C语言分层算法只要移植一下VB的就OK了。
这里VB的程序有下载,但是全部的源码稍后公布。