1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
|
import java.util.*;
import org.jdom2.Element;
import org.jdom2.JDOMException;
public class StateGraph_Construction {
public static int n=226;//MatricePreT.nbLigneGlob;
public static int m=117;//MatricePreT.nbColonneGlobT;
public static int k=52;//MatricePreT.nbColonneGlobTCP;
public static int recup;
public static ArrayList<Integer> recupTfTotalT =new ArrayList<Integer>();
public static Vector<Integer> FTs = new Vector<Integer>() ;
public static Vector<Integer> FTstcp = new Vector<Integer>() ;
public static Vector<Integer> soustraction(Vector<Integer> vecteur1,Vector<Integer> vecteur2 )
{Vector<Integer> vecteurrecup = new Vector<Integer>();
for (int i=0; i<vecteur1.size()&& i<vecteur2.size() ; i++)
{
int valeur = vecteur1.get(i)- vecteur2.get(i);
vecteurrecup.add(valeur);
}
return vecteurrecup;
}
public static Vector<Integer> addition(Vector<Integer> vecteur1,Vector<Integer> vecteur2 )
{Vector<Integer> vecteurrecup = new Vector<Integer>();
for (int i=0; i<vecteur1.size()&& i<vecteur2.size() ; i++)
{
int valeur = vecteur1.get(i)+ vecteur2.get(i);
vecteurrecup.add(valeur);
}
return vecteurrecup;
}
public static int Comparaison(Vector<Integer> vecteurMarquage,Vector<Integer> vecteur2 )
{
for (int i=0; i<vecteurMarquage.size()&& i<vecteur2.size() ; i++)
{
if (vecteurMarquage.get(i) <= vecteur2.get(i));
return 0;
}
return 1;
}
public static int getIndexTlocal (String Nom_T)
{ int index=-1;
if(Nom_T.contains("Creation")){return index = 0;}
if(Nom_T.contains("IncremtPeriod")){return index = 1;}
if(Nom_T.contains("Reset")){return index = 2;}
if(Nom_T.contains("Activation")){return index = 3;}
if(Nom_T.contains("Execution")){return index = 4;}
if(Nom_T.contains("Incrementing ")){return index = 5;}
if(Nom_T.contains("Receiving" )){return index = 6;}
if(Nom_T.contains("Releasing" )){return index = 7;}
if(Nom_T.contains("Sending" )){return index = 8;}
return index;
}
public static int getIndexTFromString (String Nom_T)
{
int i=-1;
if (Nom_T.contains("Creation"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posC = Nom_T.indexOf("C") ;
sub = Nom_T.substring(posT+1,posC) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("IncremtPeriod"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posI = Nom_T.indexOf("I") ;
sub = Nom_T.substring(posT+1,posI) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Reset"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posR = Nom_T.indexOf("R") ;
sub = Nom_T.substring(posT+1,posR) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Activation"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posA = Nom_T.indexOf("A") ;
sub = Nom_T.substring(posT+1,posA) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Execution"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posE = Nom_T.indexOf("E") ;
sub = Nom_T.substring(posT+1,posE) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Incrementing"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posI = Nom_T.indexOf("I") ;
sub = Nom_T.substring(posT+1,posI) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Receiving"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posR = Nom_T.indexOf("R") ;
sub = Nom_T.substring(posT+1,posR) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Releasing"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posR = Nom_T.indexOf("R") ;
sub = Nom_T.substring(posT+1,posR) ;
return i = Integer.parseInt(sub) ;
}
if (Nom_T.contains("Sending"))
{
String sub ="" ;
int posT = Nom_T.indexOf("T") ;
int posS = Nom_T.indexOf("S") ;
sub = Nom_T.substring(posT+1,posS) ;
return i = Integer.parseInt(sub) ;
}
return i ;
}
public static int getIndexglobal (String Nom_T)
{int i ;
i =getIndexTlocal(Nom_T)+(getIndexTFromString (Nom_T)-1)* 9 ;
return i;
}
public static ArrayList<Integer> SDtf_T()throws JDOMException, IOException
{ TestXml xml = new TestXml() ;
Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ;
ArrayList<TTP> TTPs =xml.getTransitionTTP(root);
ArrayList<TTP>listinfoTTP =xml.getTransitionTTP(root);
ArrayList<Integer> listinfoTfdy =new ArrayList<Integer>();
for (int j = 0; j < TTPs.size(); j++)
{
TTP t = new TTP();
t = (TTP) TTPs.get(j);
listinfoTTP.add(t);
listinfoTfdy.add(listinfoTTP.get(j).getTF());
}
for (int i=0;i<13;i++)
{recupTfTotalT.add(0+i*9,0);
recupTfTotalT.add(1+i*9,0);
recupTfTotalT.add(2+i*9,0);
recupTfTotalT.add(3+i*9,0);
recupTfTotalT.add(4+i*9,0);
recupTfTotalT.add(5+i*9,0);
recupTfTotalT.add(6+i*9,listinfoTfdy.get(0+i*2));
recupTfTotalT.add(7+i*9,listinfoTfdy.get(1+i*2));
recupTfTotalT.add(8+i*9,listinfoTfdy.get(26+i));
}
return recupTfTotalT ;
}
public static int tf_T(int index)
{
int tf ;
for (int i=0;i<recupTfTotalT.size();i++)
{
tf=recupTfTotalT.get(i);
recup=tf;
}
return recup;
}
public static void initialise_Hl(Vector <Integer> valeur_HL)
{for (int i=0;i<n;i++)
{
valeur_HL.add(i, 0);
}
}
public static void set_Hl(Vector <Integer> valeur_HL,int indice,int valeur)
{
for (int i=0;i<n;i++)
{
valeur_HL.set(indice, valeur);
}
}
public static int get_Hl(Vector <Integer> valeur_HL,int indice)
{
return valeur_HL.get(indice);
}
public static int CompareTF_hl(int tf,int hl )
{
if (tf >= hl)
{return 1; }
return 0;
}
public static void Firability ( Vector<Integer> FTs,Vector<Integer> FTstcp)throws JDOMException, IOException
{int [] [] matpreT = new int[n][m] ;
int [] [] matpreTCP = new int[n][k] ;
Vector<Integer> M = new Vector<Integer>(n) ;
MatricePreT.matrice_Zero( matpreT, n, m);
MatricePreT.initializepre_T( matpreT);
MatricePreTCP.matrice_Zero( matpreT, n, k);
MatricePreTCP.initializepre_TCP( matpreT);
VecteurM.Vecteur_Zero( M,n);
VecteurM.initializevecteur_T(M);
for (int i=0;i<m;i++)
{
Vector<Integer>Vect2T = MatricePreT.extraire_vecteurT( matpreT,i);
int valeurCompFTs=Comparaison(M,Vect2T);;
FTs.add(valeurCompFTs);
}
for (int i=0;i<k;i++)
{
Vector<Integer>Vect2TCP= MatricePreTCP.extraire_vecteurT( matpreTCP, i);
int valeurCompFTstcp=Comparaison(M,Vect2TCP);
FTstcp.add(valeurCompFTstcp);
}
}
public static void Firing ( Vector<Integer> FTs,Vector<Integer> FTstcp,Vector<Integer> M)throws JDOMException, IOException
{int [] [] matpreT = new int[n][m] ;
int [] [] matpreTCP = new int[n][k] ;
int [] [] matpostT = new int[n][m] ;
int [] [] matpostTCP = new int[n][k] ;
Vector<Integer>VectpreT = MatricePreT.extraire_vecteurT( matpreT,MatricePreT.getIndexglobal("T1Reset"));
Vector<Integer>VectpreTCP= MatricePreTCP.extraire_vecteurT( matpreTCP, MatricePreTCP.getIndexglobal("T13Allocation"));
Vector<Integer>VectpostT = MatricePreT.extraire_vecteurT( matpreT,MatricePreT.getIndexglobal("T1Reset"));
Vector<Integer>VectpostTCP= MatricePreTCP.extraire_vecteurT( matpreTCP, MatricePreTCP.getIndexglobal("T13Allocation"));
VecteurM.Vecteur_Zero(M, n);
VecteurM.initializevecteur_T(M);
Vector<Integer>M1T =addition ( M ,soustraction(VectpostT,VectpreT));
Vector<Integer>M1tcp =addition (M ,soustraction(VectpostTCP,VectpreTCP));
}
public static void Validity(Vector <Integer> FTs)throws JDOMException, IOException
{
int [] [] matpreT = new int[n][m] ;
Vector<Integer> M0 = new Vector<Integer>(n) ;
MatricePreT.matrice_Zero( matpreT, n, m);
MatricePreT.initializepre_T( matpreT);
Vector <Integer>valeur_Hl=new Vector <Integer>();
for (int i=0;i<m;i++)
{
Vector<Integer>Vect2T = MatricePreT.extraire_vecteurT( matpreT,i);
int valeurCompFTs=Comparaison(M0,Vect2T);;
FTs.add(valeurCompFTs);
initialise_Hl(valeur_Hl);
if (tf_T(i)==get_Hl(valeur_Hl,i))
{////////// code ?????????
}
}
}
public static int voisinage (Inarcttp inTArc1, Inarcttp inTArc2)throws JDOMException, IOException
{TestXml xml = new TestXml() ;
Element root = xml.getRoot("C:\\Users\\faten\\Desktop\\Tentative FiNALParcTool\\xmlparser\\src\\default.editeurparctool.xml") ;
ArrayList<Inarcttp> INTTP = xml.getInputArcTTP(root);
for (int j = 0; j < INTTP.size(); j++)
{
inTArc1 = (Inarcttp) INTTP.get(j) ;
j++;
inTArc2 = (Inarcttp) INTTP.get(j) ;
while(inTArc1.getWeight()!=0 &&inTArc1.getWeight()!=0)
{
if(inTArc1.getInPutArcFromPlace()==inTArc2.getInPutArcFromPlace()&&inTArc1.getInPutArcToTransitionT()!=inTArc2.getInPutArcToTransitionT())
System.out.println ("voisinage entre"+inTArc1.getInputArcFromPROC()+"et"+inTArc1.getInputArcFromPROC() );return 1;
}
} System.out.println ("voisinage entre"+inTArc1.getInputArcFromPROC()+"et"+inTArc1.getInputArcFromPROC() );return 0;
}
/*outil pour construire le programme totale à imlémenter
public static void Firing ( Vector<Integer> FTs,Vector<Integer> FTstcp,VecteurM M){}
public static void Sub(VecteurMI MI,VecteurM M){}
public static void ResetTimer(Vector<Integer> horlogeVTS){}
public static void setIncrementTimer(Vector<Integer> horlogeFTS){}
public static void StepSelection(Vector<Integer>FTstcp){}
void dPFM (Vector dFTs ,VecteurM M,VecteurMI MI ,int Hl)
{//variable local temporelle
Vector<Integer> HlVTs= new Vector<Integer>();
Vector<Integer> HlFTs= new Vector<Integer>();
Vector<Integer> FTs= new Vector<Integer>();
Vector<Integer> FTstcp= new Vector<Integer>();
dFTs == null ;
if(MatricePreT.Comparaison(M,V) || MatricePreTCP.comparaison(M,V ){
Firability (FTs,FTstcp);
FTs = TemporalTransition (dFTs);
FTstcp = CompoudTransition(dFTs);
if (FTs !=null){
VTs=Validity (FTs);
if (VTs !=null ){
Firing (VTs, M);
Sub (MI, M);
ResetTimer(Hl_VTs);}
else if (FTstcp ==null )
{setIncrementTimer(HlFTs);}
}
else if (FTstcp != null )
{
StepSelection(FTstcp);
Firing(FTs,FTstcp ,M);
Sub(MI,M);}
}
}//End dPFM
*/
public static void main(String args [])throws JDOMException, IOException{
int [] [] matpreT = new int[n][m] ;
int [] [] matpreTCP = new int[n][m] ;
Vector<Integer> M0 = new Vector<Integer>() ;
MatricePreT.matrice_Zero( matpreT, n, m);
MatricePreT.initializepre_T( matpreT);
MatricePreTCP.matrice_Zero( matpreTCP, n, m);
MatricePreTCP.initializepre_TCP(matpreTCP);
VecteurM.Vecteur_Zero(M0, n);
VecteurM.initializevecteur_T(M0);
Vector<Integer>Vect2T = MatricePreT.extraire_vecteurT( matpreT,MatricePreT.getIndexglobal("T1Creation"));
Vector<Integer>Vect2TCP= MatricePreTCP.extraire_vecteurT( matpreTCP, MatricePreTCP.getIndexglobal("T13Allocation"));
System.out.println("le vecteur de transition T1Creation:"+ Vect2T);
System.out.println("le vecteur Marquage initiale M0 :"+M0);
int a=Comparaison(M0,Vect2T);
System.out.println("le resultat de comparaison de M0 et vect2T est: "+a);
//affichage FTs,FTstcp
for (int i=0;i<m;i++)
{
int valeurCompFTs=Comparaison(M0,Vect2T);;
int valeurCompFTstcp=Comparaison(M0,Vect2TCP);
FTs.add(valeurCompFTs);
FTstcp.add(valeurCompFTstcp);
}
System.out.println("lerecupTfTotalT contient "+ SDtf_T());
int b= tf_T(getIndexglobal("T13Sending") );
System.out.println("tf de T13Sending est :"+b);
Vector <Integer> valeur_HL = new Vector <Integer>();
initialise_Hl(valeur_HL);
int x= CompareTF_hl(tf_T(getIndexglobal("T13Sending")),get_Hl(valeur_HL,getIndexglobal("T13Sending")));
System.out.println("le resultat de comparaison entre TF et Hl de T13Sending est :"+x);
System.out.println("FTs="+FTs);
System.out.println("FTstcp="+FTstcp);
Firing(FTs,FTstcp,M0);
System.out.println("M aprés firing :"+M0);
System.out.println("T1Reset: "+getIndexglobal("T1Creation"));
System.out.println(m);
}
} |