-
Notifications
You must be signed in to change notification settings - Fork 644
Minimum spanning tree plugin #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
387fa5e
bb16b82
e8ba8a9
e6f49d0
77627a3
d6e657a
ef6237b
fc76ce9
2eff609
67d06d9
10c84df
86a73b2
b322cfb
f58094e
e4b8ceb
e28b4dc
61137ba
46a4dcc
643871b
783b599
0cd76b8
d04f2f4
ee0b151
64c34c4
39e828f
6bce82a
6c4f4d1
93a9a2d
679e7bf
da42c77
bd39daa
d6ac100
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <artifactId>gephi-plugin-parent</artifactId> | ||
| <groupId>org.gephi</groupId> | ||
| <version>0.9.1</version> | ||
| </parent> | ||
|
|
||
| <groupId>com.carlschroedl.gephi</groupId> | ||
| <artifactId>spanning-tree-plugin</artifactId> | ||
| <version>1.0.0</version> | ||
| <packaging>nbm</packaging> | ||
|
|
||
| <name>Minimum Spanning Tree Plugin</name> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.netbeans.api</groupId> | ||
| <artifactId>org-openide-util</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>graphstore</artifactId> | ||
| <version>0.5.3</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>statistics-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>utils-longtask</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>graph-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.netbeans.api</groupId> | ||
| <artifactId>org-openide-util-lookup</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>io-importer-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>io-importer-plugin</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>io-processor-plugin</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.netbeans.modules</groupId> | ||
| <artifactId>org-netbeans-modules-masterfs</artifactId> <!-- See http://wiki.netbeans.org/UsingFileSystemsMasterfs --> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.10</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>filters-api</artifactId> | ||
| <scope>test</scope> | ||
| <type>jar</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>filters-plugin</artifactId> | ||
| <scope>test</scope> | ||
| <type>jar</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gephi</groupId> | ||
| <artifactId>filters-impl</artifactId> | ||
| <scope>test</scope> | ||
| <type>jar</type> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>nbm-maven-plugin</artifactId> | ||
| <configuration> | ||
| <licenseName>gpl-3.0</licenseName> | ||
| <licenseFile>gpl-3.0.txt</licenseFile> | ||
| <author>Carl Schroedl carlschroedl@gmail.com</author> | ||
| <sourceCodeUrl>https://github.com/carlschroedl/gephi-plugins</sourceCodeUrl> | ||
| <homePageUrl>https://github.com/carlschroedl/gephi-plugins/tree/minimum-spanning-tree-plugin</homePageUrl> | ||
| <publicPackages> | ||
| <publicPackage>com.carlschroedl.gephi.plugin.minimumspanningtree</publicPackage> | ||
| </publicPackages> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>2.15</version> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <reporting> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>cobertura-maven-plugin</artifactId> | ||
| <version>2.6</version> | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, when triggering code coverage collection in the NetBeans UI, it disgregards the version of the coverage plugin that is specified in the pom. Instead, NetBeans uses the most recent stable release of the plugin. In this case, there are integration problems between NetBeans 8.2 and the most recent stable release of the cobertura-maven-plugin (2.7). By running the |
||
| </plugin> | ||
| </plugins> | ||
| </reporting> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.carlschroedl.gephi.plugin.minimumspanningtree; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.gephi.graph.api.Edge; | ||
| import org.gephi.graph.api.Graph; | ||
| import org.gephi.graph.api.Node; | ||
| import org.gephi.graph.impl.utils.MapDeepEquals; | ||
| import org.openide.util.Pair; | ||
|
|
||
| /** | ||
| * This class determines whether two graphs have the same nodes and edges. Nodes | ||
| * from different graphs are considered equal if and only if their node ids are | ||
| * equal. Edges from different graphs are considered equal if and only if their | ||
| * source node ids, target node ids, and weights are equal. Two graphs are equal | ||
| * if and only if all of their nodes and edges are equal, and they have the same | ||
| * number of edges and nodes. | ||
| * All other node and edge attributes are ignored in this comparison. | ||
| */ | ||
| public class GraphTopologyEquals { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created this because I wanted my plugin's tests to assert that the result of running the algorithm was the same as a manually-verified graph loaded from file. Since I'm new to Gephi, I'm wondering if this is necessary. Are there any alternatives built in to Gephi for determining if graphs have equal topologies?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there are builtin methods for this, but this is a small class. Great that you have tests!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Cool. Thanks for confirming that I'm not duplicating existing Gephi functionality. |
||
|
|
||
| private static Pair getSourceTargetPair(Edge e) { | ||
| Object aSourceId = e.getSource().getId(); | ||
| Object aTargetId = e.getTarget().getId(); | ||
| Pair<Object, Object> pair = Pair.of(aSourceId, aTargetId); | ||
| return pair; | ||
|
|
||
| } | ||
| /** | ||
| * Compares edge collections based on source node id , target node id, and edge weight. | ||
| * @param aEdgeCollection | ||
| * @param bEdgeCollection | ||
| * @return true if all edges in both collections match, otherwise false. | ||
| */ | ||
| public static boolean edgeCollectionsAreEqual(Collection<Edge> aEdgeCollection, Collection<Edge> bEdgeCollection) { | ||
| boolean equal = true; | ||
| if (aEdgeCollection.size() == bEdgeCollection.size()) { | ||
| Map<Pair<Object, Object>, Double> aEdgeMap = new HashMap<Pair<Object, Object>, Double>(); | ||
| for (Edge aEdge : aEdgeCollection) { | ||
| double weight = aEdge.getWeight(); | ||
| aEdgeMap.put(getSourceTargetPair(aEdge), weight); | ||
| } | ||
|
|
||
| Map<Pair<Object, Object>, Double> bEdgeMap = new HashMap<Pair<Object, Object>, Double>(); | ||
| for (Edge bEdge : bEdgeCollection) { | ||
| double weight = bEdge.getWeight(); | ||
| bEdgeMap.put(getSourceTargetPair(bEdge), weight); | ||
| } | ||
|
|
||
| equal = MapDeepEquals.mapDeepEquals(aEdgeMap, bEdgeMap); | ||
| } else { | ||
| equal = false; | ||
| } | ||
| return equal; | ||
| } | ||
|
|
||
| public static boolean graphsHaveSameTopology(Graph a, Graph b) { | ||
| boolean equal = true; | ||
| a.writeLock(); | ||
| b.writeLock(); | ||
| try { | ||
| if (a.getNodeCount() == b.getNodeCount() && a.getEdgeCount() == b.getEdgeCount()) { | ||
| for (Node aNode : a.getNodes()) { | ||
| Node bNode = b.getNode(aNode.getId()); | ||
| if (null == bNode) { | ||
| equal = false; | ||
| break; | ||
| } else { | ||
| Collection<Edge> aEdges = a.getEdges(aNode).toCollection(); | ||
| Collection<Edge> bEdges = b.getEdges(bNode).toCollection(); | ||
| if (!edgeCollectionsAreEqual(aEdges, bEdges)) { | ||
| equal = false; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| equal = false; | ||
| } | ||
| } finally { | ||
| a.writeUnlock(); | ||
| b.writeUnlock(); | ||
| } | ||
| return equal; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok that this is a release version instead of a SNAPSHOT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, your plugin can declare any version number you want. Just future updates will need to increase it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!