• Tidak ada hasil yang ditemukan

Lampiran 1 Program Ant Colony

N/A
N/A
Protected

Academic year: 2019

Membagikan "Lampiran 1 Program Ant Colony"

Copied!
24
0
0

Teks penuh

(1)

Lampiran 1 Program Ant Colony

import java.text.NumberFormat; import java.util.Random;

import java.util.Vector;

/*

* To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates

* and open the template in the editor. */

/** *

* @author beny saragih */

public class AntColony{

public static void main (String args []){ int space =6;

Vector vect=null; int jumlah_kanal=64; int number_cell = 17;

double []traf = new double [number_cell]; int [][] distance = new int [17][17];

(2)
(3)
(4)
(5)
(6)
(7)

distance [15] [9] = 2 ; distance [15] [10] = 2 ; distance [15] [11] = 1 ; distance [15] [12] = 0 ; distance [15] [13] = 0 ; distance [15] [14] = 0 ; distance [15] [15] = 6 ; distance [15] [16] = 2 ; distance [16] [0] = 0 ; distance [16] [1] = 0 ; distance [16] [2] = 0 ; distance [16] [3] = 0 ; distance [16] [4] = 0 ; distance [16] [5] = 0 ; distance [16] [6] = 0 ; distance [16] [7] = 0 ; distance [16] [8] = 0 ; distance [16] [9] = 1 ; distance [16] [10] = 2 ; distance [16] [11] = 2 ; distance [16] [12] = 1 ; distance [16] [13] = 0 ; distance [16] [14] = 0 ; distance [16] [15] = 2 ; distance [16] [16] = 6 ;

vect = new Vector(); for(int aa=0;aa<1;aa++){

double[] traffics = { 5, 10, 15, 20, 17, 18, 20, 6, 9, 11, 4, 6, 5, 2, 10, 3, 1, 7, 8, 23, 22, 16};

Allocation [] cell_user = new Allocation [number_cell]; //initialisasi

for (int i=0; i <number_cell ; i ++) { cell_user [i] = new Allocation (); Random r = new Random (); int index = r.nextInt(16);

cell_user[i].setTraffic(traffics [index]); // Set which cell user belongs to. cell_user[i].setCell(i);

cell_user[i].setAllocation(false); cell_user[i].setBeginner(false); if(i==0){

(8)

cell_user[i].addAdj(0);cell_user[i].addAdj(2);cell_user[i].addAdj(4);cell_user[i].a ddAdj(5);

}else if(i==2){

cell_user[i].addAdj(1);cell_user[i].addAdj(6);cell_user[i].addAdj(7); }else if(i==3){

cell_user[i].addAdj(1);cell_user[i].addAdj(4);cell_user[i].addAdj(10); }else if(i==4){

cell_user[i].addAdj(0);cell_user[i].addAdj(1);cell_user[i].addAdj(5);cell_user[i].a ddAdj(11);cell_user[i].addAdj(10);

}else if(i==5){

cell_user[i].addAdj(1);cell_user[i].addAdj(2);cell_user[i].addAdj(6);cell_user[i].a ddAdj(11);cell_user[i].addAdj(10);cell_user[i].addAdj(4);

}else if(i==6){

cell_user[i].addAdj(2);cell_user[i].addAdj(7);cell_user[i].addAdj(12);cell_user[i]. addAdj(11);cell_user[i].addAdj(5);

}else if(i==7){

cell_user[i].addAdj(6);cell_user[i].addAdj(8);cell_user[i].addAdj(13);cell_user[i]. addAdj(12);

}else if(i==8){

cell_user[i].addAdj(7);cell_user[i].addAdj(14);cell_user[i].addAdj(13); }else if(i==9){

cell_user[i].addAdj(3);cell_user[i].addAdj(4);cell_user[i].addAdj(10);cell_user[i]. addAdj(15);

}else if(i==10){

cell_user[i].addAdj(4);cell_user[i].addAdj(5);cell_user[i].addAdj(11);cell_user[i]. addAdj(16);cell_user[i].addAdj(15);cell_user[i].addAdj(9);

}else if(i==11){

cell_user[i].addAdj(5);cell_user[i].addAdj(6);cell_user[i].addAdj(12);cell_user[i]. addAdj(16);cell_user[i].addAdj(10);

}else if(i==12){

cell_user[i].addAdj(6);cell_user[i].addAdj(7);cell_user[i].addAdj(13);cell_user[i]. addAdj(11);

}else if(i==13){

cell_user[i].addAdj(7);cell_user[i].addAdj(8);cell_user[i].addAdj(14);cell_user[i]. addAdj(12);

}else if(i==14){

(9)

}else if(i==15){

cell_user[i].addAdj(9);cell_user[i].addAdj(10);cell_user[i].addAdj(16); }else if(i==16){

cell_user[i].addAdj(10);cell_user[i].addAdj(11);cell_user[i].addAdj(15); }

}

//alokasi

//Initial allocation, the biggest pheromon

//cek sorting, s menyimpan urutan besar ke kecil int s[]=Sort(cell_user);

// for(int u=0;u<s.length;u++){

// System.out.println(cell_user[s[u]].getTraffic()); // }

Vector bloking =new Vector(); for(int a=1;a<number_cell;a++){ int awal =s[0];

s[0]=s[a]; s[a]=awal;

for (int i=0;i<number_cell;i++){ int newch=0;

int count=0; int x=s[i];

//mencari chanel awal

for(int y=0;y<jumlah_kanal;y++){ //cek interferensi

if(checkInterference(cell_user,x,newch)){ newch++;

}else{ break; }

}

int z=jumlah_kanal/space+1; for(int y=0;y<jumlah_kanal;y++){ //cek interferensi

if(count<cell_user[x].getTraffic() && newch<jumlah_kanal){ cell_user[x].addChannel(newch);

count++;

newch=newch+space; }else{

cell_user[x].setBlocking(((cell_user[x].getTraffic()-count)/cell_user[x].getTraffic())*100);

break; }

(10)

}

/* if(checkInterference(cell_user, 1, 6)){ System.out.println("Interference"); }else{

System.out.println("Tidak Interference"); }*/

// boolean solution =false;

// int n = largestNumbers(cell_user); /*while(solution==false){

n = largestNumbers(cell_user); //alokasi sel awal

cell_user[n].getTraffic(); for(int i=0;i<number_cell;i++){

} }*/

//Cek kanal sel n

for(int i=0;i<number_cell;i++){

System.out.print( "Awal: "+s[a]+" Sel :"+i + " jumlah kanal: "+cell_user[i].getTraffic()+" nomor kanal :");

for(int c=0;c<cell_user[i].getChannel().size();c++){

System.out.print(" " +(int)cell_user[i].getChannel().get(c)); }

System.out.println("---"+cell_user[i].getBlocking()+"%"); }

double avBlock=0;

for(int i=0;i<number_cell;i++){

avBlock=avBlock+cell_user[i].getBlocking(); cell_user[i].kanal=new Vector();

}

System.out.println("Blocking rata-rata:---"+avBlock/number_cell+"%");

bloking.add(avBlock/number_cell); /*

//cek status user

for (int i=0; i <number_cell;i++){

System.out.print ("Sel no :"+cell_user[i].getCell()+" jumlah Traffic:"+

cell_user[i].getTraffic());

(11)

System.out.println (" telah teralokasikan"); }

}*/

}

double[] d = new double[bloking.size()]; for(int ss=0;ss<bloking.size();ss++){ d[ss]=(double)bloking.get(ss); }

double dd= smallestNumbers(d);

// System.out.println (" Nilai terkecil: "+d[(int)dd]); vect.add(d[(int)dd]);

}

for(int ii=0;ii<vect.size();ii++){

//System.out.println("Iterasi: "+ii+" blocking: "+(double)vect.get(ii)); }

}

private static int smallestNumbers(double[] traf) { int in=0;

double smallNumber = traf[0]; for (int i = 0; i < traf.length; i++) { if (traf[i] < smallNumber) { smallNumber = traf[i]; }

}

boolean c=false;

for (int j = 0; j < traf.length; j++) {

if(smallNumber == traf[j] && c==false){ in=j;

c=true;

//System.out.println("largest number index "+j); }

}

return in; }

//Sorting

private static int[] Sort(Allocation[] v1){ double[] num=new double[v1.length]; int[] num1=new int[v1.length];

for(int x=0;x<v1.length;x++){ num[x]=v1[x].getTraffic(); num1[x]=x;

}

int n = v1.length; int k;

(12)

k = i + 1;

if (num[i] < num[k]) { double temp = num[i]; num[i] = num[k];

num[k] = temp; int temp1 = num1[i];

num1[i] = num1[k]; num1[k] = temp1; }

} }

return num1; }

// metode chek interferensi kanal

private static Boolean checkInterference (Allocation []a, int in_cell,int kanal){ Boolean interference = false;

Vector adj = a [in_cell].getAdj(); for (int i=0;i<adj.size();i++){

Vector ch=a[(int)adj.get(i)].getChannel(); if (ch.size()>0){

for (int j=0;j<ch.size();j++){

// System.out.println(kanal+":"+(int)ch.get(j)); if(Math.abs(kanal-(int)ch.get(j))<2){

interference = true; }

} } }

return interference; }

