I do not have much experience with Neo4j. For the project that I am just starting I am hoping that Neo4j will provide a good solution to the following problem.
Imagine a maze with rooms (nodes) and doors (relationships) between the rooms. The doors to some rooms are locked and their keys are held in other rooms (as properties).
In the attached image, you can reach room D by following the path A->B->C->A, picking up the key for room D in room B. However it is not possible to reach room F, since the key to room F is in room E, and the key to room E is in room D, and there is no way back from room D to room A, so room E is inaccessible (Creating a new door from room D to room C would make this possible).
I understand how I can use Neo4j to trace a path from room to room, but is it possible to create queries which take into account the keys that can be picked up on the way? For example:
- Is it possible to get from room X to room Y?
- What are all the paths that lead from room A to room Z?
- I'm in room N with these keys. Have I come to a dead end?
- What keys do I need to get from the Library to the Conservatory?
I can imagine ways of doing this that make multiple queries to the database, with each new query being dependent on the result of the previous ones, but this is likely to be laborious.
I can also imagine a single Cypher query that creates a temporary node, adds keys to this node as it traverses the graph, and checks at each door-relationship whether it has the appropriate key to continue in that direction. However, I don't know enough about Cypher to know whether this can be done.
I'm more than happy to solve this problem myself, if you can confirm that Neo4j can do this.