LISTING PROGRAM
Kode Program Algoritma L-Deque:
Public Class Ldeque
Public graph As New List(Of List(Of edge_))() Private shortestDistances As New List(Of Double)() Private predecessorVertex As New List(Of Double)()
Public totalJarak As Double Public path As List(Of Integer)
Private watch As New Classes.Stopwatch() Public elapsedTimeMs As Double = 0
Public Sub New(graph As List(Of List(Of edge_))) Me.graph = graph
path = New List(Of Integer)() End Sub
Dim k As Double
k = predecessorVertex(v)
If k = -1 OrElse u = v Then Return
End If
path.Add(CInt(Math.Truncate(k))) getPath(u, CInt(Math.Truncate(k)))
End Sub End Class
Kode Program Algoritma Floyd :
Public Class Floyd
Public P As List(Of List(Of Double)) Public M As List(Of List(Of Double))
Public totalJarak As Double
Public startIndex As Integer Public endIndex As Integer
Public result As List(Of Integer) Public N As Integer
Private watch As New Classes.Stopwatch() Public elapsedTimeMs As Double = 0
Public Sub init(inputTable As List(Of List(Of Double)), N As Double)
Me.N = CInt(Math.Truncate(N)) P = New List(Of List(Of Double))() result = New List(Of Integer)() M = inputTable
For i As Integer = 0 To N - 1 P.Add(New List(Of Double)())
For j As Integer = 0 To N - 1 P(i).Add(-1)
Next Next
End Sub
Public Function calculateShortestPath(startIndex As Integer, endIndex As Integer) As List(Of Integer)
Me.startIndex = startIndex Me.endIndex = endIndex
watch.start()
If totalJarak <> Double.PositiveInfinity Then result.Add(endIndex)
End If
elapsedTimeMs = watch.[stop]() Return result
End Function
Public Sub getPath(u As Integer, v As Integer) Dim k As Double
k = P(u)(v)
If k = -1 Then Return End If
getPath(u, CInt(Math.Truncate(k)))
result.Add(CInt(Math.Truncate(k)))
getPath(CInt(Math.Truncate(k)), v) End Sub
Public Function FloydAlgo(M As List(Of List(Of Double))) As List(Of List(Of Double))
For k As Integer = 0 To N - 1
For i As Integer = 0 To N - 1
For j As Integer = 0 To N - 1
If M(i)(k) + M(k)(j) < M(i)(j) Then M(i)(j) = M(i)(k) + M(k)(j) P(i)(j) = k
End If Next
Next Next
totalJarak = M(startIndex)(endIndex) Return M
End Function
Public Function min(i As Integer, j As Integer) As Integer If i > j Then
Return j End If