Author: ghuck
Date: 2011-06-13 19:02:32 -0700 (Mon, 13 Jun 2011)
New Revision: 25739

Added:
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java
Modified:
   csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
   
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/igraphWrapper/Makefile
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
Log:


Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml    2011-06-13 23:46:39 UTC 
(rev 25738)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml    2011-06-14 02:02:32 UTC 
(rev 25739)
@@ -43,6 +43,7 @@
     <available file="${root.dir}/plugin.props" property="plugin.prop.present"/>
     <available file="${root.dir}/License.txt" property="license.present"/>
     <available file="${root.dir}/libigraphWrapper.dylib" 
property="igraphWrapper.lib.present"/>
+    <available file="${igraph.dir}/src/.libs/libigraph.0.dylib" 
property="igraph.lib.present"/>
 
     <!-- Define the java class path -->
     <path id="project.class.path">
@@ -88,7 +89,8 @@
   <!-- =================================================================== -->
   <!-- Creates the plugin jar file                                           
-->
   <!-- =================================================================== -->
-  <target name="jar" depends="compile, copy_plugin_prop, copy_license, 
copy_igraphWrapper_lib"> 
+  <target name="jar" depends="compile, copy_plugin_prop, copy_license,
+                             copy_igraphWrapper_lib, copy_igraph_lib">  
     <jar destfile="${project.jar}">
       <manifest> <attribute name="Cytoscape-Plugin" value="${plugin_class}"/> 
</manifest>
       <fileset dir="${build.dir}" includes="**"/>
@@ -118,6 +120,15 @@
   </target>
 
   <!-- =================================================================== -->
+  <!-- If igraph.lib exist, copy it to build directory  -->    
+  <!-- =================================================================== -->
+  <target name="copy_igraph_lib" if="igraph.lib.present">
+    <echo message="copying igraph lib to build dir"/>
+    <copy todir="${build.dir}/" 
file="${igraph.dir}/src/.libs/libigraph.0.dylib"/>     
+  </target>
+
+
+  <!-- =================================================================== -->
   <!-- Copy jar file to Cytoscape plugin folder                            -->
   <!-- =================================================================== -->
   <target name="copy_jar" depends="jar">

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
    2011-06-13 23:46:39 UTC (rev 25738)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
    2011-06-14 02:02:32 UTC (rev 25739)
