Update of /cvsroot/freenet/freenet/src/freenet/node/rt
In directory sc8-pr-cvs1:/tmp/cvs-serv29527/src/freenet/node/rt

Modified Files:
        StandardNodeEstimator.java NodeEstimator.java 
Log Message:
Added yet another graph to the PeerHandler mode OCM. This time it is a graph of actual 
routing estimation values over keyspace. The y-values displayed in the graph are 
produced by the actual routing algorithm in use.

Index: StandardNodeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/StandardNodeEstimator.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -r1.31 -r1.32
--- StandardNodeEstimator.java  12 Nov 2003 01:11:02 -0000      1.31
+++ StandardNodeEstimator.java  12 Nov 2003 15:31:17 -0000      1.32
@@ -5,17 +5,22 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.math.BigInteger;
 import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
 
 import freenet.Core;
 import freenet.Key;
 
+import freenet.node.Main;
 import freenet.node.NodeReference;
 import freenet.support.DataObjectPending;
 import freenet.support.Logger;
 import freenet.support.SimpleStringMap;
 import freenet.support.graph.Bitmap;
 import freenet.support.graph.Color;
+import freenet.support.graph.Rectangle;
 
 class StandardNodeEstimator extends NodeEstimator {
        // Apologies for the notation, but read the estimator function!
@@ -484,8 +489,6 @@
                return new MyComparableStringMap(values);
        }
        
