Single Line Art / Traveling Salesman Problem Tutorial
The “Traveling Salesman Problem” (“TSP”) is a problem studied in mathematics where one tries to figure out the shortest path through a number of points. Solving for the absolute shortest route can take a lot of processing power and time, but getting a pretty good approximation can be very quick. The Eggbot, MakerBot Unicorn, and drawing robots are particularly well suited to these kinds of drawings.
Recently I tried to create some of my own single line / TSP art based using the awesome Evil Mad Science TSP guide. In doing so I think I may have figured out a way simplify the process slightly for Windows users. 1 The EMS guide has the user install Cygwin in order to provide certain elements of Unix for running the Concorde or Linkern TSP solvers. However, I accidentally discovered that once you have the “cygwin1.dll” out of the Cygwin installation, all you need to do is create a batch file for automating the TSP conversion. So, start to finish, here’s how I do it:
Programs / Scripts
- Download and install the free open source Python programming language
- Download and install the free open source GIMP image manipulation software2
- Download the Evil Mad Scientist Eggbot scripts for creating TSP vector art. You’ll want the file named, “tsp_art_tools_0_8_3.zip”
- Download the Linkern TSP solver from Georgia Tech’s website
- Download the “cygwin1.dll” file for running the Linkern TSP solver on a Windows platform
Install Scripts
- Put the “cygwin1.dll”, “linkern.exe”, “tspart.py” , “tspbitcity.py”, “tspsolution.py” into a folder location of your choice
Make a Grayscale Image
- Open your image in GIMP
- Turn the color information monochrome “Image -> Mode -> Grayscale“
- Open the color levels “Colors -> Levels“
- Wash out the image by adjusting “All Channels” in the pop-up window to some value to 2003
Make a Stippled Image
- Turn the washed out grayscale image into a stippled image “Create Image->Mode->Indexed“
- Select these options in the pop-up window
- Use black and white (1-bit) palette): Checked
- Remove unused colors from colormap: Checked
- Color dithering: Floyd-Steinberg (normal)
- Click “Convert“
- Save the file in the “Portable Bit Map” format “File->Save As” and saving the file with the extension “.pbm“
- If given the option, choose to save the PBM file in the “Raw” format
Create a Batch file to automate the Stippled Image to a TSP Line Drawing conversion
- Open “tspart.py” with your favorite text editor4 and change line 76
- From: LINKERN = ‘C:\linkern.exe’
- To: LINKERN = ‘C:\FILELOCATION\linkern.exe’
- Save “tspart.py”
- The command for converting the PBM file takes three parts, the location of Python, the location of “tspart.py” and the location of your PBM file. Here are where my files are located:
- My Python directory is located at “c:\python\python”
- My scripts are located in a subdirectory on my desktop “c:\python\python C:\Users\MakerBlock\Desktop\TSP\scripts\tspart.py”
- My PBM file is also located on my desktop “C:\Users\MakerBlock\Desktop\TSP\images\drawing.pbm”
- Open a text editor and copy these three locations into one line as follows:
- c:\python\python C:\Users\MakerBlock\Desktop\TSP\scripts\tspart.py C:\Users\MakerBlock\Desktop\TSP\images\drawing.pbm
- Save the text as a batch file named “convert2tsp.bat”
Use the Batch file to convert the Stippled Image to a TSP Line Drawing
- Double-clicking the batch file will convert “drawing.pbm” into “drawing.svg”
- To convert your next file, you can either name it to “drawing.pbm” or edit the Batch file to reflect a different PBM file name.
If you haven’t tried to create some single-line-artwork yet, give it a shot today! It’s a lot easier than it looks and the results are really satisfying!
Once you’ve gone through the above process once, it goes super quickly the second time. You basically make your image grayscale, wash it out, save as a stipple file format, and then run the batch file. The entire process takes about two minutes once you get the hang of it – with a full minute and a half or so just devoted to letting the TSP program do its thing.
- I know. I’m trying to give it up too… [↩]
- I like the PortableApps.com version [↩]
- Values between 180 and 245 should work well [↩]
- I like the PortableApps.com version of Notepad++ [↩]
| Tagged with | dnewman, drawing robot, eggbot, ems, single line art, traveling salesman, traveling salesman problem, tsp | 12 comments |








12 Comments so far
Mr T
How come TSP routes are not used as infill pattern in the slicer?
TSP Guide | Polargraph
[...] Makerbot Blog TSP Art guide [...]
TSP FTW! | MakerBlock
[...] have been having SO MUCH FUN with traveling salesman problem / single line art! I can’t wait to draw some of these with my [...]
dnewman
Thanks for writing this up! I’ll add a link to the Evil Mad Science TSP art pages if that’s fine with you. Should be handy for folks wanting an alternate tool chain not requiring Inkscape (which is near but perhaps not dear to any Eggbotter’s heart).
Dan
Dan
Please: how would I convert this TSP file to gcode for my robot? Thank you!
Dan
Or an image as you’ve done above? I get that the file is just XY coordinates. I’d rather write my own rendering pipeline to convert the file to a picture.
Thanks again!
KalleP
Thank you.
I have been trying to figure out how to glue all the bits together and the PBM file format as output I think will solve things for me
John
This is a great tutorial that any salesman can use regardless of whether or not they travel.
Gyuhwan
I followed your instructions, but error 5 occurs.
Burke LaShell
The ShapeOko CNC community has started playing with single line drawings, too. Check out this thread for a different software path.
http://www.shapeoko.com/forum/viewtopic.php?f=7&t=346
Dan
The java app that comes with my mural drawing robot will convert any jpg, bmp, png, or gif to a single line drawing as described above IN ONE STEP. Also it is open source so you can optimize it even further if you want.
Dan
oops, forgot the url: http://www.marginallyclever.com/category/drawbot-my-creations/