Graph edit distance for connected components in a graph - considering the spatial distance - graph

has anyone ever done or seen something like this?
I have two disconnected graphs of the same size with the same nodes but different edges. They may contain connected components. I want to compare one connected component "a" of graph 1 to one connected component "b" of graph 2. But I dont only want to calculate the graph edit distance for these two connected components which gives me the cost of transforming "a" to "b". In additon to that, I need to consider the spatial distance between the two connected components in their graph to also have the cost for the spatial distance between them. So transformation from "a" to "b" means to me bringing it into the same "shape" with the exact same edges AND bringing it to the same position as b is in its graph.
Example:
Graph 1 with connected component "a"
Graph 2 with connected component "b"
So now I need to add two edges two transform "a" to "b". But I also need to "move" "a" 4 steps to the right and one step down.
Are there any known algorithms for this or any approved ways to store the position of connected components and then compare it?
Thank you my dears!
My first idea was to just use some kind of edit distance and leave "a" after transformation at its initial position. Then identify the node which is furthest down and then furthest left and identify the corresponding same one in "b", then calculate the euclididan distance and give some weight to that. The exact weight is currently not in the focus.

Related

Find all disjoint connected paths in a graph

I have k pairs of starting points and end points on a graph.
As shown in the picture, I dyed the different pair in different colors.
I need to connect them two by two.
Each node can only be passed through once, and cannot pass through the starting points of other colors.
The problem is to output the number of solutions that satisfy this constraint, and output 0 if there is no solution.
Does this problem have a well known name, is there any library to solve this problem?

Creating a network graph with set node positions and concentrated edges with both circleheads and arrowheads in R

I've been trying to find a way to replicate the following network graph format in R using DiagrammeR/GraphViz, but without success (ignore the thick black arrow on N1): https://i.stack.imgur.com/oHpQz.png
The graph is a directed graph and each edge in a certain direction either ends with an arrowhead (-->) if the edge value is positive, or a circle/odot (--o) if the edge value is negative. Between a pair of nodes (ex. N1 -- A1), there can be an edge N1 --> A1 and an edge A1 --o N1, and these need to be concentrated so that the two edges look like one line with an arrowhead on one end and a circlehead on the opposite end (like this: o--->). These cannot be parallel or look like two edges ideally.
Another requirement is that the nodes have to be in very specific positions and remain there throughout model simulations where edges might change. From what I have tried and the documentation I have read, this is not possible to do in DOT format, but is possible in neato format.
This is where I get a problem. In neato, I can align the nodes exactly where I want them by defining their x,y positions. However, when I use concentrate = true to create the o---> edge from two otherwise parallel edges, only one type of arrowhead remains. So an edge that's supposed to look like o---> ends up looking like ---> or o---.
This is not a problem in DOT format as concentrate = true does what I want it to do, but in DOT I cannot assign exact node positions. I have tried getting around this using node ranks but without much luck. It seems to stack nodes I want in different ranks within the same rank. As well, concentrate = true doesn't seem to work for edges between nodes within the same rank, as it leaves them as two separate curved edges ---> and o--- without concentrating them.
The reason why I need this to work is because I'm running model simulations where the edges change, and I need to generate hundreds of such graphs. For easy comparison, the nodes need to stay in the same place for consistency.
This is the closest I could come up with using neato format (nodes are positioned the way I want but it's not showing the proper o---> for all the black edges minus self-edges; red edges are true one-way links): https://i.stack.imgur.com/YJBY7.jpg
If only the edges showed up as the proper o---> format, this would be perfect for my needs. If you know of any way to fix this issue using DiagrammeR/GraphViz, or even another program, I would be so grateful. Thanks!
You probably don't need concentrate. Look at arrowtail and dir (https://www.graphviz.org/doc/info/attrs.html#d:arrowtail and https://www.graphviz.org/doc/info/attrs.html#d:dir) and neato -n
digraph c {
graph[label="can neato do the work?"]
node[shape=circle]
a [pos="100,100"]
b [pos="200,100"]
c [pos="300,100"]
a->b [dir=both arrowtail=odot]
c->c [dir=both arrowtail=odot arrowhead=none]
}
Giving:

graph similarity having multiple edges between two nodes

There are many theories about calculating of graph similarity such as vertex edge overlap, jacard, co-sine, edit distance, signature similarity, lambda distance, deltacon so on. These things are based on single edge of the graph. But there are many graphs having multiple edges in real world.
Given similar two graphs like above, how could we calculate graph similarity?
Using previous graph similarity, there are only 2-dimension vector and the entry is just scalar that is number, but in multiple edge's graph, the entry should be tuple. Because there are one more actions between nodes. For the previous method, it could be called who-knows-whom schem, but latter graph, it could be said who-knows-whom*-how*. I think the previous mothods could be used for the multiple edge's graph easily, so there aren't logic or methods about it.
Thanks in advance!
There is not "the" way yo compute graph similarity.
Depending on your data and problem, very different approaches may be good. In many cases, simply merging the two edges into one makes perfect sense. For example, if I have two roads of capacity x and y to go from A to B - for many analyses this is comparable to having just one rode, with the combined capacity.

Gremlin- How to compute percentage of vertices with a certain property

I am trying to use a single gremlin query to determine the percentage of vertices that satisfy a certain predicate, but I'm having trouble storing and propagating the computed values.
Say I want to compute the percentage of all vertices with label "A" that have an outgoing edge with label "B". I can print out the number of vertices with label "A", a well as the number of vertices with an outgoing edge with label "B" in the same query:
g.V().limit(1).project("total","withEdgeB")
.by(g.V().hasLabel("A").count())
.by(g.V().hasLabel("A").match(__.as("a").outE("B").inV()).dedup().count())
This gives me the two relevant values: total and withEdgeB. How do I propagate and calculate with those values?
Ideally, I want something like this:
g.V().limit(1).project("total","withEdgeB","percentage")
.by(g.V().hasLabel("A").count().as("totalA"))
.by(g.V().hasLabel("A").match(__.as("a").outE("B").inV()).dedup().count().as("totalWithEdgeB"))
.by(totalWithEdgeB / totalA)
So my question is, how can I access the values totalA and totalWithEdgeB in the third by() statement? Or am I going about this all wrong?
I would use some simple calculations. Using the modern graph, find all person vertices with outgoing created edges:
gremlin> g.V().hasLabel('person').
choose(outE('created'),
constant(1),
constant(0)).fold().
project('total','withCreated','percentage').
by(count(local)).
by(sum(local)).
by(mean(local))
==>[total:4,withCreated:3,percentage:0.75]

Edge-connectivity: Does it mean to split a graph into two?

The minimum number of edges whose deletion from a graph G disconnects G.
Above is the definition of edge connectivity, does it mean G will be split into two pieces only?
or will be split into any number of pieces?
Just did not see that point, which one is right?
Say the edge-connectivity is k. It means you need to remove at least k links to split a graph into several (separated) components. Now, remove only the k-1 first links. At this point, the graph is still connected. The removal of the kth link will split it. But a link connects only two nodes, so, if each node belongs to one different potential component, it connects (at most) only two potential components. So, removing this kth link will always split the graph into only 2 components. This is not true for node-connectivity, since a node can be attached to several links, i.e. several other nodes, i.e. more than two potential components.

Resources