@@ -50,29 +50,34 @@ template <class T> MixedStrategyProfileRep<T> *TreeMixedStrategyProfileRep<T>::C
5050 return new TreeMixedStrategyProfileRep (*this );
5151}
5252
53- template <class T > T TreeMixedStrategyProfileRep<T>::GetPayoff( int pl ) const
53+ template <class T > void TreeMixedStrategyProfileRep<T>::MakeBehavior( ) const
5454{
5555 if (mixed_behav_profile_sptr.get () == nullptr ) {
5656 MixedStrategyProfile<T> tmp (Copy ());
5757 mixed_behav_profile_sptr = std::make_shared<MixedBehaviorProfile<T>>(tmp);
5858 }
59- return mixed_behav_profile_sptr->GetPayoff (pl);
6059}
6160
6261template <class T > void TreeMixedStrategyProfileRep<T>::InvalidateCache() const
6362{
6463 mixed_behav_profile_sptr = nullptr ;
6564}
6665
66+ template <class T > T TreeMixedStrategyProfileRep<T>::GetPayoff(int pl) const
67+ {
68+ MakeBehavior ();
69+ return mixed_behav_profile_sptr->GetPayoff (pl);
70+ }
71+
6772template <class T >
6873T TreeMixedStrategyProfileRep<T>::GetPayoffDeriv(int pl, const GameStrategy &strategy) const
6974{
70- MixedStrategyProfile<T> foo ( Copy () );
71- for (auto s : this ->m_support .GetStrategies (this -> m_support . GetGame ()-> GetPlayer (pl ))) {
72- foo[s] = static_cast <T>(0 );
75+ auto foo = std::make_unique<TreeMixedStrategyProfileRep>(* this );
76+ for (auto s : this ->m_support .GetStrategies (strategy-> GetPlayer ())) {
77+ (* foo) [s] = static_cast <T>(0 );
7378 }
74- foo[strategy] = static_cast <T>(1 );
75- return foo. GetPayoff (pl);
79+ (* foo) [strategy] = static_cast <T>(1 );
80+ return foo-> GetPayoff (pl);
7681}
7782
7883template <class T >
@@ -85,18 +90,18 @@ T TreeMixedStrategyProfileRep<T>::GetPayoffDeriv(int pl, const GameStrategy &str
8590 return T (0 );
8691 }
8792
88- MixedStrategyProfile<T> foo ( Copy () );
93+ auto foo = std::make_unique<TreeMixedStrategyProfileRep>(* this );
8994 for (auto strategy : this ->m_support .GetStrategies (player1)) {
90- foo[strategy] = T (0 );
95+ (* foo) [strategy] = T (0 );
9196 }
92- foo[strategy1] = T (1 );
97+ (* foo) [strategy1] = T (1 );
9398
9499 for (auto strategy : this ->m_support .GetStrategies (player2)) {
95- foo[strategy] = T (0 );
100+ (* foo) [strategy] = T (0 );
96101 }
97- foo[strategy2] = T (1 );
102+ (* foo) [strategy2] = T (1 );
98103
99- return foo. GetPayoff (pl);
104+ return foo-> GetPayoff (pl);
100105}
101106
102107template class TreeMixedStrategyProfileRep <double >;
0 commit comments