Jump to content
Sign in to follow this  
Chimp

TSP art generator

Recommended Posts

but can you make that an actual solvable maze :)

no but seriously, someone do that.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

@Chimp: Great; interesting to see TSP being used in this way^_^.

@iamtheky: This is by definition a solvable maze, as it's a single line. So in a maze like that, just keep either your left hand (c.q. your right hand) touching the nearest left (c.q. right) wall as you keep walking forward, and you'll get to the exit.:P

For those interested in the underlying maths, an example of an AutoIt script solving the TSP (Travelling Salesman Problem), see example 2 in my Simulated Annealing thread.

Edited by RTFC

Share this post


Link to post
Share on other sites

Well done @Chimp :thumbsup:

The script doesn't run properly when the path has blanks (white space) and I cannot scroll the result using the scrollbar to the right.

 

 

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Hi all, thanks for the likes and the feedback :)

@iamtheky, about the maze, as @RTFC sayd "This is by definition a solvable maze, as it's a single line", indeed it is already a maze,  but there is a funny way to find quickly the exit, here how: :)
1) to create a "maze" do like this: create a TSP art by setting sampling points to 1000 and then drag & droppo an image like the following for example  (a black square) to the tsp art generator.

x0DoloB.png

A "maze" similar to this will be created.

Gh81e2Z.png

2) now, open the folder of the script and you can find the tsp_art.svg that is the just created tsp_art, Right click it and select the open with notepad option.

go to the last line at the bottom and change this statement  stroke-width="0.25" to stroke-width="2" and save.

3) doubble.click the just modified file and it should open in a browser, zoom in or zoom out  the view of the browser to fit it on the screen if necessary abd then hit the "print screen" key.

4) now paste the screen in msPaint. There, using the eraser 'open' the "enter" of the maze at top left and the "exit" at right bottom.

5) using the fill tool, fill with a color the black line of the maze, you con see that only a part is filled, do the same with another color on the other part.

You can see that the the limit of the 2 colors is the best way to exit the maze.

6VleB63.png

@RTFC, Iv'e already used your nice TSP solver and it would be nice to use it here, but unfortunately the execution speed of AutoIt for solving a tsp problem with a number of points (towns) of the order of some thousands can not compete with the specialized program "concorde", written in C and compiled. (http://www.math.uwaterloo.ca/tsp/concorde/index.html)

 

On 10/25/2017 at 10:57 AM, UEZ said:

The script doesn't run properly when the path has blanks (white space) and I cannot scroll the result using the scrollbar to the right.

  Hi @UEZ, I've modified the script and posted in first post, now should work ok also with paths with white spaces.
About the scroll bars, my intention was to use the display window just as a little preview. For this purpose I'm using this statement within the HTML part that shows the svc file on the browser control: style="width:100%; height:100%;" this should fit the whole image in the available display area without the need of "scrolling", and it works like this on my pc,  but maybe, as you reported, this is not always the case.
The inibition of the scroll bars is due to the fact I've overlapped to the browser control area another trasparent control (a transparent label), that avoids the interaction of the user with the browser control itself. This has been done because otherwise when you drag and drop an image to the browser control, the drop event is captured by the browser control instead of by the GUI, avoiding the management of the drop event into the script.
I will try to use some other technique so to allow the use of the both (suggestions are welcome :))
... anyway, not need to say that the final generated TSP_art is saved in the same directory of the script with the name tsp_art.svg. ready to be doubble-clicked...,, also the intermediate "voronoi art" is saved in the same directory with the name of out.svg.

Edited by Chimp
update images links

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
14 hours ago, Chimp said:

unfortunately the execution speed of AutoIt for solving a tsp problem with a number of points (towns) of the order of some thousands can not compete

I'm not surprised.:lol: Thanks for the reference; unfortunately, the website appears to be down at the moment; I'll try again later.

It's funny though; the longer I look at these patterns, the more I'm reminded of brains; possibly not a coincidence that TSP optimises for shortest path and neuronal connections form a small-world network. Food for thought...:think:

Share this post


Link to post
Share on other sites

I am new to TSP art and to AutoIt.  I've downloaded all the dependencies and script into a single director (C:\TSP).  When I double-click on the script (TSP.au3), nothing happens.  I've attached an image of the directory in which I'm working.  I'd like to make TSP art from the Tree1.png file.  Thanks for any suggestions on how to proceed.

 

Image1.jpg

Share this post


Link to post
Share on other sites

Hi @DWB,