@@ -12,214 +12,19 @@
  */
 public class IgraphInterface {
 
-    public IgraphInterface() {
-        igraph INSTANCE = (igraph) Native.loadLibrary((Platform.isWindows() ? 
"msvcrt" : "c"), 
-                                                     igraph.class);
+    static{
+       //load the dynamic library
+       Native.register("igraphWrapper"); 
     }
-
-    public interface igraph extends Library {
-       
-       public class Igraph_vector_t extends Structure {
-           DoubleByReference stor_begin;
-           DoubleByReference stor_end;
-           DoubleByReference end;
-       }
-
-       public class Igraph_t extends Structure {
-            int n;
-            int directed;
-            Igraph_vector_t from;
-            Igraph_vector_t to;
-            Igraph_vector_t oi;
-            Igraph_vector_t ii;
-            Igraph_vector_t os;
-            Igraph_vector_t is;
-           //       void *attr;
-       }
-
-       
-       /* -------------------------------------------------- */
-       /* Data types                                         */
-       /* -------------------------------------------------- */
-
-       /*
-         typedef int    igraph_integer_t;
-         typedef double igraph_real_t;
-         typedef int    igraph_bool_t;
-
-
-         typedef struct igraph_s {
-            igraph_integer_t n;
-            igraph_bool_t directed;
-            igraph_vector_t from;
-            igraph_vector_t to;
-            igraph_vector_t oi;
-            igraph_vector_t ii;
-            igraph_vector_t os;
-            igraph_vector_t is;
-            void *attr;
-        } igraph_t;
-        
-
-        typedef struct TYPE(igraph_vector) {
-            BASE* stor_begin;
-            BASE* stor_end;
-            BASE* end;
-        } TYPE(igraph_vector);    
-        
-        */
-
-        /* -------------------------------------------------- */
-        /* Interface                                          */
-        /* -------------------------------------------------- */
-        
-        /*     
-        int igraph_empty(igraph_t *graph, igraph_integer_t n, igraph_bool_t 
directed);
-        int igraph_empty_attrs(igraph_t *graph, igraph_integer_t n, 
igraph_bool_t directed, void *attr);
-        int igraph_destroy(igraph_t *graph);
-        int igraph_copy(igraph_t *to, const igraph_t *from);
-        int igraph_add_edges(igraph_t *graph, const igraph_vector_t *edges, 
-                             void *attr);
-        int igraph_add_vertices(igraph_t *graph, igraph_integer_t nv, 
-                                void *attr);
-        int igraph_delete_edges(igraph_t *graph, igraph_es_t edges);
-        int igraph_delete_vertices(igraph_t *graph, const igraph_vs_t 
vertices);
-        int igraph_delete_vertices_idx(igraph_t *graph, const igraph_vs_t 
vertices, 
-                                       igraph_vector_t *idx, 
-                                       igraph_vector_t *invidx);
-        igraph_integer_t igraph_vcount(const igraph_t *graph);
-        igraph_integer_t igraph_ecount(const igraph_t *graph);
-        int igraph_neighbors(const igraph_t *graph, igraph_vector_t *neis, 
igraph_integer_t vid, 
-                             igraph_neimode_t mode); 
-        igraph_bool_t igraph_is_directed(const igraph_t *graph);
-        int igraph_degree(const igraph_t *graph, igraph_vector_t *res, 
-                          const igraph_vs_t vids, igraph_neimode_t mode, 
-                          igraph_bool_t loops);
-        int igraph_edge(const igraph_t *graph, igraph_integer_t eid, 
-                        igraph_integer_t *from, igraph_integer_t *to);         
-        int igraph_edges(const igraph_t *graph, igraph_es_t eids,
-                         igraph_vector_t *edges);
-        int igraph_get_eid(const igraph_t *graph, igraph_integer_t *eid,
-                           igraph_integer_t from, igraph_integer_t to,
-                           igraph_bool_t directed, igraph_bool_t error);
-        int igraph_get_eids(const igraph_t *graph, igraph_vector_t *eids,
-                            const igraph_vector_t *pairs,
-                            const igraph_vector_t *path,
-                            igraph_bool_t directed, igraph_bool_t error);
-        int igraph_get_eids_multi(const igraph_t *graph, igraph_vector_t *eids,
-                                  const igraph_vector_t *pairs, 
-                                  const igraph_vector_t *path,
-                                  igraph_bool_t directed, igraph_bool_t error);
-        int igraph_incident(const igraph_t *graph, igraph_vector_t *eids, 
igraph_integer_t vid,
-                            igraph_neimode_t mode);
-          
-        #define IGRAPH_FROM(g,e) (VECTOR((g)->from)[(long int)(e)])
-            #define IGRAPH_TO(g,e)   (VECTOR((g)->to)  [(long int)(e)])
-            #define IGRAPH_OTHER(g,e,v) (IGRAPH_TO(g,(e))==(v) ? 
IGRAPH_FROM((g),(e)) : IGRAPH_TO((g),(e)))
-        */
-
-
-        /* -------------------------------------------------- */
-        /* Constants                                          */
-        /* -------------------------------------------------- */
-
-        /*
-        typedef enum { IGRAPH_UNDIRECTED=0, IGRAPH_DIRECTED=1 } 
igraph_i_directed_t;
-
-        typedef enum { IGRAPH_NO_LOOPS=0, IGRAPH_LOOPS=1 } igraph_i_loops_t;
-
-        typedef enum { IGRAPH_ASCENDING=0, IGRAPH_DESCENDING=1 } 
igraph_order_t;
-
-        typedef enum { IGRAPH_OUT=1, IGRAPH_IN=2, IGRAPH_ALL=3,
-                IGRAPH_TOTAL=3 } igraph_neimode_t;
-
-        typedef enum { IGRAPH_WEAK=1, IGRAPH_STRONG=2 } igraph_connectedness_t;
-
-        typedef enum { IGRAPH_ADJ_DIRECTED=0, 
-                IGRAPH_ADJ_UNDIRECTED=1, IGRAPH_ADJ_MAX=1,
-                IGRAPH_ADJ_UPPER, IGRAPH_ADJ_LOWER, IGRAPH_ADJ_MIN,
-                IGRAPH_ADJ_PLUS } igraph_adjacency_t;
-
-        typedef enum { IGRAPH_STAR_OUT=0, IGRAPH_STAR_IN,
-                IGRAPH_STAR_UNDIRECTED, 
-                IGRAPH_STAR_MUTUAL } igraph_star_mode_t;
-
-        typedef enum { IGRAPH_TREE_OUT=0, IGRAPH_TREE_IN,
-                IGRAPH_TREE_UNDIRECTED } igraph_tree_mode_t;
-
-        typedef enum { IGRAPH_ERDOS_RENYI_GNP=0, 
-                IGRAPH_ERDOS_RENYI_GNM } igraph_erdos_renyi_t;
-
-        typedef enum { IGRAPH_GET_ADJACENCY_UPPER=0,
-                IGRAPH_GET_ADJACENCY_LOWER,
-                IGRAPH_GET_ADJACENCY_BOTH } igraph_get_adjacency_t;
-
-        typedef enum { IGRAPH_DEGSEQ_SIMPLE=0,
-                IGRAPH_DEGSEQ_VL } igraph_degseq_t;
-
-        typedef enum { IGRAPH_FILEFORMAT_EDGELIST=0,
-                IGRAPH_FILEFORMAT_NCOL,
-                IGRAPH_FILEFORMAT_PAJEK,
-                IGRAPH_FILEFORMAT_LGL,
-                IGRAPH_FILEFORMAT_GRAPHML } igraph_fileformat_type_t;
-
-        typedef enum { IGRAPH_REWIRING_SIMPLE=0 } igraph_rewiring_t;
-
-        typedef enum { IGRAPH_EDGEORDER_ID=0,
-                IGRAPH_EDGEORDER_FROM,
-                IGRAPH_EDGEORDER_TO } igraph_edgeorder_type_t;
-
-        typedef enum { IGRAPH_TO_DIRECTED_ARBITRARY=0,
-                IGRAPH_TO_DIRECTED_MUTUAL } igraph_to_directed_t;
-
-        typedef enum { IGRAPH_TO_UNDIRECTED_EACH=0,
-                IGRAPH_TO_UNDIRECTED_COLLAPSE,
-                IGRAPH_TO_UNDIRECTED_MUTUAL} igraph_to_undirected_t;
-
-        typedef enum { IGRAPH_VCONN_NEI_ERROR=0,
-                IGRAPH_VCONN_NEI_NUMBER_OF_NODES,
-                IGRAPH_VCONN_NEI_IGNORE, 
-                IGRAPH_VCONN_NEI_NEGATIVE } igraph_vconn_nei_t;
-
-        typedef enum { IGRAPH_SPINCOMM_UPDATE_SIMPLE=0,
-                IGRAPH_SPINCOMM_UPDATE_CONFIG } igraph_spincomm_update_t; 
-
-        typedef enum { IGRAPH_DONT_SIMPLIFY=0,
-                IGRAPH_SIMPLIFY } igraph_lazy_adlist_simplify_t;
-
-        typedef enum { IGRAPH_TRANSITIVITY_NAN=0,
-                IGRAPH_TRANSITIVITY_ZERO } igraph_transitivity_mode_t;
-
-        typedef enum { IGRAPH_SPINCOMM_IMP_ORIG=0, 
-                IGRAPH_SPINCOMM_IMP_NEG } igraph_spinglass_implementation_t;
-
-        typedef enum { IGRAPH_COMMCMP_VI = 0,
-                IGRAPH_COMMCMP_NMI,
-                IGRAPH_COMMCMP_SPLIT_JOIN,
-                IGRAPH_COMMCMP_RAND,
-                IGRAPH_COMMCMP_ADJUSTED_RAND } igraph_community_comparison_t;
-
-        typedef enum { IGRAPH_ADD_WEIGHTS_NO = 0,
-                IGRAPH_ADD_WEIGHTS_YES,
-                IGRAPH_ADD_WEIGHTS_IF_PRESENT } igraph_add_weights_t;
-
-        typedef enum { IGRAPH_BARABASI_BAG = 0,
-                IGRAPH_BARABASI_PSUMTREE, 
-                IGRAPH_BARABASI_PSUMTREE_MULTIPLE} igraph_barabasi_algorithm_t;
-
-        typedef enum { IGRAPH_SUBGRAPH_AUTO = 0,
-                IGRAPH_SUBGRAPH_COPY_AND_DELETE,
-                IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH
-                } igraph_subgraph_implementation_t;
-
-        typedef igraph_real_t  igraph_scalar_function_t(const igraph_vector_t 
*var, 
-                                                        const igraph_vector_t 
*par,
-                                                        void* extra);
-        typedef void igraph_vector_function_t(const igraph_vector_t *var, 
-                                              const igraph_vector_t *par,
-                                              igraph_vector_t* res, void* 
extra);
-        */
-
-
-     }
+    
+    public static native int nativeAdd(int a, int b);    
+    
+    public static native void createGraph(int edgeArray[], int length);
+    
+    //Test whether the graph is connected
+    public static native boolean isConnected();
+    
+    //Simplify the graph for community ananlysis
+    public static native void simplify();
+    
 }
\ No newline at end of file

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-06-13 23:46:39 UTC (rev 25738)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-06-14 02:02:32 UTC (rev 25739)
@@ -33,6 +33,8 @@
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
+import com.sun.jna.*;
+
 /** ---------------------------IgraphPlugin-----------------------------
  * This plugin allows to call some of igraph functions from Cytoscape
  * @author Gerardo Huck
@@ -45,27 +47,37 @@
      */
     public IgraphPlugin() {
 
-       // Make sure Igraph library is extracted in the plugins folder
-       checkLib();
+       // Make sure libraries are extracted in the plugins folder
+       checkLib("igraphWrapper");
+       checkLib("igraph.0");
 
        // Load igraph
-       loadIgraph();
+       //loadIgraph();
 
        // Use JNA to print a simple message
-       HelloWorld.hello();
+       //HelloWorld.hello();
 
-       // Add an element in menu toolbar
+        String userDir = System.getProperty("user.dir"); 
+//     JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "user dir:"+ 
userDir);   
+       NativeLibrary.addSearchPath("igraphWrapper", userDir + "/plugins");
+
+//     JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
IgraphInterface.nativeAdd(10, 20));          
+
+       // Add elements in menu toolbar
        NodeCount nodeCountAction = new NodeCount(this);
        
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) 
nodeCountAction);
+
+       IsConnected isConnectedAction = new IsConnected(this);
+       
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) 
isConnectedAction);
     }
 
     private boolean isOldVersion(){
        return false;
     }
 
