Skip to content

Commit

Permalink
add verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
lschoonheid committed Jan 19, 2023
1 parent 72a04e4 commit 165e9ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
16 changes: 7 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@ def generate(solver: Solver, n: int, stud_prefs_path, courses_path, rooms_path,


# TODO: write interface code to execute complete program from command line
def main(
stud_prefs_path: str,
courses_path: str,
rooms_path: str,
):
def main(stud_prefs_path: str, courses_path: str, rooms_path: str, verbose: bool = False):
"""Interface for executing scheduling program."""

results = generate(Randomize(), 1000, stud_prefs_path, courses_path, rooms_path)
results = generate(Randomize(verbose=True), 1, stud_prefs_path, courses_path, rooms_path, i_max=100)

sampled_schedule = random.choice(results).schedule
G = GraphVisualization(sampled_schedule)
sampled_result = random.choice(results)
print(sampled_result)
G = GraphVisualization(sampled_result.schedule)
G.visualize()
schedule_to_csv(sampled_schedule)
schedule_to_csv(sampled_result.schedule)

plot_statistics(results)

Expand All @@ -55,6 +52,7 @@ def main(
default="data/studenten_en_vakken_subset.csv",
help="Path to student enrolments csv.",
)
parser.add_argument("-v", dest="verbose", action="store_true", help="Verbose: log error messages.")
parser.add_argument("--courses", dest="courses_path", default="data/vakken_subset.csv", help="Path to courses csv.")
parser.add_argument("--rooms", dest="rooms_path", default="data/zalen_subset.csv", help="Path to rooms csv.")

Expand Down
2 changes: 1 addition & 1 deletion program_code/algorithms/randomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def assign_students_timeslots(self, schedule: Schedule, i_max=1000):

# Try making connections for i_max iterations
edges = set()
for i in tqdm(range(i_max), disable=not self.verbose):
for i in tqdm(range(i_max), disable=not self.verbose, desc="Trying connections:"):
# print(i)
if len(available_activities) == 0:
return self.verifier.Result(schedule=schedule, iterations=i, solved=True)
Expand Down
26 changes: 11 additions & 15 deletions program_code/algorithms/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@ def __init__(
self.schedule = schedule
self.iterations = iterations

# Convert True/False to int for matrix multiplication
if type(solved) is None:
self.solved = 0
elif type(solved) is bool:
self.solved = int(solved)
else:
raise ValueError("`solved` needs to be of type int | bool")
self.solved_input = solved

self.student_overbookings_input = student_overbookings
self.timeslot_overbookings_input = timeslot_overbookings
Expand All @@ -126,17 +120,17 @@ def __init__(

@cached_property
def is_solved(self):
if type(self.solved) is bool:
return self.solved
return None
# Convert True/False to int for matrix multiplication
if self.solved_input is None:
return "test"
return self.solved_input

@cached_property
def student_overbookings(self):
"""1 malus point"""
if self.student_overbookings_input is None:
return self.verifier.aggregate(self.verifier.student_overbooked, self.schedule.students)
else:
return self.student_overbookings_input
return self.student_overbookings_input

@cached_property
def students_unbooked(self):
Expand All @@ -148,19 +142,21 @@ def timeslot_overbookings(self):
"""Hard constraint"""
if self.timeslot_overbookings_input is None:
return self.verifier.aggregate(self.verifier.timeslot_overbooked, self.schedule.timeslots)
else:
return self.timeslot_overbookings_input
return self.timeslot_overbookings_input

@cached_property
def score_vector(self):
return np.array(
[self.solved, self.student_overbookings, self.timeslot_overbookings, self.students_unbooked]
[int(self.is_solved), self.student_overbookings, self.timeslot_overbookings, self.students_unbooked]
)

@cached_property
def score(self) -> float:
return self.score_matrix.dot(self.score_vector)

def __str__(self):
return str(self.__dict__)

def get_statistics(self, schedule: Schedule, iterations: int | None = None, solved: bool | None = None):
"""Wrapper function to retrieve statistics as `Result` object."""
score_vector = self.Result(
Expand Down

0 comments on commit 165e9ac

Please sign in to comment.