Author: ruschein
Date: 2010-01-15 10:43:21 -0800 (Fri, 15 Jan 2010)
New Revision: 18926
Added:
coreplugins/trunk/AutomaticLayout/src/prefuse/util/force/BackwardEulerIntegrator.java
Modified:
coreplugins/trunk/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
Log:
Restored the original "Euler" integrator and added a new "Backward Euler"
integrator.
Modified:
coreplugins/trunk/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
===================================================================
---
coreplugins/trunk/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
2010-01-15 17:57:42 UTC (rev 18925)
+++
coreplugins/trunk/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
2010-01-15 18:43:21 UTC (rev 18926)
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2007, The Cytoscape Consortium (www.cytoscape.org)
The Cytoscape Consortium is:
- Institute for Systems Biology
@@ -79,6 +79,11 @@
*/
public static final String UNWEIGHTEDATTRIBUTE = "(unweighted)";
+ /**
+ * Integrators
+ */
+ String[] integratorArray = {"Runge-Kutta", "Euler", "Backward Euler"};
+
private boolean supportWeights = true;
private LayoutProperties layoutProperties;
Map<LayoutNode,ForceItem> forceItems;
@@ -280,6 +285,10 @@
layoutProperties.add(new Tunable("numIterations", "Number of
Iterations",
Tunable.INTEGER, new
Integer(numIterations)));
+ layoutProperties.add(new Tunable("integrator", "Integration
algorithm to use",
+ Tunable.LIST, new Integer(0),
+ (Object) integratorArray,
(Object) null, 0));
+
// We've now set all of our tunables, so we can read the
property
// file now and adjust as appropriate
layoutProperties.initializeProperties();
@@ -338,8 +347,20 @@
layoutProperties.setProperty(t.getName(),
t.getValue().toString());
}
- integrator = new RungeKuttaIntegrator();
- m_fsim.setIntegrator(integrator);
+ t = layoutProperties.get("integrator");
+ if ((t != null) && (t.valueChanged() || force)) {
+ if (t.valueChanged())
+ layoutProperties.setProperty(t.getName(),
t.getValue().toString());
+ if (((Integer) t.getValue()).intValue() == 0)
+ integrator = new RungeKuttaIntegrator();
+ else if (((Integer) t.getValue()).intValue() == 1)
+ integrator = new EulerIntegrator();
+ else if (((Integer) t.getValue()).intValue() == 2)
+ integrator = new BackwardEulerIntegrator();
+ else
+ return;
+ m_fsim.setIntegrator(integrator);
+ }
edgeWeighter.updateSettings(layoutProperties, force);
}
Copied:
coreplugins/trunk/AutomaticLayout/src/prefuse/util/force/BackwardEulerIntegrator.java
(from rev 18863,
coreplugins/trunk/AutomaticLayout/src/prefuse/util/force/EulerIntegrator.java)
===================================================================
---
coreplugins/trunk/AutomaticLayout/src/prefuse/util/force/BackwardEulerIntegrator.java
(rev 0)
+++
coreplugins/trunk/AutomaticLayout/src/prefuse/util/force/BackwardEulerIntegrator.java
2010-01-15 18:43:21 UTC (rev 18926)
@@ -0,0 +1,42 @@
+/**
+ * @author ruschein
+ */
+package prefuse.util.force;
+
+import java.util.Iterator;
+
+/**
+ * Updates velocity and position data using the Backward Euler Method. This is
the
+ * simple and fast method, but is somewhat inaccurate and less smooth
+ * than more costly approaches.
+ *
+ * @author Johannes Ruscheinski
+ * @see RungeKuttaIntegrator
+ * @see EulerIntegrator
+ */
+public class BackwardEulerIntegrator implements Integrator {
+
+ /**
+ * @see
prefuse.util.force.Integrator#integrate(prefuse.util.force.ForceSimulator, long)
+ */
+ public void integrate(final ForceSimulator sim, final long timestep) {
+ float speedLimit = sim.getSpeedLimit();
+ Iterator iter = sim.getItems();
+ while (iter.hasNext()) {
+ ForceItem item = (ForceItem)iter.next();
+ float coeff = timestep / item.mass;
+ item.velocity[0] += coeff * item.force[0];
+ item.velocity[1] += coeff * item.force[1];
+ item.location[0] += timestep * item.velocity[0];
+ item.location[1] += timestep * item.velocity[1];
+ float vx = item.velocity[0];
+ float vy = item.velocity[1];
+ float v = (float)Math.sqrt(vx *vx + vy * vy);
+ if ( v > speedLimit ) {
+ item.velocity[0] = speedLimit * vx / v;
+ item.velocity[1] = speedLimit * vy / v;
+ }
+ }
+ }
+
+} // end of class EulerIntegrator
--
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.