⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlefgnash.cc

📁 Gambit 是一个游戏库理论软件
💻 CC
📖 第 1 页 / 共 4 页
字号:
}void panelEfgLiap::OnFindAll(wxCommandEvent &){  m_stopAfter->Enable(!m_findAll->GetValue());}efgNashAlgorithm *panelEfgLiap::GetAlgorithm(void) const{  SubgameSolver *algorithm = new SubgameSolver;  if (m_solveUsing->GetSelection() == 0) {    efgLiap *subAlgorithm = new efgLiap;    subAlgorithm->SetStopAfter((m_findAll->GetValue()) ?			       0 : m_stopAfter->GetValue());    subAlgorithm->SetNumTries(m_numTries->GetValue());    subAlgorithm->SetMaxitsN(m_maxits->GetValue());    algorithm->SetAlgorithm(subAlgorithm);  }  else {    nfgLiap *subAlgorithm = new nfgLiap;    subAlgorithm->SetStopAfter((m_findAll->GetValue()) ?			       0 : m_stopAfter->GetValue());    subAlgorithm->SetNumTries(m_numTries->GetValue());    subAlgorithm->SetMaxitsN(m_maxits->GetValue());    algorithm->SetAlgorithm(subAlgorithm);  }  return algorithm;}//========================================================================//                      class panelEfgPolEnum//========================================================================class panelEfgPolEnum : public panelEfgNashAlgorithm {private:  wxRadioBox *m_solveUsing;  wxCheckBox *m_findAll;  wxSpinCtrl *m_stopAfter;  // Private event handlers  void OnFindAll(wxCommandEvent &);public:  panelEfgPolEnum(wxWindow *);  efgNashAlgorithm *GetAlgorithm(void) const;  DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelEfgPolEnum, panelEfgNashAlgorithm)  EVT_CHECKBOX(idCHECKBOX_FINDALL, panelEfgPolEnum::OnFindAll)END_EVENT_TABLE()panelEfgPolEnum::panelEfgPolEnum(wxWindow *p_parent)  : panelEfgNashAlgorithm(p_parent){  SetAutoLayout(true);  wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);  wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "PolEnumSolve");  wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL);  centerSizer->Add(new wxStaticText(this, wxID_STATIC,				    "Find Nash equilibria via solving "				    "polynomial equations"),		   0, wxALL | wxCENTER, 5);  wxString solveChoices[] = { "Extensive form", "Normal form" };  m_solveUsing = new wxRadioBox(this, -1, "Find equilibria using",				wxDefaultPosition, wxDefaultSize,				2, solveChoices, 1, wxRA_SPECIFY_ROWS);  centerSizer->Add(m_solveUsing, 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, 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 panelEfgPolEnum::OnFindAll(wxCommandEvent &){  m_stopAfter->Enable(!m_findAll->GetValue());}efgNashAlgorithm *panelEfgPolEnum::GetAlgorithm(void) const{  SubgameSolver *algorithm = new SubgameSolver;  if (m_solveUsing->GetSelection() == 0) {    efgPolEnum *subAlgorithm = new efgPolEnum;    subAlgorithm->SetStopAfter((m_findAll->GetValue()) ?			       0 : m_stopAfter->GetValue());    algorithm->SetAlgorithm(subAlgorithm);  }  else {    nfgPolEnum *subAlgorithm = new nfgPolEnum;    subAlgorithm->SetStopAfter((m_findAll->GetValue()) ?			       0 : m_stopAfter->GetValue());    algorithm->SetAlgorithm(subAlgorithm);  }  return algorithm;}//========================================================================//                         class panelEfgQre//========================================================================class panelEfgQre : public panelEfgNashAlgorithm {public:  panelEfgQre(wxWindow *);  efgNashAlgorithm *GetAlgorithm(void) const;};panelEfgQre::panelEfgQre(wxWindow *p_parent)  : panelEfgNashAlgorithm(p_parent){  SetAutoLayout(true);  wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);    wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "QreSolve");  wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL);  centerSizer->Add(new wxStaticText(this, wxID_STATIC,				    "Find Nash equilibria via tracing "				    "logit 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);}efgNashAlgorithm *panelEfgQre::GetAlgorithm(void) const{  efgQre *algorithm = new efgQre;  algorithm->SetFullGraph(false);  algorithm->SetMaxLambda(1000000000);  return algorithm;}//========================================================================//                       class panelEfgSimpdiv//========================================================================const int idCHECKBOX_USELEASH = 2002;class panelEfgSimpdiv : public panelEfgNashAlgorithm {private:  wxRadioBox *m_solveUsing, *m_precision;  wxCheckBox *m_useLeash;  wxSpinCtrl *m_leashLength, *m_numRestarts;  // Private event handlers  void OnFindAll(wxCommandEvent &);  void OnUseLeash(wxCommandEvent &);public:  panelEfgSimpdiv(wxWindow *);  efgNashAlgorithm *GetAlgorithm(void) const;  DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelEfgSimpdiv, panelEfgNashAlgorithm)  EVT_CHECKBOX(idCHECKBOX_USELEASH, panelEfgSimpdiv::OnUseLeash)END_EVENT_TABLE()panelEfgSimpdiv::panelEfgSimpdiv(wxWindow *p_parent)  : panelEfgNashAlgorithm(p_parent){  SetAutoLayout(true);  wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);  wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "SimpdivSolve");  wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL);  centerSizer->Add(new wxStaticText(this, wxID_STATIC,				    "Find Nash equilibria via simplicial "				    "subdivision"),		   0, wxALL | wxCENTER, 5);  wxString solveChoices[] = { "Extensive form", "Normal form" };  m_solveUsing = new wxRadioBox(this, -1, "Find equilibria using",				wxDefaultPosition, wxDefaultSize,				2, solveChoices, 1, wxRA_SPECIFY_ROWS);  m_solveUsing->SetSelection(1);  m_solveUsing->Enable(false);  centerSizer->Add(m_solveUsing, 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 *algorithmBox = new wxStaticBox(this, wxID_STATIC,					      "Algorithm behavior");  wxStaticBoxSizer *algorithmSizer = new wxStaticBoxSizer(algorithmBox,							  wxVERTICAL);    wxBoxSizer *leashSizer = new wxBoxSizer(wxHORIZONTAL);  m_useLeash = new wxCheckBox(this, idCHECKBOX_USELEASH, "Use leash");  m_useLeash->SetValue(false);  leashSizer->Add(m_useLeash, 0, wxALL | wxCENTER, 5);  leashSizer->Add(new wxStaticText(this, wxID_STATIC, "Leash length"),		  0, wxALL | wxCENTER, 5);  m_leashLength = new wxSpinCtrl(this, -1, "100",				 wxDefaultPosition, wxDefaultSize,				 wxSP_ARROW_KEYS, 1, 10000);  m_leashLength->Enable(false);  leashSizer->Add(m_leashLength, 0, wxALL | wxCENTER, 5);  algorithmSizer->Add(leashSizer, 0, wxALL | wxCENTER, 5);  wxBoxSizer *restartSizer = new wxBoxSizer(wxHORIZONTAL);  restartSizer->Add(new wxStaticText(this, wxID_STATIC, "Number of restarts"),		    0, wxALL | wxCENTER, 5);  m_numRestarts = new wxSpinCtrl(this, -1, "20",				 wxDefaultPosition, wxDefaultSize,				 wxSP_ARROW_KEYS, 1, 10000);  restartSizer->Add(m_numRestarts, 0, wxALL | wxCENTER, 5);  algorithmSizer->Add(restartSizer, 0, wxALL | wxCENTER, 5);  centerSizer->Add(algorithmSizer, 0, wxALL | wxCENTER, 5);  topSizer->Add(centerSizer, 1, wxALL | wxCENTER, 0);  SetSizer(topSizer);  topSizer->Fit(this);  topSizer->SetSizeHints(this);  Layout();  Show(false);}void panelEfgSimpdiv::OnUseLeash(wxCommandEvent &){  m_leashLength->Enable(m_useLeash->GetValue());}efgNashAlgorithm *panelEfgSimpdiv::GetAlgorithm(void) const{  SubgameSolver *algorithm = new SubgameSolver;  if (m_precision->GetSelection() == 0) {    nfgSimpdiv<double> *subAlgorithm = new nfgSimpdiv<double>;    subAlgorithm->SetLeashLength((m_useLeash->GetValue()) ?				 m_leashLength->GetValue() : 0);    subAlgorithm->SetNumRestarts(m_numRestarts->GetValue());    algorithm->SetAlgorithm(subAlgorithm);  }  else {    nfgSimpdiv<gRational> *subAlgorithm = new nfgSimpdiv<gRational>;    subAlgorithm->SetLeashLength((m_useLeash->GetValue()) ?				 m_leashLength->GetValue() : 0);    subAlgorithm->SetNumRestarts(m_numRestarts->GetValue());    algorithm->SetAlgorithm(subAlgorithm);  }  return algorithm;}//========================================================================//                        class dialogEfgNash//========================================================================const int idTREECTRL_ALGORITHMS = 2000;BEGIN_EVENT_TABLE(dialogEfgNash, wxDialog)  EVT_TREE_SEL_CHANGING(idTREECTRL_ALGORITHMS,			dialogEfgNash::OnSelectionChanging)  EVT_TREE_ITEM_COLLAPSING(idTREECTRL_ALGORITHMS,			   dialogEfgNash::OnItemCollapsing)END_EVENT_TABLE()dialogEfgNash::dialogEfgNash(wxWindow *p_parent, const EFSupport &p_support)  : wxDialog(p_parent, -1, "Compute Nash equilibria"),    m_currentPanel(0), m_algorithms(0) {  SetAutoLayout(true);  wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);  m_algPanelSizer = new wxBoxSizer(wxHORIZONTAL);  m_algorithmTree = new wxTreeCtrl(this, idTREECTRL_ALGORITHMS,				   wxDefaultPosition, wxSize(200, 400),				   wxTR_NO_BUTTONS | wxTR_HIDE_ROOT |				   wxTR_NO_LINES | wxTR_ROW_LINES);  wxTreeItemId init = LoadAlgorithms(p_support.GetGame());  m_algPanelSizer->Add(m_algorithmTree, 0, wxALL, 5);  m_currentPanel = m_algorithms(init);  m_algPanelSizer->Add(m_currentPanel, 0, wxALL | wxCENTER, 5);  topSizer->Add(m_algPanelSizer, 1, wxALL | wxEXPAND, 5);  wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);  wxButton *okButton = new wxButton(this, wxID_OK, "OK");  okButton->SetDefault();  buttonSizer->Add(okButton, 0, wxALL, 5);  buttonSizer->Add(new wxButton(this, wxID_CANCEL, "Cancel"), 0, wxALL, 5);  //  buttonSizer->Add(new wxButton(this, wxID_HELP, "Help"), 0, wxALL, 5);  topSizer->Add(buttonSizer, 0, wxALL | wxCENTER, 5);  SetSizer(topSizer);  topSizer->Fit(this);  topSizer->SetSizeHints(this);  Layout();  CenterOnParent();  m_algorithmTree->SelectItem(init);}int dialogEfgNash::LoadAlgorithms(const efgGame &p_efg){  wxTreeItemId id;  // Eventually, these should be loaded from wxConfig; for now,  // I am going to hard-code them  wxTreeItemId root = m_algorithmTree->AddRoot("Algorithms");  wxTreeItemId standard = m_algorithmTree->AppendItem(root,						      "Standard algorithms");  m_algorithmTree->SetItemBold(standard);  // This is added to silence some BC warnings  panelEfgNashAlgorithm *panel;  id = m_algorithmTree->AppendItem(standard, "One Nash equilibrium");  m_algorithms.Define(id, panel = new panelEfgOneNash(this));  wxTreeItemId init = id;  id = m_algorithmTree->AppendItem(standard, "Two Nash equilibria");  m_algorithms.Define(id, panel = new panelEfgTwoNash(this));  id = m_algorithmTree->AppendItem(standard, "All Nash equilibria");  m_algorithms.Define(id, panel = new panelEfgAllNash(this));  id = m_algorithmTree->AppendItem(standard, "One perfect equilibrium");  m_algorithms.Define(id, panel = new panelEfgOnePerfect(this));  id = m_algorithmTree->AppendItem(standard, "Two perfect equilibria");  m_algorithms.Define(id, panel = new panelEfgTwoPerfect(this));  id = m_algorithmTree->AppendItem(standard, "All perfect equilibria");  m_algorithms.Define(id, panel = new panelEfgAllPerfect(this));  id = m_algorithmTree->AppendItem(standard, "One sequential equilibrium");  m_algorithms.Define(id, panel = new panelEfgOneSequential(this));  id = m_algorithmTree->AppendItem(standard, "Two sequential equilibria");  m_algorithms.Define(id, panel = new panelEfgTwoSequential(this));  id = m_algorithmTree->AppendItem(standard, "All sequential equilibria");  m_algorithms.Define(id, panel = new panelEfgAllSequential(this));  wxTreeItemId custom = m_algorithmTree->AppendItem(root, "Custom algorithms");  m_algorithmTree->SetItemBold(custom);  id = m_algorithmTree->AppendItem(custom, "EnumPureSolve");  m_algorithms.Define(id, panel = new panelEfgEnumPure(this));  if (p_efg.NumPlayers() == 2) {    id = m_algorithmTree->AppendItem(custom, "EnumMixedSolve");    m_algorithms.Define(id, panel = new panelEfgEnumMixed(this));    id = m_algorithmTree->AppendItem(custom, "LcpSolve");    m_algorithms.Define(id, panel = new panelEfgLcp(this));    if (p_efg.IsConstSum()) {      id = m_algorithmTree->AppendItem(custom, "LpSolve");      m_algorithms.Define(id, panel = new panelEfgLp(this));    }  }  id = m_algorithmTree->AppendItem(custom, "LiapSolve");  m_algorithms.Define(id, panel = new panelEfgLiap(this));  id = m_algorithmTree->AppendItem(custom, "PolEnumSolve");  m_algorithms.Define(id, panel = new panelEfgPolEnum(this));  id = m_algorithmTree->AppendItem(custom, "QreSolve");  m_algorithms.Define(id, panel = new panelEfgQre(this));  id = m_algorithmTree->AppendItem(custom, "SimpdivSolve");  m_algorithms.Define(id, panel = new panelEfgSimpdiv(this));  m_algorithmTree->Expand(standard);  m_algorithmTree->Expand(custom);  m_algorithmTree->Expand(root);  return init;}void dialogEfgNash::OnSelectionChanging(wxTreeEvent &p_event){  wxPanel *panel = m_algorithms(p_event.GetItem());  if (!panel) {    p_event.Veto();    return;  }  if (m_currentPanel) {    m_currentPanel->Show(false);  }  m_currentPanel = panel;  panel->Show(true);  m_algPanelSizer->Remove(1);  m_algPanelSizer->Add(panel, 0, wxALL | wxCENTER, 5);  m_algPanelSizer->Layout();  GetSizer()->Layout();  GetSizer()->Fit(this);  CenterOnParent();}void dialogEfgNash::OnItemCollapsing(wxTreeEvent &p_event){  p_event.Veto();}efgNashAlgorithm *dialogEfgNash::GetAlgorithm(void) const{  if (m_algorithms(m_algorithmTree->GetSelection())) {    return m_algorithms(m_algorithmTree->GetSelection())->GetAlgorithm();  }  else {    return 0;  }}static gOutput &operator<<(gOutput &p_stream, wxTreeItemId){ return p_stream; }#include "base/gmap.imp"template class gBaseMap<wxTreeItemId, panelEfgNashAlgorithm *>;template class gOrdMap<wxTreeItemId, panelEfgNashAlgorithm *>;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -