📄 dlnfgnash.cc
字号:
BEGIN_EVENT_TABLE(panelNfgLiap, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_FINDALL, panelNfgLiap::OnFindAll)END_EVENT_TABLE()panelNfgLiap::panelNfgLiap(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "LiapSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find Nash equilibria using " "Lyapunov function minimization"), 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, "No limit"); 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); wxStaticBox *algorithmBox = new wxStaticBox(this, wxID_STATIC, "Algorithm behavior"); wxStaticBoxSizer *algorithmSizer = new wxStaticBoxSizer(algorithmBox, wxHORIZONTAL); wxFlexGridSizer *paramSizer = new wxFlexGridSizer(2); paramSizer->Add(new wxStaticText(this, wxID_STATIC, "Number of restarts"), 0, wxALL | wxCENTER, 5); m_numTries = new wxSpinCtrl(this, -1, "100", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10000); paramSizer->Add(m_numTries, 0, wxALL, 5); paramSizer->Add(new wxStaticText(this, wxID_STATIC, "Maximum iterations in minimization"), 0, wxALL | wxCENTER, 5); m_maxits = new wxSpinCtrl(this, -1, "500", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 10, 1000); paramSizer->Add(m_maxits, 0, wxALL | wxCENTER, 5); algorithmSizer->Add(paramSizer, 0, wxALL, 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 panelNfgLiap::OnFindAll(wxCommandEvent &){ m_stopAfter->Enable(!m_findAll->GetValue());}nfgNashAlgorithm *panelNfgLiap::GetAlgorithm(void) const{ nfgLiap *algorithm = new nfgLiap; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); algorithm->SetNumTries(m_numTries->GetValue()); algorithm->SetMaxitsN(m_maxits->GetValue()); return algorithm;}//========================================================================// class panelNfgPolEnum//========================================================================class panelNfgPolEnum : public panelNfgNashAlgorithm {private: wxCheckBox *m_findAll; wxSpinCtrl *m_stopAfter; // Private event handlers void OnFindAll(wxCommandEvent &);public: panelNfgPolEnum(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelNfgPolEnum, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_FINDALL, panelNfgPolEnum::OnFindAll)END_EVENT_TABLE()panelNfgPolEnum::panelNfgPolEnum(wxWindow *p_parent) : panelNfgNashAlgorithm(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); 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 panelNfgPolEnum::OnFindAll(wxCommandEvent &){ m_stopAfter->Enable(!m_findAll->GetValue());}nfgNashAlgorithm *panelNfgPolEnum::GetAlgorithm(void) const{ nfgPolEnum *algorithm = new nfgPolEnum; algorithm->SetStopAfter((m_findAll->GetValue()) ? 0 : m_stopAfter->GetValue()); return algorithm;}//========================================================================// class panelNfgQre//========================================================================class panelNfgQre : public panelNfgNashAlgorithm {public: panelNfgQre(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgQre::panelNfgQre(wxWindow *p_parent) : panelNfgNashAlgorithm(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, 0); SetSizer(topSizer); topSizer->Fit(this); topSizer->SetSizeHints(this); Layout(); Show(false);}nfgNashAlgorithm *panelNfgQre::GetAlgorithm(void) const{ nfgQre *algorithm = new nfgQre; algorithm->SetFullGraph(false); algorithm->SetMaxLambda(1000000000); return algorithm;}//========================================================================// class panelNfgSimpdiv//========================================================================const int idCHECKBOX_USELEASH = 2002;class panelNfgSimpdiv : public panelNfgNashAlgorithm {private: wxRadioBox *m_precision; wxCheckBox *m_useLeash; wxSpinCtrl *m_leashLength, *m_numRestarts; // Private event handlers void OnFindAll(wxCommandEvent &); void OnUseLeash(wxCommandEvent &);public: panelNfgSimpdiv(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const; DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(panelNfgSimpdiv, panelNfgNashAlgorithm) EVT_CHECKBOX(idCHECKBOX_USELEASH, panelNfgSimpdiv::OnUseLeash)END_EVENT_TABLE()panelNfgSimpdiv::panelNfgSimpdiv(wxWindow *p_parent) : panelNfgNashAlgorithm(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 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 panelNfgSimpdiv::OnUseLeash(wxCommandEvent &){ m_leashLength->Enable(m_useLeash->GetValue());}nfgNashAlgorithm *panelNfgSimpdiv::GetAlgorithm(void) const{ if (m_precision->GetSelection() == 0) { nfgSimpdiv<double> *algorithm = new nfgSimpdiv<double>; algorithm->SetLeashLength((m_useLeash->GetValue()) ? m_leashLength->GetValue() : 0); algorithm->SetNumRestarts(m_numRestarts->GetValue()); return algorithm; } else { nfgSimpdiv<gRational> *algorithm = new nfgSimpdiv<gRational>; algorithm->SetLeashLength((m_useLeash->GetValue()) ? m_leashLength->GetValue() : 0); algorithm->SetNumRestarts(m_numRestarts->GetValue()); return algorithm; }}//========================================================================// class dialogNfgNash//========================================================================const int idTREECTRL_ALGORITHMS = 2000;BEGIN_EVENT_TABLE(dialogNfgNash, wxDialog) EVT_TREE_SEL_CHANGING(idTREECTRL_ALGORITHMS, dialogNfgNash::OnSelectionChanging) EVT_TREE_ITEM_COLLAPSING(idTREECTRL_ALGORITHMS, dialogNfgNash::OnItemCollapsing)END_EVENT_TABLE()dialogNfgNash::dialogNfgNash(wxWindow *p_parent, const NFSupport &p_support) : wxDialog(p_parent, -1, "Compute Nash equilibria"), 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.Game()); m_algPanelSizer->Add(m_algorithmTree, 1, 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 dialogNfgNash::LoadAlgorithms(const Nfg &p_nfg){ 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 panelNfgNashAlgorithm *panel; id = m_algorithmTree->AppendItem(standard, "One Nash equilibrium"); m_algorithms.Define(id, panel = new panelNfgOneNash(this)); wxTreeItemId init = id; id = m_algorithmTree->AppendItem(standard, "Two Nash equilibria"); m_algorithms.Define(id, panel = new panelNfgTwoNash(this)); id = m_algorithmTree->AppendItem(standard, "All Nash equilibria"); m_algorithms.Define(id, panel = new panelNfgAllNash(this)); if (p_nfg.NumPlayers() == 2) { id = m_algorithmTree->AppendItem(standard, "One perfect equilibrium"); m_algorithms.Define(id, panel = new panelNfgOnePerfect(this)); id = m_algorithmTree->AppendItem(standard, "Two perfect equilibria"); m_algorithms.Define(id, panel = new panelNfgTwoPerfect(this)); id = m_algorithmTree->AppendItem(standard, "All perfect equilibria"); m_algorithms.Define(id, panel = new panelNfgAllPerfect(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 panelNfgEnumPure(this)); if (p_nfg.NumPlayers() == 2) { id = m_algorithmTree->AppendItem(custom, "EnumMixedSolve"); m_algorithms.Define(id, panel = new panelNfgEnumMixed(this)); id = m_algorithmTree->AppendItem(custom, "LcpSolve"); m_algorithms.Define(id, panel = new panelNfgLcp(this)); if (IsConstSum(p_nfg)) { id = m_algorithmTree->AppendItem(custom, "LpSolve"); m_algorithms.Define(id, panel = new panelNfgLp(this)); } } id = m_algorithmTree->AppendItem(custom, "LiapSolve"); m_algorithms.Define(id, panel = new panelNfgLiap(this)); id = m_algorithmTree->AppendItem(custom, "PolEnumSolve"); m_algorithms.Define(id, panel = new panelNfgPolEnum(this)); id = m_algorithmTree->AppendItem(custom, "QreSolve"); m_algorithms.Define(id, panel = new panelNfgQre(this)); id = m_algorithmTree->AppendItem(custom, "SimpdivSolve"); m_algorithms.Define(id, panel = new panelNfgSimpdiv(this)); m_algorithmTree->Expand(standard); m_algorithmTree->Expand(custom); m_algorithmTree->Expand(root); return init;}void dialogNfgNash::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 dialogNfgNash::OnItemCollapsing(wxTreeEvent &p_event){ p_event.Veto();}nfgNashAlgorithm *dialogNfgNash::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, panelNfgNashAlgorithm *>;template class gOrdMap<wxTreeItemId, panelNfgNashAlgorithm *>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -