KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > analyser > DecisionTree


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 */

24
25
26 /**
27  *
28  * @author Damien Croizer
29  */

30
31 package org.objectweb.clif.analyser;
32
33 import java.io.*;
34 import java.util.*;
35 import java.lang.Math JavaDoc;
36
37
38 //this class is used for the storage of the data generated by the application of a statistic
39
//function to a view of the archive.clif
40
public class DecisionTree
41 {
42     
43     protected BrancheTest[] brancheTest;
44  
45
46     //the root of the decision tree contain 10 test branch at max
47
public DecisionTree()
48     {
49     this.brancheTest = new BrancheTest[10];
50     }
51     
52
53     public void remplirArbre(String JavaDoc test, String JavaDoc machine, int thread, int X, int Y, String JavaDoc interval, int fonction, float result)
54     {
55     int i;
56     for(i=0; brancheTest[i] != null;i++)
57         if(brancheTest[i].getName().equals(test)){
58         brancheTest[i].update(machine,thread,X,Y,interval,fonction,result);
59         break;
60         }
61     if(brancheTest[i] == null) brancheTest[i] = new BrancheTest(test,machine,thread,X,Y,interval,fonction,result);
62     
63     }
64
65     public void printArbre()
66     {
67     int a,b,c,d,e,f,g;
68     float resultat;
69     String JavaDoc resulta,resultb,resultc,resultd,resulte,resultf,resultg;
70     for(a=0;brancheTest[a] != null;a++)
71         {
72         resulta = brancheTest[a].getName();
73         for(b=0;brancheTest[a].brancheMachine[b] != null;b++)
74             {
75             resultb = resulta + "/" +brancheTest[a].brancheMachine[b].getName();
76             for(c=0;brancheTest[a].brancheMachine[b].brancheThread[c] != null;c++)
77                 {
78                 resultc = resultb +"/"+brancheTest[a].brancheMachine[b].brancheThread[c].getName();
79                 for(d=0;brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d] != null;d++)
80                     {
81                     resultd = resultc + "/" +brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].getName();
82                     for(e=0;brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e] != null;e++)
83                         {
84                         resulte = resultd + "/" +brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e].getName();
85                         for(f=0;brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e].brancheInterval[f] != null;f++)
86                             {
87                             resultf = resulte + "/" +brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e].brancheInterval[f].getName();
88                             for(g=0;brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e].brancheInterval[f].brancheFonction[g] != null;g++)
89                                 {
90                                 resultg = resultf + "/" +brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e].brancheInterval[f].brancheFonction[g].getName();
91                                 resultat = brancheTest[a].brancheMachine[b].brancheThread[c].brancheX[d].brancheY[e].brancheInterval[f].brancheFonction[g].getResult();
92                                 System.out.println(resultg+"_**_"+resultat);
93                                 }
94                             }
95                         }
96                     }
97                 }
98             }
99         }
100     
101     System.out.println("*******************");
102     }
103
104
105
106     //*************Inner class ***************
107

