From b1bff0575e1da1560f8bdd68dbcbbe424beef22c Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 1 Jul 2020 11:45:24 +0000 Subject: [PATCH] Additional small tweaks to the generate_schedule management command, maninly output. - Legacy-Id: 18115 --- .../management/commands/generate_schedule.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ietf/meeting/management/commands/generate_schedule.py b/ietf/meeting/management/commands/generate_schedule.py index a53962ad8..e9bb25353 100644 --- a/ietf/meeting/management/commands/generate_schedule.py +++ b/ietf/meeting/management/commands/generate_schedule.py @@ -8,6 +8,7 @@ import datetime import math import random import string +import sys import time from collections import defaultdict @@ -22,7 +23,7 @@ import debug # pyflakes:ignore from ietf.person.models import Person from ietf.meeting import models -OPTIMISER_MAX_CYCLES = 100 +OPTIMISER_MAX_CYCLES = 80 class Command(BaseCommand): @@ -42,7 +43,7 @@ class Command(BaseCommand): class ScheduleHandler(object): - def __init__(self, stdout, meeting_number, name, max_cycles, verbosity): + def __init__(self, stdout, meeting_number, name=None, max_cycles=OPTIMISER_MAX_CYCLES, verbosity=1): self.stdout = stdout self.verbosity = verbosity self.name = name @@ -301,6 +302,7 @@ class Schedule(object): best_cost = math.inf shuffle_next_run = False last_run_cost = None + switched_with = None for run_count in range(1, self.max_cycles+1): items = list(self.schedule.items()) @@ -334,14 +336,20 @@ class Schedule(object): switched_with = self._switch_sessions(original_timeslot, best_timeslot) switched_with = switched_with.group if switched_with else '' if self.verbosity >= 3: - self.stdout.write('Found cost reduction to {} by switching {} with {}' - .format(best_cost, session.group, switched_with)) + self.stdout.write('Run {:2}: found cost reduction to {:,} by switching {} with {}' + .format(run_count, best_cost, session.group, switched_with)) if last_run_cost == best_cost: shuffle_next_run = True last_run_violations, last_run_cost = self.calculate_dynamic_cost() - self._save_schedule(last_run_cost) + self._save(last_run_cost) + if self.verbosity >= 1 and self.stdout.isatty(): + sys.stderr.write('*' if last_run_cost < self.best_cost else '.') + sys.stderr.flush() + + if self.verbosity >= 1 and self.stdout.isatty(): + sys.stderr.write('\n') if self.verbosity >= 2: self.stdout.write('Optimiser did not find perfect schedule, using best schedule at dynamic cost {}' .format(self.best_cost)) @@ -453,7 +461,7 @@ class Schedule(object): del self.schedule[timeslot1] return session2 - def _save_schedule(self, cost): + def _save(self, cost): if cost < self.best_cost: self.best_cost = cost self.best_schedule = self.schedule.copy()