How to combine a number of coordinates with one continuous line?

4 visualizaciones (últimos 30 días)
Jay Muller
Jay Muller el 21 de Jun. de 2015
Comentada: Walter Roberson el 26 de Mzo. de 2018
Hi all,
I was wondering whether there exists a solution/algorithm for my problem: I have a large number of coordinates, e.g. nodes, that I want to automatically link with one continuous line. The problems are my restrictions:
  1. Each node must only be covered once
  2. The lines must not overlap with other lines or coordinates
  3. There's a maximum length for the lines
  4. I want to feed in arbitrary structures
Are there any ideas on how I could solve this issue? Shown are some examples for the rules, they don't cover all of them though.
Thanks a lot in advance! Jay
  6 comentarios
Image Analyst
Image Analyst el 15 de Abr. de 2017
Esteban - that's ambiguous. Do you mean you have the problem where you have a square grid and diagonal lines are not allowed? Or do you mean that you have the grid problem but the lines are diagonal, like with diamond-shaped cells instead of square shaped cells? Please post a diagram in your own new question.
João Rosas
João Rosas el 24 de Mzo. de 2018
hi! i have that same problem, can you please give me the code? i don't know how to code :(

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 21 de Jun. de 2015
Well, the easy one is step #3. Use pdist() (In the stats toolbox) to find distance from every point to every other point. Then take the max of that. If that max distance is more than your max allowable line length, then there is no solution.
Assuming it passes that test, then there could be multiple solutions. Imagine a rectangular grid. There are tons of ways you could draw a single line connecting them all: raster up/down, raster left right, raster diagonally, spiral inwards, spiral outwards, etc.
Is any solution okay? Or do you need the shortest path, like the famous "Traveling Salesman Problem"? Do you have any specified starting and ending points? Or can you start and stop on any point, and you need to find the endpoints that give you the shortest total path length?
  4 comentarios
Walter Roberson
Walter Roberson el 26 de Mzo. de 2018
The problem has not yet been clearly enough defined to code.
If the selected locations form a grid or subset of a grid, then the task becomes easier to set up.
A key question is whether any of the Hamiltonian paths are acceptable, or if the shortest such path is required. The shortest such path takes a lot more work.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 21 de Jun. de 2015
There are a number of ways to attach the traveling salesman problem. See the Mathworks suggestions: http://www.mathworks.com/search/site_search.html?q=traveling+salesman&term=traveling+salesman&c[]=entire_site_en

Walter Roberson
Walter Roberson el 21 de Jun. de 2015
Editada: Walter Roberson el 22 de Jun. de 2015
This is mostly just a traveling salesman problem with just not adding in edges that are too long. The only thing that is not normal is checking that the lines do not cross: typically they do not cross (because uncrossing them would usually lower the energy.) If the example you show, if you only provide vertices to the nodes that are adjacent horizontally and vertically then you cannot end up with a crossing line.
  2 comentarios
Jay Muller
Jay Muller el 21 de Jun. de 2015
Thank you both very much. I'll have a closer look into the TSP, as you say, maybe I "just" need to modify the algorithm a bit, e.g. by deleting unwanted lines.
Walter Roberson
Walter Roberson el 22 de Jun. de 2015
If you have a grid like you show in the examples, you cannot end up with unwanted lines provided you only populate edges between nodes that are horizontally or vertically connected. If the nodes are not on a regular grid then there could potentially be circumstances under which the edges crossed with a path that was otherwise valid.

Iniciar sesión para comentar.

Categorías

Más información sobre Solver-Based Optimization Problem Setup en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by