我需要實現一個算法找到here(第5頁)使用來自here(挑選Facebook數據,只有KB大小,如果你想深入挖掘)的數據。算法是:分析和理解這個算法
1: Ti ← 0 //Ti is pi’s count of triangles
2: for v ∈ Vi do
3: for u ∈ Nv do
4: if u ∈ Vi then
5: S ← Nv ∩ Nu
6: Ti ← Ti + |S|
7: else if u ∈ Vj then
8: Send <data,Nv> to pj if not sent already
9:
10: Check for incoming messages <t,X>:
11: if t = data then
12: Ti ← Ti+ SURROGATECOUNT(X, i)
13: else
14: Increment completion counter
15:
16: Broadcast <notifier,X>
17: while completion counter < P-1 do
18: Check for incoming messages <t,X>:
19: if t = data then
20: Ti ← Ti+ SURROGATECOUNT(X, i)
21: else
22: Increment completion counter
23:
24: MPIBARRIER
25: Find Sum T ← Pi Ti using MPIREDUCE
26: return T
據我瞭解,我需要一個二維數組。我需要查詢if
語句中的每個元素,並在Ti
變量處執行+1。
第一個問題,S ← Nv ∩ Nu
我該怎麼分配這個變量S
?
維基百科上說:A ∩ B means the set that contains all those elements that A and B have in common.
第二個問題,如果你看看數據,我需要所有的數據嗎?我想我只需要.edges
文件。
n看字符是交集,大多數編程語言有一個Set類/對象,提供該操作 –
@ cricket_007我不熟悉那個類,你可以提供和示例? – Ctrlfreak
['java.util.Set'](http://docs.oracle.com/javase/7/docs/api/java/util/Set.html)和python ['set()'](https:/ /docs.python.org/2/tutorial/datastructures.html#sets) –