Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-17-2019 05:33 PM
Hello All,
I have a seemingly simple problem.
I have a set up the following nodes:
Each student has a preference for subjects that I have added as edge properties. The edges are as follows:
Some relevant constraints:
The kicker is I want to randomly assign the students to the session and subject.
Is there a way to do this within the constraints of Cypher?
Thanks for any help you can provide.
10-23-2019 03:32 AM
Hi!
I just wanted to check something - would you be randomly assigning all the students to a subject/session? Or are the students already assigned to something?
Thanks
10-25-2019 02:22 PM
Hello,
Thanks for getting back to me.
The assignment of the students is based on their subject preference (0-5) 5 being the highest value. If they have a preference >= 3 than they will get assigned to a session for that subject.
Thanks,
11-11-2019 10:50 PM
Your model may need reworking, but for now you may capture what subject they've been assigned to by connecting them directly to session, and then going through that to see what session it is,
i.e.
(:Student {name:'Joe'})-[:HAS_PREFERENCE {score:5}]->(:Subject {name:'Maths'})
(:Student {name:'Joe'})-[:ASSIGNED]->(:Session {name:'MATHS_1})
To find subjects which a student has a preference for but has done no sessions in, you could do something like this:
MATCH (s:Student)-[hp:HAS_PREFERENCE]->(sub:Subject)
WHERE hp.score>=3 AND NOT (sub)-[:HAS_SESSION]->(:Session)<-[:ASSIGNED]-(s) //we don't want any subjects/sessions the student has already taken
For the random component, you can do something like:
WITH s, sub
MATCH (sub)-[:HAS_SESSION]->(sess:Session) //fetch back all the available sessions
WITH s, sess, rand() as r ORDER BY r LIMIT 1 //randomly pick a subject and a student (this only assigns 1 session to 1 student!)
CREATE (s)-[:ASSIGNED]->(sess)
All the sessions of the conference are now available online