1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-08-02 21:54:24 +02:00

More robust algorithm

This commit is contained in:
Ehouarn
2025-08-02 17:18:51 +02:00
parent 8e98d62b69
commit 573f2d8a22
2 changed files with 8 additions and 9 deletions

View File

@@ -365,7 +365,7 @@ class WEISurvey2025(WEISurvey):
return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
@lru_cache()
def score(self, bus):
def score_questions(self, bus):
"""
The score given by the answers to the questions
"""
@@ -391,7 +391,7 @@ class WEISurvey2025(WEISurvey):
@lru_cache()
def scores_per_bus(self):
return {bus: (self.score(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
return {bus: (self.score_questions(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
@lru_cache()
def ordered_buses(self):
@@ -400,7 +400,6 @@ class WEISurvey2025(WEISurvey):
"""
values = list(self.scores_per_bus().items())
values.sort(key=lambda item: -item[1][1])
values = values[:3]
return values
@classmethod
@@ -509,17 +508,17 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
else:
# Current bus has not enough places. Remove the least preferred student from the bus if existing
least_preferred_survey = None
least_scores = (-1, -1)
least_score = -1
# Find the least student in the bus that has a lower score than the current student
for survey2 in surveys:
if not survey2.information.valid or survey2.information.get_selected_bus() != bus:
continue
scores2 = survey2.score(bus), survey2.score_words(bus)
if current_scores <= scores2: # Ignore better students
score2 = survey2.score_questions(bus)
if current_scores[0] <= score2: # Ignore better students
continue
if least_preferred_survey is None or scores2 < least_scores:
if least_preferred_survey is None or score2 < least_score:
least_preferred_survey = survey2
least_scores = scores2
least_score = score2
if least_preferred_survey is not None:
# Remove the least student from the bus and put the current student in.

View File

@@ -110,6 +110,6 @@ class TestWEIAlgorithm(TestCase):
max_score = buses[0][1][0]
penalty += (max_score - score) ** 2
self.assertLessEqual(max_score - score, 1) # Always less than 25 % of tolerance
self.assertLessEqual(max_score - score, 1)
self.assertLessEqual(penalty / 100, 25) # Tolerance of 5 %