• Tidak ada hasil yang ditemukan

CHAPTER 5 IMPLEMENTATION AND TESTING

N/A
N/A
Protected

Academic year: 2019

Membagikan "CHAPTER 5 IMPLEMENTATION AND TESTING"

Copied!
9
0
0

Teks penuh

(1)

CHAPTER 5

IMPLEMENTATION AND TESTING

5.1 Implementation

First implementation input amount of node and node name by user. The

goal is let data save first before count the smallest distance.

1. int jml = Integer.parseInt(jumlahNode.getText());

2. String namaNode1 = namaNode.getText();

In Line 1 the amount of the node input by user. In Line 2 the name of node

input by user.

(2)

amount of node. Amount of node in menu 1 with menu 2 is difference. In Menu 2

the amount of node depend the distance where user input. In this implementation

show user input with table. There is 2 goal in this implementation. The first goal is

save beginning node, end node and distance before calculate Djikstra Algorithm.

The second goal is to make sure that is that input is right.

1. String [] jarak = new String [jml];

2. String [] nodeAwal1 = new String [jml];

3. String [] nodeAkhir1 = new String [jml];

4. int jml = Integer.parseInt(jumnode.getText());

5.nodeAwal1 = nodeAwal.getText().split("\\-", -1);

6. nodeAkhir1 = nodeAkhir.getText().split("\\-", -1);

7. jarak = arrayNode.getText().split("\\-", -1);

In line 6 input amount of node. In line 1 & 5 input beginning node then

save into array. In line 2 & 6 input end node then save into array. In line 3 & 7

input distance then save into array.

(3)

This is the code for show user input.

8. outputTabel = "+---+---+---+\n";

9. outputTabel = outputTabel + "| Asal " + "|" + " Tujuan " + "|" + " Jarak |\n"; 10. outputTabel = outputTabel + "+---+---+---+\n";

11. for(int i = 0; i < jml; i++) 12. {

13. arrayNode1[i] = Integer.parseInt(jarak[i]);

14. outputTabel=outputTabel+"|"+nodeAwal1[i]+"|"+nodeAkhir1[i]+"|"; 15. if(arrayNode1[i] <= 9)

16. {

17. outputTabel = outputTabel + arrayNode1[i] + " | \n"; 18. }

19. else 20. {

21. outputTabel = outputTabel + arrayNode1[i] + " | \n"; 22. }

23. } 24.

25. outputTabel = outputTabel + "+---+---+---+\n";

(4)

In line 8 – 26 make table to show user input in menu 2.

Third implementation is source node and final node input by user. In this

Implementation can show the result of Djikstra Algoirithm.

1. ArrayList<String> tempatAwal = new ArrayList<String> (1); 2. ArrayList<String> tempatAkhir = new ArrayList<String> (1); 3. ArrayList<String> tempatAwal1 = new ArrayList<String> (1); 4. ArrayList<String> tempatAkhir1 = new ArrayList<String> (1); 5. String awal = tanyaAwal.getText();

6. String akhir = tanyaAkhir.getText();

7. if((Arrays.asList(nodeAwal1[gh]).contains(awal))&&(namaNode[gab] == 0)) 8. {

9. tampungtempat2 = nodeAkhir1[gh]; 10. hasilJarak = 0;

16. hasilJarak = hasilJarak + arrayNode1[gh];

17. output=in2+""+tempatAwal.get(in)+"-"+ tempatAkhir.get(in)+"\n"; 18. if(Arrays.asList(nodeAkhir1[gh]).contains(akhir))

(5)

19. {

20. output = output + "+---+---+---+\n"; 21. output = output + "|Asal"+"|"+"Tujuan"+"|"+"Jarak|\n"; 22. output = output + "+---+---+---+\n";

23. output = output + "|"+nodeAwal1[gh]+"|"+nodeAkhir1[gh]+"| \n"; 24. if(arrayNode1[gh] <= 9)

37. tampungtempat2 = nodeAkhir1[gh]; 38. tempatAwal.add(nodeAwal1[gh]); 39. tempatAkhir.add(nodeAkhir1[gh]); 40. tempatAwal1.add(nodeAwal1[gh]); 41. tempatAkhir1.add(nodeAkhir1[gh]); 42. arraynode.add(arrayNode1[gh]);

43. hasilJarak = hasilJarak + arrayNode1[gh];

(6)

70. output = output + tempatAwal1.get(i) + " - " + tempatAkhir1.get(i) + "\n"; 71. output = output + "Hasil Jarak terpendek = " + min + "\n";

72. } 73. }

