Skip to content

Commit

Permalink
Add a safeguard to prevent infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
viroulep committed Mar 24, 2024
1 parent a710b00 commit 4eb73d6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions groups/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ function Assign(competition, round, assignmentSets, scorers, stationRules, attem
}
})
var totalToAssign = queue.length
var previousLength = -1;
while (queue.length > preAssignedTotal) {
var potentialInfinite = queue.length === previousLength;
previousLength = queue.length;
console.log(queue.length + ' left')
// Don't assign any more to groups with enough people pre-assigned.
var groupsToUse = eligibleGroups.filter((group) => currentByGroup[group.wcif.id].length + preAssignedByGroup[group.wcif.id] <= groupSizeLimit)
Expand Down Expand Up @@ -135,6 +138,10 @@ function Assign(competition, round, assignmentSets, scorers, stationRules, attem
}
})
})
if (!solution.feasible && potentialInfinite) {
console.log("The group assignment is not feasible, the function will break out to prevent an infinite loop.")
break;
}
queue = queue.filter((item, idx) => !indicesToErase.includes(idx))
newlyAssigned.forEach((assn) => {
currentByPerson[assn.person.wcaUserId] = assn.group
Expand Down

0 comments on commit 4eb73d6

Please sign in to comment.