<commit_before>package lila.tournament
package arena

import PairingSystem.{Data,url}

private object AntmaPairing {

  def apply(data: Data, players: RankedPlayers): List[Pairing.Prep] = players.nonEmpty ?? {
    import data._
    val a: Array[RankedPlayer] = players.toArray
    val n: Int = a.length
    def pairScore(i: Int, j: Int): Int = {
      def playedTogether(u1:String, u2:String) = if (lastOpponents.hash.get(u1).contains(u2)) 1 else 0
      def f(x: Int): Int = (11500000 - 3500000 * x) * x
      Math.abs(a(i).rank - a(j).rank) * 1000 +
      Math.abs(a(i).player.rating - a(j).player.rating) +
      f (playedTogether(a(i).player.userId, a(j).player.userId) + playedTogether(a(j).player.userId, a(i).player.userId))
    }
    val mate = WMMatching.minWeightMatching(WMMatching.fullGraph(n, pairScore))
    WMMatching.mateToEdges(mate).map (x => Pairing.prep(tour, a(x._1).player, a(x._2).player))
  }<commit_msg>cache antma pairing exceptions (just in case)<commit_after>package lila.tournament
package arena

import PairingSystem.{ Data, url }

private object AntmaPairing {

  def apply(data: Data, players: RankedPlayers): List[Pairing.Prep] = players.nonEmpty ?? {
    import data._
    val a: Array[RankedPlayer] = players.toArray
    val n: Int = a.length
    def pairScore(i: Int, j: Int): Int = {
      def playedTogether(u1: String, u2: String) =
        if (lastOpponents.hash.get(u1).contains(u2)) 1 else 0
      def f(x: Int): Int = (11500000 - 3500000 * x) * x
      Math.abs(a(i).rank - a(j).rank) * 1000 +
        Math.abs(a(i).player.rating - a(j).player.rating) +
        f {
          playedTogether(a(i).player.userId, a(j).player.userId) +
            playedTogether(a(j).player.userId, a(i).player.userId)
        }
    }
    try {
      val mate = WMMatching.minWeightMatching(WMMatching.fullGraph(n, pairScore))
      WMMatching.mateToEdges(mate).map(x => Pairing.prep(tour, a(x._1).player, a(x._2).player))
    }
    catch {
      case e: Exception =>
        logger.error("AntmaPairing", e)
        Nil
    }
  }
{'fraction_non_alphanumeric': 0.14953726254262056, 'fraction_numerical': 0.026302971261568435, 'mean_word_length': 3.1494949494949496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136606', 'n_tokens_mistral': 795, 'n_tokens_neox': 737, 'n_words': 151}