BAB 4 KESIMPULAN
4.2. Saran
Sebagai saran yang ditujukan kepada pembaca yang ingin menentukan shortest path (route terpendek) pada graf multitahap (multistage graph) dengan menggunakan Algoritma Dynamic Programming, agar dapat mengembangkan metode ini lebih luas lagi. Disini penulis hanya menyelesaikan dalam cakupan kecil yang dapat dikerjakan secara manual dan mengimplementasikannya pada Microsoft Visual Basic 6.0.
Untuk itu Penulis berharap, agar pembaca dapat menyelesaikan persoalan dalam cakupan besar, dan merekayasa suatu software untuk menyelesaikan suatu masalah dengan menggunakan software dan komputer sederhana.
DAFTAR PUSTAKA
Evans. J.R., Minieka. E., 1992. “Optimization Algorithms for Networks and Graphs.” Marcel Dekker, Inc.
Foulds. L.R., 1984. “Combinatorial Optimization for Undergraduates.” Springer – Verlag Newyork, Inc.
Johnsonbaugh. R. “Matematika Diskrit”, Edisi keempat, Jilid 2. PT. Prenhallindo Jakarta.
Jong Jek Siang, M.Sc. Drs. “Matematika Diskrit dan Aplikasinya pada Ilmu Komputer” , Penerbit ANDI Yogyakarta.
Lars Lipson Marc, Ph.D, Lipschutz Seymour, Ph.D. 2002“Matematika Diskrit 2”. Terjemahan Tim Editor Penerbit Salemba Teknika.
Mulyono. S. SE., M.Sc. “Riset Operasi”, Penerbit Fakultas Ekonomi Universitas Indonesia.
Rao. S.S. “Optimization”, Second Edition. Wiley Eastern Limited New Delhi.
Render.B., Stair.Jr.R.M., Hanna.M.E., 2003. “Quanttative Analisys for Management”, Eighth Edition. Pearson Education, Inc.
Siagian. P. 1987. “Penelitian Operasional”, Penerbit Universitas Indonesia.
Menu Program
Option Explicit Dim distX As Single Dim distY As Single
Public WithEvents theBlockCollection As myBlockCollection Public WithEvents theLineCollection As myLineCollection Private Sub Form_Load()
MAX_SHAPE = 0 DRAGGED_SHAPE = -1 SELECTED_SHAPE = -1 PREV_SELECTED_SHAPE = -1
Set theBlockCollection = New myBlockCollection Set theLineCollection = New myLineCollection MAX_LINE = 0
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) DRAGGED_SHAPE = -1
update_from_to End Sub
Private Sub Form_Unload(Cancel As Integer) End
End Sub
Private Sub lblLineCap_MouseDown(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Form_MouseDown Button, Shift, X / Screen.TwipsPerPixelX + lblLineCap(index).Left, Y / Screen.TwipsPerPixelY + lblLineCap(index).Top
End Sub
Private Sub lblLineCap_MouseMove(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Form_MouseMove Button, Shift, X / Screen.TwipsPerPixelX + lblLineCap(index).Left, Y / Screen.TwipsPerPixelY + lblLineCap(index).Top
End Sub
Private Sub lblLineCap_MouseUp(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Form_MouseUp Button, Shift, X / Screen.TwipsPerPixelX + lblLineCap(index).Left, Y / Screen.TwipsPerPixelY + lblLineCap(index).Top
End Sub
Private Sub lblShapeCap_MouseDown(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Form_MouseDown Button, Shift, X / Screen.TwipsPerPixelX + lblShapeCap(index).Left, Y / Screen.TwipsPerPixelY + lblShapeCap(index).Top
End Sub
Private Sub lblShapeCap_MouseMove(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Form_MouseMove Button, Shift, X / Screen.TwipsPerPixelX + lblShapeCap(index).Left, Y / Screen.TwipsPerPixelY + lblShapeCap(index).Top
End Sub
Private Sub lblShapeCap_MouseUp(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Form_MouseUp Button, Shift, X / Screen.TwipsPerPixelX + lblShapeCap(index).Left, Y / Screen.TwipsPerPixelY + lblShapeCap(index).Top
End Sub
Private Sub mnuAddRect_Click()
theBlockCollection.AddShape 0, theBlockCollection.getFreeTagID() End Sub
Private Sub mnuAddSquare_Click()
theBlockCollection.AddShape 1, theBlockCollection.getFreeTagID() End Sub
Private Sub mnuAddElipse_Click()
theBlockCollection.AddShape 2, theBlockCollection.getFreeTagID() End Sub
Private Sub mnuAddCircle_Click()
theBlockCollection.AddShape 3, theBlockCollection.getFreeTagID() End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Integer
For i = MAX_SHAPE To 1 Step -1 If (shp(i).Visible = True) And _
(X > shp(i).Left) And (X < shp(i).Left + shp(i).Width) _
And (Y > shp(i).Top) And (Y < shp(i).Top + shp(i).Height) Then DRAGGED_SHAPE = i If SELECTED_SHAPE <> i Then PREV_SELECTED_SHAPE = SELECTED_SHAPE SELECTED_SHAPE = i End If distX = X - shp(i).Left distY = Y - shp(i).Top lblID.Caption = shp(i).Tag Exit For End If Next i End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If DRAGGED_SHAPE <> -1 Then shp(DRAGGED_SHAPE).Left = X - distX shp(DRAGGED_SHAPE).Top = Y - distY theLineCollection.updateLines theBlockCollection(shp(DRAGGED_SHAPE).Tag).updateShapeCaptionPos End If
End Sub
Private Sub mnuChangeBackColor_Click() If SELECTED_SHAPE <> -1 Then CommonDialog1.ShowColor
shp(SELECTED_SHAPE).BackColor = CommonDialog1.Color End If
End Sub
Private Sub mnuChangeBorderColor_Click() If SELECTED_SHAPE <> -1 Then CommonDialog1.ShowColor
shp(SELECTED_SHAPE).BorderColor = CommonDialog1.Color End If
End Sub
Private Sub mnuChangeRect_Click() theBlockCollection.changeShape (0) End Sub
Private Sub mnuChangeSize_Click() frmSize.Show , Me
End Sub
Private Sub mnuChangeSquare_Click() theBlockCollection.changeShape (1) End Sub
Private Sub mnuChangeElipse_Click() theBlockCollection.changeShape (2) End Sub
Private Sub mnuChangeCircle_Click() theBlockCollection.changeShape (3) End Sub
Private Sub mnuDeleteBlock_Click()
theBlockCollection.removeShape SELECTED_SHAPE SELECTED_SHAPE = -1
End Sub
Private Sub mnuDeleteLine_Click()
theLineCollection.deleteLine SELECTED_SHAPE, PREV_SELECTED_SHAPE End Sub
Private Sub mnuFindShortPath_Click() frmFindShortPath.Show
End Sub
Private Sub mnuFindAllPaths_Click() frmFindAllPaths.Show
End Sub
Private Sub mnuJoinLine_Click()
theLineCollection.AddLine Form1.shp(PREV_SELECTED_SHAPE).Tag, Form1.shp(SELECTED_SHAPE).Tag, False
Else
MsgBox "Dua Objek Harus Dipilih!" End If
End Sub
Private Sub mnuJoinArrow_Click()
If (PREV_SELECTED_SHAPE <> -1) And (SELECTED_SHAPE <> -1) Then theLineCollection.AddLine Form1.shp(PREV_SELECTED_SHAPE).Tag, Form1.shp(SELECTED_SHAPE).Tag, True
Else
MsgBox "Dua Objek Harus Dipilih!" End If
End Sub
Private Sub mnuAddCaptionToLine_Click()
If (PREV_SELECTED_SHAPE <> -1) And (SELECTED_SHAPE <> -1) Then Dim s As String
s = InputBox("Masukkan Karakter")
theLineCollection.AddCaptionToLine Form1.shp(PREV_SELECTED_SHAPE).Tag, Form1.shp(SELECTED_SHAPE).Tag, s
Else
MsgBox "Dua object harus di pilih" End If
End Sub
Private Sub mnuAddCaptionToBlock_Click() If (SELECTED_SHAPE <> -1) Then Dim s As String
s = InputBox("Masukkan Karakter untuk sebuah bentuk", "Dynamic Program", theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaption)
theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaption = s
theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).updateShapeCaptionPos Else
MsgBox "Object harus di pilih" End If
End Sub
Private Sub mnuAddCaptionUpperToBlock_Click() If (SELECTED_SHAPE <> -1) Then
Dim s As String
s = InputBox("Masukkan Karakter untuk sebuah bentuk", "Dynamic Program", theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaptionUpper) theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaptionUpper = s
theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).bSetUpperCaptionDown = False theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).updateShapeCaptionPos Else
MsgBox "Object harus di pilih" End If
End Sub
Private Sub mnuAddCaptionLowerToBlock_Click() mnuAddCaptionUpperToBlock_Click
theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).bSetUpperCaptionDown = True theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).updateShapeCaptionPos End Sub
Private Sub mnuKeluar_Click() Dim keluar As Byte
If keluar = vbOK Then End
End If End Sub
Private Sub mnuLoad_Click()
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Trace ZR Flow Data|*.tzr|All Files|*.*" CommonDialog1.DefaultExt = "tzr"
CommonDialog1.ShowOpen
load_FILE CommonDialog1.FileName End Sub
Private Sub load_FILE(sFILE As String) On Error GoTo err_lf
Dim i As Integer
Dim mFileNum As Integer mFileNum = FreeFile If sFILE = "" Then Exit Sub For i = 1 To MAX_SHAPE Unload shp(i) Unload lblShapeCap(i) Unload lblShapeCapUpper(i) Next i MAX_SHAPE = 0
For i = theBlockCollection.Count To 1 Step -1 theBlockCollection.Remove i Next i For i = 1 To MAX_LINE Unload ln(i) Unload aDot(i) Unload arrUp(i) Unload arrDown(i) Unload lblLineCap(i) Next i MAX_LINE = 0
For i = theLineCollection.Count To 1 Step -1 theLineCollection.Remove i
Next i
Open sFILE For Input As mFileNum Dim tempS As String
Dim lineCounter As Integer Dim shapeCounter As Integer Line Input #mFileNum, tempS shapeCounter = Val(tempS) Line Input #mFileNum, tempS lineCounter = Val(tempS) Dim xS As cBlock Dim sName As String For i = 1 To shapeCounter Line Input #mFileNum, tempS sName = tempS
Line Input #mFileNum, tempS
Set xS = theBlockCollection.AddShape(Val(tempS), sName) Line Input #mFileNum, tempS
xS.shapeLeft = Val(tempS) Line Input #mFileNum, tempS
xS.shapeTop = Val(tempS) Line Input #mFileNum, tempS xS.shapeWidth = Val(tempS) Line Input #mFileNum, tempS xS.shapeHeight = Val(tempS) Line Input #mFileNum, tempS xS.shapeBackColor = Val(tempS) Line Input #mFileNum, tempS xS.shapeBorderColor = Val(tempS) Line Input #mFileNum, tempS xS.sCaption = tempS
Line Input #mFileNum, tempS xS.sCaptionUpper = tempS Line Input #mFileNum, tempS
xS.bSetUpperCaptionDown = Val(tempS) xS.updateShapeCaptionPos
xS.Visible = True Next i
Line Input #mFileNum, tempS Line Input #mFileNum, tempS Dim sFrom As String
Dim sTo As String Dim psik_index As Integer Dim xL As cLine
For i = 1 To lineCounter
Line Input #mFileNum, tempS psik_index = InStr(1, tempS, ",") sFrom = Mid(tempS, 1, psik_index - 1) sTo = Mid(tempS, psik_index + 1) Line Input #mFileNum, tempS
Set xL = theLineCollection.AddLine(sFrom, sTo, Val(tempS)) Line Input #mFileNum, tempS
xL.sCaption = tempS Next i theLineCollection.updateLines Close mFileNum update_from_to Exit Sub err_lf:
MsgBox "Buka: " & sFILE & vbNewLine & Err.Description End Sub
Private Sub mnuSave_Click()
CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt CommonDialog1.Filter = "Trace ZR Flow Data|*.tzr|All Files|*.*"
CommonDialog1.DefaultExt = "tzr" CommonDialog1.ShowSave Dim mFileNum As Integer mFileNum = FreeFile
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Output As mFileNum Dim sDl As String
sDl = " " & vbTab & " <--"
Print #mFileNum, theBlockCollection.Count & sDl & "SHAPES" Print #mFileNum, theLineCollection.Count & sDl & "LINES" Dim xB As cBlock
For Each xB In theBlockCollection Print #mFileNum, xB.TagID
Print #mFileNum, xB.shapeLeft & sDl & xB.theObjectShape.Tag & ".LEFT" Print #mFileNum, xB.shapeTop & sDl & xB.theObjectShape.Tag & ".TOP" Print #mFileNum, xB.shapeWidth & sDl & xB.theObjectShape.Tag & ".WIDTH" Print #mFileNum, xB.shapeHeight & sDl & xB.theObjectShape.Tag & ".HEIGHT"
Print #mFileNum, xB.shapeBackColor & sDl & xB.theObjectShape.Tag & ".BACKCOLOR" Print #mFileNum, xB.shapeBorderColor & sDl & xB.theObjectShape.Tag & ".BORDERCOLOR" Print #mFileNum, xB.sCaption
Print #mFileNum, xB.sCaptionUpper If xB.bSetUpperCaptionDown Then
Print #mFileNum, "1" & sDl & "Caption down" Else
Print #mFileNum, "0" & sDl & "Caption up" End If
Next xB
Dim xL As cLine Print #mFileNum, " "
Print #mFileNum, "---- LINES ---- from,to ----" For Each xL In theLineCollection
Print #mFileNum, xL.sFrom & "," & xL.sTo If xL.bShowArrow Then
Print #mFileNum, "1" & sDl & "Arrow" Else
Print #mFileNum, "0" & sDl & "Line" End If
Print #mFileNum, xL.sCaption Next xL
Close mFileNum End Sub
Private Sub theBlockCollection_linkError(sERROR As String) MsgBox sERROR
End Sub
Private Sub theLineCollection_linkError(sERROR As String) MsgBox sERROR
End Sub
Private Sub update_from_to() On Error GoTo err_uft Dim sFrom As String Dim sTo As String sFrom = "?" sTo = "?" If PREV_SELECTED_SHAPE <> -1 Then sFrom = theBlockCollection(Form1.shp(PREV_SELECTED_SHAPE).Tag).sCaption End If If SELECTED_SHAPE <> -1 Then sTo = theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaption End If
lblFromTo.Caption = "Dari: " & sFrom & " Ke: " & sTo Exit Sub
err_uft:
Debug.Print "update_from_to: " & Err.Description End Sub
Mencari seluruh lintasan
Option Explicit Dim sFrom As String
Dim sTo As String Const arrow = " -> " Dim path_id As Integer
Private Sub cmdCalcData_Click() Dim i As Integer
Dim j As Integer Dim toIndex As Integer
flxMap.Rows = Form1.theBlockCollection.Count + 1 flxMap.Cols = Form1.theBlockCollection.Count + 1 If Form1.theBlockCollection.Count > 0 Then flxMap.FixedRows = 1 flxMap.FixedCols = 1 End If For i = 0 To flxMap.Cols - 1 flxMap.ColWidth(i) = 300 Next i For i = 1 To Form1.theBlockCollection.Count flxMap.Row = i flxMap.Col = 0 flxMap.Text = Form1.theBlockCollection(i).sCaption flxMap.Row = 0 flxMap.Col = i flxMap.Text = Form1.theBlockCollection(i).sCaption flxMap.Row = i For j = 1 To flxMap.Cols - 1 flxMap.TextMatrix(i, j) = "0" flxMap.Row = i flxMap.Col = j flxMap.CellForeColor = vbBlack flxMap.CellFontBold = False Next j For j = 1 To Form1.theLineCollection.Count
If Form1.theLineCollection(j).sFrom = Form1.theBlockCollection(i).TagID Then
toIndex = Form1.theBlockCollection.getIndexFromTag(Form1.theLineCollection(j).sTo) flxMap.Col = toIndex flxMap.Text = "1" flxMap.CellForeColor = vbRed flxMap.CellFontBold = True End If Next j Next i End Sub
Private Sub cmdShowTest_Click() frmTest.Show
End Sub
Private Sub Form_Activate()
If PREV_SELECTED_SHAPE = -1 Or SELECTED_SHAPE = -1 Then lblFromTo.Caption = "Tidak ada objek yang dipilih"
cmdFindAllPaths.Enabled = False Else
cmdFindAllPaths.Enabled = True
sFrom = Form1.theBlockCollection(Form1.shp(PREV_SELECTED_SHAPE).Tag).sCaption sTo = Form1.theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaption
lblFromTo.Caption = "Dari: " & sFrom & " Ke: " & sTo End If
Private Sub findPaths(src As Integer, dest As Integer, p As String) Dim tc As String
Dim i As Integer tc = p
If (flxMap.TextMatrix(src, dest) = "1") Then
If Not (0 < InStr(1, tc, flxMap.TextMatrix(0, dest))) Then Dim s As String
s = tc s = s & arrow
s = s & flxMap.TextMatrix(0, dest) path_id = path_id + 1
txtOut.Text = txtOut.Text & path_id & ". " & s & vbNewLine End If
End If
For i = 1 To flxMap.Cols - 1
If (flxMap.TextMatrix(src, i) = "1") Then
If Not (0 < InStr(1, tc, flxMap.TextMatrix(0, i))) Then Dim s2 As String s2 = tc s2 = s2 & arrow s2 = s2 & flxMap.TextMatrix(0, i) findPaths i, dest, s2 End If End If Next i frmTest.listPaths.AddItem p If (Mid(p, Len(p)) = sTo) Then frmTest.listGoodPaths.AddItem p End If
End Sub
Private Sub printAllPaths(src As Integer, dest As Integer) Dim start As String
path_id = 0
frmTest.listPaths.Clear frmTest.listGoodPaths.Clear
txtOut.Text = txtOut.Text & "Paths from " & flxMap.TextMatrix(0, src) & " to " & flxMap.TextMatrix(0, dest) & vbNewLine
start = flxMap.TextMatrix(0, src) findPaths src, dest, start
If (path_id = 0) Then
txtOut.Text = txtOut.Text & "-- NO PATHS! --" & vbNewLine End If
txtOut.Text = txtOut.Text & vbNewLine & vbNewLine End Sub
Private Sub cmdFindAllPaths_Click() Dim i As Integer
Dim isrc As Integer Dim idest As Integer isrc = -1
idest = -1
For i = 1 To flxMap.Cols - 1
If (flxMap.TextMatrix(0, i) = sFrom) Then isrc = i
End If
If (flxMap.TextMatrix(0, i) = sTo) Then idest = i
End If Next i
If (isrc = -1) Or (idest = -1) Then MsgBox "Data ada yang salah" Exit Sub
End If
printAllPaths isrc, idest txtOut.SetFocus
txtOut.SelStart = Len(txtOut.Text) End Sub
Private Sub cmdCLS_Click() txtOut.Text = ""
End Sub
Mencari Lintasan Terpendek
Option Explicit Dim sFrom As String Dim sTo As String Const INF = 32767
Dim sRESULT(1 To 100) As String Dim iRES_SIZE As Integer Private Sub cmdCalcData_Click() Dim i As Integer
Dim j As Integer Dim toIndex As Integer
flxMap.Rows = Form1.theBlockCollection.Count + 1 flxMap.Cols = Form1.theBlockCollection.Count + 1 If Form1.theBlockCollection.Count > 0 Then flxMap.FixedRows = 1 flxMap.FixedCols = 1 End If For i = 0 To flxMap.Cols - 1 flxMap.ColWidth(i) = 530 Next i For i = 1 To Form1.theBlockCollection.Count flxMap.Row = i flxMap.Col = 0 flxMap.Text = Form1.theBlockCollection(i).sCaption flxMap.Row = 0 flxMap.Col = i flxMap.Text = Form1.theBlockCollection(i).sCaption flxMap.Row = i For j = 1 To flxMap.Cols - 1 flxMap.TextMatrix(i, j) = "0" flxMap.Col = j flxMap.CellForeColor = vbBlack flxMap.CellFontBold = False Next j
For j = 1 To Form1.theLineCollection.Count
If Form1.theLineCollection(j).sFrom = Form1.theBlockCollection(i).TagID Then
toIndex = Form1.theBlockCollection.getIndexFromTag(Form1.theLineCollection(j).sTo) flxMap.Col = toIndex
flxMap.Text = Form1.theLineCollection(j).sCaption
If (flxMap.Text = "") Then flxMap.Text = "1" ' don't allow empty!!!! (for lines with no caption) flxMap.CellForeColor = vbRed flxMap.CellFontBold = True End If Next j Next i End Sub
Private Sub prepareFSP() Dim i As Integer flxS.Rows = 2 flxDist.Rows = 2 flxPath.Rows = 2 flxS.Cols = flxMap.Cols flxDist.Cols = flxMap.Cols flxPath.Cols = flxMap.Cols If flxS.Cols > 1 Then flxS.FixedRows = 1 flxDist.FixedRows = 1 flxPath.FixedRows = 1 flxS.FixedCols = 1 flxDist.FixedCols = 1 flxPath.FixedCols = 1 End If For i = 0 To flxS.Cols - 1 flxS.ColWidth(i) = flxMap.ColWidth(i) flxDist.ColWidth(i) = flxMap.ColWidth(i) flxPath.ColWidth(i) = flxMap.ColWidth(i) flxS.TextMatrix(0, i) = flxMap.TextMatrix(0, i) flxDist.TextMatrix(0, i) = flxMap.TextMatrix(0, i) flxPath.TextMatrix(0, i) = flxMap.TextMatrix(0, i) Next i For i = 1 To flxS.Cols - 1 flxS.TextMatrix(1, i) = "False" flxS.Row = 1 flxS.Col = i flxS.CellForeColor = vbBlack flxS.CellFontBold = False flxDist.TextMatrix(1, i) = "INF" flxPath.TextMatrix(1, i) = "0" Next i End Sub
Private Sub cmdFindShortPath_Click() prepareFSP
Dim src As Integer Dim dest As Integer
src = getIndexOfTabName(sFrom) dest = getIndexOfTabName(sTo) If (src = -1) Or (dest = -1) Then MsgBox "Data Salah Input" Exit Sub
flxS.Row = 1 flxDist.Row = 1 flxPath.Row = 1 Dim MAX As Integer MAX = flxMap.Cols Dim current As Integer Dim dist_fc As Integer Dim i As Integer Dim min As Integer Dim do_search As Boolean do_search = True
current = src dist_fc = 0
flxS.TextMatrix(1, current) = "True" flxS.Row = 1 flxS.Col = current flxS.CellForeColor = vbRed flxS.CellFontBold = True flxDist.TextMatrix(1, current) = 0 Do While do_search For i = 1 To MAX - 1
If ((myVl(flxMap.TextMatrix(current, i)) <> 0) And _
(myVl(flxDist.TextMatrix(1, i)) > myVl(flxMap.TextMatrix(current, i)) + dist_fc)) Then flxDist.TextMatrix(1, i) = myVl(flxMap.TextMatrix(current, i) + dist_fc)
flxPath.TextMatrix(1, i) = current End If
Next i min = INF
For i = 1 To MAX - 1
If ((myVl(flxDist.TextMatrix(1, i)) < min) And (flxS.TextMatrix(1, i) = "False")) Then min = myVl(flxDist.TextMatrix(1, i))
current = i
dist_fc = myVl(flxDist.TextMatrix(1, i)) End If
Next i
flxS.TextMatrix(1, current) = "True" flxS.Row = 1
flxS.Col = current
flxS.CellForeColor = vbRed flxS.CellFontBold = True If (min = INF) Then do_search = False End If Loop iRES_SIZE = 0 makeAllLines_Black lblResult.Caption = "Lintasan : " current = dest Do While current <> src
If (flxPath.TextMatrix(1, current) = "0") Then
lblResult.Caption = "NO PATH FROM " & flxMap.TextMatrix(0, src) & " TO " & flxMap.TextMatrix(0, dest) & "!"
lblTheDistance.Caption = "" Exit Sub
End If
lblResult.Caption = lblResult.Caption & flxMap.TextMatrix(0, current) addTO_RESULT (current)
lblResult.Caption = lblResult.Caption & " <- " current = myVl(flxPath.TextMatrix(1, current))
Loop
lblResult.Caption = lblResult.Caption & flxMap.TextMatrix(0, src) addTO_RESULT (src)
lblTheDistance.Caption = "Tujuan: " & flxDist.TextMatrix(1, dest) markLINES
End Sub
Private Sub markLINES() Dim i As Integer Dim tagFrom As String Dim tagTo As String
For i = iRES_SIZE To 2 Step -1
tagFrom = getShapeID_from_cap(sRESULT(i)) tagTo = getShapeID_from_cap(sRESULT(i - 1)) redLINE tagFrom, tagTo
Next i End Sub
Private Sub redLINE(sFrom As String, sTo As String) Dim xL As cLine
For Each xL In Form1.theLineCollection
If (xL.sFrom = sFrom) And (xL.sTo = sTo) Then xL.theObjectLine.BorderColor = vbRed xL.theObjectLine.BorderWidth = 5 End If
Next xL End Sub
Private Sub makeAllLines_Black() Dim xL As cLine
For Each xL In Form1.theLineCollection xL.theObjectLine.BorderColor = vbBlack xL.theObjectLine.BorderWidth = 2 Next xL
End Sub
Private Function getShapeID_from_cap(sCap As String) As String Dim xB As cBlock
For Each xB In Form1.theBlockCollection If xB.sCaption = sCap Then
getShapeID_from_cap = xB.TagID End If
Next xB End Function
Private Function getIndexOfTabName(s As String) As Integer Dim i As Integer For i = 1 To flxMap.Cols - 1 If flxMap.TextMatrix(0, i) = s Then getIndexOfTabName = i Exit Function End If Next i
getIndexOfTabName = -1 End Function
Private Sub Form_Activate()
If PREV_SELECTED_SHAPE = -1 Or SELECTED_SHAPE = -1 Then lblFromTo.Caption = "nothing selected"
cmdFindShortPath.Enabled = False Else
cmdFindShortPath.Enabled = True
sFrom = Form1.theBlockCollection(Form1.shp(PREV_SELECTED_SHAPE).Tag).sCaption sTo = Form1.theBlockCollection(Form1.shp(SELECTED_SHAPE).Tag).sCaption
lblFromTo.Caption = "Dari: " & sFrom & " ke: " & sTo End If
End Sub
Private Function myVl(s As String) As Integer If s = "INF" Then myVl = INF Else myVl = Val(s) End If End Function
Private Sub addTO_RESULT(index As Integer) iRES_SIZE = iRES_SIZE + 1
sRESULT(iRES_SIZE) = flxMap.TextMatrix(0, index) End Sub
Input Ukuran Matriks
Option Explicit
Private Sub Form_Activate()
If SELECTED_SHAPE <> -1 Then
UpDownWidth.Value = Form1.shp(SELECTED_SHAPE).Width UpDownHeight.Value = Form1.shp(SELECTED_SHAPE).Height End If
End Sub
Private Sub UpDownWidth_Change() If SELECTED_SHAPE <> -1 Then Form1.shp(SELECTED_SHAPE).Width = UpDownWidth.Value If Form1.shp(SELECTED_SHAPE).Shape = 1 Or Form1.shp(SELECTED_SHAPE).Shape = 3 Then Form1.shp(SELECTED_SHAPE).Height = Form1.shp(SELECTED_SHAPE).Width End If Form1.theLineCollection.updateLines End If End Sub
Private Sub UpDownHeight_Change() If SELECTED_SHAPE <> -1 Then Form1.shp(SELECTED_SHAPE).Height = UpDownHeight.Value If Form1.shp(SELECTED_SHAPE).Shape = 1 Or Form1.shp(SELECTED_SHAPE).Shape = 3 Then Form1.shp(SELECTED_SHAPE).Width = Form1.shp(SELECTED_SHAPE).Height End If Form1.theLineCollection.updateLines
End If End Sub
Tes lintasan terpendek
Option Explicit
Private Sub cmdDrawAll_Click() Dim i As Integer Me.Cls Me.ForeColor = vbBlack For i = 0 To listPaths.ListCount - 1 drawPath (listPaths.List(i)) Next i End Sub
Private Sub drawPath(s As String) Dim i As Integer
Dim c As String Dim prevX As Integer Dim prevY As Integer i = 1
CurrentX = 10 CurrentY = 10 prevX = -1 prevY = -1
If txtFirstChar.Text = "" Then txtFirstChar.Text = "A" Do While (Mid(s, i, 1) <> "")
c = Mid(s, i, 1)
CurrentX = (Asc(c) - Asc(txtFirstChar.Text)) * 40 + 10 If (prevX <> -1) Then
Line (prevX, prevY + TextHeight("A"))-(CurrentX, CurrentY) End If prevX = CurrentX prevY = CurrentY Print c i = i + 5 CurrentY = CurrentY + 40 Loop End Sub
Private Sub listPaths_Click() Dim i As Integer Me.Cls Me.ForeColor = vbBlack If (listPaths.ListIndex <> -1) Then drawPath (listPaths.List(listPaths.ListIndex)) End If End Sub
Private Sub listGoodPaths_Click() cmdDrawAll_Click If (listGoodPaths.ListIndex <> -1) Then Me.ForeColor = vbRed drawPath (listGoodPaths.List(listGoodPaths.ListIndex)) End If End Sub