Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Christnowx
Gephi
提交
d2af0fbc
G
Gephi
项目概览
Christnowx
/
Gephi
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gephi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d2af0fbc
编写于
4月 16, 2013
作者:
M
Mathieu Bastian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update the AlgorithmsPlugin to the new Graph API
上级
431fc592
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
88 addition
and
113 deletion
+88
-113
modules/AlgorithmsPlugin/pom.xml
modules/AlgorithmsPlugin/pom.xml
+0
-4
modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/AbstractShortestPathAlgorithm.java
...lgorithms/shortestpath/AbstractShortestPathAlgorithm.java
+8
-9
modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/BellmanFordShortestPathAlgorithm.java
...rithms/shortestpath/BellmanFordShortestPathAlgorithm.java
+51
-61
modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/DijkstraShortestPathAlgorithm.java
...lgorithms/shortestpath/DijkstraShortestPathAlgorithm.java
+29
-39
未找到文件。
modules/AlgorithmsPlugin/pom.xml
浏览文件 @
d2af0fbc
...
...
@@ -14,10 +14,6 @@
<packaging>
nbm
</packaging>
<dependencies>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
dynamic-api
</artifactId>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
graph-api
</artifactId>
...
...
modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/AbstractShortestPathAlgorithm.java
浏览文件 @
d2af0fbc
...
...
@@ -45,7 +45,6 @@ import java.awt.Color;
import
java.util.HashMap
;
import
org.gephi.graph.api.Edge
;
import
org.gephi.graph.api.Node
;
import
org.gephi.graph.api.NodeData
;
/**
*
...
...
@@ -53,27 +52,27 @@ import org.gephi.graph.api.NodeData;
*/
public
abstract
class
AbstractShortestPathAlgorithm
{
protected
final
HashMap
<
Node
Data
,
Color
>
colors
;
protected
final
HashMap
<
Node
Data
,
Double
>
distances
;
protected
final
HashMap
<
Node
,
Color
>
colors
;
protected
final
HashMap
<
Node
,
Double
>
distances
;
protected
final
Node
sourceNode
;
protected
double
maxDistance
=
0
;
public
AbstractShortestPathAlgorithm
(
Node
sourceNode
)
{
this
.
sourceNode
=
sourceNode
;
colors
=
new
HashMap
<
Node
Data
,
Color
>();
distances
=
new
HashMap
<
Node
Data
,
Double
>();
colors
=
new
HashMap
<
Node
,
Color
>();
distances
=
new
HashMap
<
Node
,
Double
>();
}
protected
boolean
relax
(
Edge
edge
)
{
Node
source
=
edge
.
getSource
();
Node
target
=
edge
.
getTarget
();
double
distSource
=
distances
.
get
(
source
.
getNodeData
()
);
double
distTarget
=
distances
.
get
(
target
.
getNodeData
()
);
double
distSource
=
distances
.
get
(
source
);
double
distTarget
=
distances
.
get
(
target
);
double
weight
=
edgeWeight
(
edge
);
double
sourceWeight
=
distSource
+
weight
;
if
(
sourceWeight
<
distTarget
)
{
distances
.
put
(
target
.
getNodeData
()
,
sourceWeight
);
distances
.
put
(
target
,
sourceWeight
);
maxDistance
=
Math
.
max
(
maxDistance
,
sourceWeight
);
return
true
;
}
else
{
...
...
@@ -91,7 +90,7 @@ public abstract class AbstractShortestPathAlgorithm {
public
abstract
Edge
getPredecessorIncoming
(
Node
node
);
public
HashMap
<
Node
Data
,
Double
>
getDistances
()
{
public
HashMap
<
Node
,
Double
>
getDistances
()
{
return
distances
;
}
...
...
modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/BellmanFordShortestPathAlgorithm.java
浏览文件 @
d2af0fbc
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package
org.gephi.algorithms.shortestpath
;
import
java.util.HashMap
;
import
org.gephi.data.attributes.type.TimeInterval
;
import
org.gephi.dynamic.DynamicUtilities
;
import
org.gephi.dynamic.api.DynamicController
;
import
org.gephi.graph.api.DirectedGraph
;
import
org.gephi.graph.api.Edge
;
import
org.gephi.graph.api.Node
;
import
org.gephi.graph.api.NodeData
;
import
org.openide.util.Lookup
;
/**
*
...
...
@@ -58,19 +53,15 @@ import org.openide.util.Lookup;
public
class
BellmanFordShortestPathAlgorithm
extends
AbstractShortestPathAlgorithm
{
protected
final
DirectedGraph
graph
;
protected
final
HashMap
<
NodeData
,
Edge
>
predecessors
;
protected
TimeInterval
timeInterval
;
protected
final
HashMap
<
Node
,
Edge
>
predecessors
;
public
BellmanFordShortestPathAlgorithm
(
DirectedGraph
graph
,
Node
sourceNode
)
{
super
(
sourceNode
);
this
.
graph
=
graph
;
predecessors
=
new
HashMap
<
NodeData
,
Edge
>();
DynamicController
dynamicController
=
Lookup
.
getDefault
().
lookup
(
DynamicController
.
class
);
if
(
dynamicController
!=
null
)
{
timeInterval
=
DynamicUtilities
.
getVisibleInterval
(
dynamicController
.
getModel
(
graph
.
getGraphModel
().
getWorkspace
()));
}
predecessors
=
new
HashMap
<
Node
,
Edge
>();
}
@Override
public
void
compute
()
{
graph
.
readLock
();
...
...
@@ -78,10 +69,10 @@ public class BellmanFordShortestPathAlgorithm extends AbstractShortestPathAlgori
//Initialize
int
nodeCount
=
0
;
for
(
Node
node
:
graph
.
getNodes
())
{
distances
.
put
(
node
.
getNodeData
()
,
Double
.
POSITIVE_INFINITY
);
distances
.
put
(
node
,
Double
.
POSITIVE_INFINITY
);
nodeCount
++;
}
distances
.
put
(
sourceNode
.
getNodeData
()
,
0
d
);
distances
.
put
(
sourceNode
,
0
d
);
//Relax edges repeatedly
...
...
@@ -92,7 +83,7 @@ public class BellmanFordShortestPathAlgorithm extends AbstractShortestPathAlgori
Node
target
=
edge
.
getTarget
();
if
(
relax
(
edge
))
{
relaxed
=
true
;
predecessors
.
put
(
target
.
getNodeData
()
,
edge
);
predecessors
.
put
(
target
,
edge
);
}
}
if
(!
relaxed
)
{
...
...
@@ -103,7 +94,7 @@ public class BellmanFordShortestPathAlgorithm extends AbstractShortestPathAlgori
//Check for negative-weight cycles
for
(
Edge
edge
:
graph
.
getEdges
())
{
if
(
distances
.
get
(
edge
.
getSource
()
.
getNodeData
())
+
edgeWeight
(
edge
)
<
distances
.
get
(
edge
.
getTarget
().
getNodeData
()))
{
if
(
distances
.
get
(
edge
.
getSource
()
)
+
edgeWeight
(
edge
)
<
distances
.
get
(
edge
.
getTarget
()))
{
graph
.
readUnlock
();
throw
new
RuntimeException
(
"The Graph contains a negative-weighted cycle"
);
}
...
...
@@ -114,16 +105,14 @@ public class BellmanFordShortestPathAlgorithm extends AbstractShortestPathAlgori
@Override
protected
double
edgeWeight
(
Edge
edge
)
{
if
(
timeInterval
!=
null
)
{
return
edge
.
getWeight
(
timeInterval
.
getLow
(),
timeInterval
.
getHigh
());
}
return
edge
.
getWeight
();
}
@Override
public
Node
getPredecessor
(
Node
node
)
{
Edge
edge
=
predecessors
.
get
(
node
.
getNodeData
()
);
Edge
edge
=
predecessors
.
get
(
node
);
if
(
edge
!=
null
)
{
if
(
edge
.
getSource
()
.
getNodeData
()
!=
node
.
getNodeData
()
)
{
if
(
edge
.
getSource
()
!=
node
)
{
return
edge
.
getSource
();
}
else
{
return
edge
.
getTarget
();
...
...
@@ -132,7 +121,8 @@ public class BellmanFordShortestPathAlgorithm extends AbstractShortestPathAlgori
return
null
;
}
@Override
public
Edge
getPredecessorIncoming
(
Node
node
)
{
return
predecessors
.
get
(
node
.
getNodeData
()
);
return
predecessors
.
get
(
node
);
}
}
modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/DijkstraShortestPathAlgorithm.java
浏览文件 @
d2af0fbc
...
...
@@ -44,104 +44,93 @@ package org.gephi.algorithms.shortestpath;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.gephi.data.attributes.type.TimeInterval
;
import
org.gephi.dynamic.DynamicUtilities
;
import
org.gephi.dynamic.api.DynamicController
;
import
org.gephi.graph.api.Edge
;
import
org.gephi.graph.api.Graph
;
import
org.gephi.graph.api.Node
;
import
org.gephi.graph.api.NodeData
;
import
org.openide.util.Lookup
;
/**
*
* @author Mathieu Bastian
*/
public
class
DijkstraShortestPathAlgorithm
extends
AbstractShortestPathAlgorithm
{
protected
final
Graph
graph
;
protected
final
HashMap
<
NodeData
,
Edge
>
predecessors
;
protected
TimeInterval
timeInterval
;
protected
final
HashMap
<
Node
,
Edge
>
predecessors
;
public
DijkstraShortestPathAlgorithm
(
Graph
graph
,
Node
sourceNode
)
{
super
(
sourceNode
);
this
.
graph
=
graph
;
predecessors
=
new
HashMap
<
NodeData
,
Edge
>();
DynamicController
dynamicController
=
Lookup
.
getDefault
().
lookup
(
DynamicController
.
class
);
if
(
dynamicController
!=
null
)
{
timeInterval
=
DynamicUtilities
.
getVisibleInterval
(
dynamicController
.
getModel
(
graph
.
getGraphModel
().
getWorkspace
()));
}
predecessors
=
new
HashMap
<
Node
,
Edge
>();
}
@Override
public
void
compute
()
{
graph
.
readLock
();
Set
<
Node
>
unsettledNodes
=
new
HashSet
<
Node
>();
Set
<
Node
Data
>
settledNodes
=
new
HashSet
<
NodeData
>();
Set
<
Node
>
settledNodes
=
new
HashSet
<
Node
>();
//Initialize
for
(
Node
node
:
graph
.
getNodes
())
{
distances
.
put
(
node
.
getNodeData
()
,
Double
.
POSITIVE_INFINITY
);
distances
.
put
(
node
,
Double
.
POSITIVE_INFINITY
);
}
distances
.
put
(
sourceNode
.
getNodeData
()
,
0
d
);
distances
.
put
(
sourceNode
,
0
d
);
unsettledNodes
.
add
(
sourceNode
);
while
(!
unsettledNodes
.
isEmpty
())
{
// find node with smallest distance value
Double
minDistance
=
Double
.
POSITIVE_INFINITY
;
Node
minDistanceNode
=
null
;
for
(
Node
k
:
unsettledNodes
)
{
Double
dist
=
distances
.
get
(
k
.
getNodeData
()
);
Double
dist
=
distances
.
get
(
k
);
if
(
minDistanceNode
==
null
)
{
minDistanceNode
=
k
;
}
if
(
dist
.
compareTo
(
minDistance
)
<
0
)
{
minDistance
=
dist
;
minDistanceNode
=
k
;
}
}
unsettledNodes
.
remove
(
minDistanceNode
);
settledNodes
.
add
(
minDistanceNode
.
getNodeData
()
);
settledNodes
.
add
(
minDistanceNode
);
for
(
Edge
edge
:
graph
.
getEdges
(
minDistanceNode
))
{
Node
neighbor
=
graph
.
getOpposite
(
minDistanceNode
,
edge
);
if
(!
settledNodes
.
contains
(
neighbor
.
getNodeData
()
))
{
if
(!
settledNodes
.
contains
(
neighbor
))
{
double
dist
=
getShortestDistance
(
minDistanceNode
)
+
edgeWeight
(
edge
);
if
(
getShortestDistance
(
neighbor
)
>
dist
)
{
distances
.
put
(
neighbor
.
getNodeData
()
,
dist
);
predecessors
.
put
(
neighbor
.
getNodeData
()
,
edge
);
distances
.
put
(
neighbor
,
dist
);
predecessors
.
put
(
neighbor
,
edge
);
unsettledNodes
.
add
(
neighbor
);
maxDistance
=
Math
.
max
(
maxDistance
,
dist
);
}
}
}
}
graph
.
readUnlock
();
}
private
double
getShortestDistance
(
Node
destination
)
{
Double
d
=
distances
.
get
(
destination
.
getNodeData
()
);
Double
d
=
distances
.
get
(
destination
);
if
(
d
==
null
)
{
return
Double
.
POSITIVE_INFINITY
;
}
else
{
return
d
;
}
}
@Override
protected
double
edgeWeight
(
Edge
edge
)
{
if
(
timeInterval
!=
null
)
{
return
edge
.
getWeight
(
timeInterval
.
getLow
(),
timeInterval
.
getHigh
());
}
return
edge
.
getWeight
();
}
@Override
public
Node
getPredecessor
(
Node
node
)
{
Edge
edge
=
predecessors
.
get
(
node
.
getNodeData
()
);
Edge
edge
=
predecessors
.
get
(
node
);
if
(
edge
!=
null
)
{
if
(
edge
.
getSource
()
!=
node
)
{
return
edge
.
getSource
();
...
...
@@ -151,8 +140,9 @@ public class DijkstraShortestPathAlgorithm extends AbstractShortestPathAlgorithm
}
return
null
;
}
@Override
public
Edge
getPredecessorIncoming
(
Node
node
)
{
return
predecessors
.
get
(
node
.
getNodeData
()
);
return
predecessors
.
get
(
node
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录