I am relatively new to python and I am currently working on an agent-based model programme where I have 126 agents, which represent students in a school. I am trying to show the spread of an infection in a classroom. My goal is to split the students into 6 classrooms of a size of 21 students in each class. Where I then assign seat neighbours and also assign students to have group work groups from range size 3-9.
My current issue is that my neighbours are not being assigned and I do not know to assign my students randomly into these groups for classroom work.
I currently just have this code:
people = list of of person agent objects
random.shuffle(people)
I split my students here into 6 classrooms:
classroom_list = [people[i:i + 21] for i in range(0, len(people), 21)]
for i, p in enumerate(people):
seatmates = p.seat_neighbours
group_members = p.group_members
po = people[i:] + people[:i]
for students in classroom_list:
if students in seatmates:
if i >= 0:
seatmates.append(students[i - 1])
if i <= len(people)-2:
seatmates.append(students[i + 1])
if po:
seatmates.append(students[i])
if members in group_members:
But I don't know how to assign them into groups randomly within the range 3-9 for group size.
My seat_neighbours is an empty list where I just append to and it is an instance from my Person class where I hold attributes for my students, such as if my student is healthy or not. Each classroom should be set with assigned seats arranged in rows, giving each child two neighbours with the exception of students with end seats who only have a single neighbour.
The same with group members, it is an empty list and its an instance attribute from my Person class, which I want to call. For each classroom, the group members are randomly assigned with size range from 3-9.
The only output I get is empty lists right now for the seat neighbours.
[]
[]
[]
[]
[]
Aucun commentaire:
Enregistrer un commentaire