74. }

In line 1 & 2 declaration tempatAwal and tempatAkhir into Array List. In

line 3 & 4 declaration tempatAwal1 and tempatAkhir1 into Array List. In line 5

declaration from start node. Start depend user input. In line 6 declaration of end

node, depend on input user. In line 7 value nodeAwal1 must be the same with

value awal and value namaNode must 0. In line 9 value nodeAkhir1 give to

tampungtempat2. In line 10 make value hasilJarak to 0. In line 11 add nodeAwal1

to tempatAwal. In line 12 add value nodeAkhir1 to tempatAkhir, In line 13 add

value nodeAwal1 to tempatAwal1. In line 14 add value nodeAkhir1 to

tempatAkhir1. In line 15 add value arrayNode1 to arraynode. In line 16 count

value hasilJarak plus value arraynode. In line 17 show the path. In line 18 value

nodeAkhir1 must same with value akhir. In line 20 – 34 make table for start node,

end node and distance.

In line 35 value of nodeAwal1 must same with value tampungtempat2 and

value namaNode must 0. In line 37 value nodeAkhir1 give to tampungtempat2. In

line 38 add value nodeAwal1 to tempatAwal. In line 39 add value nodeAkhir1 to

(7)

value nodeAkhir1 to tempatAkhir1. In line 42 add value arrayNode1 to arraynode.

In line 43 value hasilJarak plus arraynode value. In line 44 show the path.

In line 46 value tampungtempat2 must the same with akhir. In line 48

value hasilJarak must be lower than min value. In line 50 value hasilJarak give to

min value. In line 51 loop array list. In line 53 show the result of array list. In line

54 show the result of result the smallest distance. In line 56 clear tempatAwal. In

line 57 clear tempatAkhir. In line 58 value min2 must same with value min. In

line 60 make value h become 0. In line 61 loop array list. In line 63 value

tempatAwal1 give to awal2, In line 64 value awal2 must same with awal. In line

66 just space. In line 67 value h plus 1. In value 68 show the number solution. In

line 70 show the path. In line 71 show the smallest distance.

5.2 Testing

There are 4 nodes.That is A, B, C, D. Then input source node. That is A, B,

A, C. Then input end node B, D, C, D. Then input distance 2, 2, 2, 2. So the path

is A-B 2, B-D 2, A-C 2, C-D 2. Now input beginning node and final node.

Begining node is A and the final node is D. Now calculate with Djikstra

Algorithm. So there is 2 path. There are A-B, B-D and A-C, C-D. First calculate

the path A-B, B-D. The distance A-B is 2. Then distance B-D is 2.So the

calculation is 2 + 2. So the result is 4. Now calculate the other path. There are

A-C, C-D. The distance A-C is 2 and C-D is 2. So the calculation is 2 + 2. So the

result is 4. The result is same. So the output is

(8)

B-D

The second solution is

A-C

C-D

The smallest distance is 4.

(9)

Referensi

Dokumen terkait

[r]

[r]

Sehubungan dengan proses Pemilihan Langsung paket pekerjaan PEMELIHARAAN JALAN/PELENGKAP JALAN BERINGI II Dinas Pekerjaan Umum &amp; Kimpraswil Kota Gorontalo Tahun Anggaran

Metode yang digunakan dalam penelitian ini adalah metode penelitian tindakan kelas (Class Action Research) yakni suatu bentuk penelitian yang bersifat reflektif

Pelelangan Sederhanan secara elekt ronik melalui LPSE. Pelelangan Sederhanan secara elekt ronik melalui

Mata kuliah PTK menyajikan serangkaian materi kuliah yang akan membekali Anda dengan wawasan, sikap dan keretampilan melakukan PTK dalam upaya guru memperbaiki kualitas

Pihak lain yang bukan direktur utama/pimpinan perusahan yang namanya tidak tercantum dalam akta pendirian/anggaran dasar, sepanjang pihak lain tersebut adalah

Dengan ditetapkan status desa menjadi kelurahan sebagaimana dimaksud dalam pasal 2 ayat (1), kewenangan desa sebagai suatu kesatuan masyarakat hukum yang berhak mengatur dan