-    private void checkLib() {
+    private void checkLib(String lib) {
     // TODO: Make this cross-platform
-       File dynamicLib = new File ("./plugins/libigraph.dylib");
+       File dynamicLib = new File ("./plugins/lib" + lib + ".dylib");
        if (!dynamicLib.exists() || isOldVersion()){
            String message;         
            try {
@@ -73,7 +85,7 @@
                    getCodeSource().getLocation().toString().
                    substring(6);
                JarFile jar = new JarFile("./plugins/igraphPlugin.jar");
-               ZipEntry entry = jar.getEntry("libigraph.dylib");
+               ZipEntry entry = jar.getEntry("lib" + lib + ".dylib");
                File efile = new File("./plugins/", entry.getName());
            
                InputStream in = 
@@ -90,7 +102,7 @@
                out.close();
                in.close();
 
-               message = "Igraph library extracted!"; 
+               message = lib + " library extracted!"; 
            }
            catch (Exception e) {
                e.printStackTrace();
@@ -126,11 +138,12 @@
            try {
                // Change the value and load the library.
                System.setProperty("java.library.path", "./plugins"  + ":" + 
orig_path);
-               System.loadLibrary("igraph");
+               //              System.loadLibrary("igraph.0");
+               System.loadLibrary("igraphWrapper");
            }
 
-           catch (UnsatisfiedLinkError error){
-               String message = "Problem detected while loading igraph 
Library.\n"                 
+           catch (UnsatisfiedLinkError error) {
+               String message = "Problem detected while loading library.\n"    
            
                    + error.getMessage() 
                    + "\nPlease check your plugins folder.";
                JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message);
@@ -144,11 +157,11 @@
                field.setAccessible(accessible);   
            }
        }
-       catch (Exception exception){
+       catch (Exception exception) {
            res = false;
        }
 
-       finally{
+       finally {
            return res;
        }
     }

Added: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IsConnected.java
===================================================================
--- 
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-06-14 02:02:32 UTC (rev 25739)
@@ -0,0 +1,123 @@
+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.task.Task;
+import cytoscape.task.TaskMonitor;
+
+
+import giny.model.*;
+
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.Platform;
+
+public class IsConnected extends CytoscapeAction {
+
+
+    private IgraphTaskThread t; //This thread is actually where the action is
+    private Thread currentThread;
+
+
+    public IsConnected(IgraphPlugin myPlugin) {
+       super("IsConnected");
+       setPreferredMenu("Plugins.Igraph");
+    }
+
+    public void actionPerformed(ActionEvent e) {
+       JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Is Connected?: " 
+ isConnected());
+    }
+
+    public boolean isConnected() {
+
+       loadGraph_optimized();
+        return IgraphInterface.isConnected(); //Only call this function if the 
graph has been loaded
+
+
+//     boolean res = false;
+//     try {
+//         ArrayList<Integer> nodes = loadGraph_optimized();
+//         JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Graph 
loaded...Number of nodes: " + nodes.size());      
+//         res = IgraphInterface.isConnected();
+//     }
+//     catch (Exception e) {
+//         e.printStackTrace();
+//         JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Igraph 
Plugin error:\n" + e.getMessage());          
+//         res =  false;
+//     }
+//     finally{
+//         return res;
+//     }
+
+
+//         t = new IgraphTaskThread();
+//         t.setAlgorithm(1);
+
+//         //This marks the current thread
+//         currentThread = Thread.currentThread();
+
+//         t.start();
+//         try{
+//             t.join(); //Join the background thread running the algorithm 
with the current thread showing the progressbar
+//         }
+//         catch(InterruptedException e){
+//             //System.out.println("Algorithm terminated");
+//             //The failed C algorithm may cause issues here
+//         e.printStackTrace();
+//         JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Igraph 
Plugin error:\n" + e.getMessage()); 
+//         }
+
+//     return t.getResult();
+    }
+
+    //This will load the graph into c
+    public static ArrayList<Integer> loadGraph_optimized(){
+
+        // Nodes are ordered according to node array.
+        CyNetwork network = Cytoscape.getCurrentNetwork();
+       
+        ArrayList<Integer> selectedNodeIndices = new ArrayList<Integer>();
+
+        int[] edgeIndicesArray = network.getEdgeIndicesArray();
+        int[] nodeArray = network.getNodeIndicesArray();
+
+        // Create a reverse mapping
+        HashMap<Integer, Integer> nodeIdMapping = new HashMap<Integer, 
Integer>(nodeArray.length);
+        for(int i=0; i<nodeArray.length; i++){
+            nodeIdMapping.put(nodeArray[i], i);
+        }
+
+        // Get the selectedNodes
+        // Return the selected node array list
+        Iterator<Node> nodeIt = network.getSelectedNodes().iterator();
+        while(nodeIt.hasNext()){
+            
+            Node node = nodeIt.next();
+            ////System.out.println("This is gd:" + 
nodeIdMapping.get(node.getRootGraphIndex()));
+            
selectedNodeIndices.add(nodeIdMapping.get(node.getRootGraphIndex()));
+        }
+
+        //If this works then it will be a lot faster
+        int[] edgeArray = new int[edgeIndicesArray.length * 2];
+
+        //Get all edges, then simplify in igraph
+        for(int i = 0; i < edgeIndicesArray.length; i++){
+
+            edgeArray[i*2] = 
nodeIdMapping.get(network.getEdgeSourceIndex(edgeIndicesArray[i]));
+            edgeArray[i*2 + 1] = 
nodeIdMapping.get(network.getEdgeTargetIndex(edgeIndicesArray[i]));
+        }
+
+        IgraphInterface.createGraph(edgeArray, edgeArray.length);
+       IgraphInterface.simplify();
+
+        return selectedNodeIndices;
+    }
+    
+}
\ No newline at end of file

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/Makefile
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/Makefile   
2011-06-13 23:46:39 UTC (rev 25738)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/Makefile   
2011-06-14 02:02:32 UTC (rev 25739)
@@ -1,16 +1,20 @@
 all: libigraphWrapper.dylib
 
 
-libigraphWrapper.dylib: igraphJNA.cpp igraphJNA.h                              
                                                                                
                                                                                
          
-       g++ -fPIC -shared -soname,libigraphWrapper.dylib ${CFLAGS} ${LIB_FLAGS} 
-o libigraphWrapper.dylib igraphJNA.cpp
+igraphJNA.o : igraphJNA.cpp igraphJNA.h                                        
                                                                                
                                                                                
+       g++ -c -fPIC ${CFLAGS} ${STATIC_LIBS} -o igraphJNA.o igraphJNA.cpp
 
+libigraphWrapper.dylib : igraphJNA.o
+       g++ -shared -soname,libigraphWrapper.dylib ${LIB_FLAGS}-o 
libigraphWrapper.dylib igraphJNA.o
+
 clean :
+       rm igraphJNA.o 
        rm libIgraphWrapper.dylib 
 
 
 CFLAGS=-I${IGRAPH_PATH}/include
 LIB_FLAGS=-L${IGRAPH_PATH}/src/.libs -ligraph 
+STATIC_LIBS=-L${IGRAPH_PATH}/src/libs/ 
 
+IGRAPH_PATH=/Users/gerardohuck/igraph
 
-IGRAPH_PATH := /Users/gerardohuck/igraph/
-

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-06-13 23:46:39 UTC (rev 25738)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-06-14 02:02:32 UTC (rev 25739)
@@ -1,15 +1,7 @@
 //Author Gang Su
 //[email protected]
-//functions to be exported
-//The purpose of this program, is to port some of the igraph funcions/focus on 
community structure detection
-//To cytoscape.
 
 
-
-
-
-
-
 /*include this igraph.h first*/
 #include "igraph.h"
 #include "igraphJNA.h"
@@ -27,24 +19,28 @@
 //use a global graph object
 //Make sure there's only one active graph @ a time to reduce confusions
 igraph_t g;
+int existsGraph = 0;
 
 void createGraph(int edgeArray[], int length){
 
-       igraph_vector_t v;
-       igraph_vector_init(&v, length);
-       for(int i=0; i<length; i++){
-               VECTOR(v)[i] = edgeArray[i];
-       }
+  // Destroy old graph if it exists
+  if (existsGraph) {
+    igraph_destroy(&g);
+    existsGraph = 0;
+  }
 
-       //Create undirected graphs here.
-       //Can be extended to create directed graph.
-       //But the problem is the original graph may contain both
-       //Directed an undirected edges.
-       igraph_create(&g, &v, 0, 0);
-       //cout << "Graph Created";
-       //igraph_bool_t simple;
-       //igraph_is_simple(&g, &simple);
-       //return (bool)simple;
+  igraph_vector_t v;
+  igraph_vector_init(&v, length);
+  for(int i=0; i<length; i++){
+    VECTOR(v)[i] = edgeArray[i];
+  }
+
+  igraph_create(&g, &v, 0, 0);
+  existsGraph = 1;
+  printf("Graph created! Number of nodes: %d\n", nodeCount());
+
+  // Free resources no longer needed
+  igraph_vector_destroy(&v);
 }
 
 //Boolean, test whether the current graph is simple
@@ -56,16 +52,16 @@
 //     //return 1;
 // }
 
-// bool isConnected(){
-//     igraph_bool_t connected;
-//     igraph_is_connected(&g, &connected, IGRAPH_STRONG);
-//     return (bool)connected;
-// }
+bool isConnected(){
+       igraph_bool_t connected;
+       igraph_is_connected(&g, &connected, IGRAPH_STRONG);
+       return (bool)connected;
+}
 
-// void simplify(){
-//     igraph_simplify(&g, 1, 1);
-// }
-// //////////////////////////////
+void simplify(){
+  igraph_simplify(&g, 1, 1, 0);
+}
+//////////////////////////////
 // void clusters(int membership[], int csize[], int* numCluster){
 //     igraph_vector_t membership_v;
 //     igraph_vector_t csize_v;
@@ -91,10 +87,10 @@
        
 // }
 
-// //get nodeCount and edgeCount of the current loaded graph
-// int nodeCount(){
-//     return (int)igraph_vcount(&g);
-// }
+//get nodeCount and edgeCount of the current loaded graph
+int nodeCount(){
+       return (int)igraph_vcount(&g);
+}
 
 // int edgeCount(){
 //     return (int)igraph_ecount(&g);
@@ -578,13 +574,13 @@
 // }
 
 
-// //extern "C"{
-// //Simple adding of two integers
-// int nativeAdd( int a, int b )
-// {
-//    return( a + b );
-// }
-
+extern "C"{
+//Simple adding of two integers
+  int nativeAdd( int a, int b )
+  {
+    return( a + b );
+  }
+}
 // //Add one to the passed integer via pointer
 // void nativeIncrement(int* iptr){
 //     *iptr += 1;

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-06-13 23:46:39 UTC (rev 25738)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-06-14 02:02:32 UTC (rev 25739)
@@ -5,7 +5,7 @@
 extern "C"
 {
   //test functions
-/*   int nativeAdd( int a, int b ); */
+  int nativeAdd( int a, int b );
 /*   void nativeIncrement(int* iptr); */
 /*   int nativeArrayReset(int data[], int length); */
 /*   int nativeCountAdd(int value); */
@@ -18,10 +18,10 @@
   //igraph functions
   void createGraph(int edgeArray[], int length);
 /*   bool isSimple(); */
-/*   bool isConnected(); */
-/*   void simplify(); */
+  bool isConnected();
+  void simplify();
 /*   void clusters(int membership[], int csize[], int* numCluster); */
-/*   int nodeCount(); */
+  int nodeCount();
 /*   int edgeCount(); */
 
 /*   void fastGreedy(int membership[], double* modularity, int csize[], int * 
numCluster); */

-- 
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.

Reply via email to