Author: ghuck
Date: 2011-07-24 20:46:52 -0700 (Sun, 24 Jul 2011)
New Revision: 26259
Added:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/MinimumSpanningTreeUnweighted.java
Removed:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java.nocompile
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphAPI.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
Log:
Minimum Spanning Tree computation stub created
Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml 2011-07-23 00:17:20 UTC
(rev 26258)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml 2011-07-25 03:46:52 UTC
(rev 26259)
@@ -156,9 +156,9 @@
<!-- =================================================================== -->
<!-- Clean up libraries extracted in plugins folder -->
<!-- =================================================================== -->
- <target name="clean-libs" depends="init">
+ <target name="clean-libs" depends="init, clean">
<delete file="${cytoscape.plugin.dir}/libigraphWrapper.dylib"/>
- <delete file="${cytoscape.plugin.dir}/libigraph.0.dylib"/>
+ <delete file="${cytoscape.plugin.dir}/jna.jar"/>
</target>
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphAPI.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphAPI.java
2011-07-23 00:17:20 UTC (rev 26258)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphAPI.java
2011-07-25 03:46:52 UTC (rev 26259)
@@ -37,33 +37,12 @@
public class IgraphAPI {
-
- public class IsConnected extends CytoscapeAction {
- Boolean selectedOnly;
-
- public IsConnected(IgraphPlugin myPlugin, String name, boolean
selectedOnly) {
- super(name);
- setPreferredMenu("Plugins.Igraph.IsConnected");
- this.selectedOnly = new Boolean(selectedOnly);
- }
-
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Is
Connected?: " + isConnected(this.selectedOnly));
- }
-
- public boolean isConnected(boolean selectedOnly) {
- loadGraph(selectedOnly);
- return IgraphInterface.isConnected();
- }
-
- }
-
/**
* This function loads the current graph into Igraph.
*
*/
- public static HashMap<Integer,Integer> loadGraph(boolean selectedOnly){
+ public static HashMap<Integer,Integer> loadGraph(boolean selectedOnly,
boolean directed){
CyNetwork network = Cytoscape.getCurrentNetwork();
@@ -108,9 +87,14 @@
}
}
- IgraphInterface.createGraph(edgeArray, i);
- // IgraphInterface.simplify();
+ int directedInt;
+ if (directed)
+ directedInt = 1;
+ else
+ directedInt = 0;
+ IgraphInterface.createGraph(edgeArray, i, directedInt);
+
return nodeIdMapping;
} // loadGraph()
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
2011-07-23 00:17:20 UTC (rev 26258)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
2011-07-25 03:46:52 UTC (rev 26259)
@@ -1,3 +1,22 @@
+/**************************************************************************************
+Copyright (C) Gerardo Huck, 2011
+
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************************/
+
package cytoscape.plugins.igraph;
import com.sun.jna.Library;
@@ -20,7 +39,7 @@
public static native int nativeAdd(int a, int b);
// Create an igraph's graph
- public static native void createGraph(int edgeArray[], int length);
+ public static native void createGraph(int edgeArray[], int length, int
directed);
// Test whether the graph is connected
public static native boolean isConnected();
@@ -46,5 +65,8 @@
boolean isWeighted,
double weights[]);
+ // Minimum spanning tree - unweighted
+ public static native int minimum_spanning_tree_unweighted(int res[]);
+
}
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
2011-07-23 00:17:20 UTC (rev 26258)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
2011-07-25 03:46:52 UTC (rev 26259)
@@ -56,7 +56,7 @@
// Make sure libraries are extracted in the plugins folder
if (extractFileFromJar("jna.jar")) {
- JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "Igraph
plugin succesfully installed!\nIt will be available the next time you run
Cytoscape.");
+ JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Igraph
plugin succesfully installed!\nIt will be available the next time you run
Cytoscape.");
return;
}
@@ -68,20 +68,27 @@
//JOptionPane.showMessageDialog(Cytoscape.getDesktop(),
IgraphInterface.nativeAdd(10, 20));
// Create Igraph object
- IgraphAPI igraph = new IgraphAPI();
+ // IgraphAPI igraph = new IgraphAPI();
// Add elements in menu toolbar
- IgraphAPI.IsConnected isConnectedAction1 = igraph.new
IsConnected(this, "All nodes", false);
+ IsConnected isConnectedAction1 = new IsConnected(this, "All nodes",
false);
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction1);
- IgraphAPI.IsConnected isConnectedAction2 = igraph.new
IsConnected(this, "Selected Nodes", true);
+ IsConnected isConnectedAction2 = new IsConnected(this, "Selected
Nodes", true);
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction2);
+
+ MinimumSpanningTreeUnweighted mst = new
MinimumSpanningTreeUnweighted(this, "All nodes", false);
+
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) mst);
+
+ MinimumSpanningTreeUnweighted mst2 = new
MinimumSpanningTreeUnweighted(this, "Selected Nodes", true);
+
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) mst2);
// Layouts
CyLayouts.addLayout(new CircleLayout(), "Igraph");
CyLayouts.addLayout(new StarLayout(), "Igraph");
CyLayouts.addLayout(new FruchtermanReingoldLayout(true), "Igraph");
+
} catch (Exception e) {
e.printStackTrace();
String message = "Error while initializing Igraph Plugin:\n" +
e.getMessage();
@@ -125,7 +132,7 @@
catch (Exception e) {
e.printStackTrace();
String message = "Igraph Plugin: Error While extracting file
from igraph plugin jar :\n" + e.getMessage();
- JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
+ JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message);
}
Copied:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java
(from rev 25942,
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java.nocompile)
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java
(rev 0)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java
2011-07-25 03:46:52 UTC (rev 26259)
@@ -0,0 +1,58 @@
+/**************************************************************************************
+Copyright (C) Gerardo Huck, 2011
+
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************************/
+
+package cytoscape.plugins.igraph;
+
+import java.awt.event.ActionEvent;
+import javax.swing.JOptionPane;
+import java.util.*;
+
+import cytoscape.Cytoscape;
+import cytoscape.*;
+import cytoscape.data.*;
+import cytoscape.plugin.CytoscapePlugin;
+import cytoscape.util.CytoscapeAction;
+
+import giny.model.*;
+
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.Platform;
+
+
+public class IsConnected extends CytoscapeAction {
+
+ Boolean selectedOnly;
+
+ public IsConnected(IgraphPlugin myPlugin, String name, boolean
selectedOnly) {
+ super(name);
+ setPreferredMenu("Plugins.Igraph.IsConnected");
+ this.selectedOnly = new Boolean(selectedOnly);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Is Connected?: "
+ isConnected(this.selectedOnly));
+ }
+
+ public boolean isConnected(boolean selectedOnly) {
+ IgraphAPI.loadGraph(selectedOnly, false);
+ return IgraphInterface.isConnected();
+ }
+
+}
Deleted:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java.nocompile
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java.nocompile
2011-07-23 00:17:20 UTC (rev 26258)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java.nocompile
2011-07-25 03:46:52 UTC (rev 26259)
@@ -1,119 +0,0 @@
-/**************************************************************************************
-Copyright (C) Gerardo Huck, 2011
-
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-**************************************************************************************/
-
-package cytoscape.plugins.igraph;
-
-import java.awt.event.ActionEvent;
-import javax.swing.JOptionPane;
-import java.util.*;
-
-import cytoscape.Cytoscape;
-import cytoscape.*;
-import cytoscape.data.*;
-import cytoscape.plugin.CytoscapePlugin;
-import cytoscape.util.CytoscapeAction;
-
-import giny.model.*;
-
-import com.sun.jna.Library;
-import com.sun.jna.Native;
-import com.sun.jna.Platform;
-
-
-public class IgraphLib {
-
- public class IsConnected extends CytoscapeAction {
-
- Boolean selectedOnly;
-
- public IsConnected(IgraphPlugin myPlugin, String name, boolean
selectedOnly) {
- super(name);
- setPreferredMenu("Plugins.Igraph.IsConnected");
- this.selectedOnly = new Boolean(selectedOnly);
- }
-
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Is
Connected?: " + isConnected(this.selectedOnly));
- }
-
- public boolean isConnected(boolean selectedOnly) {
- loadGraph(selectedOnly);
- return IgraphInterface.isConnected();
- }
-
- }
-
- /**
- * This function loads the current graph into Igraph.
- *
- */
- public static HashMap<Integer,Integer> loadGraph(boolean selectedOnly){
-
- CyNetwork network = Cytoscape.getCurrentNetwork();
-
- // Create a reverse mapping
- int nodeCount;
- if(selectedOnly) {
- nodeCount = network.getSelectedNodes().size();
- } else {
- nodeCount = network.getNodeCount();
- }
- HashMap<Integer, Integer> nodeIdMapping = new HashMap<Integer,
Integer>(nodeCount);
- int j = 0;
- Iterator<Node> nodeIt;
- if(selectedOnly) {
- nodeIt = network.getSelectedNodes().iterator();
- } else {
- nodeIt = network.nodesIterator();
- }
-
- while(nodeIt.hasNext()){
- Node node = nodeIt.next();
- nodeIdMapping.put(node.getRootGraphIndex(), j);
- j++;
- }
-
-
- // Write edges (as pairs of consecutive nodes) in edgeArray
- int[] edgeArray = new int[network.getEdgeCount() * 2];
- int i = 0;
-
- Iterator<Edge> it = network.edgesIterator();
- while (it.hasNext()) {
- Edge e = (CyEdge) it.next();
-
- Node source = e.getSource();
- Node target = e.getTarget();
-
- if(!selectedOnly || (network.isSelected(source) &&
network.isSelected(target)) ){
- edgeArray[i] =
nodeIdMapping.get(source.getRootGraphIndex());
- edgeArray[i + 1] =
nodeIdMapping.get(target.getRootGraphIndex());
- i += 2;
- }
- }
-
- IgraphInterface.createGraph(edgeArray, i);
- // IgraphInterface.simplify();
-
- return nodeIdMapping;
- } // loadGraph()
-
-
-
-}
\ No newline at end of file
Added:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/MinimumSpanningTreeUnweighted.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/MinimumSpanningTreeUnweighted.java
(rev 0)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/MinimumSpanningTreeUnweighted.java
2011-07-25 03:46:52 UTC (rev 26259)
@@ -0,0 +1,189 @@
+/**************************************************************************************
+Copyright (C) Gerardo Huck, 2011
+
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************************/
+
+package cytoscape.plugins.igraph;
+
+import java.awt.event.ActionEvent;
+import javax.swing.JOptionPane;
+import java.util.*;
+
+import cytoscape.Cytoscape;
+import cytoscape.*;
+import cytoscape.data.*;
+import cytoscape.plugin.CytoscapePlugin;
+import cytoscape.util.CytoscapeAction;
+import cytoscape.logger.CyLogger;
+
+import giny.model.*;
+
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.Platform;
+
+
+public class MinimumSpanningTreeUnweighted extends CytoscapeAction {
+
+ Boolean selectedOnly;
+
+ public MinimumSpanningTreeUnweighted(IgraphPlugin myPlugin, String name,
boolean selectedOnly) {
+ super(name);
+ setPreferredMenu("Plugins.Igraph.Minimum Spanning Tree (Unweighted)");
+ this.selectedOnly = new Boolean(selectedOnly);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+
+ CyLogger logger =
CyLogger.getLogger(MinimumSpanningTreeUnweighted.class);
+
+ try {
+ CyNetwork network = Cytoscape.getCurrentNetwork();
+ int numNodes;
+ if (selectedOnly)
+ numNodes = network.getSelectedNodes().size();
+ else
+ numNodes = network.getNodeCount();
+
+ /* Load graph into Igraph library */
+ HashMap<Integer,Integer> mapping =
IgraphAPI.loadGraph(selectedOnly, false);
+
+ /* Prepare variables to hold results from native call
*/
+ int[] mst = new int[2 * numNodes - 2];
+ int numEdges;
+
+ /* Compute MST */
+ numEdges = IgraphInterface.minimum_spanning_tree_unweighted(mst);
+
+ logger.info("Nodes in MST: " + numNodes);
+ logger.info("Edges in MST: " + numEdges);
+ String nodesString = new String();
+ for (int i = 0; i < 2 * numEdges; i++)
+ nodesString = nodesString + mst[i] + ", ";
+ logger.info("Nodes: "+ nodesString);
+
+ /* Create new network & networkView */
+
+ // Prepare nodes
+ int[] nodes = new int[numNodes];
+ int j = 0;
+ Iterator<Node> nodeIt;
+ if(selectedOnly) {
+ nodeIt = network.getSelectedNodes().iterator();
+ } else {
+ nodeIt = network.nodesIterator();
+ }
+
+ while(nodeIt.hasNext()){
+ Node node = nodeIt.next();
+ nodes[j] = node.getRootGraphIndex();
+ j++;
+ }
+
+ // Prepare edges
+ int[] edges = new int[numEdges];
+ int i = 0;
+
+
+ // create node reverse mapping (igraphId -> rootGraphIndex)
+ HashMap<Integer,Integer> reverseMapping = new
HashMap<Integer,Integer>(mapping.size());
+
+ Iterator<Map.Entry<Integer,Integer>> mapIter =
mapping.entrySet().iterator();
+ while (mapIter.hasNext()) {
+ Map.Entry entry = (Map.Entry) mapIter.next();
+ reverseMapping.put((Integer) entry.getValue(), (Integer)
entry.getKey());
+ }
+
+
+ for (int k = 0; k < 2 * numEdges; k += 2) {
+
+ // get rootGraphId's for both nodes of this edge
+ int n1 = reverseMapping.get(mst[k]);
+ int n2 = reverseMapping.get(mst[k + 1]);
+
+ // Get edges starting or ending in n1
+ int[] adjacentEdgesArray =
network.getAdjacentEdgeIndicesArray(n1,
+
true, // undirected edges
+
true, // incoming edges
+
true); // outgoing edges
+
+ for (int l = 0; l < adjacentEdgesArray.length; l++) {
+ Edge edge = network.getEdge(adjacentEdgesArray[l]);
+ int edgeSource = edge.getSource().getRootGraphIndex();
+ int edgeTarget = edge.getTarget().getRootGraphIndex();
+
+ if (edgeSource == n2 || edgeTarget == n2) {
+ // This edge is in the MST!
+ edges[i] = edge.getRootGraphIndex();
+ i++;
+ break;
+ }
+ }
+ }
+
+ if (i != numEdges) {
+ JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "ERROR!
Edges found: " + i + " , should be: " + numEdges);
+ return;
+ }
+
+
+// Iterator<Edge> edgeIt = network.edgesIterator();
+// while(edgeIt.hasNext()){
+// Edge edge = (CyEdge) edgeIt.next();
+// Node source = edge.getSource();
+// Node target = edge.getTarget();
+
+// int n1 = mapping.get(source.getRootGraphIndex());
+// int n2 = mapping.get(target.getRootGraphIndex());
+
+// logger.info("N1 = " + n1 + " N2 = " + n2);
+
+// for(int k = 0; k < 2 * numEdges; k += 2) {
+// if (mst[k] == n1 && mst[k + 1] == n2){
+// edges[i] = edge.getRootGraphIndex();
+// logger.info("Edge: " + edges[i] + ", i = " + i);
+// i++;
+// break;
+// }
+// }
+// }
+
+// JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "i = " + i +
" , numEdges = " + numEdges);
+
+
+ String newNetworkName = "Minimum Spanning Tree (" +
network.getTitle() + ")";
+
+ CyNetwork newNetwork = Cytoscape.createNetwork(nodes,
+ edges,
+ newNetworkName,
+ network,
+ true);
+
+
+ /* Set node positions */
+
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ String message = "Error:\n" + ex.getMessage();
+ JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
+ }
+
+
+ }
+
+}
\ No newline at end of file
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
2011-07-23 00:17:20 UTC (rev 26258)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
2011-07-25 03:46:52 UTC (rev 26259)
@@ -466,7 +466,7 @@
}
}
- IgraphInterface.createGraph(edgeArray, i);
+ IgraphInterface.createGraph(edgeArray, i, 0); // no need for directed
graph
return nodeIdMapping;
} // loadGraphPartition()
Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
2011-07-23 00:17:20 UTC (rev 26258)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
2011-07-25 03:46:52 UTC (rev 26259)
@@ -1,8 +1,23 @@
-//Author Gang Su
-//[email protected]
+/**************************************************************************************
+Copyright (C) Gerardo Huck, 2011
+Copyright (C) Gang Su, 2009
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
-/*include this igraph.h first*/
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************************/
+
+
#include "igraph.h"
#include "igraphJNA.h"
#include <iostream>
@@ -11,23 +26,15 @@
using namespace std;
-
-// Testing passing of an integer
-// Try global variables just in case
-int count = 0;
-
// Use a global graph object
-// Make sure there's only one active graph @ a time to reduce confusions
+// Make sure there's only one active graph at a time to reduce confusions
igraph_t g;
int existsGraph = 0;
-void createGraph(int edgeArray[], int length){
+void createGraph(int edgeArray[], int length, int directed){
// Destroy old graph if it exists
- if (existsGraph) {
- igraph_destroy(&g);
- existsGraph = 0;
- }
+ destroy_graph();
igraph_vector_t v;
igraph_vector_init(&v, length);
@@ -35,7 +42,7 @@
VECTOR(v)[i] = edgeArray[i];
}
- igraph_create(&g, &v, 0, 0);
+ igraph_create(&g, &v, 0, directed);
existsGraph = 1;
printf("Graph created! Number of nodes: %d\n", nodeCount());
@@ -44,52 +51,63 @@
}
+// Destroy graph if it exists
+void destroy_graph() {
+ if (existsGraph) {
+ igraph_destroy(&g);
+ existsGraph = 0;
+ }
+}
+
+
bool isConnected(){
- igraph_bool_t connected;
- igraph_is_connected(&g, &connected, IGRAPH_STRONG);
- return (bool)connected;
+ igraph_bool_t connected;
+ igraph_is_connected(&g, &connected, IGRAPH_STRONG);
+ return (bool)connected;
+ destroy_graph();
}
+
void simplify(){
igraph_simplify(&g, 1, 1, 0);
}
-
void layoutCircle(double x[], double y[]){
- igraph_matrix_t locs;
- igraph_matrix_init(&locs, 0, 0);
+ igraph_matrix_t locs;
+ igraph_matrix_init(&locs, 0, 0);
- // Execute layout
- igraph_layout_circle(&g, &locs);
+ // Execute layout
+ igraph_layout_circle(&g, &locs);
- long int nRow = igraph_matrix_nrow(&locs);
- long int nCol = igraph_matrix_ncol(&locs);
- for(int i=0; i<nRow; i++){
- x[i] = MATRIX(locs, i, 0);
- y[i] = MATRIX(locs, i, 1);
- }
- // Clean up
- igraph_matrix_destroy(&locs);
+ long int nRow = igraph_matrix_nrow(&locs);
+ long int nCol = igraph_matrix_ncol(&locs);
+ for(int i=0; i<nRow; i++){
+ x[i] = MATRIX(locs, i, 0);
+ y[i] = MATRIX(locs, i, 1);
+ }
+ // Clean up
+ igraph_matrix_destroy(&locs);
}
void starLayout(double x[], double y[], int centerId) {
- igraph_matrix_t locs;
- igraph_matrix_init(&locs, 0, 0);
+ igraph_matrix_t locs;
+ igraph_matrix_init(&locs, 0, 0);
- // Execute layout
- igraph_layout_star(&g, &locs, centerId, NULL);
+ // Execute layout
+ igraph_layout_star(&g, &locs, centerId, NULL);
- long int nRow = igraph_matrix_nrow(&locs);
- long int nCol = igraph_matrix_ncol(&locs);
- for(int i=0; i<nRow; i++){
- x[i] = MATRIX(locs, i, 0);
- y[i] = MATRIX(locs, i, 1);
- }
+ long int nRow = igraph_matrix_nrow(&locs);
+ long int nCol = igraph_matrix_ncol(&locs);
+ for(int i=0; i<nRow; i++){
+ x[i] = MATRIX(locs, i, 0);
+ y[i] = MATRIX(locs, i, 1);
+ }
- // Clean up
- igraph_matrix_destroy(&locs);
+ // Clean up
+ igraph_matrix_destroy(&locs);
+ destroy_graph();
}
//Fruchterman - Reingold Layout
@@ -104,62 +122,94 @@
bool isWeighted,
double weights[]){
- long int vcount = igraph_vcount(&g);
- long int ecount = igraph_ecount(&g);
+ long int vcount = igraph_vcount(&g);
+ long int ecount = igraph_ecount(&g);
- igraph_matrix_t locs;
- igraph_matrix_init(&locs, vcount, 2);
- for (int i = 0; i < vcount; i++){
- MATRIX(locs, i, 0) = x[i];
- MATRIX(locs, i, 1) = y[i];
- }
+ igraph_matrix_t locs;
+ igraph_matrix_init(&locs, vcount, 2);
+ for (int i = 0; i < vcount; i++){
+ MATRIX(locs, i, 0) = x[i];
+ MATRIX(locs, i, 1) = y[i];
+ }
- igraph_vector_t weights_vector;
- if (isWeighted) {
- igraph_vector_init(&weights_vector, ecount);
- for (int i = 0; i < ecount; i++){
- VECTOR(weights_vector)[i] = weights[i];
- }
- }
+ igraph_vector_t weights_vector;
+ if (isWeighted) {
+ igraph_vector_init(&weights_vector, ecount);
+ for (int i = 0; i < ecount; i++){
+ VECTOR(weights_vector)[i] = weights[i];
+ }
+ }
- if (isWeighted) {
- igraph_layout_fruchterman_reingold(&g,
- &locs,
- iter,
- maxDelta,
- area,
- coolExp,
- repulserad,
- useSeed,
- &weights_vector,
- 0,
- 0);
+ if (isWeighted) {
+ igraph_layout_fruchterman_reingold(&g,
+ &locs,
+ iter,
+ maxDelta,
+ area,
+ coolExp,
+ repulserad,
+ useSeed,
+ &weights_vector,
+ 0,
+ 0);
- } else {
- igraph_layout_fruchterman_reingold(&g,
- &locs,
- iter,
- maxDelta,
- area,
- coolExp,
- repulserad,
- useSeed,
- 0, // weights
- 0,
- 0);
- }
+ } else {
+ igraph_layout_fruchterman_reingold(&g,
+ &locs,
+ iter,
+ maxDelta,
+ area,
+ coolExp,
+ repulserad,
+ useSeed,
+ 0, // weights
+ 0,
+ 0);
+ }
- for(int i=0; i<vcount; i++){
- x[i] = MATRIX(locs, i, 0);
- y[i] = MATRIX(locs, i, 1);
- }
+ for(int i=0; i<vcount; i++){
+ x[i] = MATRIX(locs, i, 0);
+ y[i] = MATRIX(locs, i, 1);
+ }
- // Clean up
- igraph_matrix_destroy(&locs);
- igraph_vector_destroy(&weights_vector);
+ // Clean up
+ igraph_matrix_destroy(&locs);
+ igraph_vector_destroy(&weights_vector);
+ destroy_graph();
}
+int minimum_spanning_tree_unweighted(int res[]) {
+
+ igraph_t mst;
+ int from, to;
+
+ // Calculate MST
+ igraph_minimum_spanning_tree_unweighted(&g, &mst);
+
+ // Copy results
+ int e = igraph_ecount(&mst);
+ printf("Number of edges in MST: %d\n", e);
+
+ for(int i = 0; i < e ; i++) {
+ igraph_edge(&mst, i, &from, &to);
+ res[2 * i] = from;
+ res[2 * i + 1] = to;
+ }
+
+ // Clean up
+ igraph_destroy(&mst);
+ destroy_graph();
+
+ return e;
+}
+
+
+// int igraph_minimum_spanning_tree(const igraph_t *graph, igraph_vector_t
*res,
+// const igraph_vector_t *weights);
+// int igraph_minimum_spanning_tree_prim(const igraph_t *graph, igraph_t *mst,
+// const igraph_vector_t *weights);
+
extern "C"{
//Simple adding of two integers
int nativeAdd(int a, int b)
@@ -169,49 +219,15 @@
}
+int nodeCount(){
+ return (int)igraph_vcount(&g);
+}
//////////////////////////////
-//Boolean, test whether the current graph is simple
-//Can only be called when a graph has been loaded
-// bool isSimple(){
-// igraph_bool_t simple;
-// igraph_is_simple(&g, &simple);
-// return (bool)simple;
-// //return 1;
-// }
-
-// void clusters(int membership[], int csize[], int* numCluster){
-// igraph_vector_t membership_v;
-// igraph_vector_t csize_v;
-// igraph_integer_t numCluster_v = 0;
-
-// igraph_vector_init(&membership_v, 0);
-// igraph_vector_init(&csize_v, 0);
-
-// //last argument is ignored
-// //The problem here is that the length of the array is unknown
-// igraph_clusters(&g, &membership_v, &csize_v, &numCluster_v,
IGRAPH_WEAK);
-
-// *numCluster = (int)numCluster_v;
-
-// //Convert data back
-// for(int i=0; i<igraph_vector_size(&membership_v); i++){
-// membership[i] = VECTOR(membership_v)[i];
-// }
-
-// for(int i=0; i<igraph_vector_size(&csize_v); i++){
-// csize[i] = VECTOR(csize_v)[i];
-// }
-
-// }
-
//get nodeCount and edgeCount of the current loaded graph
-int nodeCount(){
- return (int)igraph_vcount(&g);
-}
// int edgeCount(){
// return (int)igraph_ecount(&g);
Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
2011-07-23 00:17:20 UTC (rev 26258)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
2011-07-25 03:46:52 UTC (rev 26259)
@@ -1,19 +1,33 @@
-//Author Gang Su.
-//[email protected]
+/**************************************************************************************
+Copyright (C) Gerardo Huck, 2011
+Copyright (C) Gang Su, 2009
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************************/
+
+
extern "C"
{
+ // Basic functions
+ void createGraph(int edgeArray[], int length, int directed);
+ void destroy_graph();
-
// Igraph functions
- void createGraph(int edgeArray[], int length);
bool isConnected();
void simplify();
int nodeCount();
- /* bool isSimple(); */
- /* int edgeCount(); */
- /* void clusters(int membership[], int csize[], int* numCluster); */
// Layouts
void layoutCircle(double x[], double y[]);
@@ -29,24 +43,12 @@
bool isWeighted,
double weights[]);
+ // Minimum spanning tree - unweighted
+ int minimum_spanning_tree_unweighted(int res[]);
-/* void fastGreedy(int membership[], double* modularity, int csize[], int *
numCluster); */
-/* void labelPropagation(int membership[], double* modularity); */
-/* void walkTrap(int membership[], double*modularity, int csize[], int *
numCluster); */
-/* void edgeBetweenness(int membership[], double*modularity, int csize[],
int * numCluster); */
-/* void spinGlass(int membership[], double* modularity, int csize[], int*
numCluster); */
-/* void spinGlassSingle(int target, int community[], int* community_size);
//only compute community close to the target id */
//test functions
int nativeAdd(int a, int b);
-/* void nativeIncrement(int* iptr); */
-/* int nativeArrayReset(int data[], int length); */
-/* int nativeCountAdd(int value); */
-/* void nativeArrayTest(int data[]); */
-/* void nativeMemoryAllocate(int **data, int *length); //pointer to pointer
reference */
-/* void nativePointerMemoryAllocate(int *data, int *length); //single
pointer reference */
-/* void nativeListAllocate(int*** data, int** list_lengths, int*
data_length); //Return a zig-zag type */
-/* void nativeMatrixAllocate(int** data, int* nrow, int* ncol); */
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.