# Recursive or Iterative culling: How to cull connected lines without breaking the chain?

How do I loop or repeat a cluster?

Part of a definition I’m working on creates groups of connected lines. I would like to be able to randomly cull lines without breaking up the connected group.

Below is an example. The red lines can’t be culled without breaking or shortening the chain. If I randomly select one and only ONE blue line, it can be culled with no chance of breaking the chain. Randomly cull two blue lines, and I might break the chain.

Here’s a definition that culls random lines: dont break the chain multi-input.gh (42.6 KB)

As uploaded, if you move the “number of lines to cull” slider and keep the “random seed” slider, you’ll see how a single iteration of this method can fail when culling multiple lines.

Because I don’t know anything about recursive or iterative solving, the only way I can cull more than one blue line and guarantee that I won’t break the chain would be to cluster this definition and connect it to itself in a line, repeatedly.

My Question: What methods/plug-ins are available for looping/chaining a cluster like this? Are there tutorials that explain how to do this?

I got the following without any iteration but see that I missed some segments, so back to the GH canvas…

dont break the chain_2020Nov27a.gh (21.0 KB)

The goal is to have a slider that culls X number of lines, choosing them randomly, without breaking the lines into unconnected sets. If the number on the slider exceeds the number of lines that can be culled without creating unconnected sets, it should stop culling.

So, take one line away, yielding a v or a quad, re-run the algorithm on the results, again preventing lines that aren’t within surface borders from being culled… repeated.

When I manually cull random lines this way, the variety of results I get is very organic. That’s the goal.

Sorry, I don’t know what that means? Have fun.

1 Like

In the original red and blue image, delete any blue line. If the remaining two blue lines from that triangle aren’t part of a closed loop, turn them red. Repeat.

If you delete one line from a triangle yhe 2 others won’t be closed, smtg I don’t understand in your goal

Step 1: evaluate which lines are part of a closed loop, ie part of something that produces a surface when run input to Boundary Surfaces.

Step 2: Delete one of these lines, at random.

Step 3: take the results of step 2 and return to step 1. Repeat until Step 1 doesn’t find any lines that fit it’s criteria.

Ok but are you looking for kind of animation?

Animation is not necessary. I just need to loop the algorithm x number of times, for deleting a variable number of lines.

I don’t know if this might be helpful,
it generates every possible path between 2 points in a graph

source code is ctrl+c and ctrl+v from here: https://www.geeksforgeeks.org/find-paths-given-source-destination/ and stupidly adapted in 30 seconds

applied to your graph it finds 4032 different solutions to get from node 20 to node 22, in 40ms
(and -of course- it does not travel through nodes 15 and 24 because they would create a closed loop with node 16)

note: code could be cleaned a lot to avoid all the replace/split text

it requires the component “Graph from lines” from the awesome plugin Fox

all_possible_paths.gh (18.2 KB)

This is not what I’m trying to do. Aesthetically, for this project, I’m trying to create dead ends, and some closed loops. My goal in culling is to give it a more chaotic appearance.

That said, this is potentially a very cool option to add to the mix that I hadn’t even thought of. Thanks!