Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
7324b9c1
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7324b9c1
编写于
6月 29, 2016
作者:
G
Greg Hogan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-4132] [gelly] Fix boxed comparison in CommunityDetection algorithm
This closes #2185
上级
918e5d0c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
19 deletion
+18
-19
flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
...va/org/apache/flink/graph/library/CommunityDetection.java
+18
-19
未找到文件。
flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/library/CommunityDetection.java
浏览文件 @
7324b9c1
...
...
@@ -48,9 +48,9 @@ import java.util.TreeMap;
*/
public
class
CommunityDetection
<
K
>
implements
GraphAlgorithm
<
K
,
Long
,
Double
,
Graph
<
K
,
Long
,
Double
>>
{
private
Integer
maxIterations
;
private
int
maxIterations
;
private
D
ouble
delta
;
private
d
ouble
delta
;
/**
* Creates a new Community Detection algorithm instance.
...
...
@@ -63,7 +63,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
* @param maxIterations The maximum number of iterations to run.
* @param delta The hop attenuation parameter. Its default value is 0.5.
*/
public
CommunityDetection
(
Integer
maxIterations
,
D
ouble
delta
)
{
public
CommunityDetection
(
int
maxIterations
,
d
ouble
delta
)
{
this
.
maxIterations
=
maxIterations
;
this
.
delta
=
delta
;
...
...
@@ -91,7 +91,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
public
void
sendMessages
(
Vertex
<
K
,
Tuple2
<
Long
,
Double
>>
vertex
)
throws
Exception
{
for
(
Edge
<
K
,
Double
>
edge
:
getEdges
())
{
sendMessageTo
(
edge
.
getTarget
(),
new
Tuple2
<
Long
,
Double
>(
vertex
.
getValue
().
f0
,
sendMessageTo
(
edge
.
getTarget
(),
new
Tuple2
<>(
vertex
.
getValue
().
f0
,
vertex
.
getValue
().
f1
*
edge
.
getValue
()));
}
}
...
...
@@ -101,9 +101,9 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
public
static
final
class
VertexLabelUpdater
<
K
>
extends
GatherFunction
<
K
,
Tuple2
<
Long
,
Double
>,
Tuple2
<
Long
,
Double
>>
{
private
D
ouble
delta
;
private
d
ouble
delta
;
public
VertexLabelUpdater
(
D
ouble
delta
)
{
public
VertexLabelUpdater
(
d
ouble
delta
)
{
this
.
delta
=
delta
;
}
...
...
@@ -112,17 +112,17 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
MessageIterator
<
Tuple2
<
Long
,
Double
>>
inMessages
)
throws
Exception
{
// we would like these two maps to be ordered
Map
<
Long
,
Double
>
receivedLabelsWithScores
=
new
TreeMap
<
Long
,
Double
>();
Map
<
Long
,
Double
>
labelsWithHighestScore
=
new
TreeMap
<
Long
,
Double
>();
Map
<
Long
,
Double
>
receivedLabelsWithScores
=
new
TreeMap
<>();
Map
<
Long
,
Double
>
labelsWithHighestScore
=
new
TreeMap
<>();
for
(
Tuple2
<
Long
,
Double
>
message
:
inMessages
)
{
// split the message into received label and score
L
ong
receivedLabel
=
message
.
f0
;
D
ouble
receivedScore
=
message
.
f1
;
l
ong
receivedLabel
=
message
.
f0
;
d
ouble
receivedScore
=
message
.
f1
;
// if the label was received before
if
(
receivedLabelsWithScores
.
containsKey
(
receivedLabel
))
{
D
ouble
newScore
=
receivedScore
+
receivedLabelsWithScores
.
get
(
receivedLabel
);
d
ouble
newScore
=
receivedScore
+
receivedLabelsWithScores
.
get
(
receivedLabel
);
receivedLabelsWithScores
.
put
(
receivedLabel
,
newScore
);
}
else
{
// first time we see the label
...
...
@@ -131,7 +131,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
// store the labels with the highest scores
if
(
labelsWithHighestScore
.
containsKey
(
receivedLabel
))
{
D
ouble
currentScore
=
labelsWithHighestScore
.
get
(
receivedLabel
);
d
ouble
currentScore
=
labelsWithHighestScore
.
get
(
receivedLabel
);
if
(
currentScore
<
receivedScore
)
{
// record the highest score
labelsWithHighestScore
.
put
(
receivedLabel
,
receivedScore
);
...
...
@@ -144,9 +144,9 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
if
(
receivedLabelsWithScores
.
size
()
>
0
)
{
// find the label with the highest score from the ones received
Double
maxScore
=
-
Double
.
MAX
_VALUE
;
L
ong
maxScoreLabel
=
vertex
.
getValue
().
f0
;
for
(
L
ong
curLabel
:
receivedLabelsWithScores
.
keySet
())
{
double
maxScore
=
Double
.
MIN
_VALUE
;
l
ong
maxScoreLabel
=
vertex
.
getValue
().
f0
;
for
(
l
ong
curLabel
:
receivedLabelsWithScores
.
keySet
())
{
if
(
receivedLabelsWithScores
.
get
(
curLabel
)
>
maxScore
)
{
maxScore
=
receivedLabelsWithScores
.
get
(
curLabel
);
...
...
@@ -155,14 +155,14 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
}
// find the highest score of maxScoreLabel
D
ouble
highestScore
=
labelsWithHighestScore
.
get
(
maxScoreLabel
);
d
ouble
highestScore
=
labelsWithHighestScore
.
get
(
maxScoreLabel
);
// re-score the new label
if
(
maxScoreLabel
!=
vertex
.
getValue
().
f0
)
{
highestScore
-=
delta
/
getSuperstepNumber
();
}
// else delta = 0
// update own label
setNewVertexValue
(
new
Tuple2
<
Long
,
Double
>(
maxScoreLabel
,
highestScore
));
setNewVertexValue
(
new
Tuple2
<>(
maxScoreLabel
,
highestScore
));
}
}
}
...
...
@@ -173,8 +173,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
Vertex
<
K
,
Long
>,
Vertex
<
K
,
Tuple2
<
Long
,
Double
>>>
{
public
Vertex
<
K
,
Tuple2
<
Long
,
Double
>>
map
(
Vertex
<
K
,
Long
>
vertex
)
{
return
new
Vertex
<
K
,
Tuple2
<
Long
,
Double
>>(
vertex
.
getId
(),
new
Tuple2
<
Long
,
Double
>(
vertex
.
getValue
(),
1.0
));
return
new
Vertex
<>(
vertex
.
getId
(),
new
Tuple2
<>(
vertex
.
getValue
(),
1.0
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录