witam,
znowu mam podobny problem. znowu warunek przepuszcza wartosc, tylko tym razem zrobilem, jak kolega Krzysiek pokazal, ale mimo to przepuszczne sa wartosci ktore byc nie powinny.
zaczynamy od tego ze mam historie po jakich node doszedlem od req_from do req_to. wszystko jest zapisane w history_array. teraz, wg tego co jest tam zapisane, ide do node+1 szukam indexu w nodes array, po znalezieniu ide do wawvlength array i zbieram dostepne wavelengths i pakuje do avaliable_vector,
moze na przykladzie, wiec jesli w history array mam zapisane 0 1 3 5, ide do nodes array[0][i] i szukam pozycji 1. po znalezieniu, ide do wawalngth_array[0][index 1] [j] i zbieram dostepne i nie dostepne wavelengths. i teraz problem polega na tym ze od czasu do czasu, przy duzych ilosciach nodes, program do avaliable wsadza wartosci ktore juz istnieja w notAvaliable_vecor.
ja wiem ze to troche zagmatae co napisalem, ale moze ktos znajdzie chwile zeby to rozgryzc. kod metody jest tu:
public void random_order(int req_to){
System.out.println("Random order");
//clear everything
avaliable_Vector.clear();
notAvaliable_Vector.clear();
int position=0, wavelength;
int tempPosition=0;
//if history contains node 0 1 2, go to node 0, find position of 1, assume index=5
//then go to wavelngths array fd i=0, sd i=5 and add all wavelengths to correct vectors.
for(int i=1; i<history_Array[req_to].length; i++){
if(history_Array[req_to][i] != -1){ //go to history array and find first element
for(int j=0; j<Nodes_Array[history_Array[req_to][position]].length; j++){ //find index of "second" element from history array
if(Nodes_Array[history_Array[req_to][position]][j]==history_Array[req_to][position+1]){
tempPosition=j;
break;
}
}
for(int k=0; k<wavelength_Array[history_Array[req_to][position]][tempPosition].length; k++){
if(wavelength_Array[history_Array[req_to][position]][tempPosition][k]==0){
//add the avaliable wavelengths to the avaliable array
if(!avaliable_Vector.contains(k) && !notAvaliable_Vector.contains(k)){
avaliable_Vector.add(k);
System.out.println("k = "+k);
}
}
else if(wavelength_Array[history_Array[req_to][position]][tempPosition][k]==1){ //add all used wavelengths to vector
if(!notAvaliable_Vector.contains(k)){
notAvaliable_Vector.add(k);
if(avaliable_Vector.contains(k)){ //remove the wavelengths used by other path
avaliable_Vector.remove(k);
}
}
}
}
if (avaliable_Vector.size()==0){ //if no wavelength avaliable for any of the paths
System.out.println("No avaliable wavelength");
return;
}
position++;
}
// if (avaliable_Vector.size()==0){ //if no wavelength avaliable for any of the paths
// System.out.println("No avaliable wavelength");
// return;
// }
}
Random wav = new Random(); //generate the avaliable waveleght from avaliable
do{
wavelength=wav.nextInt(wave_amount);
}
while(notAvaliable_Vector.contains(wavelength));
System.out.println("Selected wave = "+wavelength);
wavelength_asigment(req_to, wavelength);
established++; //raise the established connection
}
a caly program mozna pobrac stad: http://www.4shared.com/file/119854869/10e825ce/Network_project.html
zeby wywalil blad, i zeby zobaczyc co sie tam dziej w debug mode, najlepiej podac nastepujace wartosci:
numbero of nodes 10,
maximum number of conections 10
number of request 45
potem wybrac fixed routing 1
a potem random order 4
przy mniejszej liczbie nodes, generalnie jest ok.
z gory dzieki.
pozdrawiam