Author: ghuck
Date: 2011-07-09 10:04:17 -0700 (Sat, 09 Jul 2011)
New Revision: 26129
Modified:
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/cytoscape/plugins/igraph/layouts/CircleLayout.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
Log:
Full weighted layout support added
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-09 06:02:08 UTC (rev 26128)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
2011-07-09 17:04:17 UTC (rev 26129)
@@ -71,10 +71,9 @@
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction2);
// Layouts
- CyLayouts.addLayout(new CircleLayout() , "Igraph");
- CyLayouts.addLayout(new StarLayout() , "Igraph");
- CyLayouts.addLayout(new FruchtermanReingoldLayout(), "Igraph");
-
+ CyLayouts.addLayout(new CircleLayout(), "Igraph");
+ CyLayouts.addLayout(new StarLayout(), "Igraph");
+ CyLayouts.addLayout(new FruchtermanReingoldLayout(true), "Igraph");
}
@@ -121,56 +120,5 @@
}
return;
} // checkLib
-
-
-// protected boolean loadIgraph() {
-
-// boolean res = true;
-
-// // Reset the "sys_paths" field of the ClassLoader to null.
-// Class clazz = ClassLoader.class;
-// Field field;
-// try {
-// field = clazz.getDeclaredField("sys_paths");
-// boolean accessible = field.isAccessible();
-// if (!accessible)
-// field.setAccessible(true);
-// Object original = field.get(clazz);
-
-// // Get original PATH
-// String orig_path = System.getProperty("java.library.path");
-
-// // Reset it to null so that whenever "System.loadLibrary" is
called, it will be reconstructed with the changed value
-// field.set(clazz, null);
-// try {
-// // Change the value and load the library.
-// System.setProperty("java.library.path", "./plugins" + ":" +
orig_path);
-// // System.loadLibrary("igraph.0");
-// System.loadLibrary("igraphWrapper");
-// }
-
-// catch (UnsatisfiedLinkError error) {
-// String message = "Problem detected while loading library.\n"
-// + error.getMessage()
-// + "\nPlease check your plugins folder.";
-// JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message);
-
-// res = false;
-// }
-
-// finally {
-// // Revert back the changes
-// field.set(clazz, original);
-// field.setAccessible(accessible);
-// }
-// }
-// catch (Exception exception) {
-// res = false;
-// }
-
-// finally {
-// return res;
-// }
-// }
}
\ 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-09 06:02:08 UTC (rev 26128)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
2011-07-09 17:04:17 UTC (rev 26129)
@@ -53,14 +53,24 @@
protected LayoutProperties layoutProperties;
+ /**
+ * Value to set for doing unweighted layouts
+ */
+ public static final String UNWEIGHTEDATTRIBUTE = "(unweighted)";
+
+ /**
+ * Whether or not to use edge weights for layout
+ */
+ protected boolean supportWeights = false;
+
public AbstractIgraphLayout() {
super();
- logger = CyLogger.getLogger(AbstractIgraphLayout.class);
- // logger.setDebug(true);
+ //logger = CyLogger.getLogger(AbstractIgraphLayout.class);
+ if (edgeWeighter == null)
+ edgeWeighter = new EdgeWeighter();
-// layoutProperties = new LayoutProperties(getName());
-// initialize_properties();
+ layoutProperties = new LayoutProperties(getName());
}
// METHODS WHICH MUST BE OVERRIDEN IN CHILD CLASS
@@ -71,7 +81,8 @@
public abstract int layout(double[] x,
double[] y,
LayoutPartition part,
- HashMap<Integer,Integer> mapping);
+ HashMap<Integer,Integer> mapping,
+ double[] weights);
/**
* getName is used to construct property strings
@@ -106,7 +117,11 @@
// Initialize layout properties
layoutProperties.initializeProperties();
-
+
+ if (supportWeights) {
+ edgeWeighter.getWeightTunables(layoutProperties,
getInitialAttributeList());
+ }
+
// Force the settings update
updateSettings(true);
}
@@ -116,6 +131,9 @@
*/
public void updateSettings(boolean force) {
layoutProperties.updateValues();
+
+ if (supportWeights)
+ edgeWeighter.updateSettings(layoutProperties, force);
}
/**
@@ -130,7 +148,46 @@
// END OF METHODS WHICH MAY BE OVERRIDEN
+ // We don't support node attribute-based layouts
/**
+ * Tells Cytoscape whether we support node attribute based layouts
+ *
+ * @return nulls, which indicates that we don't
+ */
+ public byte[] supportsNodeAttributes() {
+ return null;
+ }
+
+ // We do support edge attribute-based layouts
+ /**
+ * Tells Cytoscape whether we support node attribute based layouts
+ *
+ * @return null if supportWeights is false, otherwise return the attribute
+ * types that can be used for weights.
+ */
+ public byte[] supportsEdgeAttributes() {
+ if (!supportWeights)
+ return null;
+
+ byte[] attrs = { CyAttributes.TYPE_INTEGER, CyAttributes.TYPE_FLOATING
};
+
+ return attrs;
+ }
+
+ /**
+ * Returns "(unweighted)", which is the "attribute" we
+ * use to tell the algorithm not to use weights
+ *
+ * @returns List of our "special" weights
+ */
+ public List<String> getInitialAttributeList() {
+ ArrayList<String> list = new ArrayList<String>();
+ list.add(UNWEIGHTEDATTRIBUTE);
+
+ return list;
+ }
+
+ /**
* Overload updateSettings for using it without arguments
*/
public void updateSettings() {
@@ -187,6 +244,14 @@
// Load graph into native library
HashMap<Integer,Integer> mapping = loadGraphPartition(part,
selectedOnly);
+ double[] weights;
+ // If performing a weighted layout, deal with weights
+ if (supportWeights) {
+ weights = calculateWeights(part);
+ } else {
+ weights = new double[1]; // not sure if leaving it uninitialized
would cause problems
+ }
+
// Check whether it has been canceled by the user
if (canceled)
return;
@@ -195,7 +260,7 @@
taskMonitor.setStatus("Calling native code: Partition: " +
part.getPartitionNumber());
// Do Layout
- layout(x,y, part, mapping);
+ layout(x,y, part, mapping, weights);
// Check whether it has been canceled by the user
if (canceled)
@@ -334,7 +399,8 @@
* This function loads a partition into igraph
*
*/
- public static HashMap<Integer,Integer> loadGraphPartition(LayoutPartition
part, boolean selectedOnly){
+ public static HashMap<Integer,Integer> loadGraphPartition(LayoutPartition
part,
+ boolean
selectedOnly){
CyLogger logger = CyLogger.getLogger(AbstractIgraphLayout.class);
@@ -420,5 +486,44 @@
}
}
+
+ // Calculate edge weights
+ double[] calculateWeights(LayoutPartition part) {
+ part.calculateEdgeWeights();
+
+ // Write edge weight in an array
+ double[] edgeWeights = new double[part.edgeCount()];
+ int i = 0;
+
+ Iterator<LayoutEdge> it = part.getEdgeList().iterator();
+
+ if (selectedOnly) {
+ while (it.hasNext()) {
+ LayoutEdge e = (LayoutEdge) it.next();
+
+ LayoutNode source = e.getSource();
+ LayoutNode target = e.getTarget();
+
+ if (source.isLocked() || target.isLocked())
+ continue;
+
+ edgeWeights[i] = e.getWeight();
+ i++;
+ }
+ } else {
+ while (it.hasNext()) {
+ LayoutEdge e = (LayoutEdge) it.next();
+
+ LayoutNode source = e.getSource();
+ LayoutNode target = e.getTarget();
+
+ edgeWeights[i] = e.getWeight();
+ i++;
+ }
+ }
+
+ return edgeWeights;
+ }
+
}
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/CircleLayout.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/CircleLayout.java
2011-07-09 06:02:08 UTC (rev 26128)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/CircleLayout.java
2011-07-09 17:04:17 UTC (rev 26129)
@@ -42,7 +42,8 @@
public int layout(double[] x,
double[] y,
LayoutPartition part,
- HashMap<Integer,Integer> mapping) {
+ HashMap<Integer,Integer> mapping,
+ double[] weights) {
// Simplify graph
IgraphInterface.simplify();
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
2011-07-09 06:02:08 UTC (rev 26128)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
2011-07-09 17:04:17 UTC (rev 26129)
@@ -34,20 +34,22 @@
public class FruchtermanReingoldLayout 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 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
- public FruchtermanReingoldLayout() {
+ public FruchtermanReingoldLayout(boolean supportEdgeWeights) {
super();
logger = CyLogger.getLogger(FruchtermanReingoldLayout.class);
+ supportWeights = supportEdgeWeights;
+
layoutProperties = new LayoutProperties(getName());
- initialize_properties();
+ this.initialize_properties();
}
/**
@@ -55,7 +57,8 @@
* 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",
@@ -98,7 +101,7 @@
* Get new values from tunables and update parameters
*/
public void updateSettings(boolean force) {
- layoutProperties.updateValues();
+ super.updateSettings(force);
// Get initialNoIterations
Tunable t1 = layoutProperties.get("iterNumber");
@@ -130,6 +133,7 @@
if ((t6 != null) && (t6.valueChanged() || force))
randomize = ((Boolean) t6.getValue()).booleanValue();
+ updateSettings(layoutProperties, force);
}
@@ -139,7 +143,8 @@
public int layout(double[] x,
double[] y,
LayoutPartition part,
- HashMap<Integer,Integer> mapping) {
+ HashMap<Integer,Integer> mapping,
+ double[] weights) {
int numNodes = mapping.size();
@@ -147,7 +152,6 @@
double maxDelta = maxDeltaCoefficient * numNodes;
double area = areaCoefficient * numNodes * numNodes;
double repulseRad = repulseRadCoefficient * area * numNodes;
- double[] weights = new double[numNodes];
// Store current node positions if necessary
if (!randomize) {
@@ -163,7 +167,7 @@
coolExp,
repulseRad,
!randomize,
- false,
+ supportWeights,
weights);
return 1;
@@ -174,7 +178,10 @@
* for this layout.
*/
public String getName() {
- return "Igraph Fruchterman-Reingold Layout";
+ if (supportWeights)
+ return "Igraph Edge-Weighted Fruchterman-Reingold Layout";
+ else
+ return "Igraph Fruchterman-Reingold Layout";
}
/**
@@ -182,7 +189,10 @@
* of the layout
*/
public String toString() {
- return "Fruchterman-Reingold Layout";
+ if (supportWeights)
+ return "Edge-Weighted Fruchterman-Reingold Layout";
+ else
+ return "Fruchterman-Reingold Layout";
}
}
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
2011-07-09 06:02:08 UTC (rev 26128)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
2011-07-09 17:04:17 UTC (rev 26129)
@@ -42,7 +42,8 @@
public int layout(double[] x,
double[] y,
LayoutPartition part,
- HashMap<Integer,Integer> mapping) {
+ HashMap<Integer,Integer> mapping,
+ double[] weights) {
// Simplify graph
IgraphInterface.simplify();
--
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.