-       
-       
        protected class StandardHTMLReportTool implements NodeEstimator.HTMLReportTool
        {
 
@@ -633,7 +636,8 @@
                /* (non-Javadoc)
                 * @see 
freenet.node.rt.NodeEstimator.HTMLReportTool#drapGraphOnImage(boolean, 
freenet.support.graph.Bitmap)
                 */
-               public void drapGraphOnImage(boolean dontClipPoints, Bitmap 
bmp,boolean drawHistoryIfPresent,Hashtable lineColors) {
+               
+               public void drapGraphOnImage(boolean dontClipPoints, Bitmap 
bmp,boolean drawHistoryIfPresent,int drawMode,Hashtable lineColors) {
                        Color c = (Color)lineColors.get(graphName(T_SUCCESS_SEARCH));
                        if(c != null)
                                
getEstimator(T_SUCCESS_SEARCH).getHTMLReportingTool().drapGraphOnImage(false, 
bmp,drawHistoryIfPresent, c, null);
@@ -646,6 +650,125 @@
                        c = (Color)lineColors.get(graphName(T_DNF));
                        if(c != null)
                                
getEstimator(T_DNF).getHTMLReportingTool().drapGraphOnImage(false, 
bmp,drawHistoryIfPresent, c, null);
+                       c = (Color)lineColors.get("combined");
+                       if(c!= null)
+                               drawCombinedGraph(bmp, drawMode, c);
+               }
+               //if 'c' == null then only the return value will be calculated but no 
graph actually rendered
+               //The width on the bitmap will still be used however
+               //TODO: Rename method
+               public lowestHighestPair drawCombinedGraph(Bitmap bmp, int drawMode, 
Color c) {
+                       LinkedList l = new LinkedList();
+                       BigInteger keyspaceLastKey = 
Key.keyspace.subtract(BigInteger.ONE);
+                       BigInteger keyspaceStepLength = 
keyspaceLastKey.divide(BigInteger.valueOf(bmp.getWidth())); //Pregenerate these values 
to save us some later calculations
+                       lowestHighestPair retval = new lowestHighestPair(); 
+                       int htl = 10;
+                       int size = 10000;
+                       RoutingTable rt = Main.origRT;
+                       if(!(rt instanceof NGRoutingTable))
+                               throw new IllegalStateException("Not using NGR");
+                       NGRoutingTable ngrt = (NGRoutingTable)rt;
+                       double pLegitDNF = ngrt.getPLegitDNF();
+                       //Prevent everyone from affecting the estimator while we 
iterate over different htls/sizes/...
+                       //A change during the iteration makes the graphs look really 
strange.
+                       synchronized (StandardNodeEstimator.this) {   
+                               switch (drawMode) {
+                                       case 0 :
+                                               {
+                                                       GraphDataSet g = 
generateGraphData(bmp.getWidth(), keyspaceStepLength, htl, size, pLegitDNF);
+                                                       g.lineCol = c;
+                                                       retval.lowest = g.lowest;
+                                                       retval.highest = g.highest;
+                                                       l.add(g);
+                                                       break;
+                                               }
+                                       case 1 :
+                                               {
+                                                       for (int i = 0; i <= 25; i = i 
+ 2) {
+                                                               GraphDataSet g = 
generateGraphData(bmp.getWidth(), keyspaceStepLength, i, size, pLegitDNF);
+                                                               g.lineCol = c;
+                                                               retval.lowest = 
Math.min(g.lowest, retval.lowest);
+                                                               retval.highest = 
Math.max(g.highest, retval.highest);
+                                                               l.addFirst(g); //Make 
sure we draw the recentmost graph last (=on top of the others)
+                                                               if(c!= null) c = 
Color.add(c, new Color(10, 10, 10)); //larger the HTL the lighter the color
+                                                       }
+                                                       break;
+                                               }
+                                       case 2 :
+                                               {
+                                                       for (int i = 1024; i <= 1024 * 
1024; i = i * 2) {
+                                                               GraphDataSet g = 
generateGraphData(bmp.getWidth(), keyspaceStepLength, htl, i, pLegitDNF);
+                                                               g.lineCol = c;
+                                                               retval.lowest = 
Math.min(g.lowest, retval.lowest);
+                                                               retval.highest = 
Math.max(g.highest, retval.highest);
+                                                               l.addFirst(g); //Make 
sure we draw the recentmost graph last (=on top of the others)
+                                                               if(c!= null) c = 
Color.add(c, new Color(10, 10, 10)); //The larger the keysize, the lighter the color
+                                                       }
+                                                       break;
+                                               }
+                               }
+                       }
+                       if(c != null)
+                       {
+                               //bmp.scaleView(new 
Rectangle(0,retval.highest,bmp.getWidth(),retval.lowest)); //this is here mostly to be 
able to handle negative estimates
+                               Iterator it = l.iterator();
+                               while(it.hasNext()){
+                                       GraphDataSet n = (GraphDataSet)it.next();
+                                       n.lowest = retval.lowest;
+                                       n.highest = retval.highest;
+                                       drapGraphOnImage(bmp,n);
+                               }
+                       }
+                       return retval;
+               }
+
+               private GraphDataSet generateGraphData(int samples,BigInteger 
keyspaceStepLength,int htl, long size,double pLegitDNF){
+                       GraphDataSet g = new GraphDataSet();
+                       g.val = new long[samples];
+
+                       BigInteger at = BigInteger.ZERO;
+                       RoutingTable rt = Main.origRT;
+                       if(!(rt instanceof NGRoutingTable))
+                               throw new IllegalStateException("Not using NGR");
+                       NGRoutingTable ngrt = (NGRoutingTable)rt;
+                       TimeEstimator e = ngrt.getGlobalEstimator();
+                       TimeEstimator rGlobal =  ngrt.getGlobalEstimator();
+                       for (int i = 0; i < samples; i++)
+                       {
+                               Key k =new Key(at);
+                               g.val[i] = 
estimate(k,htl,size,rGlobal.guessTime(k),pLegitDNF);
+                               g.lowest = Math.min(g.lowest, g.val[i]);
+                               g.highest = Math.max(g.highest, g.val[i]);
+                               at = at.add(keyspaceStepLength);
+                       }
+                       return g;
+               }
+               
+               private class GraphDataSet{
+                       long[] val;
+                       Color lineCol;
+                       long lowest=Integer.MAX_VALUE;
+                       long highest=0;
+               }
+               
+               private void drapGraphOnImage(Bitmap bmp, GraphDataSet g) {
+               
+                                       // lowest ... highest
+                                       // lowest mapped to 0
+                                       // highest mapped to height
+                                       double multiplier = ((double) bmp.getHeight() 
- 1) / ((double) (g.highest - g.lowest));
+                                       if (g.lineCol != null) {
+                                               bmp.setPenColor(g.lineCol);
+                                               int initposition = (int) ((g.val[0] - 
g.lowest) * multiplier);
+                                               initposition = bmp.getHeight() - 
(initposition + 1);
+                                               bmp.moveTo(0,initposition);
+                                               for (int i = 1; i < bmp.getWidth(); 
i++) {
+                                                       int position = (int) 
((g.val[i] - g.lowest) * multiplier);
+                                                       position = bmp.getHeight() - 
(position + 1);
+                                                       //bmp.setPixel(i, position);
+                                                       bmp.drawTo(i,position);
+                                               }
+                                       }
                }
 
                

Index: NodeEstimator.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/rt/NodeEstimator.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- NodeEstimator.java  11 Nov 2003 20:57:41 -0000      1.13
+++ NodeEstimator.java  12 Nov 2003 15:31:17 -0000      1.14
@@ -9,6 +9,7 @@
 import freenet.node.NodeReference;
 import freenet.support.DataObject;
 import freenet.support.graph.Bitmap;
+import freenet.support.graph.Color;
 
 
 abstract public class NodeEstimator implements DataObject {
@@ -78,6 +79,12 @@
        
        /** Returns a tool which can be used for generating HTML reports of this 
estimator. */ 
        abstract public NodeEstimator.HTMLReportTool getHTMLReportingTool();
+       
+       public static class lowestHighestPair{
+               public long highest = Long.MIN_VALUE;
+               public long lowest = Long.MAX_VALUE;
+       }
+       
        /** An interface which represents a tool that gives the user of the
        * NodeEstimator some help with rendering the estimator to HTML */
        public interface HTMLReportTool
@@ -94,8 +101,14 @@
                abstract public TimeEstimator getEstimator(String type);
                /**     Draws all estimator graphs on the supplied
                bitmap.  lineColors is expected to map from estimator names to Colors
-               If a color for any type of estimator is missing then the graph for 
that estimator won't be drawn to the bmp**/
-               public void drapGraphOnImage(boolean dontClipPoints, Bitmap 
bmp,boolean drawHistoryIfPresent,Hashtable lineColors);
+               If a color for any type of estimator is missing then the graph for 
that estimator won't be drawn to the bmp
+               If any of the supplied colors is a color for the 'combined' graph then 
the parameter 'drawMode' will effect the drawing of that graph:
+               drawMode == 0 -> Use common case values for all of the estimation 
parameters
+               drawMode == 1 -> Draw the graph for a couple of different HTLs, use 
common case values for all of the rest of the estimation parameters
+               drawMode == 2 -> Draw the graph for a couple of different sizes, use 
common case values for all of the rest of the estimation parameters
+               **/
+               public void drapGraphOnImage(boolean dontClipPoints, Bitmap 
bmp,boolean drawHistoryIfPresent,int drawMode,Hashtable lineColors);
+               lowestHighestPair drawCombinedGraph(Bitmap bmp, int drawMode, Color c);
        }
        /**
         * @return peak successful search time

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to