codecogs equations

fredag 8 februari 2019

Zen of Python: Flat is better than nested

Previous:
If this model is going to be useful, it needs to be able to read data in a realistic format. That includes at least being able to take in data on when students are available, as datetime strings. 

In the first model, I used a discretized time model, and the assignment variables were stored in a list of lists with equal length. One dimension for students, and one for time. This representation requires a lot of nested loops. Now, I set the challenge as being able to handle increased complexity with a more readable model. For this, I changed the representation from list of lists to a dict that maps student-time pairs to the assignment variables. 

This changes the way groups of variables are retrieved. For example:

The upside is particularly clear when we want to sum in the non-primary dimension, and won't have to do transposing. In this case, we also get out of retrieving by indexes.

In summary I was happy with the outcome of this change. The flat representation both handles a new feature, and makes for clearer operations. New results, using this data:

The lessons are 20 minutes.
Coloring: Dark blue is active. Light blue is available student. Red is teacher waiting time.

Inga kommentarer:

Skicka en kommentar