def METHOD_NAME(self, pairings):
    # Don't swap sides! The child class RandomDrawWithSideConstraints assumes
    # that in this algorithm, affs will stay affs and negs will stay negs.
    if not (self.options["avoid_history"] or self.options["avoid_institution"]):
        return
    if self.options["avoid_conflicts"] == "off":
        return
    for pairing in pairings:
        if self._badness(pairing) > 0:
            for j in range(self.options["max_swap_attempts"]):
                swap_pairing = random.choice(pairings)
                if swap_pairing == pairing:
                    continue
                badness_orig = self._badness(pairing, swap_pairing)
                pairing.teams[1], swap_pairing.teams[1] = swap_pairing.teams[1], pairing.teams[1]
                badness_new = self._badness(pairing, swap_pairing)
                if badness_new == 0:
                    break  # yay!
                elif badness_new >= badness_orig or self._badness(swap_pairing) > 0:
                    # swap back and try again
                    pairing.teams[1], swap_pairing.teams[1] = swap_pairing.teams[1], pairing.teams[1]
                # else, if improvement but not perfect, keep swap and try again
            else:
                pairing.flags.append("max_swapped")