Author: ghuck
Date: 2011-08-11 04:44:12 -0700 (Thu, 11 Aug 2011)
New Revision: 26531
Added:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldGridLayout.java
Modified:
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/igraphJNA.cpp
csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
Log:
Added Fruchtermann-Reignolds layout for large graphs
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
2011-08-10 23:28:17 UTC (rev 26530)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
2011-08-11 11:44:12 UTC (rev 26531)
@@ -64,6 +64,18 @@
boolean useSeed,
boolean isWeighted,
double weights[]);
+ // Fruchterman - Reingold Grid Layout
+ public static native void layoutFruchtermanGrid(double x[],
+ double y[],
+ int iter,
+ double maxDelta,
+ double area,
+ double coolExp,
+ double repulserad,
+ boolean useSeed,
+ boolean isWeighted,
+ double weights[],
+ double cellSize);
// 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-08-10 23:28:17 UTC (rev 26530)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
2011-08-11 11:44:12 UTC (rev 26531)
@@ -84,9 +84,10 @@
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) mst4);
// Layouts
- CyLayouts.addLayout(new CircleLayout(), "Igraph");
- CyLayouts.addLayout(new StarLayout(), "Igraph");
- CyLayouts.addLayout(new FruchtermanReingoldLayout(true), "Igraph");
+ CyLayouts.addLayout(new CircleLayout(),
"Igraph");
+ CyLayouts.addLayout(new StarLayout(),
"Igraph");
+ CyLayouts.addLayout(new FruchtermanReingoldLayout(true),
"Igraph");
+ CyLayouts.addLayout(new FruchtermanReingoldGridLayout(true),
"Igraph");
} catch (Exception e) {
Added:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldGridLayout.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldGridLayout.java
(rev 0)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldGridLayout.java
2011-08-11 11:44:12 UTC (rev 26531)
@@ -0,0 +1,213 @@
+/**************************************************************************************
+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.layout;
+
+import cytoscape.plugins.igraph.*;
+import cytoscape.logger.CyLogger;
+import cytoscape.layout.LayoutProperties;
+import csplugins.layout.LayoutPartition;
+import cytoscape.layout.Tunable;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import java.awt.GridLayout;
+
+import java.util.*;
+
+public class FruchtermanReingoldGridLayout extends AbstractIgraphLayout {
+
+ private int iterNumber = 500; // Number of iterations
+ private double maxDeltaCoefficient = 1.0; // Maximum distance to move
a node in each iteration
+ private double areaCoefficient = 1.0; // Area parameter
+ private double coolExp = 1.5; // The cooling exponent of
the simulated annealing
+ private double repulseRadCoefficient = 1.0; // Determines the radius at
which vertex-vertex repulsion cancels out attraction of adjacent vertices
+ private boolean randomize = true; // Randomize node position
before layout
+ private double cellSizeCoefficient = 1.0; // The size of the grid
cells, in which repulsions are taken into account
+
+ public FruchtermanReingoldGridLayout(boolean supportEdgeWeights) {
+ super();
+ logger = CyLogger.getLogger(FruchtermanReingoldGridLayout.class);
+
+ supportWeights = supportEdgeWeights;
+
+ layoutProperties = new LayoutProperties(getName());
+ this.initialize_properties();
+ }
+
+ /**
+ * Adds tunable objects for adjusting plugin parameters
+ * Initializes default values for those parameters
+ */
+ protected void initialize_properties() {
+ super.initialize_properties();
+
+ // Add new properties to layout
+ layoutProperties.add(new Tunable("iterNumber",
+ "Number of Iterations",
+ Tunable.INTEGER,
+ new Integer(iterNumber)));
+
+ layoutProperties.add(new Tunable("maxDeltaCoefficient",
+ "Distance to move nodes in each
iteration",
+ Tunable.DOUBLE,
+ new Double(maxDeltaCoefficient)));
+
+ layoutProperties.add(new Tunable("areaCoefficient",
+ "Area to use in layout",
+ Tunable.DOUBLE,
+ new Double(areaCoefficient)));
+
+ layoutProperties.add(new Tunable("coolExp",
+ "Cooling exponent of the simulated
annealing",
+ Tunable.DOUBLE,
+ new Double(coolExp)));
+
+ layoutProperties.add(new Tunable("repulseRadCoefficient",
+ "Radius at which vertex-vertex
repulsion cancels out attraction of adjacent vertices",
+ Tunable.DOUBLE,
+ new Double(repulseRadCoefficient)));
+
+ layoutProperties.add(new Tunable("cellSize",
+ "The size of the grid cells in which
node repulsions are computed.",
+ Tunable.DOUBLE,
+ new Double(cellSizeCoefficient)));
+
+ layoutProperties.add(new Tunable("randomize",
+ "Randomize node locations before
laying out nodes",
+ Tunable.BOOLEAN,
+ new Boolean(randomize)));
+
+ // Initialize layout properties
+ layoutProperties.initializeProperties();
+
+ // Force the settings update
+ updateSettings(true);
+ }
+
+ /**
+ * Get new values from tunables and update parameters
+ */
+ public void updateSettings(boolean force) {
+ super.updateSettings(force);
+
+ // Get initialNoIterations
+ Tunable t1 = layoutProperties.get("iterNumber");
+ if ((t1 != null) && (t1.valueChanged() || force))
+ iterNumber = ((Integer) t1.getValue()).intValue();
+
+ // Get maxDeltaCoefficient
+ Tunable t2 = layoutProperties.get("maxDeltaCoefficient");
+ if ((t2 != null) && (t2.valueChanged() || force))
+ maxDeltaCoefficient = ((Double) t2.getValue()).doubleValue();
+
+ // Get areaCoefficient
+ Tunable t3 = layoutProperties.get("areaCoefficient");
+ if ((t3 != null) && (t3.valueChanged() || force))
+ areaCoefficient = ((Double) t3.getValue()).doubleValue();
+
+ // Get coolExp
+ Tunable t4 = layoutProperties.get("coolExp");
+ if ((t4 != null) && (t4.valueChanged() || force))
+ coolExp = ((Double) t4.getValue()).doubleValue();
+
+ // Get repulseRadCoefficient
+ Tunable t5 = layoutProperties.get("repulseRadCoefficient");
+ if ((t5 != null) && (t5.valueChanged() || force))
+ repulseRadCoefficient = ((Double) t5.getValue()).doubleValue();
+
+ // Get coolExp
+ Tunable t6 = layoutProperties.get("cellSize");
+ if ((t6 != null) && (t6.valueChanged() || force))
+ coolExp = ((Double) t6.getValue()).doubleValue();
+
+ // Get randomize
+ Tunable t7 = layoutProperties.get("randomize");
+ if ((t7 != null) && (t7.valueChanged() || force))
+ randomize = ((Boolean) t7.getValue()).booleanValue();
+
+ updateSettings(layoutProperties, force);
+ }
+
+
+ /**
+ * Do the layout on a graph alrealy loaded into igraph
+ */
+ public int layout(double[] x,
+ double[] y,
+ LayoutPartition part,
+ HashMap<Integer,Integer> mapping,
+ double[] weights) {
+
+
+ int numNodes = mapping.size();
+
+ double maxDelta = maxDeltaCoefficient * numNodes;
+ double area = areaCoefficient * numNodes * numNodes;
+ double repulseRad = repulseRadCoefficient * area * numNodes;
+ double cellSize = cellSizeCoefficient * Math.sqrt(numNodes);
+
+ // Store current node positions if necessary
+ if (!randomize) {
+ loadPositions(part, mapping, x, y);
+ }
+
+ // Make native method call
+ IgraphInterface.layoutFruchtermanGrid(x,
+ y,
+ iterNumber,
+ maxDelta,
+ area,
+ coolExp,
+ repulseRad,
+ !randomize,
+ supportWeights,
+ weights,
+ cellSize);
+
+ return 1;
+ }
+
+ /**
+ * getName is used to construct property strings
+ * for this layout.
+ */
+ public String getName() {
+ if (supportWeights)
+ return "Igraph Edge-Weighted Fruchterman-Reingold Layout (for large
graphs)";
+ else
+ return "Igraph Fruchterman-Reingold Layout (for large graphs)";
+ }
+
+ /**
+ * toString is used to get the user-visible name
+ * of the layout
+ */
+ public String toString() {
+ if (supportWeights)
+ return "Edge-Weighted Fruchterman-Reingold Layout (for large
graphs)";
+ else
+ return "Fruchterman-Reingold Layout (for large graphs)";
+ }
+
+}
+
+
+
Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
2011-08-10 23:28:17 UTC (rev 26530)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
2011-08-11 11:44:12 UTC (rev 26531)
@@ -17,7 +17,6 @@
**************************************************************************************/
-
#include "igraph.h"
#include "igraphJNA.h"
#include <iostream>
@@ -179,6 +178,73 @@
destroy_graph();
}
+void layoutFruchtermanGrid(double x[],
+ double y[],
+ int iter,
+ double maxDelta,
+ double area,
+ double coolExp,
+ double repulserad,
+ bool useSeed,
+ bool isWeighted,
+ double weights[],
+ double cellSize) {
+
+
+ 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_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_grid_fruchterman_reingold(&g,
+ &locs,
+ iter,
+ maxDelta,
+ area,
+ coolExp,
+ repulserad,
+ cellSize,
+ useSeed,
+ &weights_vector);
+
+ } else {
+ igraph_layout_grid_fruchterman_reingold(&g,
+ &locs,
+ iter,
+ maxDelta,
+ area,
+ coolExp,
+ repulserad,
+ cellSize,
+ useSeed,
+ 0); // weights
+ }
+
+ 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);
+ destroy_graph();
+}
+
int minimum_spanning_tree_unweighted(int res[]) {
igraph_t mst;
Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
2011-08-10 23:28:17 UTC (rev 26530)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
2011-08-11 11:44:12 UTC (rev 26531)
@@ -22,16 +22,21 @@
{
// Basic functions
void createGraph(int edgeArray[], int length, int directed);
+
void destroy_graph();
// Igraph functions
bool isConnected();
+
void simplify();
+
int nodeCount();
// Layouts
void layoutCircle(double x[], double y[]);
+
void starLayout(double x[], double y[], int centerId);
+
void layoutFruchterman(double x[],
double y[],
int iter,
@@ -43,12 +48,24 @@
bool isWeighted,
double weights[]);
+ void layoutFruchtermanGrid(double x[],
+ double y[],
+ int iter,
+ double maxDelta,
+ double area,
+ double coolExp,
+ double repulserad,
+ bool useSeed,
+ bool isWeighted,
+ double weights[],
+ double cellSize);
+
+
// Minimum spanning tree - unweighted
int minimum_spanning_tree_unweighted(int res[]);
// Minimum spanning tree - weighted
int minimum_spanning_tree_weighted(int res[], double weights[]);
-
//test functions
--
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.