@@ -316,7 +316,7 @@ MixedStrategyProfile<T> &MixedStrategyProfile<T>::operator=(const MixedStrategyP
316316template <class T > Vector<T> MixedStrategyProfile<T>::GetStrategy(const GamePlayer &p_player) const
317317{
318318 CheckVersion ();
319- auto strategies = m_rep->m_support .GetStrategies (p_player);
319+ auto strategies = m_rep->GetSupport () .GetStrategies (p_player);
320320 Vector<T> probs (strategies.size ());
321321 std::transform (strategies.begin (), strategies.end (), probs.begin (),
322322 [this ](const GameStrategy &s) { return (*m_rep)[s]; });
@@ -326,12 +326,12 @@ template <class T> Vector<T> MixedStrategyProfile<T>::GetStrategy(const GamePlay
326326template <class T > MixedStrategyProfile<T> MixedStrategyProfile<T>::ToFullSupport() const
327327{
328328 CheckVersion ();
329- MixedStrategyProfile<T> full (m_rep->m_support .GetGame ()->NewMixedStrategyProfile (T (0 )));
329+ MixedStrategyProfile<T> full (m_rep->GetSupport () .GetGame ()->NewMixedStrategyProfile (T (0 )));
330330
331- for (const auto &player : m_rep->m_support .GetGame ()->GetPlayers ()) {
331+ for (const auto &player : m_rep->GetSupport () .GetGame ()->GetPlayers ()) {
332332 for (const auto &strategy : player->GetStrategies ()) {
333333 full[strategy] =
334- (m_rep->m_support .Contains (strategy)) ? (*m_rep)[strategy] : static_cast <T>(0 );
334+ (m_rep->GetSupport () .Contains (strategy)) ? (*m_rep)[strategy] : static_cast <T>(0 );
335335 }
336336 }
337337 return full;
@@ -343,17 +343,18 @@ template <class T> MixedStrategyProfile<T> MixedStrategyProfile<T>::ToFullSuppor
343343
344344template <class T > void MixedStrategyProfile<T>::ComputePayoffs() const
345345{
346- if (!m_payoffs.empty ()) {
347- // caches (m_payoffs and m_strategyValues) are valid,
348- // so don't compute anything, simply return
346+ if (m_cache.m_valid ) {
349347 return ;
350348 }
351- for (const auto &player : m_rep->m_support .GetPlayers ()) {
352- m_payoffs[player] = GetPayoff (player);
353- for (const auto &strategy : m_rep->m_support .GetStrategies (player)) {
354- m_strategyValues[player][strategy] = GetPayoff (strategy);
349+ Cache newCache;
350+ for (const auto &player : m_rep->GetSupport ().GetPlayers ()) {
351+ newCache.m_payoffs [player] = GetPayoff (player);
352+ for (const auto &strategy : m_rep->GetSupport ().GetStrategies (player)) {
353+ newCache.m_strategyValues [player][strategy] = GetPayoff (strategy);
355354 }
356355 }
356+ newCache.m_valid = true ;
357+ m_cache = std::move (newCache);
357358};
358359
359360template <class T > T MixedStrategyProfile<T>::GetLiapValue() const
@@ -362,12 +363,11 @@ template <class T> T MixedStrategyProfile<T>::GetLiapValue() const
362363 ComputePayoffs ();
363364
364365 auto liapValue = static_cast <T>(0 );
365- for (auto p : m_payoffs) {
366- liapValue += std::transform_reduce (
367- m_strategyValues.at (p.first ).begin (), m_strategyValues.at (p.first ).end (),
368- static_cast <T>(0 ), std::plus<T>(), [&p](const auto &v) -> T {
369- return sqr (std::max (v.second - p.second , static_cast <T>(0 )));
370- });
366+ for (const auto &p : m_cache.m_payoffs ) {
367+ const auto &values = m_cache.m_strategyValues .at (p.first );
368+ liapValue += sum_function (values, [&](const auto &v) {
369+ return sqr (std::max (v.second - p.second , static_cast <T>(0 )));
370+ });
371371 }
372372 return liapValue;
373373}
@@ -376,13 +376,14 @@ template <class T> T MixedStrategyProfile<T>::GetRegret(const GameStrategy &p_st
376376{
377377 CheckVersion ();
378378 ComputePayoffs ();
379+
379380 auto player = p_strategy->GetPlayer ();
380381 T best_other_payoff = maximize_function (
381382 filter_if (player->GetStrategies (), [&](const auto &s) { return s != p_strategy; }),
382383 [this , &player](const auto &strategy) -> T {
383- return m_strategyValues.at (player).at (strategy);
384+ return m_cache. m_strategyValues .at (player).at (strategy);
384385 });
385- return std::max (best_other_payoff - m_strategyValues.at (player).at (p_strategy),
386+ return std::max (best_other_payoff - m_cache. m_strategyValues .at (player).at (p_strategy),
386387 static_cast <T>(0 ));
387388}
388389
@@ -392,9 +393,9 @@ template <class T> T MixedStrategyProfile<T>::GetRegret(const GamePlayer &p_play
392393 ComputePayoffs ();
393394 auto br_payoff =
394395 maximize_function (p_player->GetStrategies (), [this , p_player](const auto &strategy) -> T {
395- return m_strategyValues.at (p_player).at (strategy);
396+ return m_cache. m_strategyValues .at (p_player).at (strategy);
396397 });
397- return br_payoff - m_payoffs.at (p_player);
398+ return br_payoff - m_cache. m_payoffs .at (p_player);
398399}
399400
400401template <class T > T MixedStrategyProfile<T>::GetMaxRegret() const
0 commit comments