473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

finding shortest path

4
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.


Expand|Select|Wrap|Line Numbers
  1. Public Class WebForm1
  2. Inherits System.Web.UI.Page
  3.  
  4. Public Const VERTEXNUM As Integer = 4
  5. Public Const HUGE As Integer = 32000
  6. Public Shared vertices() As String = {"Bukit Bintang", "China Town", "Chow Kit", "Istana Negara"}
  7.  
  8. 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}}
  9.  
  10.  
  11. Public visited(VERTEXNUM) As Integer
  12. Public curMinCost As Integer = HUGE
  13.  
  14. Public curMinHamNum As Integer = 0
  15. Public currentRoute(VERTEXNUM) As Integer
  16.  
  17. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  18.  
  19. main()
  20.  
  21. End Sub
  22.  
  23.  
  24. Public Function main() As Integer
  25.  
  26. Dim start As Integer = 0
  27. Dim j As Integer
  28.  
  29.  For j = 0 To VERTEXNUM - 1
  30.  
  31. If (j <> start) Then
  32. findRoute(start, j, edges(start, j), 0)
  33. End If
  34. Next j
  35.  
  36.  
  37. TextBox1.Text &= "lowest cost hamiltonian cycle: " & curMinHamNum & " w/ cost " & curMinCost & Environment.NewLine
  38.  
  39. 'changing line as follows will allow all 7 lines to be printed in WinForms application
  40.  
  41. Return 0
  42.  
  43. End Function
  44.  
  45.  
  46. Public Sub findRoute(ByVal start As Integer, ByVal current As Integer, ByVal costSoFar As Integer, ByVal numVisited As Integer)
  47.  
  48. Dim j As Integer
  49. currentRoute(numVisited) = current
  50.  
  51.  
  52.  
  53. If (current = start) Then
  54. If (numVisited = VERTEXNUM - 1) Then
  55. foundHamiltonian(start, costSoFar + edges(current, start))
  56. End If
  57. Else
  58. visited(current) = 1
  59. For j = 0 To VERTEXNUM - 1
  60.  
  61. If (visited(j) = 0) Then
  62. findRoute(start, j, costSoFar + edges(current, j), numVisited + 1)
  63. End If
  64. Next j
  65. visited(current) = 0
  66.  
  67. End If
  68.  
  69. End Sub
  70.  
  71. Public Sub foundHamiltonian(ByVal start As Integer, ByVal cost As Integer)
  72.  
  73. Dim j As Integer
  74. Static hamNum As Integer = 0
  75.  
  76. hamNum = hamNum + 1
  77.  
  78. TextBox1.Text &= "#:" & hamNum & " " & vertices(start)
  79.  
  80. For j = 0 To VERTEXNUM - 1
  81.  
  82. TextBox1.Text &= "->" & vertices(currentRoute(j))
  83. Next j
  84.  
  85. TextBox1.Text &= "costs " & cost & Environment.NewLine
  86.  
  87. If (cost < curMinCost) Then
  88. curMinCost = cost
  89. curMinHamNum = hamNum
  90. End If
  91.  
  92. End Sub
  93.  
  94. End Class
Oct 5 '07 #1
5 2384
kenobewan
4,871 Expert 4TB
Still unsure where the problem lies, you are having trouble using foundHamiltonian?
Oct 5 '07 #2
aleya
4
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
Oct 6 '07 #3
kenobewan
4,871 Expert 4TB
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.
Oct 6 '07 #4
aleya
4
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?
Oct 7 '07 #5
aleya
4
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?
Oct 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
6
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...
6
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...
20
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....
5
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...
5
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...
0
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,
2
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.