I want to remove edge between two vertices, so my code in java tinkerpop3 as below
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
if(g.V(toV).inE(edgeLabel).bothV().hasId(fromV.id()).hasNext()){
List<Edge> edgeList = g.V(toV).inE(edgeLabel).toList();
for (Edge edge:edgeList){
if(edge.outVertex().id().equals(fromV.id())) {
TitanGraph().tx();
edge.remove();
TitanGraph().tx().commit();
return;//Remove edge ok, now return.
}
}
}
}
Is there a simpler way to remove edge between two vertices by a direct query to that edge and remove it? Thank for your help.
Example: G = rmedge(G,1,2) removes the edge between node 1 and node 2 from graph G . Example: G = rmedge(G,{'a' 'b'},{'d' 'c'}) removes two edges from graph G , the first of which is between node 'a' and node 'd' .
Both have time complexity O(V + E), where V is the number of vertices and E is the number of edges.
In the case of two edges, merging them into a single edge. When dissolving vertices into surrounding faces, you can often end up with very large, uneven n-gons. The face split option limits dissolve to only use the corners of the faces connected to the vertex.
If no edge exists between these two vertices, then g [i] [j] = 0 and g [j] [i] = 0. The graph after removal and adjacency matrix after removal of edge between vertex X and Y:
In Edge Select mode (keyboard shortcut 2 ), select the edge you want to get rid of, press the space bar and type dissolve ... then choose Dissolve Edges. Show activity on this post. To remove an edge while keeping surrounding geometry, in Blender terminology you Dissolve it. Delete then Dissolve Edges or...
Inserting an edge: To insert an edge between two vertices suppose i and j, set the corresponding values in the adjacency matrix equal to 1, i.e. g =1 and g =1 if both the vertices i and j exists.
Here's an example of how to drop edges between two vertices (where you just have the ids of those vertices:
gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[7][1-knows->2]
==>e[8][1-knows->4]
For purpose of the example, let's say we want to drop edges between vertex 1 and vertex 2. We could find those with:
gremlin> g.V(1).bothE().where(otherV().hasId(2))
==>e[7][1-knows->2]
and then remove it with:
gremlin> g.V(1).bothE().where(otherV().hasId(2)).drop()
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[8][1-knows->4]
If you have the actual vertices, then you could just do:
gremlin> g.V(v1).bothE().where(otherV().is(v2)).drop()
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[8][1-knows->4]
You could re-write your function as:
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
g.V(fromV).bothE().hasLabel(edgeLabel).where(__.otherV().is(toV)).drop().iterate();
g.tx().commit();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With