Traveling Salesman with iterative macro
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Greetings,
I have this workflow which uses a nearest neighbor macro (greedy algorithm) to do a local optimization approximating the traveling salesman problem. It simply iterates through each remaining location until every location is visited (because of the sheer number of permutations it is impossible to do a global optimization) and determines the shortest path visiting every location. I want to approximate the global optimization by reiterating the macro with each location serving as the starting point. Then I want it to select the route with the shortest total distance and output that. I believe this means I will need an iterative macro within an iterative macro. I am simply not familiar enough with how to program this in Alteryx, and I would be very appreciative for any assistance that you can offer.
Thank you very much,
Daniel
Solved! Go to Solution.
- Labels:
- Iterative Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
What finally made iterative macros "click" for me was to approach them as follows:
Two paths from the input:
- 1, sample the first row for processing - send the eventual output of that processing to the "final output"
- 2, skip the first row - send everything but the first row to the "loop output" (which comes back to the input)
This is the simplest approach to looping: you pick off the first row every time through the loop, and do something.
For your problem, all you need to do is substitute in your logic into the "processing" section. If your processing is excruciatingly complex, you could even make that it's own simple "worker" macro, thus turning your iterative macro into more of a "loop controller" and nothing more.
And... as it happens, your "excruciatingly complex" "worker macro could even contain another iterative macro inside it... and if desired that embedded iterative macro could be another "loop controller" that contains another "worker".
Next thing you know, you're doing OOP (object oriented programming) using Alteryx: you just draw the skeleton of the overall process. Make sure that processing is flowing as you desire. Once it is, start to add the heavy lifting that does the actual work.
Not sure if that helps. I also once wrote an recursive iterative macro and documented the heck out of it, but I don't think that applies very nicely here. (This can be found in this post.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you for your response, and I'm sorry for the delay. I did solve the issue by picking off one row at a time. It turned out to be a lot easier than I thought.
Thank you,
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Daniel - I am working on a similar problem and was wondering if you could share more of your solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This is amazing! It's almost exactly what I was looking for. Only way to get better would be to get an exact distance by route like with a google maps api, but I imagine that would be waaaay to complex. But this, it just worked! I'm amazed! Thank you so much for sharing.
