📄 dlnfgnash.cc
字号:
class nfgAllPerfect : public nfgNashAlgorithm {public: gText GetAlgorithm(void) const { return "AllPerfect"; } gList<MixedSolution> Solve(const NFSupport &, gStatus &);};gList<MixedSolution> nfgAllPerfect::Solve(const NFSupport &p_support, gStatus &p_status){ gArray<int> players(p_support.Game().NumPlayers()); for (int pl = 1; pl <= players.Length(); pl++) { players[pl] = pl; } try { gNullStatus status; gNullOutput gnull; /* one round of elimination of weakly dominated strategies */ NFSupport support = p_support.Undominated(false, players, gnull, status); nfgEnumMixed<double> algorithm; algorithm.SetStopAfter(0); return algorithm.Solve(support, p_status); } catch (...) { return gList<MixedSolution>(); }}//========================================================================// class panelNfgAllPerfect//========================================================================class panelNfgAllPerfect : public panelNfgNashAlgorithm {public: panelNfgAllPerfect(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgAllPerfect::panelNfgAllPerfect(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "AllPerfectSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find all perfect Nash equilibria"), 0, wxALL | wxCENTER, 5); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "This algorithm requires no parameters"), 0, wxALL | wxCENTER, 5); topSizer->Add(centerSizer, 1, wxALL | wxCENTER, 5); SetSizer(topSizer); topSizer->Fit(this); topSizer->SetSizeHints(this); Layout(); Show(false);}nfgNashAlgorithm *panelNfgAllPerfect::GetAlgorithm(void) const{ return new nfgAllPerfect;}//========================================================================// class panelNfgEnumPure//========================================================================class panelNfgEnumPure : public panelNfgNashAlgorithm {private: wxCheckBox *m_findAll; wxSpinCtrl *m_stopAfter; // Private event handlers void OnFindAll(wxCommandEvent &);public: panelNfgEnumPure(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelNfgEnumPure, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_FINDALL, panelNfgEnumPure::OnFindAll)END_EVENT_TABLE()panelNfgEnumPure::panelNfgEnumPure(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "EnumPureSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find Nash equilibria by enumerating " "pure strategies"), 0, wxALL | wxCENTER, 5); wxStaticBox *stopAfterBox = new wxStaticBox(this, wxID_STATIC, "Number to find"); wxStaticBoxSizer *stopAfterSizer = new wxStaticBoxSizer(stopAfterBox, wxHORIZONTAL); m_findAll = new wxCheckBox(this, idCHECKBOX_FINDALL, "Find all"); m_findAll->SetValue(false); stopAfterSizer->Add(m_findAll, 0, wxALL | wxCENTER, 5); stopAfterSizer->Add(new wxStaticText(this, wxID_STATIC, "Stop after"), 0, wxALL | wxCENTER, 5); m_stopAfter = new wxSpinCtrl(this, -1, "1", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10000); stopAfterSizer->Add(m_stopAfter, 0, wxALL | wxCENTER, 5); centerSizer->Add(stopAfterSizer, 0, wxALL | wxCENTER, 5); topSizer->Add(centerSizer, 1, wxALL | wxCENTER, 0); SetSizer(topSizer); topSizer->Fit(this); topSizer->SetSizeHints(this); Layout(); Show(false);}void panelNfgEnumPure::OnFindAll(wxCommandEvent &){ m_stopAfter->Enable(!m_findAll->GetValue());}nfgNashAlgorithm *panelNfgEnumPure::GetAlgorithm(void) const{ nfgEnumPure *algorithm = new nfgEnumPure; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); return algorithm;}//========================================================================// class panelNfgEnumMixed//========================================================================class panelNfgEnumMixed : public panelNfgNashAlgorithm {private: wxRadioBox *m_precision; wxCheckBox *m_findAll; wxSpinCtrl *m_stopAfter; // Private event handlers void OnFindAll(wxCommandEvent &);public: panelNfgEnumMixed(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelNfgEnumMixed, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_FINDALL, panelNfgEnumMixed::OnFindAll)END_EVENT_TABLE()panelNfgEnumMixed::panelNfgEnumMixed(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "EnumMixedSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find Nash equilibria by enumerating " "mixed strategies"), 0, wxALL | wxCENTER, 5); wxString precisionChoices[] = { "Floating point", "Rational" }; m_precision = new wxRadioBox(this, -1, "Precision", wxDefaultPosition, wxDefaultSize, 2, precisionChoices, 1, wxRA_SPECIFY_ROWS); centerSizer->Add(m_precision, 0, wxALL | wxCENTER, 5); wxStaticBox *stopAfterBox = new wxStaticBox(this, wxID_STATIC, "Number to find"); wxStaticBoxSizer *stopAfterSizer = new wxStaticBoxSizer(stopAfterBox, wxHORIZONTAL); m_findAll = new wxCheckBox(this, idCHECKBOX_FINDALL, "Find all"); m_findAll->SetValue(false); stopAfterSizer->Add(m_findAll, 0, wxALL | wxCENTER, 5); stopAfterSizer->Add(new wxStaticText(this, wxID_STATIC, "Stop after"), 0, wxALL | wxCENTER, 5); m_stopAfter = new wxSpinCtrl(this, -1, "1", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10000); stopAfterSizer->Add(m_stopAfter, 0, wxALL | wxCENTER, 5); centerSizer->Add(stopAfterSizer, 0, wxALL | wxCENTER, 5); topSizer->Add(centerSizer, 1, wxALL | wxCENTER, 0); SetSizer(topSizer); topSizer->Fit(this); topSizer->SetSizeHints(this); Layout(); Show(false);}void panelNfgEnumMixed::OnFindAll(wxCommandEvent &){ m_stopAfter->Enable(!m_findAll->GetValue());}nfgNashAlgorithm *panelNfgEnumMixed::GetAlgorithm(void) const{ if (m_precision->GetSelection() == 0) { nfgEnumMixed<double> *algorithm = new nfgEnumMixed<double>; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); return algorithm; } else { nfgEnumMixed<gRational> *algorithm = new nfgEnumMixed<gRational>; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); return algorithm; }}//========================================================================// class panelNfgLcp//========================================================================const int idCHECKBOX_LIMITDEPTH = 2002;class panelNfgLcp : public panelNfgNashAlgorithm {private: wxRadioBox *m_precision; wxCheckBox *m_findAll, *m_limitDepth; wxSpinCtrl *m_stopAfter, *m_maxDepth; // Private event handlers void OnFindAll(wxCommandEvent &); void OnStopAfter(wxSpinEvent &); void OnLimitDepth(wxCommandEvent &);public: panelNfgLcp(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelNfgLcp, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_FINDALL, panelNfgLcp::OnFindAll) EVT_SPINCTRL(idSPINCTRL_STOPAFTER, panelNfgLcp::OnStopAfter) EVT_CHECKBOX(idCHECKBOX_LIMITDEPTH, panelNfgLcp::OnLimitDepth)END_EVENT_TABLE()panelNfgLcp::panelNfgLcp(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "LcpSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find Nash equilibria via linear " "complementarity program"), 0, wxALL | wxCENTER, 5); wxString precisionChoices[] = { "Floating point", "Rational" }; m_precision = new wxRadioBox(this, -1, "Precision", wxDefaultPosition, wxDefaultSize, 2, precisionChoices, 1, wxRA_SPECIFY_ROWS); centerSizer->Add(m_precision, 0, wxALL | wxCENTER, 5); wxStaticBox *stopAfterBox = new wxStaticBox(this, wxID_STATIC, "Number to find"); wxStaticBoxSizer *stopAfterSizer = new wxStaticBoxSizer(stopAfterBox, wxHORIZONTAL); m_findAll = new wxCheckBox(this, idCHECKBOX_FINDALL, "Find all"); m_findAll->SetValue(false); stopAfterSizer->Add(m_findAll, 0, wxALL | wxCENTER, 5); stopAfterSizer->Add(new wxStaticText(this, wxID_STATIC, "Stop after"), 0, wxALL | wxCENTER, 5); m_stopAfter = new wxSpinCtrl(this, idSPINCTRL_STOPAFTER, "1", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10000); stopAfterSizer->Add(m_stopAfter, 0, wxALL | wxCENTER, 5); centerSizer->Add(stopAfterSizer, 0, wxALL | wxCENTER, 5); wxStaticBox *depthBox = new wxStaticBox(this, wxID_STATIC, "Algorithm behavior"); wxStaticBoxSizer *depthSizer = new wxStaticBoxSizer(depthBox, wxHORIZONTAL); m_limitDepth = new wxCheckBox(this, idCHECKBOX_LIMITDEPTH, "Limit depth"); m_limitDepth->SetValue(false); m_limitDepth->Enable(false); depthSizer->Add(m_limitDepth, 0, wxALL | wxCENTER, 5); depthSizer->Add(new wxStaticText(this, wxID_STATIC, "Maximum depth"), 0, wxALL | wxCENTER, 5); m_maxDepth = new wxSpinCtrl(this, -1, "10", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 1000); m_maxDepth->Enable(false); depthSizer->Add(m_maxDepth, 0, wxALL | wxCENTER, 5); centerSizer->Add(depthSizer, 0, wxALL | wxCENTER, 5); topSizer->Add(centerSizer, 1, wxALL | wxCENTER, 0); SetSizer(topSizer); topSizer->Fit(this); topSizer->SetSizeHints(this); Layout(); Show(false);}void panelNfgLcp::OnFindAll(wxCommandEvent &){ m_stopAfter->Enable(!m_findAll->GetValue()); m_limitDepth->Enable(m_findAll->GetValue() || m_stopAfter->GetValue() > 1); m_maxDepth->Enable((m_findAll->GetValue() || m_stopAfter->GetValue() > 1) && m_limitDepth->GetValue());}void panelNfgLcp::OnStopAfter(wxSpinEvent &){ m_limitDepth->Enable(m_stopAfter->GetValue() > 1); m_maxDepth->Enable(m_stopAfter->GetValue() > 1 && m_limitDepth->GetValue());}void panelNfgLcp::OnLimitDepth(wxCommandEvent &){ m_maxDepth->Enable(m_limitDepth->GetValue());}nfgNashAlgorithm *panelNfgLcp::GetAlgorithm(void) const{ if (m_precision->GetSelection() == 0) { nfgLcp<double> *algorithm = new nfgLcp<double>; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); algorithm->SetMaxDepth((m_limitDepth->GetValue()) ? m_maxDepth->GetValue() : 0); return algorithm; } else { nfgLcp<gRational> *algorithm = new nfgLcp<gRational>; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); algorithm->SetMaxDepth((m_limitDepth->GetValue()) ? m_maxDepth->GetValue() : 0); return algorithm; }}//========================================================================// class panelNfgLp//========================================================================class panelNfgLp : public panelNfgNashAlgorithm {private: wxRadioBox *m_precision; wxCheckBox *m_findAll; wxSpinCtrl *m_stopAfter; // Private event handlers void OnFindAll(wxCommandEvent &);public: panelNfgLp(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelNfgLp, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_FINDALL, panelNfgLp::OnFindAll)END_EVENT_TABLE()panelNfgLp::panelNfgLp(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "LpSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find Nash equilibria via linear " "program"), 0, wxALL | wxCENTER, 5); wxString precisionChoices[] = { "Floating point", "Rational" }; m_precision = new wxRadioBox(this, -1, "Precision", wxDefaultPosition, wxDefaultSize, 2, precisionChoices, 1, wxRA_SPECIFY_ROWS); centerSizer->Add(m_precision, 0, wxALL | wxCENTER, 5); // The "find all" feature of LpSolve currently does not work; // therefore, the controls are disabled in this version wxStaticBox *stopAfterBox = new wxStaticBox(this, wxID_STATIC, "Number to find"); wxStaticBoxSizer *stopAfterSizer = new wxStaticBoxSizer(stopAfterBox, wxHORIZONTAL); m_findAll = new wxCheckBox(this, idCHECKBOX_FINDALL, "Find all"); m_findAll->SetValue(false); m_findAll->Enable(false); stopAfterSizer->Add(m_findAll, 0, wxALL | wxCENTER, 5); stopAfterSizer->Add(new wxStaticText(this, wxID_STATIC, "Stop after"), 0, wxALL | wxCENTER, 5); m_stopAfter = new wxSpinCtrl(this, -1, "1", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10000); m_stopAfter->Enable(false); stopAfterSizer->Add(m_stopAfter, 0, wxALL | wxCENTER, 5); centerSizer->Add(stopAfterSizer, 0, wxALL | wxCENTER, 5); topSizer->Add(centerSizer, 1, wxALL | wxCENTER, 0); SetSizer(topSizer); topSizer->Fit(this); topSizer->SetSizeHints(this); Layout(); Show(false);}void panelNfgLp::OnFindAll(wxCommandEvent &){ m_stopAfter->Enable(!m_findAll->GetValue());}nfgNashAlgorithm *panelNfgLp::GetAlgorithm(void) const{ if (m_precision->GetSelection() == 0) { nfgLp<double> *algorithm = new nfgLp<double>; return algorithm; } else { nfgLp<gRational> *algorithm = new nfgLp<gRational>; return algorithm; }}//========================================================================// class panelNfgLiap//========================================================================class panelNfgLiap : public panelNfgNashAlgorithm {private: wxCheckBox *m_findAll; wxSpinCtrl *m_stopAfter, *m_numTries; wxSpinCtrl *m_maxits; // Private event handlers void OnFindAll(wxCommandEvent &);public: panelNfgLiap(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -