1

I am trying to see if there is a known solution to my problem, possibly lacking the right search terms or similar,

The problem is given a circular or square grid of points size $X$, can you escape all the wires Size $Y$ and clearance between the points / traces is size $Z$ for a reference example, and if possible a bonus of is there an algorithm that can be run to generate that pattern

For an example from the one I have manually tried (second image), The grid points are 0.25 and the wires are 0.2mm, and clearance is 0.2mm, In this specific case I went with spacing for 2 traces to be able to escape horizontally and vertically, so pad + 2 trace + 3 space, or 0.75mm, this also allows for 3 traces diagonally, For reference this use case is circuit boards, and escaping out of compact arrays of electrodes

I have stumbled upon what is called the "maximum flow algorithm" which seems related, but struggle to find good reference if its applicable to this problem,

The top image so far is my attempt to reduce the problem space so far, As with the even symmetry arrays I am working with are so far all escapable with 4 way symmetry, I figured I would start by attempting to solve it just for those corners,

The green points would be the pads that need to escape, the red is where they need to reach to escape,

I am currently approaching it with brute forcing in mind, compute every path an escape from every pad, and then iterate through the list until I find one with no conflicts, but hoping someone knows this by a different name, with a less computationally expensive solution,

For more context, I am hoping to try and use this math for much bigger arrays than the one pictured

enter image description here

enter image description here

Kenta S
  • 16,151
  • 15
  • 26
  • 53
Reroute
  • 113
  • 1
    What does "escape" mean? Why are the dimensions important? Is the problem simply to find non-intersecting paths from the green pads to the red pads? If so, max-flow sounds like the way to go. – saulspatz Aug 17 '20 at 03:43
  • Each pad needs a non intersecting path to the outside of the grid, dimensions where for me important, and was not sure if that would change how the problem was approached if that part was variable, The green/red pads technically are already escaped, so I colored them differently. each other pad would need to reach a red dot – Reroute Aug 17 '20 at 03:56
  • Just to check my understanding. In the first diagram,, we need to construct 3 non-intersecting paths, each leading from one of the green dots to a red dot. Also, I assume that they have to end at 3 different red dots, and that these cannot be at the three pads that are already escaped. I believe the max-flow algorithm will work if all of that is true, but I'll need to think about it. – saulspatz Aug 17 '20 at 04:17
  • That is correct @saulspatz, The solution will need to eventually be scaled up to 6x6 to 15x15 patterns per corner (15 green pads wide, 15 tall), I started with simple to make testing ideas fairly easy – Reroute Aug 17 '20 at 08:00

2 Answers2

2

Your problem can be formulated as a maximum flow algorithm. A description of the problem and two algorithms for its solution are given in chapter 26 of "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein. You should read the first section of the chapter to understand my remarks.

The problem is not exactly a network flow problem as it stands, but we can easily modify it to put it into that form. First, we notice that a flow network is a digraph (directed graph), and the given graph is not directed. We modify the given network by replacing each edge, that is each line segment between two dots, by two directed edges, one in each direction. It is unnecessary to do this with the pads, since we don't want any flow into the pads. For the segments incident on the pads, just direct the edge away from the pad. (I would simply delete the pads that are already escaped from the graph.) Furthermore, we don't want any flow out of the red dots, so instead of replacing the segments incident on them by two edges, simply direct the segments into the red dots.

The next problem is that a flow network has a single source and a single sink, whereas our network has several of each. We add a "super-source" with an edge to each pad, and a "super-sink" with and edge from each red dot.

The third deficiency is that edges in a flow network are capacitated. We easily deal with this by giving each edge a capacity of $1$.

Now, the network we have constructed still has problems. We have introduced what the authors call "anti-parallel" edges, that is edges between the same pair of nodes, but in opposite directions. The authors explain how to deal with this in the paragraph starting at the bottom of page 711.