108     class BrancheTest
109     {
110     private String JavaDoc name;
111     protected BrancheMachine[] brancheMachine;
112
113
114     //each test branch can contain 10 blade branch at max
115
public BrancheTest(String JavaDoc test, String JavaDoc machine, int thread, int X, int Y, String JavaDoc interval, int fonction, float result)
116     {
117         this.name=test;
118         this.brancheMachine = new BrancheMachine[10];
119         brancheMachine[0] = new BrancheMachine(machine,thread,X,Y,interval,fonction,result);
120
121     }
122
123     public void update(String JavaDoc machine, int thread, int X, int Y, String JavaDoc interval, int fonction, float result)
124     {
125     int i;
126     for(i=0; brancheMachine[i] != null;i++)
127         if(brancheMachine[i].getName().equals(machine)){
128         brancheMachine[i].update(thread,X,Y,interval,fonction,result);
129         break;
130         }
131         if(brancheMachine[i] == null) brancheMachine[i] = new BrancheMachine(machine,thread,X,Y,interval,fonction,result);
132     
133     }
134
135
136     public String JavaDoc getName(){ return this.name;}
137     }
138     
139
140      class BrancheMachine
141     {
142     private String JavaDoc name;
143     protected BrancheThread[] brancheThread;
144
145
146     //each blade branch contain 10 theads branch at max
147
public BrancheMachine(String JavaDoc machine,int thread,int X, int Y, String JavaDoc interval, int fonction, float result)
148     {
149         this.name=machine;
150         this.brancheThread = new BrancheThread[10];
151         brancheThread[0] =new BrancheThread(thread, X, Y, interval, fonction,result);
152
153     }
154
155     public void update(int thread, int X, int Y, String JavaDoc interval, int fonction, float result)
156     {
157     int i;
158     for(i=0; brancheThread[i] != null;i++)
159         if(brancheThread[i].getName()==thread){
160         brancheThread[i].update(X,Y,interval,fonction,result);
161         break;
162         }
163         if(brancheThread[i] == null) brancheThread[i] = new BrancheThread(thread,X,Y,interval,fonction,result);
164     
165     }
166
167     public String JavaDoc getName(){ return this.name;}
168     }
169   
170   
171    class BrancheThread
172     {
173     private int name;
174     protected BrancheX[] brancheX;
175
176
177     //each thread branch contain at max 10 X branch
178
public BrancheThread(int thread,int X, int Y, String JavaDoc interval, int fonction, float result)
179     {
180         this.name=thread;
181         this.brancheX = new BrancheX[10];
182         brancheX[0] =new BrancheX(X,Y,interval,fonction,result);
183
184     }
185
186     public void update(int X, int Y, String JavaDoc interval, int fonction, float result)
187     {
188     int i;
189     for(i=0; brancheX[i] != null;i++)
190         if(brancheX[i].getName()==X){
191         brancheX[i].update(Y,interval,fonction,result);
192         break;
193         }
194         if(brancheX[i] == null) brancheX[i] = new BrancheX(X,Y,interval,fonction,result);
195     
196     }
197
198     public int getName(){ return this.name;}
199     }
200
201
202
203    class BrancheX
204     {
205     private int name;
206     protected BrancheY[] brancheY;
207
208
209     //each X branch contain at max 10 Y branch
210
public BrancheX(int X, int Y, String JavaDoc interval, int fonction, float result)
211     {
212         this.name=X;
213         this.brancheY = new BrancheY[10];
214         brancheY[0] =new BrancheY(Y,interval,fonction,result);
215
216     }
217
218     public void update(int Y, String JavaDoc interval, int fonction, float result)
219     {
220     int i;
221     for(i=0; brancheY[i] != null;i++)
222         if(brancheY[i].getName()==Y){
223         brancheY[i].update(interval,fonction,result);
224         break;
225         }
226         if(brancheY[i] == null) brancheY[i] = new BrancheY(Y,interval,fonction,result);
227     
228     }
229
230     public int getName(){ return this.name;}
231     }
232
233
234
235
236   class BrancheY
237     {
238     private int name;
239     protected BrancheInterval[] brancheInterval;
240
241
242     //each Y branch contain at max 10 Interval branch
243

244     public BrancheY(int Y, String JavaDoc interval, int fonction, float result)
245     {
246         this.name=Y;
247         this.brancheInterval = new BrancheInterval[10];
248         brancheInterval[0] =new BrancheInterval(interval,fonction,result);
249
250     }
251
252     public void update(String JavaDoc interval, int fonction, float result)
253     {
254     int i;
255     for(i=0; brancheInterval[i] != null;i++)
256         if(brancheInterval[i].getName().equals(interval)){
257         brancheInterval[i].update(fonction,result);
258         break;
259         }
260         if(brancheInterval[i] == null) brancheInterval[i] = new BrancheInterval(interval,fonction,result);
261     
262     }
263
264     public int getName(){ return this.name;}
265     }
266
267
268
269
270
271   class BrancheInterval
272     {
273     private String JavaDoc name;
274     protected BrancheFonction[] brancheFonction;
275
276
277
278     //each Interval branch contain at max 10 function branch
279

280     public BrancheInterval(String JavaDoc interval, int fonction, float result)
281     {
282         this.name=interval;
283         this.brancheFonction = new BrancheFonction[10];
284         brancheFonction[0] =new BrancheFonction(fonction,result);
285
286     }
287
288     public void update(int fonction, float result)
289     {
290         int i;
291         for(i=0; brancheFonction[i] != null;i++);
292         brancheFonction[i] = new BrancheFonction(fonction,result);
293         
294     }
295     public String JavaDoc getName(){ return this.name;}
296   }
297
298
299  class BrancheFonction
300     {
301     private int name;
302     protected float result;
303
304     // a function branch are the lieves of the tree and get the result of the application of a function
305
//on a view generated from the archive.clif file
306
public BrancheFonction(int fonction,float result)
307     {
308         this.name = fonction;
309         this.result = result;
310     }
311     
312     public float getResult(){ return this.result;}
313     public int getName(){ return this.name;}
314
315
316     }
317
318
319 }
320
Popular Tags