Author: ghuck
Date: 2009-07-21 13:52:19 -0700 (Tue, 21 Jul 2009)
New Revision: 17503
Modified:
csplugins/trunk/soc/ghuck/plugin/build.xml
csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java
Log:
This version makes ForceDirected an extension of AbstractGraphPartition.
Now the graph is partitioned in connected components, and the layout algorithm
is excecuted on each partition.
It still have problems:
- Results not stetically pleasant.
- Null pointer errors when working with big networks.
Modified: csplugins/trunk/soc/ghuck/plugin/build.xml
===================================================================
--- csplugins/trunk/soc/ghuck/plugin/build.xml 2009-07-21 19:19:22 UTC (rev
17502)
+++ csplugins/trunk/soc/ghuck/plugin/build.xml 2009-07-21 20:52:19 UTC (rev
17503)
@@ -1,135 +1,140 @@
-<!-- =================================================================== -->
-<!-- Plugin build file -->
-<!-- =================================================================== -->
-
-<project name="GPU Layout Plugin" default="jar" basedir=".">
-
- <!-- =================================================================== -->
- <!-- Initialization target -->
- <!-- =================================================================== -->
- <target name="init">
- <property name="plugin_name" value="GpuLayout"/>
- <property name="plugin_class" value="GpuLayout.GpuLayout"/>
- <property name="project.jar" value="${plugin_name}.jar"/>
- <property name="version" value="0.1"/>
- <property name="year" value="2009"/>
-
- <echo message="Building plugin ${plugin_name} version ${version}..."/>
-
- <!-- Define the plugin directories -->
- <property name="root.dir" value="."/>
- <property name="src.dir" value="${root.dir}/src"/>
- <property name="build.dir" value="${root.dir}/build"/>
- <property name="manifest.dir" value="${root.dir}/manifest"/>
- <property name="lib.dir" value="${root.dir}/lib"/>
- <property name="cuda_src.dir" value="${src.dir}/gpuGraphDrawing"/>
-
- <!-- Define the Cytoscape directories -->
- <property name="cytoscape.dir" value="/home/gerardo/Cytoscape_v2.6.2"/>
- <property name="cytoscape.lib.dir" value="${cytoscape.dir}/lib"/>
- <property name="cytoscape.plugin.dir" value="${cytoscape.dir}/plugins"/>
-
- <!-- Inheritable properties -->
- <property name="debug" value="on"/>
- <property name="optimize" value="off"/>
- <property name="deprecation" value="on"/>
- <property name="nowarn" value="true"/>
- <property name="fork" value="false"/>
-
- <!-- Check the availability of some files -->
- <available file="${cytoscape.dir}/cytoscape.jar"
property="cytoscape.present"/>
- <available file="${root.dir}/plugin.props" property="plugin.prop.present"/>
- <available file="${root.dir}/libGpuLayout.so"
property="static.lib.present"/>
- <available file="${root.dir}/License.txt" property="license.present"/>
-
- <!-- Define the java class path -->
- <path id="project.class.path">
- <pathelement location="${cytoscape.dir}/cytoscape.jar"/>
- <pathelement path="${java.class.path}/"/>
- </path>
-
- </target>
-
- <!-- =================================================================== -->
- <!-- Compiles the project -->
- <!-- =================================================================== -->
- <target name="compile" depends="init" >
-
- <echo message="COMPILE ${plugin_name} ..."/>
-
- <mkdir dir="${build.dir}"/>
-
- <javac srcdir="${src.dir}"
- excludes="${excludes}"
- classpathref="project.class.path"
- destdir="${build.dir}"
- debug="${debug}"
- nowarn="${nowarn}"
- deprecation="${deprecation}"
- optimize="${optimize}"
- fork="${fork}"/>
- </target>
-
-
- <!-- =================================================================== -->
- <!-- Executes "make" in gpuGraphDrawing, buiding static library -->
- <!-- =================================================================== -->
- <target name="cuda_compile" depends="compile" >
- <echo message="Compiling CUDA's code..."/>
- <exec executable="make" dir="${cuda_src.dir}"/>
- </target>
-
-
- <!-- =================================================================== -->
- <!-- Creates the plugin jar file
-->
- <!-- =================================================================== -->
- <target name="jar" depends="compile, copy_plugin_prop, copy_static_lib,
copy_license, cuda_compile" >
-
- <jar destfile="${project.jar}">
- <manifest> <attribute name="Cytoscape-Plugin" value="${plugin_class}"/>
</manifest>
- <fileset dir="${build.dir}" includes="**"/>
- </jar>
-
- </target>
-
- <!-- If plugin.prop exist, copy it to build directory -->
- <target name="copy_plugin_prop" if="plugin.prop.present">
- <copy todir="${build.dir}/" file="${root.dir}/plugin.props"/>
- </target>
-
- <!-- If static.lib exist, copy it to build directory -->
- <target name="copy_static_lib" depends="cuda_compile">
- <echo message="copying static lib to build dir"/>
- <copy todir="${build.dir}/" file="${root.dir}/libGpuLayout.so"/>
- </target>
-
- <!-- If License.txt exist, copy it to build directory -->
- <target name="copy_license" if="license.present">
- <copy todir="${build.dir}/" file="${root.dir}/License.txt"/>
- </target>
-
-
-
- <!-- =================================================================== -->
- <!-- Copy jar file and library to Cytoscape plugin folder -->
- <!-- =================================================================== -->
- <target name="copy_jar" depends="jar">
- <copy todir="${cytoscape.plugin.dir}/" file="${root.dir}/${project.jar}"/>
- <copy todir="${cytoscape.plugin.dir}/" file="${root.dir}/libGpuLayout.so"/>
- </target>
-
-
-
- <!-- =================================================================== -->
- <!-- Clean up, get back to original state -->
- <!-- =================================================================== -->
- <target name="clean" depends="init">
- <delete dir="${build.dir}"/>
- <exec executable="make" dir="${cuda_src.dir}">
- <arg line="clean"/>
- </exec>
- </target>
-
-</project>
-
-<!-- End of file -->
+<!-- =================================================================== -->
+<!-- Plugin build file -->
+<!-- =================================================================== -->
+
+<project name="GPU Layout Plugin" default="jar" basedir=".">
+
+ <!-- =================================================================== -->
+ <!-- Initialization target -->
+ <!-- =================================================================== -->
+ <target name="init">
+ <property name="plugin_name" value="GpuLayout"/>
+ <property name="plugin_class" value="GpuLayout.GpuLayout"/>
+ <property name="project.jar" value="${plugin_name}.jar"/>
+ <property name="version" value="0.1"/>
+ <property name="year" value="2009"/>
+
+ <echo message="Building plugin ${plugin_name} version ${version}..."/>
+
+ <!-- Define the plugin directories -->
+ <property name="root.dir" value="."/>
+ <property name="src.dir" value="${root.dir}/src"/>
+ <property name="build.dir" value="${root.dir}/build"/>
+ <property name="manifest.dir" value="${root.dir}/manifest"/>
+ <property name="lib.dir" value="${root.dir}/lib"/>
+ <property name="cuda_src.dir" value="${src.dir}/gpuGraphDrawing"/>
+
+ <!-- Define the Cytoscape directories -->
+ <property name="cytoscape.dir" value="/home/gerardo/Cytoscape_v2.6.2"/>
+ <property name="cytoscape.lib.dir" value="${cytoscape.dir}/lib"/>
+ <property name="cytoscape.plugin.dir" value="${cytoscape.dir}/plugins"/>
+
+ <!-- Inheritable properties -->
+ <property name="debug" value="on"/>
+ <property name="optimize" value="off"/>
+ <property name="deprecation" value="on"/>
+ <property name="nowarn" value="true"/>
+ <property name="fork" value="false"/>
+
+ <!-- Check the availability of some files -->
+ <available file="${cytoscape.dir}/cytoscape.jar"
property="cytoscape.present"/>
+ <available file="${root.dir}/plugin.props" property="plugin.prop.present"/>
+ <available file="${root.dir}/libGpuLayout.so"
property="static.lib.present"/>
+ <available file="${root.dir}/License.txt" property="license.present"/>
+
+ <!-- Define the java class path -->
+ <path id="project.class.path">
+ <pathelement location="${cytoscape.dir}/cytoscape.jar"/>
+ <pathelement path="${java.class.path}/"/>
+ <fileset dir="${cytoscape.lib.dir}">
+ <include name="**/*.jar"/>
+ </fileset>
+ <fileset dir="${cytoscape.plugin.dir}">
+ <include name="**/*.jar"/>
+ </fileset>
+ </path>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the project -->
+ <!-- =================================================================== -->
+ <target name="compile" depends="init" >
+
+ <echo message="COMPILE ${plugin_name} ..."/>
+
+ <mkdir dir="${build.dir}"/>
+
+ <javac srcdir="${src.dir}"
+ excludes="${excludes}"
+ classpathref="project.class.path"
+ destdir="${build.dir}"
+ debug="${debug}"
+ nowarn="${nowarn}"
+ deprecation="${deprecation}"
+ optimize="${optimize}"
+ fork="${fork}"/>
+ </target>
+
+
+ <!-- =================================================================== -->
+ <!-- Executes "make" in gpuGraphDrawing, buiding static library -->
+ <!-- =================================================================== -->
+ <target name="cuda_compile" depends="compile" >
+ <echo message="Compiling CUDA's code..."/>
+ <exec executable="make" dir="${cuda_src.dir}"/>
+ </target>
+
+
+ <!-- =================================================================== -->
+ <!-- Creates the plugin jar file
-->
+ <!-- =================================================================== -->
+ <target name="jar" depends="compile, copy_plugin_prop, copy_static_lib,
copy_license, cuda_compile" >
+
+ <jar destfile="${project.jar}">
+ <manifest> <attribute name="Cytoscape-Plugin" value="${plugin_class}"/>
</manifest>
+ <fileset dir="${build.dir}" includes="**"/>
+ </jar>
+
+ </target>
+
+ <!-- If plugin.prop exist, copy it to build directory -->
+ <target name="copy_plugin_prop" if="plugin.prop.present">
+ <copy todir="${build.dir}/" file="${root.dir}/plugin.props"/>
+ </target>
+
+ <!-- If static.lib exist, copy it to build directory -->
+ <target name="copy_static_lib" depends="cuda_compile">
+ <echo message="copying static lib to build dir"/>
+ <copy todir="${build.dir}/" file="${root.dir}/libGpuLayout.so"/>
+ </target>
+
+ <!-- If License.txt exist, copy it to build directory -->
+ <target name="copy_license" if="license.present">
+ <copy todir="${build.dir}/" file="${root.dir}/License.txt"/>
+ </target>
+
+
+
+ <!-- =================================================================== -->
+ <!-- Copy jar file and library to Cytoscape plugin folder -->
+ <!-- =================================================================== -->
+ <target name="copy_jar" depends="jar">
+ <copy todir="${cytoscape.plugin.dir}/" file="${root.dir}/${project.jar}"/>
+ <copy todir="${cytoscape.plugin.dir}/" file="${root.dir}/libGpuLayout.so"/>
+ </target>
+
+
+
+ <!-- =================================================================== -->
+ <!-- Clean up, get back to original state -->
+ <!-- =================================================================== -->
+ <target name="clean" depends="init">
+ <delete dir="${build.dir}"/>
+ <exec executable="make" dir="${cuda_src.dir}">
+ <arg line="clean"/>
+ </exec>
+ </target>
+
+</project>
+
+<!-- End of file -->
Modified: csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java
===================================================================
--- csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java 2009-07-21
19:19:22 UTC (rev 17502)
+++ csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java 2009-07-21
20:52:19 UTC (rev 17503)
@@ -40,6 +40,7 @@
import java.awt.Rectangle;
import java.util.Iterator;
import java.lang.reflect.Field;
+import java.util.*;
import cytoscape.CyNetwork;
import cytoscape.Cytoscape;
@@ -48,9 +49,16 @@
import cytoscape.view.CyNetworkView;
import cytoscape.data.CyAttributes;
+import csplugins.layout.LayoutPartition;
+import csplugins.layout.LayoutEdge;
+import csplugins.layout.LayoutNode;
+import csplugins.layout.EdgeWeighter;
+import csplugins.layout.algorithms.graphPartition.*;
-public class ForceDirected extends AbstractLayout{
+public class ForceDirected extends AbstractGraphPartition
+{
+
private double H_SIZE = 5000.0;
private double V_SIZE = 5000.0;
private String GPU_LIBRARY = "GpuLayout";
@@ -77,6 +85,12 @@
layoutProperties = new LayoutProperties(getName());
initialize_properties();
}
+
+ public boolean supportsSelectedOnly() {
+ return false;
+ }
+
+
/**
* Adds tunable objects for adjusting plugin parameters
@@ -196,13 +210,8 @@
/**
* This function does the "heavy work", calling the native code
*/
- public void construct() {
+ public void layoutPartion (LayoutPartition part) {
- //Show message on screen with AdjMatIndex and AdjMatVals
- /*String message3 = "GpuLayout Plugin started!\n";
- JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message3);
- */
-
// Show message on the task monitor
taskMonitor.setStatus("Initializing");
@@ -211,86 +220,74 @@
// Calls initialize_local
initialize();
-
-
-
- // Pack the arguments needed for calling native code
-
+
// Get the number of edges and nodes
- int numNodes = network.getNodeCount();
- int numEdges = network.getEdgeCount();
+ int numNodes = part.nodeCount();
+ int numEdges = part.edgeCount();
- // Allocate memory for storing graph edges
+ // Get node's list
+ List<LayoutNode> nodeList = part.getNodeList();
+
+ // Allocate memory for storing graph edges information (to be used as
arguments for JNI call)
int[] AdjMatIndex = new int[numNodes + 1];
- int[] AdjMatVals = new int[2 * numEdges];
+ int[] AdjMatVals = new int[2 * numEdges];
-
-
- // Initialize mapping beetwen aliases and node's ID
- int[] node_map = new int[numNodes];
-
// Create an iterator for processing the nodes
- Iterator<Node> it = network.nodesIterator();
+ Iterator<LayoutNode> it = nodeList.iterator();
- // Auxiliary variable to keep track of nodes aliases
- int alias = 0;
-
- // Iterate over the nodes
- while (it.hasNext()) {
-
- // Get next node
- Node node = (Node) it.next();
-
- // Add alias and node ID to node_map
- node_map[alias] = network.getIndex(node);
-
- // Increment alias
- alias++;
- }
-
- // Check whether it has been canceled by the user
- if (canceled)
- return;
-
- // Auxiliary variable used to keep track of the position in AdjMatVals
+ // Auxiliary variables
int position = 0;
-
+ int currentNodePosition = 0;
+
// Iterate over all nodes
- for (alias = 0; alias < numNodes; alias++){
+ while (it.hasNext()){
- // Set AdjMatIndex[alias] to point to start of neighbors list of
this node
- AdjMatIndex[alias] = position;
+ // Get next node
+ LayoutNode node = (LayoutNode) it.next();
+
+ // Get index of node
+ int currentNodeIndex = network.getIndex(node.getNode());
+
+ // Set AdjMatIndex[current_node_index] to point to start of
neighbors list of this node
+ AdjMatIndex[currentNodePosition] = position;
- // Get current node's index
- int current_node_index = node_Alias2Index(node_map, alias);
-
// Get neighbors of node
- int[] neighbors = network.neighborsArray(current_node_index);
+ List<LayoutNode> neighbors = node.getNeighbors();
// Process neighbors of node, adding them in AdjMatVals
- for (int i = 0; i < neighbors.length; i++){
- int current_neighbor_index = neighbors[i];
+ Iterator<LayoutNode> neighborsIterator = neighbors.iterator();
+ while (neighborsIterator.hasNext() ){
+
+ // Get the next neighbor
+ LayoutNode currentNeighbor = (LayoutNode)
neighborsIterator.next();
+
+ // Get the position in nodeList of neighbor
+ int currentNeighborPosition = nodeList.indexOf(currentNeighbor);
+ // Get index of currentNeighbor
+ int currentNeighborIndex =
network.getIndex(currentNeighbor.getNode());
+
// Take into account both directed (in both directions) and
undirected edges
- int multiplicity = network.getEdgeCount(current_node_index,
current_neighbor_index, true)
- + network.getEdgeCount(current_neighbor_index,
current_node_index, false);
+ int multiplicity = network.getEdgeCount(currentNodeIndex,
currentNeighborIndex, true)
+ + network.getEdgeCount(currentNeighborIndex,
currentNodeIndex, false);
// Add current_neighbor to AdjMatVals "multiplicity" times
for (int j = 0; j < multiplicity; j++){
// Add alias of current_neighbor to AjdMatVals
- AdjMatVals[position] = node_Index2Alias(node_map,
current_neighbor_index);
+ AdjMatVals[position] = currentNeighborPosition;
// Increment position
position++;
- }
-
+ }
}
+ // Increment currentNodePosition
+ currentNodePosition++;
}
// Mark end of AdjMatIndex, so that you can now where ends AdjMatVals
- AdjMatIndex[alias] = position;
+ AdjMatIndex[currentNodePosition] = position;
// Show message on screen with AdjMatIndex and AdjMatVals
@@ -300,14 +297,13 @@
message2 = message2 + "\nAdhMatVals\n";
for (int i = 0; i < AdjMatVals.length; i++)
message2 = message2 + " " +AdjMatVals[i];
- JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message2);
+ JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message2);
*/
-
+
// Check whether it has been canceled by the user
if (canceled)
return;
-
-
+
// Reset the "sys_paths" field of the ClassLoader to null.
Class clazz = ClassLoader.class;
Field field;
@@ -375,52 +371,36 @@
if (canceled)
return;
-
// Update Node position
-
+ part.resetNodes(); // reset the nodes so we get the new average location
+
// Iterate over all nodes
- for (alias = 0; alias < numNodes; alias++){
-
- // Get current node's index
- int current_node_index = node_Alias2Index(node_map, alias);
+ currentNodePosition = 0;
+
+ // Create an iterator for processing the nodes
+ Iterator<LayoutNode> iterator2 = nodeList.iterator();
+
+ while (iterator2.hasNext()){
- // Get current node
- Node node = network.getNode(current_node_index);
-
+ // Get next node
+ LayoutNode node = (LayoutNode) iterator2.next();
+
// Set node's X and Y positions
-
networkView.getNodeView(node).setXPosition(node_positions[alias][0]);
-
networkView.getNodeView(node).setYPosition(node_positions[alias][1]);
-
+ node.setX(node_positions[currentNodePosition][0]);
+ node.setY(node_positions[currentNodePosition][1]);
+
+ // Move node to desired location
+ part.moveNodeToLocation(node);
+
+ currentNodePosition++;
}
- // (UPDATE NODES?????) I don't know if that will be required..
-
return;
- }// Construct()
+ }// layoutPartion(LayoutPartition part)
-
/**
- * Get the index of a node in node_map, given the alias
- */
- public int node_Alias2Index(int[] map, int alias){
- return (map[alias]);
- }
-
-
- /**
- * Get the alias (ordinal value) of a node in a node_map
- */
- public int node_Index2Alias(int[] map, int index){
- for (int i = 0; i < map.length; i++)
- if (map[i] == index)
- return i;
- return -1;
- }
-
-
- /**
* Native method that computes the layout and returns position of nodes
*/
private native
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---