renaming the file cygwin1-20180309.dll to cygwin1.dll should fix....
let us know ...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Chimp
      An "improper" "unusual" use of Excel
      the script allows the creation of artistic images by simply coloring the background of the individual cells of the Excel workbook.
      Although definitely useless ... I find it quite funny though
      have a good time
      many thanks to @UEZ , @Malkey , @water
      p.s.
      I think the pixelite + color to array process can be simplified, but I used the two ready-made functions provided by UEZ and Malkey. I thank both of you (credits  and links in listing)
      p.p.s.
      strange behaviour: while excell is filling cells, if you move the mouse pointer off the excell window, the fill speed increases ... (?)

       
      ; =============================================================================================================================== ; Name ..........: Excel in art ; Description ...: This script allows the creation of artistic images in Excel from a choosed picture. ; The picture is done by simply coloring the background of the individual cells of an Excel workbook. ; Although definitely useless, I find it quite funny though ; ; Return values .: An artistic image in an Excel workbook ; Author ........: Addiego Gianni (chimp) ; Modified ......: ; Remarks .......: Many thanks to UEZ, Malkey and Water ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== #include <GDIPlus.au3> #include <Excel.au3> _PixelsToCells(50) ; <-- Parameter 50 is the cumber of horizontal Excel cells to be filled MsgBox(64, "All done", "Excel art is ready") Func _PixelsToCells($iHcells = 50) ; Check application object Local $oExcel = _Excel_Open() If Not IsObj($oExcel) Then MsgBox(16, "Error", "Sorry, You need to have 'Excel' intalled") ; Choose Image File Local $sPath = FileOpenDialog("Choose Image File", @ScriptDir & "", "Images (*.gif;*.png;*.jpg;*.bmp)| All (*.*)") If $sPath = '' Then Exit MsgBox(16, "Error", "Sorry, no image was chosen") ; Create a new Excel workbook $oWorkbook = _Excel_BookNew($oExcel, 1) ; initialize GDI+ _GDIPlus_Startup() Local $hBmp = _GDIPlus_BitmapCreateFromFile($sPath) Local $iWidth = _GDIPlus_ImageGetWidth($hBmp) ; get image width ; Local $iHeight = _GDIPlus_ImageGetHeight($hBmp) ; not needed here Local $iStep = $iWidth / $iHcells ; calculate the pixelation factor Local $hBitmap_new = _GDIPlus_PixelateBitmap($hBmp, $iStep) ; pixelate the image Local $aPixelColors = _FileImageToArray($hBitmap_new) ; get pixel colors ; reduce Excel columns width Local $xx = 1, $yy = 1 For $iCol = 0 To UBound($aPixelColors, 2) - 1 Step $iStep $oWorkbook.Sheets(1).Columns($xx).ColumnWidth = 1 $xx += 1 Next ; reduce Excel rows height For $iRow = 0 To UBound($aPixelColors) - 1 Step $iStep $oWorkbook.Sheets(1).Rows($yy).RowHeight = 9 $yy += 1 Next $xx = 1 $yy = 1 For $iRow = 0 To UBound($aPixelColors) - 1 Step $iStep For $iCol = 0 To UBound($aPixelColors, 2) - 1 Step $iStep $oWorkbook.Sheets(1).Range(_Excel_ColumnToLetter($xx) & $yy).Interior.Color = Number("0x" & $aPixelColors[$iRow][$iCol]) $xx += 1 Next $yy += 1 $xx = 1 Next _GDIPlus_BitmapDispose($hBmp) _GDIPlus_Shutdown() EndFunc ;==>_PixelsToCells ; by UEZ ; https://www.autoitscript.com/forum/topic/167707-imagepixelate/?do=findComment&comment=1227509 Func _GDIPlus_PixelateBitmap($hBitmap, $iPixelate, $bSmooth = 1) Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap) Local $iNewW = Round($iWidth / $iPixelate, 0), $iNewH = Round($iHeight / $iPixelate, 0) Local $hBitmap_scaled = _GDIPlus_BitmapCreateFromScan0($iNewW, $iNewH) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_scaled) Local $iInterpolation = 5 If $bSmooth Then $iInterpolation = $GDIP_INTERPOLATIONMODE_BILINEAR _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $iInterpolation) _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBitmap, 0, 0, $iNewW, $iNewH) _GDIPlus_GraphicsDispose($hCtxt) Local $hBitmap_pixelated = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_pixelated) _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $GDIP_INTERPOLATIONMODE_NearestNeighbor) _GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBitmap_scaled, 0, 0, $iNewW, $iNewH, -$iPixelate, -$iPixelate, $iWidth + 2 * $iPixelate, $iHeight + 2 * $iPixelate) _GDIPlus_GraphicsDispose($hCtxt) Return $hBitmap_pixelated EndFunc ;==>_GDIPlus_PixelateBitmap ; by Malkey ; https://www.autoitscript.com/forum/topic/112540-is-there-a-function-for-reading-images-into-2d-arrays/?do=findComment&comment=788472 Func _FileImageToArray($hImage) Local $Reslt, $stride, $format, $Scan0, $iIW, $iIH ; , $hImage Local $v_Buffer, $width, $height ; _GDIPlus_Startup() ; $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iIW = _GDIPlus_ImageGetWidth($hImage) $iIH = _GDIPlus_ImageGetHeight($hImage) ProgressOn("Progress Bar", "Filling a " & $iIW & " x " & $iIH & " size array.", "0 percent") $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iIW, $iIH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Local $aArray[$height][$width] For $j = 0 To $iIH - 1 For $i = 0 To $iIW - 1 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) $aArray[$j][$i] = StringRegExpReplace(Hex(DllStructGetData($v_Buffer, 1), 6), "(.{2})(.{2})(.{2})", "\3\2\1") ; To RGB format Next ProgressSet(Int(100 * $j / ($iIH)), Int(100 * $j / ($iIH)) & " percent") Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) ProgressOff() _GDIPlus_ImageDispose($hImage) Return $aArray EndFunc ;==>_FileImageToArray  
    • By wakillon
      Bitmap2AscII use Lucida Console font with a size set to 8, so Windows 8/8.1 users need to change their notepad font and size for get a correct display.
      Image Rescale slider is only available when saving as image.
      A click on the "PreviewEdit" open AscII string in Notepad.
      You can save as Text, Html or Image (add the extension you want)
      Each setting change is immediately applied.
       
      Downloads available in the download section
       
      Hope you like it ! 
       
×
×
  • Create New...