micfong-z / OptiWay

SCIE A1 CS Project Repo
MIT License
0 stars 2 forks source link

`timetable_generator.py` fails to run #16

Closed needlesslygrim closed 12 months ago

needlesslygrim commented 12 months ago

Whenever I try to run timetable_generator.py I get the following error:

Traceback (most recent call last):
  File "/home/needlesslygrim/src/rust/OptiWay/timetable_generation/timetable_generator.py", line 682, in <module>
    time_table3 = generator.generate_as_al_level()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/needlesslygrim/src/rust/OptiWay/timetable_generation/timetable_generator.py", line 561, in generate_as_al_level
    room = random.choice(
           ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/random.py", line 373, in choice
    raise IndexError('Cannot choose from an empty sequence')
IndexError: Cannot choose from an empty sequence

It originates in the following code(formatted by me):

room = random.choice(
    list(
        self.avail_rooms[floor]
        - filled_timetable[day1][p11]
        - filled_timetable[day2][p21]
        - filled_timetable[day3][p31]
        - filled_rooms[index][floor]
    )
)  # minus the as time slots as well

Am I missing something?

0010SS commented 12 months ago

The algorithm is not robust due to the randomness of timetables and class arrangements... Please try running it multiple times.

needlesslygrim commented 12 months ago

Ah, that makes sense. I might open a PR that makes the program loop until it's not empty.

needlesslygrim commented 12 months ago

Just written the code, once #15 is merged I'll open the PR