Author: scooter
Date: 2011-01-18 11:06:16 -0800 (Tue, 18 Jan 2011)
New Revision: 23492

Modified:
   
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutEdge.java
   
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutNode.java
   
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/algorithms/force/ForceDirectedLayout.java
Log:
Provide a "discrete layout" setting for ForceDirected, and in support of that, 
make LayoutEdge and LayoutNode implement Comparable.


Modified: 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutEdge.java
===================================================================
--- 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutEdge.java
  2011-01-18 18:18:13 UTC (rev 23491)
+++ 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutEdge.java
  2011-01-18 19:06:16 UTC (rev 23492)
@@ -54,7 +54,7 @@
  * to information about the weights associated with edges, and pointers to the
  * LayoutNodes that are joined by this edge.
  */
-public class LayoutEdge {
+public class LayoutEdge implements Comparable <LayoutEdge> {
        // instance variables
        private LayoutNode v1;
        private LayoutNode v2;
@@ -181,6 +181,15 @@
                return this.edge;
        }
 
+  /**
+   * Return the edge's identifier.
+   *
+   * @return        String containing the edge's identifier
+   */
+  public String getIdentifier() {
+               return this.edge.getIdentifier();
+       }
+
        /**
         * Return a string representation for this LayoutEdge.
         *
@@ -219,4 +228,16 @@
                return "normal";
            }
        }
+
+       /**
+        * Returns the natural order of two LayoutEdges determined by comparing 
the edge
+        * identifiers.
+        *
+        * @param o2 the LayoutEdge we're comparing ourselves to
+        * @return -1 if this is less than o2, 0 if they are equal, and 1 if 
this is greater than o2
+        */
+       public int compareTo(LayoutEdge o2) {
+               return getIdentifier().compareTo(o2.getIdentifier());
+       }
+
 }

Modified: 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutNode.java
===================================================================
--- 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutNode.java
  2011-01-18 18:18:13 UTC (rev 23491)
+++ 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/LayoutNode.java
  2011-01-18 19:06:16 UTC (rev 23492)
@@ -77,7 +77,7 @@
 /**
 
  */
-public abstract class LayoutNode {
+public abstract class LayoutNode implements Comparable<LayoutNode> {
 
     // static (class) variables
     static final double EPSILON = 0.0000001D;
@@ -400,5 +400,16 @@
        return this.index;
     }
 
+               /**
+                * Returns the natural order of two LayoutNodes determined by 
comparing the node
+                * identifiers.
+                *
+                * @param o2 the LayoutNode we're comparing ourselves to
+                * @return -1 if this is less than o2, 0 if they are equal, and 
1 if this is greater than o2
+                */
+               public int compareTo(LayoutNode o2) {
+                       return getIdentifier().compareTo(o2.getIdentifier());
+               } 
 
-}
\ No newline at end of file
+
+}

Modified: 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/algorithms/force/ForceDirectedLayout.java
===================================================================
--- 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/algorithms/force/ForceDirectedLayout.java
        2011-01-18 18:18:13 UTC (rev 23491)
+++ 
cytoscape/trunk/coreplugins/AutomaticLayout/src/main/java/csplugins/layout/algorithms/force/ForceDirectedLayout.java
        2011-01-18 19:06:16 UTC (rev 23492)
@@ -73,6 +73,7 @@
        double defaultSpringCoefficient = 1e-4f;
        double defaultSpringLength = 50;
        double defaultNodeMass = 3.0;
+       boolean discrete = false;
 
        /**
         * Value to set for doing unweighted layouts
@@ -135,8 +136,16 @@
 
                forceItems.clear();
 
+               List<LayoutNode> nodeList = part.getNodeList();
+               List<LayoutEdge> edgeList = part.getEdgeList();
+
+               if (discrete) {
+                       Collections.sort(nodeList);
+                       Collections.sort(edgeList);
+               }
+
                // initialize nodes
-               for (LayoutNode ln: part.getNodeList()) {
+               for (LayoutNode ln: nodeList) {
                        if ( !forceItems.containsKey(ln) )
                                forceItems.put(ln, new ForceItem());
                        ForceItem fitem = forceItems.get(ln); 
@@ -147,7 +156,7 @@
                }
                
                // initialize edges
-               for (LayoutEdge e: part.getEdgeList()) {
+               for (LayoutEdge e: edgeList) {
                        LayoutNode n1 = e.getSource();
                        ForceItem f1 = forceItems.get(n1); 
                        LayoutNode n2 = e.getTarget();
@@ -276,7 +285,7 @@
                edgeWeighter.getWeightTunables(layoutProperties, 
getInitialAttributeList());
 
                layoutProperties.add(new Tunable("force_alg_settings", 
"Algorithm settings",
-                                                Tunable.GROUP, new 
Integer(5)));
+                                                Tunable.GROUP, new 
Integer(6)));
 
                layoutProperties.add(new Tunable("defaultSpringCoefficient", 
"Default Spring Coefficient",
                                                 Tunable.DOUBLE, new 
Double(defaultSpringCoefficient)));
@@ -290,6 +299,9 @@
                layoutProperties.add(new Tunable("numIterations", "Number of 
Iterations",
                                                 Tunable.INTEGER, new 
Integer(numIterations)));
 
+               layoutProperties.add(new Tunable("discrete", "Force discrete 
layouts (slower)",
+                                                Tunable.BOOLEAN, new 
Boolean(false)));
+
 //             layoutProperties.add(new Tunable("integrator", "Integration 
algorithm to use",
 //                                              Tunable.LIST, new Integer(0), 
 //                                              (Object) integratorArray, 
(Object) null, 0));
@@ -353,7 +365,14 @@
                }
 
 
+               t = layoutProperties.get("discrete");
+               if ((t != null) && (t.valueChanged() || force)) {
+                       discrete = ((Boolean) t.getValue()).booleanValue();
+                       if (t.valueChanged())
+                               layoutProperties.setProperty(t.getName(), 
t.getValue().toString());
+               }
 
+
                integrator = new RungeKuttaIntegrator();
                /*
                t = layoutProperties.get("integrator");

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