Generation of Network graphs in Grasshopper

Hi all, Hi @Helvetosaur I have a question I tried a lot for threads to generate network graphs based on the relationships in Grasshopper. I wish I could get any help to proceed.

Sorry, I personally don’t know anything about this… :slightly_frowning_face:

do you want to code it on your own?

@Helvetosaur No problem Sir. Thank you for the reply.

@Baris Are there any other options available in grasshopper? I can do it. But the unfortunate thing I am anticipating is that I do not know how to handle the placement of points without the intersection of lines/edges. That’s the target.

Am not a programmer, but I learned a bit of it in python. I wish to know any thread on updating the whole points based on any change of any points.

Thanks in advance.

You mean that you are after some sort of reverse engineering? i.e. given a VV Tree ( * ) (that’s all you need - even if there’s islands around) do the Graph (in fact a Dendrogram of a Graph). This means that if the VV ( * ) is wrong you’ll get bananas.

( * ) A classic adjacency Matrix does the very same job.

If so that’s very easy via code (C# in my case). I could provide an entry level take on that - minus the island detection (strictly internal stuff that one).

BTW: Have in mind that you can’t auto-translate C# to P.

not sure if I get your point.

@Baris thanks.

@PeterFotiadis I have made the adjacency matrix. It is not a dendrogram; the branches of the trees may share some twigs. My objective is that without much cross over I want to place the points and create a neat network.

After giving an adjacency matrix of the network given below, we should be in a position to get this network.
image

Do you have the Vertices (Nodes) as well or only the AdjMatrix? (meaning an abstract relation of Nodes).

Nodes I need to generate from AdjMatrix. I need to make the network from AdjMatrix. I do have individual relationships as well, From and To lists.

I have bad and good news:

  1. Bad: your thing is solvable the way that a Hamiltonian path is solvable. This means several days (Amateur’s solution [like the ones posted frequently in Internet] : N factorial) or … several milliseconds. In plain Engilish a pro level backtracing is required. Obviously posting a similar solution is out of question (this is an Academic Forum after all and people receive “indicative” hints/help - unless the issue is about some artistic thing and the likes).

  2. Good: Imagine having the Adj Matrix on hand, Then do random Pts (as Nodes) where their Count is the Square Matrix Rows/Cols Count. Then using the Matrix as a VV Tree (and the Pts as Nodes) a Graph is made. Up to that phase is kid’s stuff. Obviously there’s Ccx chaos (case: flat Graph) and the likes. Like this one:

Then using K2 we attempt to reduce the ccx events to a bare minimum (that’s a wish NOT a 100% assured situation) by dealing actually with collitions in divited connections segments (resulting finally Curves). So the previous Ccx Chaos becomes:

Ugly news: in real-life is impossible to control that kind of K2 thing without 100% code. When I’ll post an indicative solution you’ll see the reason: it has to do with a heuristic (so to spaek) approach where you change Goal values and you inpect interactively the result (then either reject or keep the “good” results in some sort of Solution Tree). Imagine K2 within several loops. You can think the approach as some sort of MOO (so to speak).

1 Like

Thank you for the wonderful explanation and time. I am trying to code the network. I have created points against each assigned node and moved them to place individually. There will be multiple solutions, as you have indicated.

Note: if you have no experience with advanced backtracing … well … try the K2 way.

TIP: test your skills against a Hamiltonian path (that’s a very tough challenge mind - “similar” to yours).

PS: Tested some things that are not internal thus I can publish them in a Forum like this using, say, 100x100 Matrices. That’s a totally different animal than using, say, 10x10 Matrices. Obviously the more the Nodes the more ambiguous a solution becomes. So “by keeping track on solutions” I mean sampling the solutions with the less ccx events that … er … hmm … “look good” as well (the latter is not very scientific … but who cares?)

Finally a few notes on K2: That thing is an “optimizer” (so to speak). Meaning that if you feed it with bananas (by inputing “wrong/incompatible” Goal values and/or Goals) you’ll either get bananas or get bananas. All that having in mind the obvious: a Graph with Curves has a propability to being resolved 100000 times more than a Graph with Lines.

Now … imagine using, say, 4 Goals. Assume that each Goal value belongs to an Interval of [0.1 - 5.0]. Having in mind that you MAY be OK with 5 ccx events OR with 10 OR with 666 … you should try a lot of permutations (rather a colossal amount to he exact). Meaning that a “relaxation” that is not within a Loop (or several) is out of question - at least having real-life real-results in mind.

See a K2 test (Karma: a must) after … er … several milliseconds (my upper limit for waiting a stupid computer is 300 ms).

Here’s a hint: an amateur’s approach about using K2 to cut that Graph mustard.

  1. Random points + adj Matrix > a Line Graph where 700++ ccx events occur > 1M miles away from what we need:

  1. Line Graph + K2 + Karma: 6-7 ccx events (Note: this MAY be the min threshold for that particular Matrix):


From_Matrix_To_Graph_Help_K2_Collider_V1.gh (18.3 KB)

And why this is only for amateurs? Well … just modify the 5 sliders and observe how the N of ccx events rises (not to mention the required particle index mapping for the paramount post K2 action: create Curves from the relaxed particles). How can we solve that? Well … it’s elementary via C#.

More after the last dance: Abu Dhabi final F1 race (forza Lewis).

If you’re trying to lay out and draw network graphs in 2D you might also consider implementing e.g. GraphViz and calling that as a subprocess through Python (see this thread). Here’s an old example demonstrating the output:

@PeterFotiadis Thanks it is beautiful. This could be used to position the points through iterations. @AndersDeleuran Your work is brilliant. GraphViz seems to be a good thread. Thanks.
Finite Automaton | Graphviz

1 Like

D-I-S-A-S-T-E-R:

Lewis got a DNF (gearbox => kaput). So moral is low and thus I postpone (until the W14 emerges from the dust) any C# development on that matter.

Moral: How the Mighty Have Fallen.

PS: for managing correctly the relaxed particles you’ll need (a) to keep track on them and then (b) redo the Tree.


All in all: while we waiting for that W14 (a born killer, no less) … this is the current state of things:

From chaos:

To this:




1 Like

Your work is really good. Have you developed any plugins to bring networkx and graphviz to Grasshopper? I wish to make the network and get the coordinates of the vertices.