Dynamically create relationships

Hello. I'm newbie.
I want to solve this problem with neo4j database and thinking about proper tools and approaches:
I have a data with students and data with flats/houses. The goal is to settled these students to the flats based on the preferences/sex/age also preferenced about the flat (balkony, own bathroom, garden). The idea is to settled every students one by one to the flat and finally have all flats occupied.
Question 1. How to create these relations dynamically with query?
Question 2. How to define the condition for preferences in query? For instance, we have a priority of settling in one flat mostly persons with same sex and pair should be in one flat with double room.
In my view: we have node student and node flat. Relationship between students like: knows, in relationship with and attributes:

  • student: age, sex, wants balkony, wants private room
  • flat: number of rooms, number of private rooms, number of doubles, number of rooms with balkony, garden, square meters.
    I hope its clear. Thanks.