SGSolve
sgsolutionhandler.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 SGSOLUTIONHANDLER_V2_HPP
23 #define SGSOLUTIONHANDLER_V2_HPP
24 
25 #include "sgplotsettings.hpp"
26 #include "sgsolution_maxminmax.hpp"
27 #include "sgcustomplot.hpp"
28 #include "sgsimulationhandler.hpp"
29 #include "sgplotcontroller.hpp"
30 #include "sgstatecombomodel.hpp"
31 #include "sgactioncombomodel.hpp"
32 
34 
69 class SGSolutionHandler : public QObject
70 {
71  Q_OBJECT
72 
73 private:
75 
80 
82  QWidget * parent;
83 
85  double payoffBound;
86 
88  bool solnLoaded;
89 
90  // Plots
94 
96  vector<SGCustomPlot *> statePlots;
97 
100 
102  QVBoxLayout * layout;
103 
105  QGridLayout * statePlotsLayout;
106 
109 
112 
115 
118 
121 
122  // Methods
124  void plotSolution();
126  void plotSolution(SGCustomPlot * plot, int state,
127  bool addSquares);
129  void configureGridLines(SGCustomPlot * plot);
131  QString generatePlotTitle(int state, int action,bool addIterRev);
133  QCPRange getBounds(const QVector<double> & x) const;
135  void addPoint(const SGPoint & point,QCustomPlot* plot,
136  const QCPScatterStyle & style);
138  QCPCurve * vectorToQCPCurve(SGCustomPlot * plot,
139  const SGPoint & point,
140  const SGPoint & dir);
142  QCPItemLine * sgToQCPItemLine(SGCustomPlot * plot,
143  const SGPoint & point,
144  const SGPoint & dir);
145 public:
147 
149  SGSolutionHandler(QWidget * parent = 0);
150 
152  void setSolution(const SGSolution_MaxMinMax & newSoln);
155  {return soln;}
156 
158  QVBoxLayout * getLayout() const
159  { return layout; }
160 
162  QAction * getDetailedTitlesAction() const
163  { return detailedTitlesAction; }
164 
165  SGPlotSettings * getPlotSettingsPtr()
166  { return & plotSettings; }
167 
169  QAction * getEqualizeAxesAction() const
170  { return equalizeAxesAction; }
171 
176 
178  void prevAction() { emit prevActionSignal(); }
180  void nextAction() { emit nextActionSignal(); }
181 
182 signals:
183  void nextActionSignal();
184  void prevActionSignal();
185 
186 public slots:
188  void inspectPoint(SGPoint point,
189  int state, bool isDetailPlot);
190 
192  void simulateEquilibrium(SGPoint point,
193  int state, bool isDetailPlot);
195  void replotSlot() { plotSolution(); }
196 
197 };
198 
199 #endif
SGSolutionHandler::sgToQCPItemLine
QCPItemLine * sgToQCPItemLine(SGCustomPlot *plot, const SGPoint &point, const SGPoint &dir)
Converts point,dir into a QCPItemLine associated with the given plot.
Definition: sgsolutionhandler.cpp:648
SGSolutionHandler::getLayout
QVBoxLayout * getLayout() const
Returns the layout.
Definition: sgsolutionhandler.hpp:158
SGSolutionHandler::parent
QWidget * parent
The parent widget, which is an SGMainWindow object.
Definition: sgsolutionhandler.hpp:82
SGSolutionHandler
Handles the widgets for displaying the solution.
Definition: sgsolutionhandler.hpp:70
SGSolutionHandler::nextAction
void nextAction()
Increments the action profile through the SGPlotController.
Definition: sgsolutionhandler.hpp:180
SGPlotController
Handles the plot settings for SGSolutionHandler.
Definition: sgplotcontroller.hpp:41
SGSolutionHandler::layout
QVBoxLayout * layout
Master layout for the solution handler.
Definition: sgsolutionhandler.hpp:102
SGSolutionHandler::getBounds
QCPRange getBounds(const QVector< double > &x) const
Gets bounds for the plots.
Definition: sgsolutionhandler.cpp:659
SGSolutionHandler::inspectPoint
void inspectPoint(SGPoint point, int state, bool isDetailPlot)
Inspect point slot.
Definition: sgsolutionhandler.cpp:677
SGPlotController::moveBackwards
void moveBackwards()
Decrements the current iteration.
Definition: sgplotcontroller.hpp:159
SGPlotController::moveForwards
void moveForwards()
Increments the current iteration.
Definition: sgplotcontroller.hpp:149
SGSolutionHandler::moveForwards
void moveForwards()
Increments the iteration through the SGPlotController.
Definition: sgsolutionhandler.hpp:175
SGSolutionHandler::defaultZeroLinePen
QPen defaultZeroLinePen
Default pen for zero lines.
Definition: sgsolutionhandler.hpp:120
SGSolutionHandler::statePlots
vector< SGCustomPlot * > statePlots
Vector of state plots.
Definition: sgsolutionhandler.hpp:96
SGSolutionHandler::defaultGridLinePen
QPen defaultGridLinePen
Default pen for grid lines.
Definition: sgsolutionhandler.hpp:117
SGSolutionHandler::configureGridLines
void configureGridLines(SGCustomPlot *plot)
Turns on or off grid lines and zero lines.
Definition: sgsolutionhandler.cpp:451
SGSolutionHandler::vectorToQCPCurve
QCPCurve * vectorToQCPCurve(SGCustomPlot *plot, const SGPoint &point, const SGPoint &dir)
Converts point,dir into a QCPCurve associated with the given plot.
Definition: sgsolutionhandler.cpp:628
SGSolutionHandler::addPoint
void addPoint(const SGPoint &point, QCustomPlot *plot, const QCPScatterStyle &style)
Adds a point to the indicated graph in the indicated scatter style.
Definition: sgsolutionhandler.cpp:616
SGSolutionHandler::statePlotsLayout
QGridLayout * statePlotsLayout
Layout holding the state plots.
Definition: sgsolutionhandler.hpp:105
SGSolutionHandler::getSolution
const SGSolution_MaxMinMax & getSolution() const
Returns a const reference to the solution.
Definition: sgsolutionhandler.hpp:154
SGSolutionHandler::equalizeAxesAction
QAction * equalizeAxesAction
Action for equalizing axes.
Definition: sgsolutionhandler.hpp:111
SGSolutionHandler::getEqualizeAxesAction
QAction * getEqualizeAxesAction() const
Returns the equalize axes action.
Definition: sgsolutionhandler.hpp:169
SGSolutionHandler::plotSolution
void plotSolution()
Plots the solution from start to end.
Definition: sgsolutionhandler.cpp:209
SGPlotSettings
Definition: sgplotsettings.hpp:28
SGCustomPlot
A customized version of QCustomPlot.
Definition: sgcustomplot.hpp:41
SGSolution_MaxMinMax
Records the progress of SGSolver_MaxMinMax::solve().
Definition: sgsolution_maxminmax.hpp:40
SGSolutionHandler::detailPlot
SGCustomPlot * detailPlot
Left hand plot that shows construction of a point.
Definition: sgsolutionhandler.hpp:92
SGSolutionHandler::controller
SGPlotController * controller
A pointer to the associated plot controller.
Definition: sgsolutionhandler.hpp:79
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGSolutionHandler::detailedTitlesAction
QAction * detailedTitlesAction
Action to toggle detailed titles.
Definition: sgsolutionhandler.hpp:108
SGSolutionHandler::setSolution
void setSolution(const SGSolution_MaxMinMax &newSoln)
Sets the solution to newSoln.
Definition: sgsolutionhandler.cpp:168
SGSimulationHandler
Widget for forward simulating an equilibrium.
Definition: sgsimulationhandler.hpp:54
SGSolutionHandler::solnLoaded
bool solnLoaded
True if a solution has been loaded.
Definition: sgsolutionhandler.hpp:88
SGSolutionHandler::replotSlot
void replotSlot()
Replot slot.
Definition: sgsolutionhandler.hpp:195
SGSolutionHandler::generatePlotTitle
QString generatePlotTitle(int state, int action, bool addIterRev)
Generates title for the detail plot.
Definition: sgsolutionhandler.cpp:553
SGSolutionHandler::soln
SGSolution_MaxMinMax soln
Solution.
Definition: sgsolutionhandler.hpp:77
SGSolutionHandler::prevAction
void prevAction()
Decrements the action profile through the SGPlotController.
Definition: sgsolutionhandler.hpp:178
SGSolutionHandler::moveBackwards
void moveBackwards()
Decrements the iteration through the SGPlotController.
Definition: sgsolutionhandler.hpp:173
SGSolutionHandler::payoffBound
double payoffBound
A bound on the size of payoffs.
Definition: sgsolutionhandler.hpp:85
SGSolutionHandler::plotSettings
SGPlotSettings plotSettings
Plot settings.
Definition: sgsolutionhandler.hpp:99
SGSolutionHandler::simulateEquilibrium
void simulateEquilibrium(SGPoint point, int state, bool isDetailPlot)
Simulate equilibrium slot.
Definition: sgsolutionhandler.cpp:686
SGSolutionHandler::SGSolutionHandler
SGSolutionHandler(QWidget *parent=0)
Constructor.
Definition: sgsolutionhandler.cpp:24
SGSolutionHandler::getDetailedTitlesAction
QAction * getDetailedTitlesAction() const
Returns the detailed titles action.
Definition: sgsolutionhandler.hpp:162
SGSolutionHandler::simHandler
SGSimulationHandler * simHandler
Pointer to simulation handler.
Definition: sgsolutionhandler.hpp:114