I need to sort students into classes based on their preferences and I am planning to use the Hungarian Algorithm to sort them. The problem that I am running into though is that there are more people than classes and each class has a minimum number of people that it needs to have.
In my dataset, there are ~550 students, and each one has a list of top 5 preferences. Every preference is an ID that corresponds to a class. Each class has a minimum and maximum capacity (in my case a min cap of 15 people and a max cap of 27 people) and there are 21 classes in the dataset.
Here is an example dataset for every student:
| first choice | second choice | third choice | fourth choice | fith choice | |
|---|---|---|---|---|---|
| [email protected] | 4 | 7 | 1 | 8 | 21 |
| [email protected] | 6 | 9 | 14 | 17 | 2 |
Here is an example dataset for every class:
| Class Title | Class ID | Min Cap | Max Cap |
|---|---|---|---|
| Class Title1 | 1 | 15 | 27 |
| Class Title2 | 2 | 15 | 27 |
| Class Title3 | 3 | 15 | 27 |
Because there are ~550 students and 21 classes and for the Hungarian algorithm to work, I was planning to make "copies" of the classes. I would first make 15 copies of every class (like class 1.1, 1.2, 1.3, 1.4, 2.1, 2.2, 2.3, etc.) to fill the minimum requirement of the class and then would add even more copies to the most popular classes among the students until there is an equal number of students and copies of classes.
My question is: how would I loop the copying of the variables that would, in the algorithm act like their own classes or choices for classes (since the choices would also need to be different as to put the people to different copies of the same class and not have them compete for only one variable when there are other copies of it) but then after the sorting is done, the copies could be traced back to the original?
Thank you in advance and let me know if there is anything I can clarify
You should know that some
types in Python aremutable types, one of them is thelisttype:You may describe a
listin Python like a pointer that points toward the cells.An other example may be this:
As you can see the
ivariable is not passed by reference, since it's animmutable typedvariable. But look at this:The same thing is true for
dicts, so that if you want to have a copy [indipendent from the original] of that dictionary you will have to do something like this:So, if you need a short answer:
You just have to create them with
b = a