We have one final problem. Many of the nodes have multiple incoming and outgoing edges. It is possible for there to be a total flow of more than $1$ through such a node, which would mean that we have crossing paths. To obviate this, replace each such node $v$ by two nodes, say $v_I$ and $v_O$. All the incoming edges go to $v_I$ instead of $v$ and all the outgoing edges leave from $v_I$ instead of $v$. Finally there is a single edge, of capacity $1$ from $v_I$ to $v_O$. It is clear that there will be no more than one path through the new "node".

Once a maximum flow is found, the edges with a flow of $1$ in them give the desired paths, once they are translated back to the original network. While the modified network may sound complicated, and would be difficult to draw, I think it would be straight-forward to program. Translation back to the original network shouldn't present a problem.

Now, which max-flow algorithm should you actually use? In general, the push-relabel algorithms described in section 26.4 are the fastest, and are no harder to implement than the Ford-Fulkerson type algorithms, though they are harder to understand intuitively. (If you read the section, the authors try to give an intuitive explanation on page 737. The explanation makes no sense, and I would advise you to ignore it.) Ordinarily, I would opt for push-relabel, but in this instance, I think Edmonds-Karp algorithm described on page 727 might be preferable. The issue is that newtork flow algorithms are guaranteed to find a way to escape all the pads, if such a way exists, but they aren't guaranteed to find the simplest paths, whatever "simplest" means. Edmonds-Karp uses breadth-first search, and should find short paths.

From a programming standpoint, the major effort will surely be constructing the modified network, and in translating the answer back into terms of the original network. You can plug in one of the flow algorithms and see if it works satisfactorily. If not, plug in the other one.

Since all edges have capacity $1$, it's possible that some specialized algorithm exists that would be more efficient than a generic max-flow algorithm, but as a practical matter, I'd prefer using a tried-and-true method to developing a new one, unless the old method is too inefficient. Given the sizes of your networks, I don't think efficiency will be a problem.

I found an old C++ program of mine that implements push-relabel. It was probably written for a class, and I doubt it's production-quality code, but if you think it would be of use to you, I'd be glad to put it on github for you.

saulspatz
  • 53,131
  • Would be great to have some starting point code. And thank you for the detailed reply. Will read up on your source tonight – Reroute Aug 18 '20 at 03:55
  • https://github.com/saulspatz/maxflow From the comments, it appears that this follows a prior edition of the book, and the algorithm may be slightly different, but that shouldn't matter. The major work will be in preparing the input, as I said before. – saulspatz Aug 18 '20 at 14:13
1

Disclosure : Here is a developed idea, not at all an achieved answer, but certainly too large for a mere comment.

Instead of using a graph with a square grid structure, a different data structure could be more adapted. This data structure is (almost) a tree. We can ask or not for this tree to be "balanced" (all branches have the same depth).

Let us give precisions. In your last figure, consider the bottom right (i.e., third) quadrant. Don't take into account what you call the "reference" path (which can be added at the end): in this way, every segment of every path can be coded with one of the following 3 "tokens" that will be "istalled" at the nodes of the tree:

0 for going West, 1 for SouthWest, 2 for South,

to which we must add a special token "3" needed for connecting the paths to the root of the tree by creating "ficticious" segments.

For example starting anticlockwise from path 0 (the reference path), the fourth path would be coded 3110001101111 (by the way without needing "token" 2).

Now, how can an algorithm can take profit of this data structure ? It is too early for me to have an answer but one can say already that :

  • The tree should be initialized (by hand in a first step) by a thorough placement of the initial "3"s.

  • Then, we have to settle between a depth-first or a breadth-first growing of the tree or a mixture of both ; we certainly need a backtracking process (easy in a tree structure!), with hopefully, in a further step, a heuristic guiding. The big question is how to check (efficiently...) at each new built segment whether or not there is an intersection with an already existing branch (i.e. a violation of the tree structure)...

Once more, it is far from an achieved result, but my experience is that a constructive exchange of ideas on such an issue is very valuable, and avoids the pitfall of providing a full solution that does not fit the needs...

Jean Marie
  • 81,803