Author: jflesch
Date: 2007-08-25 19:35:04 +0000 (Sat, 25 Aug 2007)
New Revision: 14881

Modified:
   trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
   trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
Log:
Stop the optimisation process when idling enought

Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java  
2007-08-25 19:25:53 UTC (rev 14880)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java  
2007-08-25 19:35:04 UTC (rev 14881)
@@ -194,6 +194,7 @@
                Thread refresherTh = null;

                int lastStep = 4;
+               double totalKinetic = 0.0;

                for (int i = 0 ; i < Node.NMB_STEPS && !stop ; i++) {
                        int currentStep = (6 * i) / Node.NMB_STEPS;
@@ -215,15 +216,24 @@
                                }
                        }

-                       if (i%100 == 0)
+                       if (i%100 == 0) {
                                Logger.info(this, "- Step 
"+Integer.toString(i)+"/"+Node.NMB_STEPS);
+                               Logger.info(this, "- Kinetic : 
"+Double.toString(totalKinetic));
+                       }

+                       totalKinetic = 0.0;
+
                        for (Iterator it = nodes.iterator();
                             it.hasNext();) {
                                Node node = (Node)it.next();
-                               node.computeVelocity(nodes);
+                               totalKinetic += node.computeVelocity(nodes);
                        }

+                       if (totalKinetic < Node.MIN_KINETIC) {
+                               Logger.info(this, "Wow, seems optimized :)");
+                               break;
+                       }
+
                        boolean move = false;

                        for (Iterator it = nodes.iterator();

Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java  2007-08-25 
19:25:53 UTC (rev 14880)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java  2007-08-25 
19:35:04 UTC (rev 14881)
@@ -126,6 +126,7 @@
        public final static double REPULSE_LIMIT           = 10000;
        public final static double FACTOR_DECELERATION     = 1.1;
        public final static double FACTOR_INITIAL_DISTANCE = 5.0;
+       public final static double MIN_KINETIC             = 1.0; /* will stop 
if < */

        /**
         * attracted by its peers/neightbours
@@ -165,8 +166,9 @@

        /**
         * see http://en.wikipedia.org/wiki/Force-based_algorithms
+        * @return velocity
         */
-       public void computeVelocity(Vector nodeList) {
+       public double computeVelocity(Vector nodeList) {
                double netForceX = 0.0;
                double netForceY = 0.0;

@@ -220,6 +222,8 @@

                velocityX += netForceX;
                velocityY += netForceY;
+
+               return Math.sqrt( Math.pow(velocityX,2) + Math.pow(velocityY, 
2));
        }

        /**


Reply via email to