Asymmetric link forces in D3 force-directed graph - d3.js

Is it possible to create a custom (link) force in a d3 force-directed graph, such that the link strength is asymmetric? What I mean is that I want two nodes A and B, and B is completely oblivious to node A, but node A is constantly trying to remain a certain distance (maybe 0?) from node B.
More generally, I'd like two graphs G1 and G2 where G1 is draggable and moves like a regular force-directed graph (oblivious to G2), and the nodes in G2 are constantly trying to re-position themselves relative to G1 in a certain way.

Related

Matching non-isomorphic graphs

I have two graphs G1 and G2, which are not isomorphic. I need to make a new graph G1' such that, with the minimum changes in G1, it will have the nodes of both G1 as well as G2. For example, let's say there is a node n1 in G1 with three connecting nodes n11, n12, n13. If now a 'corresponding' node n2 in G2 has 5 nodes n21, n22, n23, n24, n25, then n1' in G1' also needs to have five nodes n11', n12', n13', n14', n15'. The first three copied from G1 and the two extra nodes which will have value of the last of the three. The tree emanating from the extra nodes will be either entirely newly created or will comprise some extra nodes from G1 that haven't got equivalent nodes in G2 (are not 'exhausted' in some sense).
The problems are 1) finding the most suitable seed as the starting point so that the starting views are as much similar as possible 2) Building the tree from the extra nodes keeping the added node count to the minimum
Edit:
I will try to explain this further with the help of an illustration. My knowledge of graph theory is very superficial, so please excuse me if something sounds silly.
I broadly want to obtain a graph which, with the minimum number of node manipulations, can take the form of one of the two non-isomorphic source graphs.
In the example above graph G' can take two forms G or H with some amount pf node shuffling.
1) To make it G, we keep all the orange nodes at their position. The dotted nodes will 'merge' to their neighboring nodes. So B21' will have the value of A21 and will be at the same position (dissolving the corresponding edges). Likewise will happen with the pairs B31'-A31, B14'-A15 B25'-B23, A32'-A22 and A23'-A32. With this configuration the graph would resembles G completely, without any edges 'sticking out'
2) To make it isomorphic with H, A11 and A12, will take the values of A13, A32 and A32' that of A23, A23' that of A22. The dotted nodes will 'come out' of their merged positions.
The problem is to find G'. Maybe there is no ready graph operation or the solution is impossible, but any pointer to achieve this with any degree of approximation and efficiency is most welcome.
NB: The starting nodes A1 and B1 are arbitrary. First half of the problem is identifying these nodes so that the views are as much similar as possible.
This is at least as hard as the graph isomorphism problem which is currently not known to be solvable in polynomial time. As such, you should not expect to be able to find an efficient algorithm for your problem.
The correspondence is straightforward to see because if G1 and G2 were in fact isomorphic, you would have G1' = G1, so an algorithm which solves this problem could be used to solve the graph isomorphism problem.

How to efficiently update a collection of paths through a graph after adding edges to the graph?

My application may be modeled as a rooted, oriented multidigraph with possible parallel arcs and one distinguished source but with no loops or cycles.
The primary features of the application are a subset of the possible paths induced by the graph. That is, at some level, a better model for the application may be instead a rooted star digraph with no parallel arcs such that each arc represents a root-emanating path in the former multidigraph.
Let (f : Rooted-Multidigraphs -> Star-Digraphs) be the reclassification that interprets any root-emanating path (not necessarily terminating at a leaf) as a distinct arc.
Let (g : Star-Digraphs -> Star-Digraphs) be a series of arbitrary filters that prunes all domain-invalid arcs from a star digraph.
Then, although my application relies on data that constitutes a multigraph G, the application is primarily responsible for reporting features associated with star-graph T = g(f(G)).
Moreover, should any modifications occur to G -- specifically, arc deletions and additions -- with G becoming G', then the collection of valid paths must also be updated to T' = g(f(G')).
Say, for example, modifications d0*, d1* remove arcs #0 and #1, respectively, from a graph; modifications d2 and d3 add arcs #2 and #3 to a graph; and, overall, modification d successively applies d0*, d1*, d2, and d3 in some unspecified order.
If the filter g doesn't remove any path along a newly added arc (like #2 and #3 above), are there any efficient non-mutating methods (persistent data structures like radix trees, e.g., or functional-programming algorithms) for determining the updated target graph T' = g(f(d(G)) from just
G
T = g(f(G))
deleted arcs {#0, #1}
added arcs {#2, #3}
without directly applying either g or the composite function (g.f)?

How to find connected triangles on a 3d mesh

I have a file exported from a 3d application like Blender or Maya. I am able to read the files. I end up with indices describing each triangle and a vertex list.
The file can have more than one connected mesh, two spheres for example. I want to select individual meshes by finding connected triangles. What is the best way to do this? What geometric algorithms can I use? Any examples? Can it be multi threaded?
What you need is a graph solution.
Take all the data, the vertices become nodes in the graph, the edges linking vertices, link the nodes in the graph. Run a DSF/BFS on it marking all the nodes that you visit. All the nodes marked belong to the same object.
Run it again starting from an unmarked nodes to find additional objects.
You can construct a graph in parallel if you think it's easier, but you should be able to do it with the geometrical data as well.
A graph solution indeed, but with triangles as nodes and adjacent edges as connections between nodes. This can then be solved as a max clique problem.

how to test for bipartite in directed graph

Although we can check a if a graph is bipartite using BFS and DFS (2 coloring ) on any given undirected graph, Same implementation may not work for the directed graph.
So for testing same on directed graph , Am building a new undirected graph G2 using my source graph G1, such that for every edge E[u -> v] am adding an edge [u,v] in G2.
So by applying a 2 coloring BFS I can now find if G2 is bipartite or not.
and same applies for the G1 since these two are structurally same. But this method is costly as am using extra space for graph. Though this will suffice my purpose as of now, I'd like know if there any better implementations for the same.
Thanks In advance.
You can execute the algorithm to find the 2-partition of an undirected graph on a directed graph as well, you just need a little twist. (BTW, in the algorithm below I assume that you will eventually find a 2-coloring. If not, then you will run into a node that is already colored and you find you need to color it to the other color. Then you just exit saying it's not bipartite.)
Start from any node and do the 2-coloring by traversing the edges. If you have traversed every edge and every node in the graph then you have your partition. If not, then you have a component that is 2-colored and there are no edges leaving the component. Pick any node not in the component and repeat. If you get into a situation when you have a few components that are all 2-colored, and there are no edges leaving any of them, and you encounter an edge that originates in a node in the component you are currently building and goes into a node in one of the previous components then you just merge the current component with the older one (and possibly need to flip the color of every node in one of the components -- flip it in the smaller component). After merging just continue. You can do the merge, because at the time of the merge you have scanned only one edge between the two components, so flipping the coloring of one of the components leaves you in a valid state.
The time complexity is still O(max(|N|,|E|)), and all you need is an extra field for every node indicating which component that node is in.

draw edge from node to edge in graphviz

Is it possible to draw an edge from a Node to the center of an existing Edge in graphviz? I would like to duplicate this type of reaction diagram, common in chemical or biological networks.
Thanks!
--Peter
Yes, you can use invisible nodes, like in this example for instance.
Then play with creating subgraphs for A and B where
rank=same
and then an edge where
constraint=false
for the connection from C to the invisible node. This will put the first two above C.

Resources