From 94c635b7473afd02e4686fc553e9901fada00489 Mon Sep 17 00:00:00 2001 From: benkeks Date: Wed, 26 Jun 2024 14:44:12 +0200 Subject: [PATCH] Add on-the-fly minimum selection in energy game solving This trick from Brihaye & Goeminne (2023) has practically enabled better runtimes in https://github.com/Gobbel2000/gpuequiv/ (and also improves theoretical complexity.) --- .../io/equiv/eqfiddle/game/EnergyGame.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala b/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala index 18ae7dd..ea15099 100644 --- a/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala +++ b/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala @@ -24,10 +24,20 @@ trait EnergyGame extends SimpleGame with GameLazyDecision[EnergyGame.Energy] { } yield attackerVictoryPrices(s).map(w.unapplyEnergyUpdate(_)) val productMoves = possibleMoves.reduceLeft( - (b, a) => b.flatMap(i => a.map(j => i lub j))) + (b, a) => filterMinimal(b.flatMap(i => a.map(j => i lub j)))) productMoves.toSet } } + + private def filterMinimal(energies: List[Energy]) = { + // if energy list becomes big, prune dominated energies on-the-fly at defender positions + // to prevent exponential blowup of options. + if (energies.size > 2) { + energies.filterNot(e1 => energies.exists(e2 => e2 < e1)) + } else { + energies + } + } } object EnergyGame {