Titan graph query - graph

Consider a vertex (V1) in Titan Graph having few out going edges having labels L1,L2,L3 and L4. Now how to find all edges from V1 having labels either L1 or L2 using TitanVertexQuery.
I have tried using GremlinPipeline, it works but unable to achieve the same using TitanVertexQuery.
Regards,
Karthik

Pretty short answer:
v.query().direction(Direction.OUT).labels("L1", "L2").edges()

Related

Does igraph has "has_path" function?

I am trying to port code from python NetworkX to R igraph. In NetworkX there is a function with the name has_path that finds if two vertices have a path. I want to find in an efficient way all the vertices of a graph that don't have an edge between them but they have a path.
I think you can use the code below to check if there is a path from vertex V1 to V2 (the graph can be directed or undirected)
c(!is.infinite(distances(g, V1, V2, mode = "out")))
If you need to check this repeatedly in an undirected graph, simply break it into connected components and check if both vertices are within the same component. This will be very efficient, as the components need to be found only once.
See the components function. It gives you a membership vector. You need to check if the position corresponding to the two vertices has the same value (same component index).
If the graph is directed, the simplest solution is the one posted by #ThomasIsCoding. This is perfectly fine for a one-time check. Speeding up repeated checks is more trouble and warrants its own question.

Draw edges through nodes in Graphviz

I am trying to draw a graph using Graphviz in Dot language, and this graph has edges which runs through nodes.
Please see the attached picture below.
So far I did not able to find a way to do this. Any help would be highly appreciated!.
Thanks in advance. ( Tips on any other way to render a graph like this would also be really helpful )
The information above is not that sufficient, however you can check the Drawing with Constrained ranks (Ref: Drawing graphs with dot by "Emden Gansner and Eleftherios Koutsofios and Stephen North").
Graph with constrained ranks
Please read the below for more information :Drawing graphs with dot
Had the same issue today, this worked for me in layout=dot.
(1) setting splines to false
(2) have the specific edge attribute constraint set to false, for edges which must go through another node.
splines=false
x -> y [constraint=false]
Be aware it only worked OK because I did not use a label for the edge.
Using the edge attributes taillabel and headlabel worked for me.

Set up a (igraph) graph using the XY co-ordinates for nodes

I am trying to create an igraph graph using the co-ordinates of nodes. I realized that there are no direct ways to do this through the igraph package for R.
There are ways to plot a graph on a 2D space using the layout() function, but I need to create a graph from known co-ordinates of nodes. I'll appreciate any help anyone can provide with this.
Why I'm trying to set up a graph this way? After parametrizing the graph nodes with co-ordinates, I want to connect the nodes using a probability measure that takes the distance between the nodes into account.
Thanks.
Hitaysh
# Initial Co-ordinates of nodes
n = 1000 # no. of nodes
nodes.coord <- data.frame(x=runif(n,min=0,max=n),
y=runif(n,min=0,max=n))
# Set up a graph with nodes on above co-ordinates...
P.S. This is my first post on StackOverflow. Any constructive feedback on how to ask questions better, is also welcome.
After reading your question afew more times, i'm guessing that something like this will work
n = 20 # no. of nodes
set.seed(15)
nodes.coord <- data.frame(
x=runif(n,min=0,max=n),
y=runif(n,min=0,max=n)
)
gg <- graph.empty(n)
plot(gg, layout=as.matrix(nodes.coord[,c("x","y")]))
But if you are going to connect nodes based on distance, it probably makes sense to find the connections prior to creating the igraph object since you already know the locations.

Coloring a graph using Depth first traversal

I know that for coloring graph nodes, backtracking/brute force is a common solution. But I was wondering if using DFS I can also achieve a solution ?
Backtracking gives you the opportunity to go back and try other color possibility in order to paint all the nodes with N colors
DFS will start from one node and color it, then jump to its neighbor and color it in different color than its neighbors etc ...
I did a search about using this method but I didn't find an algorithm that uses this.
Question: Is using DFS possible for coloring graph nodes. If yes, is it more efficient than backtracking ?
Thank you
I believe there is some confusion when comparing backtracking and DFS wrt vertex coloring. DFS traversal for a graph gives full enumeration of its vertices in a sequence related to its structure. It does not, however, constitute a full enumeration for the vertex coloring problem, which would require taking into account the possible colors of the vertices.
Thus, if I understand correctly, what you have implemented is a greedy heuristic coloring for a graph directed by DFS.
On the other hand, a backtracking/brute force solution as you name it (such as [Randall-Brown 72]) will provide an exact solution for the minimum coloring problem since it considers every possible vertex coloring. Note that DFS traversal could be used to sort the vertices initially (topological sort) and feed that order to the exact solver.

Calling vertices in Igraph

This question pertains to the calling of vertices in Igraph.
Lets say we have a directed graph
g<-graph(c(1:10),directed=T)
and i want to find the vertices pointing to vertex 2.
Lets say you want to find the vertices pointed "to" vertex 1.
Why won't using the "to" condition work
V(g)[to(1)]
but rather this?
V(g)[nei(1,"to")]
It works for me?
> g<-graph(c(1:10),directed=T)
> V(g)[to(1)]
Vertex sequence:
[1] 2
> V(g)[nei(1,"to")]
Vertex sequence:
[1] 2
Personally I like working with edgelists. Alternatively you could do it like this:
# Get edgelist:
E <- get.edgelist(g)
# To 1 in directed graph:
E[E[,2]==1,1]
# Connected to 1 in undirected graph:
c(E[E[,2]==1,1],E[E[,1]==1,2])
to works only with edge sequences; e.g., E(g)[to(1)] gives you all the edges that point to vertex 1. IMHO this is quite logical since vertices do not "point" anywhere (the edges do) so it does not make sense to use from or to.
Also, the "official" way of using nei is nei(1, "out") and not nei(1, "to") although it could be the case that "to" works as well. You can use outnei(1) as well.
Disclaimer: I am one of the authors of igraph although I did not write the R interface so there might be a better reason than the one I explained above.

Resources