Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Traveling Salesman with iterative macro

danielrg
6 - Meteoroid

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 

3 REPLIES 3
JohnJPS
15 - Aurora

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

 

danielrg
6 - Meteoroid

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

lhutchison34
5 - Atom

Daniel - I am working on a similar problem and was wondering if you could share more of your solution. 

Labels