location (2 list boxes), the system then will generate the shortest path to reach the end point.
for your information i got a code in C and succesfully translated it into vb.net. however this code had fix the length during the declaration. what i want to do now is keep the distances in database (sql server) and during calculation it'll retrieve data from database.i had create the database in sql server. the problem now is how to start the calculation. Anyone here have idea on doing this or some code examples that can share it with me. how could i edit these code into something like that. please help me since i am new with this.
Thanks in advance.
below is the code i had translated from C to vb.net. i want to get the output just like the code velow. ikindly please guide and help me.
Expand|Select|Wrap|Line Numbers
- Public Class WebForm1
- Inherits System.Web.UI.Page
- Public Const VERTEXNUM As Integer = 4
- Public Const HUGE As Integer = 32000
- Public Shared vertices() As String = {"Bukit Bintang", "China Town", "Chow Kit", "Istana Negara"}
- Public Shared edges(,) As Double = {{0, 0.9, 2.1, 3.1}, {0.9, 0, 2.2, 1.4}, {2.1, 2.2, 0, 3.4}, {3.1, 1.4, 3.4, 0}}
- Public visited(VERTEXNUM) As Integer
- Public curMinCost As Integer = HUGE
- Public curMinHamNum As Integer = 0
- Public currentRoute(VERTEXNUM) As Integer
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- main()
- End Sub
- Public Function main() As Integer
- Dim start As Integer = 0
- Dim j As Integer
- For j = 0 To VERTEXNUM - 1
- If (j <> start) Then
- findRoute(start, j, edges(start, j), 0)
- End If
- Next j
- TextBox1.Text &= "lowest cost hamiltonian cycle: " & curMinHamNum & " w/ cost " & curMinCost & Environment.NewLine
- 'changing line as follows will allow all 7 lines to be printed in WinForms application
- Return 0
- End Function
- Public Sub findRoute(ByVal start As Integer, ByVal current As Integer, ByVal costSoFar As Integer, ByVal numVisited As Integer)
- Dim j As Integer
- currentRoute(numVisited) = current
- If (current = start) Then
- If (numVisited = VERTEXNUM - 1) Then
- foundHamiltonian(start, costSoFar + edges(current, start))
- End If
- Else
- visited(current) = 1
- For j = 0 To VERTEXNUM - 1
- If (visited(j) = 0) Then
- findRoute(start, j, costSoFar + edges(current, j), numVisited + 1)
- End If
- Next j
- visited(current) = 0
- End If
- End Sub
- Public Sub foundHamiltonian(ByVal start As Integer, ByVal cost As Integer)
- Dim j As Integer
- Static hamNum As Integer = 0
- hamNum = hamNum + 1
- TextBox1.Text &= "#:" & hamNum & " " & vertices(start)
- For j = 0 To VERTEXNUM - 1
- TextBox1.Text &= "->" & vertices(currentRoute(j))
- Next j
- TextBox1.Text &= "costs " & cost & Environment.NewLine
- If (cost < curMinCost) Then
- curMinCost = cost
- curMinHamNum = hamNum
- End If
- End Sub
- End Class