0

I am trying to write code that allocates jobs to 20 different students. These jobs are randomly chosen from a list of jobs which - with a binary matrix - also indicates, whether student i can do that job.

starting_solution = [[]] * 20
for i in range(20):
    counter = 0
    while True and counter < 10000:
        counter += 1
        possible_index = random.choice(list(set([x for x in range(len(order_data))])
                                            - set(done_jobs)))
    if job_matrix[possible_index][i] == '1':

If student i can do the job, the code checks whether the student has enough time left:

    if sum(student_durations[i]) - student_durations[i][-1] + possible_time < 28800:

If this is the case, I would like to add the job to the schedule of student i, which is entry i in the nested list created earlier. Now, if I use the following code, for some reason the job gets added to all entries (0 - 19) of the schedule.

    starting_solution[i].append(possible_index)

I tried a lot of different things, including printing the list and i before appending and after. I always corresponds to only one value and if I print starting_solution[i], it also outputs the correct entry.

martineau
  • 119,623
  • 25
  • 170
  • 301
Elias
  • 3
  • 1

0 Answers0