Gremlin: Select Vertices that have edges that share a property - scala

This is in gremlin-scala. I have the traversal at a Vertex point (which is what '_' stands for below:
_.as("vertex").outE().as("outEdge").in().inE().as("inEdge")
.select("inEdge","outEdge").by("fullName")
.where("inEdge", P.eq("outEdge")).select("vertex")
But I am getting an error referencing the .in() after the .as("outEdge") statement:
Error:(55, 40) Cannot prove that org.apache.tinkerpop.gremlin.structure.Edge <:< gremlin.scala.Vertex.
Can anyone help me figure out what is going wrong here, and more importantly, is this the correct way to find Vertices that have a matching property on its edges?
Thanks in advance.

I think that syntax is incorrect. Change:
_.as("vertex").outE().as("outEdge").in()
to
_.as("vertex").outE().as("outEdge").inV()
when you do outE() you are on an edge, so you must traverse to a Vertex which would be either inV() (the vertex adjacent to where you started), outV() (the vertex you started from since you traversed outE(), or bothV() which would yield both the vertices at either end of the edge.
I think your method for comparing properties makes sense. Someone else might post a way to simplify further.

Related

Breadth First Search controlled by edge number in networkx?

I know the networkx could provide the breadth-first search (bfs) results based on the control of depth. I am wondering is there a workaround so I can control the result with the number of edges? For example, I hope to get 10 edges around a node i by bfs. But I don't know what depth it could be.
The bfs controlled by the depth is something like
bfs = nx.bfs_edges(G, source=i, depth_limit=5)
I hope to use a function something like
bfs = nx.bfs_edges(G, source=i, number=k)
As I hope to find all the edges around a node. So it looks like the nx.edge_bfs is a better option? This function returns all the edges currently. Could we modify it somehow? I hope the source node can be located as center as possible, i.e., the yield edges could evenly around the source node.
After looking at the source code of nx.edge_bfs, it looks like this function itself returns an iterator which yields the edges surround the source node one by one. And it basically returns the surrounding edges like a circle.
It could be better if someone could confirm this. Here is the source link

How to convert Valve.VR.HmdMatrix34_t to UnityEngine.Transform

I am trying to get pass this error
cannot convert from 'Valve.VR.HmdMatrix34_t' to 'UnityEngine.Transform'
when importing MixCast SDK. Does anyone know how to cast
'Valve.VR.HmdMatrix34_t to'UnityEngine.Transform?
I've looked at https://valvesoftware.github.io/steamvr_unity_plugin/api/Valve.VR.HmdMatrix34_t.html struct and it it does not help me much.
So the problem is where to find detailed information about the HmdMatrix34_t struct, to be able to cast it to Unity Transform.
P.S. The info about the struct is valuable and can be a start point for me, but I will really price a code sample where I can see how to extract unity Vector3 for position, rotation and scale (or the full Transform).
A transformation matrix is a 4x4 array, but only 3x4 of that is really used. This is what the Valve HmdMatrix34_t ("t" for "type", it's a C thing) is. Simply inject the cell values from the HmdMatrix into the the first three rows (or columns, I always get the precedence mixed up) of a Unity Matrix4x4 and then assign it to your transform.
Where you may go wrong is understanding where the HmdMatrix sits in the scene graph, and thus whether to apply it directly or use its inverse.

Fetch outgoing edge property value between two vertices in scala gremlin

I am trying to fetch edge property value between two vertices. E.g. A-->B
A and B are two vertices and it has edge with property(name).
My code looks like:
graph.V().hasLabel(A).outE().value("name").headOption()
It gives me the property value for name.
In a given two vertices, i am getting None as output
graph.traversal().V().hasLabel(A).outE("test").outV().hasLabel(B).properties("name").headOption()
'test' - Edge Label
'name' - Edge property
Any idea what is wrong with my query.
Apologies for not being able to answer this in your comments on the previous question you asked. I think what you are looking for is:
graph.traversal().V()
.hasLabel("A").outE("test").as("x").otherV()
.hasLabel("B").select("x").properties("name");
If you just want the values of the properties on the edge you can do the following:
graph.traversal().V()
.hasLabel("A").outE("test").as("x").otherV()
.hasLabel("B").select("x").values("name");
Side Note (Why is your original traversal wrong): Your original traversal:
graph.traversal().V().hasLabel(A).outE("test").outV().hasLabel(B).properties("name").headOption()
is doing the following:
Get all vertices with the label "A"
From those vertices follow the outward going edges which have the label "test" to vertices which have the label "B"
Then get the property "name" from those vertices
You are actually asking for the properties on the vertex.

Gremlin: otherV() not working inside order().by()

I'm using Tinkerpop 3.0.1 (Titan 1.0.0), and I try to list all edges for a vertex, sorted by degree of the node on the other end of the edge.
I tried:
g.V(1482896).bothE().order().by(otherV().bothE().count(), decr)
I get the following error from Titan:
The path history of the traverser does not contain a previous vertex: [e[1d2m8u-1d70ts-b2t-vs7k][82628848-DIRECTED->1482896]]
The strange thing is, there is a previous vertex in the path (namely vertex #1482896. I'm confused on how to solve this one.
Answering my own question, after playing around with this, I found a workaround:
g.V(123).bothE().as('edges')
.otherV().order().by(bothE().count(), decr)
.select('edges')
This will effectively sort edges adjacent to vertex #123 by highest degree of the node on the other end of the edge.

DirectCompute atomic counter

In a compute shader (with Unity) I have a raycast finding intersections with mesh triangles. At some point I would like to return how many intersections are found.
I can clearly see how many intersections there are by marking the pixels, however if I simply increment a global int for every intersection in the compute shader (and return via a buffer), the number I get back makes no sense. I assume this is because I'm creating a race condition.
I see that opengl has "atomic counters" : https://www.opengl.org/wiki/Atomic_Counter, which seem like what I need in this situation. I have had no luck finding such a feature in either the Unity nor the DirectCompute documentation. Is there a good way to do this?
I could create an appendBuffer, but it seems silly as I literally need to return just a single int.
HA! That was easy. I'll leave this here just in-case someone runs into the same problem.
HLSL has a whole set of "interlocked" functions that prevent this sort of thing from happening:
https://msdn.microsoft.com/en-us/library/windows/desktop/ff476334(v=vs.85).aspx
In my case it was:
InterlockedAdd(collisionCount, 1);
To replace
collisionCount++;
And that's it!