+ Reply to Thread
Results 1 to 8 of 8

Shortest Path between Locations (without repeating)

  1. #1
    Registered User
    Join Date
    01-04-2017
    Location
    US
    MS-Off Ver
    2016
    Posts
    6

    Shortest Path between Locations (without repeating)

    I'm missing something obvious here and I just can't figure out how to quite go about it.

    I've essentially got a list of 20 locations - then looking up their zip codes and referencing them to lat/long.

    I want to take the 1st location (marking it as 1) and find the next closest location from it of the 19 remaining (and mark that location as 2). Then find the next closest location to location #2 and mark that as #3, etc. More or less trying to find the shortest distance path that taking me to all locations on that list without repeating. Short example below.

    Good on finding the distance and comparing it, my issue is more with how to knock a location off from the list once it's been selected.

    Any assistance would be appreciated it.

    Please Login or Register  to view this content.
    More or less the X loop doesn't do anything - I correctly find the location closest to Alpha but don't go beyond that because it just gets stuck there.

  2. #2
    Registered User
    Join Date
    01-04-2017
    Location
    US
    MS-Off Ver
    2016
    Posts
    6

    Re: Shortest Path between Locations (without repeating)

    The version below largely works - but it's re-selecting some locations (eg location is getting chosen as #4 and later being chosen again as #40).

    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Shortest Path between Locations (without repeating)

    First, the algorithm you describe will not necessarily give the shortest path across all locations.

    If you have a fixed starting point, and want to visit 19 more points, there are 19! possible paths, or 1.2 x 1017. (See Travelling Salesman Problem for a famous description of what you're trying to do.)

    That being said I will dig into your code and see if I can answer your question as asked.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    01-04-2017
    Location
    US
    MS-Off Ver
    2016
    Posts
    6

    Re: Shortest Path between Locations (without repeating)

    Ah, perhaps a bad descriptor then. I'd like to find the next closest location based upon my base location (so Alpha = 1, find closest to Alpha = 2/Beta, find closest to 2/Beta = 3/Charlie, etc) for my 20 locations.

    I know it pretty much is guaranteed to be non-optimal path but it's more focused on minimizing day to day travel (1 location = 1 day).

    Feel free to scrap and adjust as necessary - but hopefully my adjusted description is a little clearer.

    The important caveat is not repeating locations.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Shortest Path between Locations (without repeating)

    There are some things about your code that are a bit confusing, and might be clearer if you included your Excel file. For example, by are you multliplying R * 4? Why do you have a For loop that goes from 1 To 1? What is TestLoc? How are you marking points that have already been used?

  6. #6
    Registered User
    Join Date
    01-04-2017
    Location
    US
    MS-Off Ver
    2016
    Posts
    6

    Re: Shortest Path between Locations (without repeating)

    Ah - I've got some information in there I cleaned up in the code. I'm running this for multiple individuals (when it works) so the loop is for each individual (the location ID assigned to them is in columns 1, 5, 9, etc).

    So Column A is the identifying info I'm lookup up to obtain lat/lon, Column B/C are identifying info that's not being used, and Column D contains the visit order.

    So BaseLoc is my default start point, then it loops through all 20 locations (calculating distance from the BaseLoc) and records the closest location. It then resets BaseLoc to that location and repeats (in theory skipping locations that were already assigned).

  7. #7
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Re: Shortest Path between Locations (without repeating)

    if you know it is always 20 locations, couldn't you just declare 20 separate variables a default value of 0 or something and assign them their respective positions? then do until no more zeros are left?

    alternatively, if you want a more elegant solution, something like hiding/editing the used ones and only looking at visible/unedited locations could be another route to your desired results.

    Don't quite understand all of your code, so not going to give example code, sorry.


  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Shortest Path between Locations (without repeating)

    There are some things about your code that are a bit confusing, and might be clearer if you included your Excel file.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Shortest Path Between Cells (VBA)
    By basschmidt in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-18-2018, 06:07 PM
  2. VBA that calculates the shortest path
    By den_1985 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-05-2016, 05:58 AM
  3. Shortest path problem with excel solver
    By halatehini in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 01-11-2016, 12:51 PM
  4. color and count repeating empty cell locations
    By henneman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2010, 05:53 AM
  5. Returning file path locations
    By scanavan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-27-2007, 10:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1