(13)

Lampiran 2 Program FEA

import java.text.NumberFormat; import java.util.Random;

import java.util.Vector;

/*

* To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates

* and open the template in the editor. */

/** *

* @author beny saragih */

public class FEA{

public static void main (String args []){ int space =6;

int jumlah_kanal=64; int number_cell = 17;

double []traf = new double [number_cell]; Vector vect = new Vector();

(14)
(15)
(16)
(17)
(18)
(19)

distance [15] [9] = 2 ; distance [15] [10] = 2 ; distance [15] [11] = 1 ; distance [15] [12] = 0 ; distance [15] [13] = 0 ; distance [15] [14] = 0 ; distance [15] [15] = 6 ; distance [15] [16] = 2 ; distance [16] [0] = 0 ; distance [16] [1] = 0 ; distance [16] [2] = 0 ; distance [16] [3] = 0 ; distance [16] [4] = 0 ; distance [16] [5] = 0 ; distance [16] [6] = 0 ; distance [16] [7] = 0 ; distance [16] [8] = 0 ; distance [16] [9] = 1 ; distance [16] [10] = 2 ; distance [16] [11] = 2 ; distance [16] [12] = 1 ; distance [16] [13] = 0 ; distance [16] [14] = 0 ; distance [16] [15] = 2 ; distance [16] [16] = 6 ;

for(int aa=0;aa<1;aa++){

double[] traffics = { 5, 10, 15, 20, 17, 18, 20, 6, 9, 11, 4, 6, 5, 2, 10, 3, 1, 7, 23, 22, 16};

Allocation [] cell_user = new Allocation [number_cell]; //initialisasi

for (int i=0; i <number_cell ; i ++) { cell_user [i] = new Allocation (); Random r = new Random (); int index = r.nextInt(16);

cell_user[i].setTraffic(traffics [index]); // Set which cell user belongs to. cell_user[i].setCell(i);

cell_user[i].setAllocation(false); cell_user[i].setBeginner(false); if(i==0){

cell_user[i].addAdj(1);cell_user[i].addAdj(3);cell_user[i].addAdj(4); }else if(i==1){

cell_user[i].addAdj(0);cell_user[i].addAdj(2);cell_user[i].addAdj(4);cell_user[i].a ddAdj(5);

(20)

cell_user[i].addAdj(1);cell_user[i].addAdj(6);cell_user[i].addAdj(7); }else if(i==3){

cell_user[i].addAdj(1);cell_user[i].addAdj(4);cell_user[i].addAdj(10); }else if(i==4){

cell_user[i].addAdj(0);cell_user[i].addAdj(1);cell_user[i].addAdj(5);cell_user[i].a ddAdj(11);cell_user[i].addAdj(10);

}else if(i==5){

cell_user[i].addAdj(1);cell_user[i].addAdj(2);cell_user[i].addAdj(6);cell_user[i].a ddAdj(11);cell_user[i].addAdj(10);cell_user[i].addAdj(4);

}else if(i==6){

cell_user[i].addAdj(2);cell_user[i].addAdj(7);cell_user[i].addAdj(12);cell_user[i]. addAdj(11);cell_user[i].addAdj(5);

}else if(i==7){

cell_user[i].addAdj(6);cell_user[i].addAdj(8);cell_user[i].addAdj(13);cell_user[i]. addAdj(12);

}else if(i==8){

cell_user[i].addAdj(7);cell_user[i].addAdj(14);cell_user[i].addAdj(13); }else if(i==9){

cell_user[i].addAdj(3);cell_user[i].addAdj(4);cell_user[i].addAdj(10);cell_user[i]. addAdj(15);

}else if(i==10){

cell_user[i].addAdj(4);cell_user[i].addAdj(5);cell_user[i].addAdj(11);cell_user[i]. addAdj(16);cell_user[i].addAdj(15);cell_user[i].addAdj(9);

}else if(i==11){

cell_user[i].addAdj(5);cell_user[i].addAdj(6);cell_user[i].addAdj(12);cell_user[i]. addAdj(16);cell_user[i].addAdj(10);

}else if(i==12){

cell_user[i].addAdj(6);cell_user[i].addAdj(7);cell_user[i].addAdj(13);cell_user[i]. addAdj(11);

}else if(i==13){

cell_user[i].addAdj(7);cell_user[i].addAdj(8);cell_user[i].addAdj(14);cell_user[i]. addAdj(12);

}else if(i==14){

cell_user[i].addAdj(8);cell_user[i].addAdj(13); }else if(i==15){

(21)

cell_user[i].addAdj(10);cell_user[i].addAdj(11);cell_user[i].addAdj(15); }

}

//alokasi

//Initial allocation, the biggest pheromon

//cek sorting, s menyimpan urutan besar ke kecil int s[]=Sort(cell_user);

// for(int u=0;u<s.length;u++){

// System.out.println(cell_user[s[u]].getTraffic()); // }

for (int i=0;i<number_cell;i++){ int newch=0;

int count=0; int x=s[i];

//mencari chanel awal

for(int y=0;y<jumlah_kanal;y++){ //cek interferensi

if(checkInterference(cell_user,x,newch)){ newch++;

}else{ break; }

}

int z=jumlah_kanal/space+1; for(int y=0;y<jumlah_kanal;y++){ //cek interferensi

if(count<cell_user[x].getTraffic() && newch<jumlah_kanal){ cell_user[x].addChannel(newch);

count++;

newch=newch+space; }else{

cell_user[x].setBlocking(((cell_user[x].getTraffic()-count)/cell_user[x].getTraffic())*100);

break; }

}

}

/* if(checkInterference(cell_user, 1, 6)){ System.out.println("Interference"); }else{

(22)

// boolean solution =false;

// int n = largestNumbers(cell_user); /*while(solution==false){

n = largestNumbers(cell_user); //alokasi sel awal

cell_user[n].getTraffic(); for(int i=0;i<number_cell;i++){

} }*/

//Cek kanal sel n

for(int i=0;i<number_cell;i++){

System.out.print( "Sel :"+i + " jumlah kanal: "+cell_user[i].getTraffic()+" nomor kanal :");

for(int c=0;c<cell_user[i].getChannel().size();c++){

System.out.print(" " +(int)cell_user[i].getChannel().get(c)); }

System.out.println("---"+cell_user[i].getBlocking()+"%"); }

double avBlock=0;

for(int i=0;i<number_cell;i++){

avBlock=avBlock+cell_user[i].getBlocking(); }

System.out.println("Blocking rata-rata:---"+avBlock/number_cell+"%");

/*

//cek status user

for (int i=0; i <number_cell;i++){

System.out.print ("Sel no :"+cell_user[i].getCell()+" jumlah Traffic:"+ cell_user[i].getTraffic());

if (cell_user[i].getAllocation()==false){ System.out.println (" belum teralokasi"); }else{

System.out.println (" telah teralokasikan"); }

}*/

vect.add(avBlock/number_cell); }

for(int ii=0;ii<vect.size();ii++){

//System.out.println("Iterasi: "+ii+" blocking: "+(double)vect.get(ii)); }

}

private static int largestNumbers(Allocation[] cell_user) { double [] traf = new double[cell_user.length];

(23)

if(cell_user[i].getBenginner()==true); traf [i] = 0;

traf [i] = cell_user[i].getTraffic(); }

int in=0;

double largeNumber = traf[0]; for (int i = 0; i < traf.length; i++) { if (traf[i] > largeNumber) { largeNumber = traf[i]; }

}

boolean c=false;

for (int j = 0; j < traf.length; j++) {

if(largeNumber == traf[j] && c==false){ in=j;

c=true;

//System.out.println("largest number index "+j); }

}

return in; }

//Sorting

private static int[] Sort(Allocation[] v1){ double[] num=new double[v1.length]; int[] num1=new int[v1.length];

for(int x=0;x<v1.length;x++){ num[x]=v1[x].getTraffic(); num1[x]=x;

}

int n = v1.length; int k;

for (int m = n; m >= 0; m--) { for (int i = 0; i < n - 1; i++) { k = i + 1;

if (num[i] < num[k]) { double temp = num[i]; num[i] = num[k];

num[k] = temp; int temp1 = num1[i];

num1[i] = num1[k]; num1[k] = temp1; }

} }

(24)

// metode chek interferensi kanal

private static Boolean checkInterference (Allocation []a, int in_cell,int kanal){ Boolean interference = false;

Vector adj = a [in_cell].getAdj(); for (int i=0;i<adj.size();i++){

Vector ch=a[(int)adj.get(i)].getChannel(); if (ch.size()>0){

for (int j=0;j<ch.size();j++){

// System.out.println(kanal+":"+(int)ch.get(j)); if(Math.abs(kanal-(int)ch.get(j))<2){

interference = true; }

} } }

return interference; }

Referensi

Dokumen terkait

* To change this template file, choose Tools | Templates * and open the template in the

* To change this template file, choose Tools | Templates * and open the template in the editor...

* To change this license header, choose License Headers in Project Properties.. * To change this template file, choose Tools

intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

Pengertian di atas menunjukkan adanya beberapa variabel yang perlu dikelola secara sinegik, terpadu dan sistematik oleh guru, yakni: (1) ruang kelas menunjukkan

Agar model pembelajaran seni musik dengan model tutor sebaya mencapai tingkat keberhasilan yang diharapkan, peneliti meru- muskan langkah-langkah pembelajaran me- liputi: