SGSolve
sggamehandler.hpp
1 // This file is part of the SGSolve library for stochastic games
2 // Copyright (C) 2019 Benjamin A. Brooks
3 //
4 // SGSolve free software: you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // SGSolve is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see
16 // <http://www.gnu.org/licenses/>.
17 //
18 // Benjamin A. Brooks
19 // ben@benjaminbrooks.net
20 // Chicago, IL
21 
22 #ifndef SGGAMEHANDLER_H
23 #define SGGAMEHANDLER_H
24 
25 #include <QtWidgets>
26 #include <QAbstractTableModel>
27 #include <QTableView>
28 #include "sggame.hpp"
29 #include "sgpayofftablemodel.hpp"
30 #include "sgprobabilitytablemodel.hpp"
31 #include "sgtableview.hpp"
32 
34 
46 class SGGameHandler : public QObject
47 {
48  Q_OBJECT;
49 
50 private:
52 
56 
58  double errorTol;
59 
63  vector<SGProbabilityTableModel*> probabilityModels;
64 
66  QVBoxLayout * layout;
67 
69  QPushButton * solveButton;
71  QPushButton * solveButton_V2;
73  QPushButton * cancelButton;
74 
75  // Edits
77  QLineEdit * deltaEdit;
79  vector<QLineEdit *> numActionsEdits;
81  QLineEdit * numStatesEdit;
83  QLineEdit * errorTolEdit;
84 
85  // Combo box
87  QComboBox * currentStateCombo;
88 
89  // Tables
91  QTableView * payoffTableView;
93  vector<SGTableView *> probabilityTableViews;
95  QVBoxLayout * probabilityTableLayout;
96 
97  // Check box
99  QCheckBox * feasibleCheckBox;
100 
101 public:
103 
105  SGGameHandler();
107 
108  ~SGGameHandler();
109 
111 
113  void setGame(const SGGame & _game);
114 
116  const SGGame & getGame() const
117  { return game; }
118 
120  double getErrorTol() const
121  { return errorTol; }
122 
124  QVBoxLayout * getLayout() const
125  { return layout; }
126 
128  QPushButton * getSolveButton() const
129  { return solveButton; }
130 
132  QPushButton * getSolveButton_V2() const
133  { return solveButton_V2; }
134 
136  QPushButton * getCancelButton() const
137  { return cancelButton; }
138 
140 
142  void setState(int state);
143 
144 private:
146 
147  void initializeModels();
149  void pushBackProbabilityTable(int newS);
153  void changeNumberOfStates(int newS);
154 
155 private slots:
157  void currentStateChanged(int newS);
159  void stateAdded();
161  void action1Added();
163  void action2Added();
165  void actionAdded(int player);
166 
168  void stateRemoved();
170  void action1Removed();
172  void action2Removed();
174 
176  void actionRemoved(int player);
178  void discountFactorChanged(const QString & text);
179 
181  void errorTolChanged(const QString & text);
182 
184  void nextState();
186  void prevState();
187 
188 public slots:
190  void setConstrained(int newState);
191 
192 };
193 
194 
195 #endif
SGGameHandler::actionRemoved
void actionRemoved(int player)
Removes action for the given player.
Definition: sggamehandler.cpp:506
SGGameHandler::action1Added
void action1Added()
Action added for player 1. Calls actionAdded.
Definition: sggamehandler.cpp:442
SGGameHandler::pushBackProbabilityTable
void pushBackProbabilityTable(int newS)
Adds a new probability table model.
Definition: sggamehandler.cpp:348
SGGameHandler::numActionsEdits
vector< QLineEdit * > numActionsEdits
Vector of edits for players' numbers of actions.
Definition: sggamehandler.hpp:79
SGGameHandler::setGame
void setGame(const SGGame &_game)
Replaces the current game with _game.
Definition: sggamehandler.cpp:271
SGGameHandler::errorTolChanged
void errorTolChanged(const QString &text)
Changes the error tolerance.
Definition: sggamehandler.cpp:435
SGGameHandler::actionAdded
void actionAdded(int player)
Adds a new action for the indicated player.
Definition: sggamehandler.cpp:452
SGGameHandler::errorTolEdit
QLineEdit * errorTolEdit
Edit for controlling error tolerance.
Definition: sggamehandler.hpp:83
SGGameHandler::cancelButton
QPushButton * cancelButton
Button that cancels solve.
Definition: sggamehandler.hpp:73
SGGameHandler::numStatesEdit
QLineEdit * numStatesEdit
Edit for number of states.
Definition: sggamehandler.hpp:81
SGGameHandler::nextState
void nextState()
Advances currentState to the next state.
Definition: sggamehandler.cpp:412
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SGGameHandler::changeNumberOfStates
void changeNumberOfStates(int newS)
Adds/removes models to achieve correct number of states.
Definition: sggamehandler.cpp:291
SGGameHandler::prevState
void prevState()
Decreases currentState to the previous state.
Definition: sggamehandler.cpp:420
SGGameHandler::layout
QVBoxLayout * layout
Layout for the game tab.
Definition: sggamehandler.hpp:66
SGGameHandler::~SGGameHandler
~SGGameHandler()
Destructor.
Definition: sggamehandler.cpp:263
SGGameHandler::errorTol
double errorTol
Error tolerance for measuring convergence.
Definition: sggamehandler.hpp:58
SGGameHandler::setState
void setState(int state)
Changes the current state.
Definition: sggamehandler.cpp:378
SGGameHandler::popBackProbabilityTable
void popBackProbabilityTable()
Removes last probability table model.
Definition: sggamehandler.cpp:368
SGGameHandler::SGGameHandler
SGGameHandler()
Constructor.
Definition: sggamehandler.cpp:25
SGGameHandler::action2Removed
void action2Removed()
Action removed for player 2. Calls actionRemoved.
Definition: sggamehandler.cpp:501
SGGameHandler::action1Removed
void action1Removed()
Action removed for player 1. Calls actionRemoved.
Definition: sggamehandler.cpp:496
SGGameHandler::currentStateChanged
void currentStateChanged(int newS)
Slot for changing the state. Calls setState.
Definition: sggamehandler.cpp:407
SGGameHandler::action2Added
void action2Added()
Action added for player 2. Calls actionAdded.
Definition: sggamehandler.cpp:447
SGGameHandler::solveButton_V2
QPushButton * solveButton_V2
Button that triggers solve routine.
Definition: sggamehandler.hpp:71
SGGameHandler::probabilityTableLayout
QVBoxLayout * probabilityTableLayout
Layout for holding transition probability tables.
Definition: sggamehandler.hpp:95
SGGameHandler::getSolveButton
QPushButton * getSolveButton() const
Returns the solveButton.
Definition: sggamehandler.hpp:128
SGPayoffTableModel
Derived class for payoff table models.
Definition: sgpayofftablemodel.hpp:42
SGGameHandler::probabilityModels
vector< SGProbabilityTableModel * > probabilityModels
Vector of models for interfacing with transition probabilities.
Definition: sggamehandler.hpp:63
SGGameHandler::getGame
const SGGame & getGame() const
Returns constant reference to the current game.
Definition: sggamehandler.hpp:116
SGGameHandler::getCancelButton
QPushButton * getCancelButton() const
Returns the cancelButton.
Definition: sggamehandler.hpp:136
SGGameHandler::getSolveButton_V2
QPushButton * getSolveButton_V2() const
Returns the solveButton_V2.
Definition: sggamehandler.hpp:132
SGGameHandler::stateRemoved
void stateRemoved()
Removes the current state.
Definition: sggamehandler.cpp:535
SGGameHandler::setConstrained
void setConstrained(int newState)
Changes whether or not feasible set will be calculated.
Definition: sggamehandler.cpp:565
SGGameHandler::payoffTableView
QTableView * payoffTableView
Table for displaying stage payoffs.
Definition: sggamehandler.hpp:91
SGGameHandler::discountFactorChanged
void discountFactorChanged(const QString &text)
Changes the discount factor.
Definition: sggamehandler.cpp:428
SGGameHandler
This class handles the widgets for editing/displaying the game.
Definition: sggamehandler.hpp:47
SGGameHandler::getErrorTol
double getErrorTol() const
Returns the error tolerance.
Definition: sggamehandler.hpp:120
SGGameHandler::currentStateCombo
QComboBox * currentStateCombo
Drop down menu for selecting a state.
Definition: sggamehandler.hpp:87
SGGameHandler::getLayout
QVBoxLayout * getLayout() const
Returns the layout.
Definition: sggamehandler.hpp:124
SGGameHandler::probabilityTableViews
vector< SGTableView * > probabilityTableViews
Vector of tables for displaying transition probabilities.
Definition: sggamehandler.hpp:93
SGGameHandler::deltaEdit
QLineEdit * deltaEdit
For editing the discount factor.
Definition: sggamehandler.hpp:77
SGGameHandler::solveButton
QPushButton * solveButton
Button that triggers solve routine.
Definition: sggamehandler.hpp:69
SGGameHandler::stateAdded
void stateAdded()
Adds a new state. Calls changeNumberOfStates.
Definition: sggamehandler.cpp:485
SGGameHandler::game
SGGame game
The game object.
Definition: sggamehandler.hpp:48
SGGameHandler::feasibleCheckBox
QCheckBox * feasibleCheckBox
Check box for whether or not to calculate feasible set.
Definition: sggamehandler.hpp:99
SGGameHandler::payoffModel
SGPayoffTableModel * payoffModel
The model for interfacing with payoffs.
Definition: sggamehandler.hpp:61
SGGameHandler::initializeModels
void initializeModels()
Delete old data models and create new ones.
Definition: sggamehandler.cpp:313