简体   繁体   中英

Implementing dijkstra's algorithm in VBA

I have a spreadsheet set up with a bunch of distances to different restaurants. For simplicity, lets say all of column A has the restaurant names / code (Say a code is a number, 2 through XXX). Then, in B through XXX - 1 there is a number displaying the distance between the restaurant in A , and the restaurant whose code is the column number.

How would I go about implementing dijkstra's algorithm to find the shortest path given 2 user-entered inputs?

See below for a screenshot of the example spreadsheet: 电子表格的屏幕截图

What you would do is to write VBA code that loops over all the data that have distance information and store them in a proper graph data structure. I am not sure whether your data represent an undirected graph or whether it is just coincidence that you have a lower triangle matrix representation.

Anyway, after having transformed the data in a proper VBA data structure you could take an existing solution and make it work with your data structure. Or, in the first place, you make sure that the data structure fits to an existing solution. You can find a VBA Dijkstra implementation here .

If you want to implement it yourself, you can find many illustrative examples on the net, like here , to help you understand the algorithm itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM