📄 dlnfgnash.cc
字号:
//// $Source: /home/gambit/CVS/gambit/sources/gui/dlnfgnash.cc,v $// $Date: 2002/09/14 23:24:39 $// $Revision: 1.14.2.4 $//// DESCRIPTION:// Dialog for selecting algorithms to compute Nash equilibria//// This file is part of Gambit// Copyright (c) 2002, The Gambit Project//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//#include "wx/wxprec.h"#ifndef WX_PRECOMP#include "wx/wx.h"#endif // WX_PRECOMP#include "wx/spinctrl.h"#include "dlnfgnash.h"#include "base/gnullstatus.h"#include "nash/nfgpure.h"#include "nash/enum.h"#include "nash/lemke.h"#include "nash/nfgcsum.h"#include "nash/nliap.h"#include "nash/nfgalleq.h"#include "nash/nfgqre.h"#include "nash/simpdiv.h"const int idCHECKBOX_FINDALL = 2000;const int idSPINCTRL_STOPAFTER = 2001;class panelNfgNashAlgorithm : public wxPanel {public: panelNfgNashAlgorithm(wxWindow *p_parent) : wxPanel(p_parent, -1) { } virtual nfgNashAlgorithm *GetAlgorithm(void) const = 0;};//========================================================================// class nfgOneNash//========================================================================class nfgOneNash : public nfgNashAlgorithm {public: gText GetAlgorithm(void) const { return "OneNash"; } gList<MixedSolution> Solve(const NFSupport &, gStatus &);};gList<MixedSolution> nfgOneNash::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); if (p_support.Game().NumPlayers() == 2) { if (IsConstSum(p_support.Game())) { nfgLp<double> algorithm; return algorithm.Solve(support, p_status); } else { nfgLcp<double> algorithm; algorithm.SetStopAfter(1); return algorithm.Solve(support, p_status); } } else { nfgSimpdiv<double> algorithm; return algorithm.Solve(support, p_status); } } catch (...) { return gList<MixedSolution>(); }}//========================================================================// class panelNfgOneNash//========================================================================class panelNfgOneNash : public panelNfgNashAlgorithm {public: panelNfgOneNash(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgOneNash::panelNfgOneNash(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "OneNashSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find one Nash equilibrium"), 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 *panelNfgOneNash::GetAlgorithm(void) const{ return new nfgOneNash;}//========================================================================// class nfgTwoNash//========================================================================class nfgTwoNash : public nfgNashAlgorithm {public: gText GetAlgorithm(void) const { return "TwoNash"; } gList<MixedSolution> Solve(const NFSupport &, gStatus &);};gList<MixedSolution> nfgTwoNash::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 { NFSupport support(p_support); while (true) { gNullStatus status; gNullOutput gnull; NFSupport newSupport = support.Undominated(true, players, gnull, status); if (newSupport == support) { break; } else { support = newSupport; } } if (p_support.Game().NumPlayers() == 2) { nfgEnumMixed<double> algorithm; algorithm.SetStopAfter(2); return algorithm.Solve(support, p_status); } else { nfgPolEnum algorithm; algorithm.SetStopAfter(2); return algorithm.Solve(support, p_status); } } catch (...) { return gList<MixedSolution>(); }}//========================================================================// class panelNfgTwoNash//========================================================================class panelNfgTwoNash : public panelNfgNashAlgorithm {public: panelNfgTwoNash(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgTwoNash::panelNfgTwoNash(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "TwoNashSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find two 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 *panelNfgTwoNash::GetAlgorithm(void) const{ return new nfgTwoNash;}//========================================================================// class nfgAllNash//========================================================================class nfgAllNash : public nfgNashAlgorithm {public: gText GetAlgorithm(void) const { return "AllNash"; } gList<MixedSolution> Solve(const NFSupport &, gStatus &);};gList<MixedSolution> nfgAllNash::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 { NFSupport support(p_support); while (true) { gNullStatus status; gNullOutput gnull; NFSupport newSupport = support.Undominated(true, players, gnull, status); if (newSupport == support) { break; } else { support = newSupport; } } if (p_support.Game().NumPlayers() == 2) { nfgEnumMixed<double> algorithm; algorithm.SetStopAfter(0); return algorithm.Solve(support, p_status); } else { nfgPolEnum algorithm; algorithm.SetStopAfter(0); return algorithm.Solve(support, p_status); } } catch (...) { return gList<MixedSolution>(); }}//========================================================================// class panelNfgAllNash//========================================================================class panelNfgAllNash : public panelNfgNashAlgorithm {public: panelNfgAllNash(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgAllNash::panelNfgAllNash(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "AllNashSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find all 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 *panelNfgAllNash::GetAlgorithm(void) const{ return new nfgAllNash;}//========================================================================// class nfgOnePerfect//========================================================================class nfgOnePerfect : public nfgNashAlgorithm {public: gText GetAlgorithm(void) const { return "OnePerfect"; } gList<MixedSolution> Solve(const NFSupport &, gStatus &);};gList<MixedSolution> nfgOnePerfect::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); nfgLcp<double> algorithm; algorithm.SetStopAfter(1); return algorithm.Solve(support, p_status); } catch (...) { return gList<MixedSolution>(); }}//========================================================================// class panelNfgOnePerfect//========================================================================class panelNfgOnePerfect : public panelNfgNashAlgorithm {public: panelNfgOnePerfect(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgOnePerfect::panelNfgOnePerfect(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "OnePerfectSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find one perfect Nash equilibrium"), 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 *panelNfgOnePerfect::GetAlgorithm(void) const{ return new nfgOnePerfect;}//========================================================================// class nfgTwoPerfect//========================================================================class nfgTwoPerfect : public nfgNashAlgorithm {public: gText GetAlgorithm(void) const { return "TwoPerfect"; } gList<MixedSolution> Solve(const NFSupport &, gStatus &);};gList<MixedSolution> nfgTwoPerfect::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(2); return algorithm.Solve(support, p_status); } catch (...) { return gList<MixedSolution>(); }}//========================================================================// class panelNfgTwoPerfect//========================================================================class panelNfgTwoPerfect : public panelNfgNashAlgorithm {public: panelNfgTwoPerfect(wxWindow *); nfgNashAlgorithm *GetAlgorithm(void) const;};panelNfgTwoPerfect::panelNfgTwoPerfect(wxWindow *p_parent) : panelNfgNashAlgorithm(p_parent){ SetAutoLayout(true); wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL); wxStaticBox *centerBox = new wxStaticBox(this, wxID_STATIC, "TwoPerfectSolve"); wxStaticBoxSizer *centerSizer = new wxStaticBoxSizer(centerBox, wxVERTICAL); centerSizer->Add(new wxStaticText(this, wxID_STATIC, "Find two 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 *panelNfgTwoPerfect::GetAlgorithm(void) const{ return new nfgTwoPerfect;}//========================================================================// class nfgAllPerfect//========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -