0

We have some people (for example 70 persons) and some tables (for example 4 tables). the people visite each other on each table. (for example the capacity of tables are 20,20,20,10).

After the first session they stand up and again sit randomly. we have a specific number of sessions for example 3 sessions. I modeled this process by a graph. the nodes are persons and tables and the relationship is [SITS_ON]. for example:

 (p:Person)-[SITS_ON{session:2}]->(t:Table)

means person p sits on table t in session 2.

Now I need to find the number of collisions during the process. I want to know how many times the people already visited, visit each other again. person A sat on table t1 in session 1. person B sat on table t1 in session 1. person A sat on table t3 in session 2. person B sat on table t3 in session 2. so a collision. I want to know the number of collision like this in a given graph

Taja Jan
  • 942
  • 1
  • 1
  • 11
  • 1
    Please edit your question to show what you've tried, where you're stuck, sample input, expected output, etc. – David Makogon Dec 25 '18 at 21:29
  • How do you identify a specific `Person` - a `Person` `id`? Same question for `Table`. – rickhg12hs Dec 25 '18 at 23:55
  • specific person can be by name property – Jean-Sylvain Paré Dec 26 '18 at 00:09
  • I'm not sure how you are counting collisions, but using Neo4j's example movie database, does this give you some ideas? `match (p1:Person)-[:ACTED_IN]->(m1:Movie)<-[:ACTED_IN]-(p2:Person), (p1)-[:ACTED_IN]->(m2:Movie)<-[:ACTED_IN]-(p2) return p1,m1,m2,p2` – rickhg12hs Dec 26 '18 at 05:52
  • You also might want to ask your question on the [Neo4j Community Website](https://community.neo4j.com/c/neo4j-graph-platform/cypher). – rickhg12hs Dec 27 '18 at 18:12

1 Answers1

1

Note that this example would need to be refined if you wanted this to scale, but all you need to do is MATCH pairs of people based on your collision criteria, and then count how many times that occurs. Since you don't count the first collision as as collision, all you need to do to compensate is subtract 1 from the final count.

MATCH (p1:Person)-[r1:SITS_ON]->(t:Table)<-[r2:SITS_ON]<-(p2:Person)
WHERE ID(p1) < ID(p2) // Remove Cartesian Product/redundancy
  AND r1.session == r2.session // Collision if table and session match
RETURN p1.name, p2.name, count(*)-1 as collisions
Tezra
  • 8,463
  • 3
  • 31
  • 68