keep a copy of my current dissertation example to investiaget further and another...
[IRC.git] / Robust / src / Benchmarks / oooJava / dissertation-example-investigate / OoOJavaExample.java
1 //import java.io.*;
2 //import java.util.*;
3
4 public class OoOJavaExample {
5   
6   public static void main( String[] args ) {
7     OoOJavaExample ex = new OoOJavaExample( 1234, 100, 0.05f, 15 );
8     ex.runExample();
9   }
10
11   private HashSet roots;
12   //private HashMap bin2set;
13
14   public OoOJavaExample( int seed, int numTrees, float probNull, int maxTreeDepth ) {
15     Random random = new Random( seed );
16
17     roots = new HashSet();
18     for( int i = 0; i < numTrees; ++i ) {
19       roots.add( makeNewTree( random, probNull, maxTreeDepth ) );
20     }
21
22     //bin2set = new HashMap();
23   }
24
25   private TreeNode makeNewTree( Random random, float probNull, int maxTreeDepth ) {
26
27     TreeNode root = new TreeNode( random.nextFloat() );
28
29     TreeNode left = buildSubTree( random, probNull, maxTreeDepth, 0 ); 
30     root.left = left;
31     
32     TreeNode right = buildSubTree( random, probNull, maxTreeDepth, 0 ); 
33     root.right = right;
34     
35     return root;
36   }
37
38
39   private TreeNode buildSubTree( Random random, float probNull, int maxTreeDepth, int depth ) {
40
41     TreeNode node = new TreeNode( random.nextFloat() );
42     if( depth > maxTreeDepth || random.nextFloat() < probNull ) {
43       genreach retearly;
44       return node;
45     }
46
47     TreeNode left = buildSubTree( random, probNull, maxTreeDepth, depth + 1 );
48     node.left = left;
49     
50     TreeNode right = buildSubTree( random, probNull, maxTreeDepth, depth + 1 );
51     node.right = right;
52
53     genreach retlate;
54     return node;
55   }
56
57   public void runExample() {
58     Iterator itr = roots.iterator();
59
60     int zzz = 0;
61       
62     while( itr.hasNext() ) {
63       TreeNode root = (TreeNode) itr.next();
64   
65       sese par {
66         int weightBin = (int) root.computeTreeWeight();
67       }
68       sese seq {
69         zzz += weightBin;
70         /*
71         HashSet set = (HashSet)bin2set.get( weightBin );
72         if( set == null ) {
73           set = new HashSet();
74           bin2set.put( weightBin, set );
75         }
76         set.add( root );
77         */
78       }
79     }
80
81     System.out.println( "Num weight bins: "+zzz ); //bin2set.size() );
82   }
83 }