Does counting hops start from zero of from one? - cypher

When counting hops, has the first node (the one that is directly connected) the distance of one hop or zero hops?
For example, in this code will return the results when the path is equal to or shorter than 3 hops:
MATCH path=(n {id: 0})-[relationships * ..3]->(m {id: 8})
RETURN path,relationships;
So is this actually A->B->C->D or A->B->C. What is defined as hop, number of nodes or relations that are traversed?
I couldn't find this information anywhere.

The variable length path pattern, *..3 is the same as 1..3 which means at least one hop, and at most 3. So this allows for any of:
A,B
A,B,C
A,B,C,D
This behavior is documented starting on page 11 of the openCypher specification that is available here

Related

Retrieving neighbors along a serial chain in Cypher

I have a graph with three types of nodes: Division (brown), Line (blue), and Note (green).
The Division is connected to the first Line with a directional PRECEDES relationship. Each subsequent Line is connected to the previous one with another PRECEDES relationship. This serial chain is a few hundred nodes long.
This cypher query below will return the Division node followed by all the serial Line nodes.
MATCH (div{id:'some-id')-[:PRECEDES *0..]->(line)
RETURN line
I'm new to cypher and I'm struggling to figure out how to also return the green Note nodes, which are linked to Line nodes via a directional EXPLAINS relationship.
To get the green Notes, you need to add a match that connects to line
MATCH (div{id:'some-id')-[:PRECEDES *0..]->(line)
Optional MATCH (note:Note) -[:EXPLAINS] -> (line)
RETURN line, note

PDDL How to assign number for many predicates

I have tile based map, where agent needs to go from one tile to another, Some tiles have (occupied pos-X-Y) meaning that agent cant step on these tiles named pos-X-Y. This part works, but I need to make these tiles occupied only in certain turns. I tried to use action-cost and add a number to each (occupied pos-X-Y) like this: (occupied pos-X-Y Z) planning to compare the Z number with the current action-cost. But I couldnt even assign the number to the occupied tile.
How do I assign a number to these occupied tiles and how do I compare it with the action-cost?
Have you tried functions Numeric Fluents ?
Your move action can increase a "turn" function.
A (forbidden_turn ?t - tile) function can be affected with an integer value, then you can use it in a precondition. But this requires your planner to support negative preconditions.
Otherwise, you can use a allowed turn function.
I figured it out (with help). Instead of using numbers I created many objects, I will call them turns, then I set that, turn 2 is always after turn 1, turn 3 is always after turn 2 etc. and I added these turns as the letter z in "(occupied pos-X-Y Z)". And when actor moved I just changed his turn to the next number based on the rule I created earlier.

Find index in bitmask

Halo Binary experts out there,
I have a bitmask representing ON options of a room, say 11001 (Opt #1, 4, 5)
Another user tries to search with his own bitmask (say 111000 (Opt #4, 5, 6)
Doing a (Room | Search) != 0 means it compares the mask and see if there's a same switch ON (In this case #4)
The thing is, switch #4 is the 2nd 'active' switch of the Room, and the 1st for the 'Search'.
I need the user to also find that #4 is the 2nd switch of the Room.
User have the separate bitmask to check against.
Both Room and User can only have 3 switch on
My approach can know which is the last(biggest) index, using UserMask2 for example(3rd option):
if(RoomMask | UserMask2 != 0) A = (RoomMask - UserMask2 = 11001 - 10000 = 01001).
if (A < RoomMask) UserMask2 is the 3rd switch because minus-ing by UserMask2 makes it lower than UserMask2
This only finds if a certain UserMask is indeed on the RoomMask' biggest bit.
But I'm not sure how to continue.
This is used for Matchmaking search using Photon, which uses SQL and I probably have to manage to do this with a single WHERE query(not sure if it can store variables.)
https://doc.photonengine.com/en-us/pun/current/lobby-and-matchmaking/matchmaking-and-lobby#sql_lobby_type
I hope I'm clear enough
Cheers!
Your question is not very clear and hence I'm not 100% that this answer is what you are looking for. Still, here you have.
You can search for contents of columns using the like key, where you have two wildcards:
% means anything,
_ means any character.
Now, suppose that you want to find a match for switches 1, 4 and 7 in a map of, say, 10 possible switches (being 1 the leftmost in this example), you could use the clause:
WHERE Bitmap like '1__1__1___`
of course, this is just an example and you would need to adapt it to your specific context.

Why I can't choose only a number as variable's name in titan graph database

I've worked with TinkerFactory.createModern & TinkerFactory.createTheCrew and I've noticed only numbers have been chosen as variables if I'm not mistaking...what I mean is that by "g.V(1)" you can reach Vertex number 1 so I want to do the same but i get the error shown in the picture.
for instance, I want to reach 'V[5]' by typing "g.V(5)"
This is the Picture of the error that I get
The numbers you refer to in g.V(1) are the ids which are automatically assigned to each vertex. So when you say g.V(1) you are asking for the vertex with ID 1. Which is not necessarily the first vertex. Titan uses quite large numbers for example
The error you are having is a different issue though. Variables cannot start with number. They must start with a letter. So do this instead:
v1 = graph.addVertex('name', 'something');

Binary Search Tree Minimum Value

I am new to binary search tree data structure. One thing I don't understand is why the leftest node is the smallest
10
/ \
5 12
/ \ / \
1 6 0 14
In the above instance, 0 is the smallest value not 1.
Let me know where I got mixed up.
Thank you!
That tree is not binary search tree.
Creating a binary search tree is a process which starts with adding
elements.
You can do it with array.
First there is no element so make it root.Then start adding elements as node.If the new value is bigger than before add it array[2 x n + 1] (call index of the last value: n). If it is smaller than before add it to array[2 x n]. So all values left of any node is smaller than it and all values right of any node is bigger than it. Even 10 and 6's place.6 cannot be 11.(at your tree,it isn't actually.).That's all !
For a tree to be considered as a binary search tree, it must satisfy the following property:
... the key in each node must be greater than all keys stored in the left sub-tree, and smaller than all keys in right sub-tree
Source: https://en.wikipedia.org/wiki/Binary_search_tree
The tree you posted is not a binary search tree because the root node (10) is not smaller than all keys in the right sub-tree (node 0)
I'm not really sure of your question, but binary search works by comparing the search-value to the value of the node, starting with the root node (value 10 here). If the search-value is less, it then looks at the left node of the root (value 5), otherwise it looks next at the right node (12).
It doesn't matter so much where in the tree the value is as long as the less and greater rule is followed.
In fact, you want to have trees set up like this (except for the bad 0 node), because the more balanced a tree is (number of nodes on left vs. number of nodes on right), the faster your search will be!
A tree balancing algorithm might, for example, look for the median value in a list of values and make that the value of the root node.