I am developing a program using VB.NET that will accept a start and end
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. - 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
5 2338
Still unsure where the problem lies, you are having trouble using foundHamiltonian?
what i mean is...i had kept the distance and edges in database. right now is i want to adjust the code just like mapping system. there will be start and end location user could select ( 2 list boxes)..and then once calculate button is clicked...system will run the code. it different from what i do now since the code above i set the distance and vertices in the code, not in the database.
how could i adjust the code that could integrate with the sql database created? i wish to get the output same as the code that i paste above. please help me with this
If you are going to use a database, then you have use a connection and queries. Here is a good place to start with a connection string.
i have a question here.i want to increase the number of location(vertexnum) involve to 15. firstly i up the number of location to 5. but the output doesnt show up. what should i change instead of the value of VERTEXNUM, edges and vertices?
i have a question here.i want to increase the number of location(vertexnum) involve to 15. firstly i up the number of location to 5. but the output doesnt show up. what should i change instead of the value of VERTEXNUM, edges and vertices?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Porthos |
last post by:
Hi All,
I'm trying to find the minimum value of a set of data (see below).
I want to compare the lengths of these attribute values and display
the lowest one.
This would be simple if I could...
|
by: Lau |
last post by:
How do I easily calculate the shortest path between two geographical spots on
a map?
The map is divided into zones. So I guess it is possible to use Dijkstra’s
Shortest Path algorithm, but it...
|
by: ThanhVu Nguyen |
last post by:
Hi all,
I need recommendation for a very fast shortest path algorithm. The
edges are all directed, positive weights. Dijkstra shortest path will
solve it just fine but the if the graph is not...
|
by: Webdad |
last post by:
Hi!
I running my first year as industrial engineer (informatics)
We have an assignment to do :
.... create a playfield (matrix). Some places in that field are
blocked, so you can't pass them....
|
by: leezard |
last post by:
I am developing a program using VB.NET that will accept a start and end
point, the system then will generate the shortest path to reach the end
point. Anyone here have idea on doing this or some...
|
by: costantinos |
last post by:
Hello. I have implemented the Dijkstra shortest path algorithm, it
works fine but I have one question on how I can improve something.
I want to find all the possible shortest paths from a node...
|
by: diffuser78 |
last post by:
Is there any function in networkx which can compute the shortest mean
path length. (Shortest length between all pairs of the nodes in the
graph).
Thanks,
|
by: Bytter |
last post by:
Hi everyone,
I need to implement a very quick (performance-wise) Dijkstra shortest
path in python, and found that libboost already has such thing. Problem
is: I cannot find the installation...
|
by: Glenton |
last post by:
Hi All
Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm:
#!/usr/bin/env python
#This is meant to solve a maze with Dijkstra's...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |