Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ gambit_SOURCES = \
src/gui/dlnash.cc \
src/gui/dlnash.h \
src/gui/dlnashmon.cc \
src/gui/dlnashmon.h \
src/gui/dlnewtable.cc \
src/gui/dlnewtable.h \
src/gui/dlnfglogit.cc \
Expand Down
74 changes: 9 additions & 65 deletions src/gui/analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <wx/wx.h>
#endif // WX_PRECOMP
#include <wx/tokenzr.h>

#include "gambit.h"
#include "core/tinyxml.h" // for XML parser for Load()

Expand All @@ -37,77 +36,22 @@ namespace Gambit::GUI {
// class AnalysisProfileList
//=========================================================================

// Use anonymous namespace to make these helpers private
namespace {

class NotNashException final : public std::runtime_error {
public:
NotNashException() : std::runtime_error("Output line does not contain a Nash equilibrium") {}
~NotNashException() noexcept override = default;
};

template <class T>
MixedStrategyProfile<T> OutputToMixedProfile(GameDocument *p_doc, const wxString &p_text)
void AnalysisProfileList<T>::AddProfile(const MixedStrategyProfile<T> &p_profile)
{
MixedStrategyProfile<T> profile(p_doc->GetGame()->NewMixedStrategyProfile(static_cast<T>(0.0)));

if (wxStringTokenizer tok(p_text, wxT(",")); tok.GetNextToken() == wxT("NE")) {
if (tok.CountTokens() == static_cast<unsigned int>(profile.MixedProfileLength())) {
for (size_t i = 1; i <= profile.MixedProfileLength(); i++) {
profile[i] =
lexical_cast<Rational>(std::string((const char *)tok.GetNextToken().mb_str()));
}
return profile;
}
m_mixedProfiles.push_back(std::make_shared<MixedStrategyProfile<T>>(p_profile));
if (m_doc->GetGame()->IsTree()) {
m_behavProfiles.push_back(std::make_shared<MixedBehaviorProfile<T>>(p_profile));
}

throw NotNashException();
m_current = m_mixedProfiles.size();
}

template <class T>
MixedBehaviorProfile<T> OutputToBehavProfile(GameDocument *p_doc, const wxString &p_text)
{
MixedBehaviorProfile<T> profile(p_doc->GetGame());

wxStringTokenizer tok(p_text, wxT(","));

if (tok.GetNextToken() == wxT("NE")) {
if (tok.CountTokens() == static_cast<unsigned int>(profile.BehaviorProfileLength())) {
for (size_t i = 1; i <= profile.BehaviorProfileLength(); i++) {
profile[i] = lexical_cast<Rational>(std::string(tok.GetNextToken().mb_str()));
}
return profile;
}
}

throw NotNashException();
}

} // end anonymous namespace

template <class T> void AnalysisProfileList<T>::AddOutput(const wxString &p_output)
void AnalysisProfileList<T>::AddProfile(const MixedBehaviorProfile<T> &p_profile)
{
try {
if (m_isBehav) {
auto profile =
std::make_shared<MixedBehaviorProfile<T>>(OutputToBehavProfile<T>(m_doc, p_output));
m_behavProfiles.push_back(profile);
m_mixedProfiles.push_back(
std::make_shared<MixedStrategyProfile<T>>(profile->ToMixedProfile()));
m_current = m_behavProfiles.size();
}
else {
auto profile =
std::make_shared<MixedStrategyProfile<T>>(OutputToMixedProfile<T>(m_doc, p_output));
m_mixedProfiles.push_back(profile);
if (m_doc->GetGame()->IsTree()) {
m_behavProfiles.push_back(std::make_shared<MixedBehaviorProfile<T>>(*profile));
}
m_current = m_mixedProfiles.size();
}
}
catch (NotNashException &) {
}
m_behavProfiles.push_back(std::make_shared<MixedBehaviorProfile<T>>(p_profile));
m_mixedProfiles.push_back(std::make_shared<MixedStrategyProfile<T>>(p_profile.ToMixedProfile()));
m_current = m_behavProfiles.size();
}

template <class T> void AnalysisProfileList<T>::BuildNfg()
Expand Down
5 changes: 2 additions & 3 deletions src/gui/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class AnalysisOutput {
virtual std::string GetStrategyProb(int p_strategy, int p_index = -1) const = 0;
virtual std::string GetStrategyValue(int p_strategy, int p_index = -1) const = 0;

virtual void AddOutput(const wxString &) = 0;

/// Map all behavior profiles to corresponding mixed profiles
virtual void BuildNfg() = 0;

Expand Down Expand Up @@ -169,7 +167,8 @@ template <class T> class AnalysisProfileList final : public AnalysisOutput {
//! @name Adding profiles to the list
//!
//@{
void AddOutput(const wxString &) override;
void AddProfile(const MixedStrategyProfile<T> &);
void AddProfile(const MixedBehaviorProfile<T> &);
/// Map all behavior profiles to corresponding mixed profiles
void BuildNfg() override;

Expand Down
Loading
Loading