BCESolve
bcesolverworker.hpp
1// This file is part of the BCESolve library for games of incomplete
2// information
3// Copyright (C) 2022 Benjamin A. Brooks
4//
5// BCESolve free software: you can redistribute it and/or modify it
6// under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// BCESolve is distributed in the hope that it will be useful, but
11// WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see
17// <http://www.gnu.org/licenses/>.
18//
19// Benjamin A. Brooks
20// ben@benjaminbrooks.net
21// Chicago, IL
22
23#ifndef BCESOLVERWORKER_HPP
24#define BCESOLVERWORKER_HPP
25
26#include "bceabstractgame.hpp"
27#include "bcegame.hpp"
28#include "bce.hpp"
29#include <QObject>
30#include "bcegurobicallback.hpp"
31#include <QMessageBox>
32
34
45class BCESolverWorker : public QObject {
46 Q_OBJECT;
47
48private:
49
55 vector<double> weightData;
57 vector<vector<double> > mapBoundaryData;
64
65public:
66
69 vector<double> _weightData,
70 vector<vector<double> > _mapBoundaryData,
71 BCEGurobiCallback * _callback,
72 bool _mapBoundaryOption,
73 double _minAngleIncrement):
74 game(_game), weightData(_weightData),
75 mapBoundaryData(_mapBoundaryData), callback(_callback),
76 mapBoundaryOption(_mapBoundaryOption),minAngleIncrement(_minAngleIncrement)
77 {}
78
80 const BCESolution& getSolution() const {
81 return solution;
82 }
83
84public slots:
85
87
94 void startSolve() {
95 try {
96
97 BCESolver solver(game);
98
99 // Populate constraints
100 solver.populate();
101
102 // Set callback object
103 solver.model.setCallback(callback);
104 callback->setFullOutput(true);
105
106 // Solve the model
107 solver.solve(weightData);
108
109 // If map boundary is checked in the game tab, map the boundary
110 if (mapBoundaryOption) {
111 callback->setFullOutput(false);
114 callback->setFullOutput(true);
115 }
116
117 // A realization of 11 signals that the solve routine was interrupted
118 if (solver.model.get(GRB_IntAttr_Status)!=11) {
119 solver.getSolution(solution);
121 }
122 }
123 catch(BCEException &e) {
124 emit(exceptionSignal(QString::fromStdString(e.getMessage())));
125 }
126 catch(std::exception &e) {
127 string str(e.what());
128 emit(exceptionSignal(QString::fromStdString(str)));
129 }
130 catch(GRBException &e) {
131 emit(exceptionSignal(QString::fromStdString(e.getMessage() +
132 "The error code for this GRBException was: " +
133 to_string(e.getErrorCode()))));
134 }
135
136 // Send a signal to end the solver thread.
137 emit(workFinished());
138
139 }
140
141signals:
142
146 void sendSolution(BCESolution *soln,bool isBoundaryMapped);
148 void exceptionSignal(QString message);
149
150};
151
152#endif
153
Exception class for BCESolve.
Definition: bceexception.hpp:33
string getMessage()
Returns an error message.
Definition: bceexception.hpp:79
const char * what() const
Reimplements std::exception::what().
Definition: bceexception.hpp:72
The base class for games of incomplete information.
Definition: bcegame.hpp:40
Callback object to communicate with the gurobi solver.
Definition: bcegurobicallback.hpp:30
void setFullOutput(bool toggle)
Controls how much information is printed to the log tab.
Definition: bcegurobicallback.hpp:47
Class for storing data produced by BCESolver.
Definition: bcesolution.hpp:64
Solves a BCEAbstractGame using gurobi.
Definition: bcesolver.hpp:47
GRBModel model
The GUROBI model.
Definition: bcesolver.hpp:206
void populate()
Main populate routine.
Definition: bcesolver.cpp:163
void mapBoundary(const char *fname)
Maps the frontier.
Definition: bcesolver.cpp:526
void solve(vector< double > &objectiveWeights)
Solve method.
Definition: bcesolver.cpp:474
void getSolution(BCESolution &output)
Returns the data object.
Definition: bcesolver.cpp:700
void setMinAngleIncr(double incr)
Used to set the minimum angle increment. Called by bcesolverworker.hpp.
Definition: bcesolver.hpp:91
Class for solving games created in the game tab.
Definition: bcesolverworker.hpp:45
void workFinished()
Signals that the solve routine has ended.
BCEGurobiCallback * callback
Callback, allows communication with Gurobi solver.
Definition: bcesolverworker.hpp:59
void sendSolution(BCESolution *soln, bool isBoundaryMapped)
Signals a pointer to the solution found by the solver.
BCESolverWorker(BCEGame _game, vector< double > _weightData, vector< vector< double > > _mapBoundaryData, BCEGurobiCallback *_callback, bool _mapBoundaryOption, double _minAngleIncrement)
Constructor.
Definition: bcesolverworker.hpp:68
vector< double > weightData
Weights on the objectives, as supplied by the user in the game tab.
Definition: bcesolverworker.hpp:55
const BCESolution & getSolution() const
Returns a reference to the solution object.
Definition: bcesolverworker.hpp:80
void exceptionSignal(QString message)
Signals an exception thrown during the solve routine.
void startSolve()
Triggered when the user clicks the "Solve" button in the game tab.
Definition: bcesolverworker.hpp:94
vector< vector< double > > mapBoundaryData
Weights on map boundary objectives, supplied in the game tab.
Definition: bcesolverworker.hpp:57
BCESolution solution
Solution, either default or the custom game (see class description).
Definition: bcesolverworker.hpp:53
bool mapBoundaryOption
True if the solver will be mapping the boundary.
Definition: bcesolverworker.hpp:61
BCEGame game
Game.
Definition: bcesolverworker.hpp:46
double minAngleIncrement
Minimum angle increment, used for mapping the boundary.
Definition: bcesolverworker.hpp:63