1 24 25 26 30 31 32 33 34 35 package org.objectweb.clif.analyser; 36 37 import java.io.*; 38 import java.util.*; 39 import java.lang.Math ; 40 import org.objectweb.clif.analyser.lib.gui.GuiPanelAutomaticAnalyser; 41 42 43 44 public class Brain 45 { 46 private int minth; 47 private int maxti; 48 private String [][] testmachine; 49 private String [] tabinterval; 50 private String [] tabthread; 51 private Rule rule; 52 private Neuronous[] neuronous = new Neuronous[100]; 53 54 55 public Brain(Rule rule,int minth,int maxti,String [][] testmachine) 56 { 57 this.minth=minth; 58 this.maxti=maxti; 59 this.testmachine=testmachine; 60 this.rule = rule; 61 for(int i=0;rule.hyp[i] != null;i++) this.neuronous[i] = new Neuronous(rule.hyp[i]); 62 tabthread = new String [15]; 63 tabinterval = new String [15]; 64 tabthread[0] = "-1"; 65 tabthread[1] = "1"; 66 tabthread[2] = ""+minth; 67 tabinterval[0] = "0-" + maxti; 68 } 69 72 public void start() 73 { 74 System.out.println("Brain "+rule.getName() +" started"); 75 for(int i=0; neuronous[i] != null;i++) neuronous[i].start(); 76 } 77 78 79 82 public void stop() 83 { 84 System.out.println("Brain "+rule.getName() +" stopped"); 85 for(int i=0; neuronous[i] != null;i++) neuronous[i].stop(); 86 } 87 88 89 90 91 92 93 class Neuronous implements Runnable 94 { 95 private Thread thisThread; 96 private volatile Thread monitor; 97 private Hypothesis hyp; 98 private String varname; 99 private String vartest; 100 private String varmachine; 101 private int varthread; 102 private String varinterval; 103 private long debut; 104 private long fin; 105 private View vue; 106 private StringTokenizer st; 107 108 public Neuronous(Hypothesis hyp) 109 { 110 this.hyp = hyp; 111 } 112 113 114 117 public void start() 118 { 119 monitor = new Thread (this); 120 monitor.start(); 121 } 122 123 124 127 public void stop() 128 { 129 monitor = null; 130 } 131 132 133 public void run() 134 { 135 int i=0; 136 thisThread = Thread.currentThread(); 137 138 while (monitor == thisThread) { 139 try { 140 Thread.sleep(10000); 141 } catch (InterruptedException e) {} 142 143 144 if(hyp.getTest().startsWith("VAR")){ 145 for(int a=0;testmachine[a][0]!=null;a++){ 146 vartest = testmachine[a][0]; 147 if(hyp.getMachine().startsWith("VAR")){ 148 for(int b=1;testmachine[a][b]!=null;b++){ 149 varmachine = testmachine[a][b]; 150 creer(); 151 } 152 }else{ 153 varmachine = hyp.getMachine(); 154 creer(); 155 } 156 } 157 }else{ 158 vartest = hyp.getTest(); 159 int index; 160 for(index=0;!(testmachine[index][0].equals(vartest));index++); 161 if(hyp.getTest().startsWith("VAR")){ 162 for(int a=1;testmachine[index][a]!=null;a++){ 163 varmachine = testmachine[index][a]; 164 creer(); 165 } 166 }else{ 167 varmachine = hyp.getMachine(); 168 creer(); 169 } 170 } 171 172 173 } } 176 177 178 public void creer() 179 { 180 181 if(hyp.getThread().startsWith("VAR")){ 182 for(int a=0;tabthread[a]!=null;a++){ 183 varthread = (new Integer (tabthread[a])).intValue(); 184 if(hyp.getInterval().startsWith("VAR")){ 185 for(int b=0;tabinterval[b]!=null;b++){ 186 varinterval = tabinterval[b]; 187 st = new StringTokenizer(varinterval,"-"); 188 debut = (new Long (st.nextToken())).longValue(); 189 fin = (new Long (st.nextToken())).longValue(); 190 generer(); 191 } 192 }else{ 193 varinterval = hyp.getInterval(); 194 st = new StringTokenizer(varinterval,"-"); 195 debut = (new Long (st.nextToken())).longValue(); 196 fin = (new Long (st.nextToken())).longValue(); 197 generer(); 198 } 199 } 200 }else{ 201 varthread = (new Integer (hyp.getThread())).intValue(); 202 if(hyp.getInterval().startsWith("VAR")){ 203 for(int a=0;tabinterval[a]!=null;a++){ 204 varinterval = tabinterval[a]; 205 st = new StringTokenizer(varinterval,"-"); 206 debut = (new Long (st.nextToken())).longValue(); 207 fin = (new Long (st.nextToken())).longValue(); 208 generer(); 209 } 210 }else{ 211 varinterval = hyp.getInterval(); 212 st = new StringTokenizer(varinterval,"-"); 213 debut = (new Long (st.nextToken())).longValue(); 214 fin = (new Long (st.nextToken())).longValue(); 215 generer(); 216 } 217 } 218 } 219 220 221 222 public void generer() 223 { 224 varname = "auto_"+vartest+"_"+varmachine+"_"+varthread+"_"+ hyp.getX()+"_"+hyp.getY()+"_"+debut+"_"+fin; 225 View vue = new View(varname,vartest,varmachine,varthread,"hyp.getX()","hyp.getY()",debut,fin); 226 if(hyp.getFonction()==0) Fonction.fonctionMax(vue); 227 if(hyp.getFonction()==1) Fonction.fonctionMin(vue); 228 if(hyp.getFonction()==2) Fonction.fonctionMoyenne(vue); 229 if(hyp.getFonction()==3) Fonction.fonctionEcart(vue); 230 if(hyp.getFonction()==4) Fonction.fonctionPente(vue); 231 } 232 233 234 235 236 } 237 238 239 } 240 | Popular Tags |