Browse Source

towards strategy generation in game solver

Former-commit-id: fb582ba531
tempestpy_adaptions
dehnert 8 years ago
parent
commit
56b5b98a2c
  1. 8
      resources/3rdparty/cudd-3.0.0/cplusplus/cuddObj.cc
  2. 4
      resources/3rdparty/cudd-3.0.0/cplusplus/cuddObj.hh
  3. 42
      src/solver/SymbolicGameSolver.cpp
  4. 36
      src/solver/SymbolicGameSolver.h
  5. 8
      src/solver/SymbolicMinMaxLinearEquationSolver.h

8
resources/3rdparty/cudd-3.0.0/cplusplus/cuddObj.cc

@ -2667,22 +2667,22 @@ ADD::MaxAbstract(const ADD& cube) const
return ADD(p, result); return ADD(p, result);
} // ADD::MaxAbstract } // ADD::MaxAbstract
ADD
BDD
ADD::MinAbstractRepresentative(const ADD& cube) const ADD::MinAbstractRepresentative(const ADD& cube) const
{ {
DdManager *mgr = checkSameManager(cube); DdManager *mgr = checkSameManager(cube);
DdNode *result = Cudd_addMinAbstractRepresentative(mgr, node, cube.node); DdNode *result = Cudd_addMinAbstractRepresentative(mgr, node, cube.node);
checkReturnValue(result); checkReturnValue(result);
return ADD(p, result);
return BDD(p, result);
} // ADD::MinRepresentative } // ADD::MinRepresentative
ADD
BDD
ADD::MaxAbstractRepresentative(const ADD& cube) const ADD::MaxAbstractRepresentative(const ADD& cube) const
{ {
DdManager *mgr = checkSameManager(cube); DdManager *mgr = checkSameManager(cube);
DdNode *result = Cudd_addMaxAbstractRepresentative(mgr, node, cube.node); DdNode *result = Cudd_addMaxAbstractRepresentative(mgr, node, cube.node);
checkReturnValue(result); checkReturnValue(result);
return ADD(p, result);
return BDD(p, result);
} // ADD::MaxRepresentative } // ADD::MaxRepresentative
ADD ADD

4
resources/3rdparty/cudd-3.0.0/cplusplus/cuddObj.hh

@ -336,8 +336,8 @@ public:
ADD MinAbstract(const ADD& cube) const; ADD MinAbstract(const ADD& cube) const;
ADD MinAbstractExcept0(const ADD& cube) const; ADD MinAbstractExcept0(const ADD& cube) const;
ADD MaxAbstract(const ADD& cube) const; ADD MaxAbstract(const ADD& cube) const;
ADD MinAbstractRepresentative(const ADD& cube) const;
ADD MaxAbstractRepresentative(const ADD& cube) const;
BDD MinAbstractRepresentative(const ADD& cube) const;
BDD MaxAbstractRepresentative(const ADD& cube) const;
ADD Plus(const ADD& g) const; ADD Plus(const ADD& g) const;
ADD Times(const ADD& g) const; ADD Times(const ADD& g) const;
ADD Threshold(const ADD& g) const; ADD Threshold(const ADD& g) const;

42
src/solver/SymbolicGameSolver.cpp

@ -1,21 +1,26 @@
#include "src/solver/SymbolicGameSolver.h" #include "src/solver/SymbolicGameSolver.h"
#include "src/storage/dd/DdManager.h"
#include "src/storage/dd/Bdd.h" #include "src/storage/dd/Bdd.h"
#include "src/storage/dd/Add.h" #include "src/storage/dd/Add.h"
#include "src/settings/SettingsManager.h" #include "src/settings/SettingsManager.h"
#include "src/settings/modules/NativeEquationSolverSettings.h" #include "src/settings/modules/NativeEquationSolverSettings.h"
#include "src/utility/constants.h"
#include "src/utility/macros.h"
#include "src/exceptions/IllegalFunctionCallException.h"
namespace storm { namespace storm {
namespace solver { namespace solver {
template<storm::dd::DdType Type, typename ValueType> template<storm::dd::DdType Type, typename ValueType>
SymbolicGameSolver<Type, ValueType>::SymbolicGameSolver(storm::dd::Add<Type, ValueType> const& gameMatrix, storm::dd::Bdd<Type> const& allRows, storm::dd::Bdd<Type> const& illegalPlayer1Mask, storm::dd::Bdd<Type> const& illegalPlayer2Mask, std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables, std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs, std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables) : gameMatrix(gameMatrix), allRows(allRows), illegalPlayer1Mask(illegalPlayer1Mask.template toAdd<ValueType>()), illegalPlayer2Mask(illegalPlayer2Mask.template toAdd<ValueType>()), rowMetaVariables(rowMetaVariables), columnMetaVariables(columnMetaVariables), rowColumnMetaVariablePairs(rowColumnMetaVariablePairs), player1Variables(player1Variables), player2Variables(player2Variables) {
SymbolicGameSolver<Type, ValueType>::SymbolicGameSolver(storm::dd::Add<Type, ValueType> const& A, storm::dd::Bdd<Type> const& allRows, storm::dd::Bdd<Type> const& illegalPlayer1Mask, storm::dd::Bdd<Type> const& illegalPlayer2Mask, std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables, std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs, std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables) : A(A), allRows(allRows), illegalPlayer1Mask(illegalPlayer1Mask.ite(A.getDdManager().getConstant(storm::utility::infinity<ValueType>()), A.getDdManager().template getAddZero<ValueType>())), illegalPlayer2Mask(illegalPlayer2Mask.ite(A.getDdManager().getConstant(storm::utility::infinity<ValueType>()), A.getDdManager().template getAddZero<ValueType>())), rowMetaVariables(rowMetaVariables), columnMetaVariables(columnMetaVariables), rowColumnMetaVariablePairs(rowColumnMetaVariablePairs), player1Variables(player1Variables), player2Variables(player2Variables), generatePlayer1Strategy(false), generatePlayer2Strategy(false) {
// Intentionally left empty. // Intentionally left empty.
} }
template<storm::dd::DdType Type, typename ValueType> template<storm::dd::DdType Type, typename ValueType>
SymbolicGameSolver<Type, ValueType>::SymbolicGameSolver(storm::dd::Add<Type, ValueType> const& gameMatrix, storm::dd::Bdd<Type> const& allRows, storm::dd::Bdd<Type> const& illegalPlayer1Mask, storm::dd::Bdd<Type> const& illegalPlayer2Mask, std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables, std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs, std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables, double precision, uint_fast64_t maximalNumberOfIterations, bool relative) : AbstractGameSolver(precision, maximalNumberOfIterations, relative), gameMatrix(gameMatrix), allRows(allRows), illegalPlayer1Mask(illegalPlayer1Mask.template toAdd<ValueType>()), illegalPlayer2Mask(illegalPlayer2Mask.template toAdd<ValueType>()), rowMetaVariables(rowMetaVariables), columnMetaVariables(columnMetaVariables), rowColumnMetaVariablePairs(rowColumnMetaVariablePairs), player1Variables(player1Variables), player2Variables(player2Variables) {
SymbolicGameSolver<Type, ValueType>::SymbolicGameSolver(storm::dd::Add<Type, ValueType> const& A, storm::dd::Bdd<Type> const& allRows, storm::dd::Bdd<Type> const& illegalPlayer1Mask, storm::dd::Bdd<Type> const& illegalPlayer2Mask, std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables, std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs, std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables, double precision, uint_fast64_t maximalNumberOfIterations, bool relative) : AbstractGameSolver(precision, maximalNumberOfIterations, relative), A(A), allRows(allRows), illegalPlayer1Mask(illegalPlayer1Mask.template toAdd<ValueType>()), illegalPlayer2Mask(illegalPlayer2Mask.template toAdd<ValueType>()), rowMetaVariables(rowMetaVariables), columnMetaVariables(columnMetaVariables), rowColumnMetaVariablePairs(rowColumnMetaVariablePairs), player1Variables(player1Variables), player2Variables(player2Variables), generatePlayer1Strategy(false), generatePlayer2Strategy(false) {
// Intentionally left empty. // Intentionally left empty.
} }
@ -27,9 +32,9 @@ namespace storm {
bool converged = false; bool converged = false;
do { do {
// Compute tmp = A * x + b
// Compute tmp = A * x + b.
storm::dd::Add<Type, ValueType> xCopyAsColumn = xCopy.swapVariables(this->rowColumnMetaVariablePairs); storm::dd::Add<Type, ValueType> xCopyAsColumn = xCopy.swapVariables(this->rowColumnMetaVariablePairs);
storm::dd::Add<Type, ValueType> tmp = this->gameMatrix.multiplyMatrix(xCopyAsColumn, this->columnMetaVariables);
storm::dd::Add<Type, ValueType> tmp = this->A.multiplyMatrix(xCopyAsColumn, this->columnMetaVariables);
tmp += b; tmp += b;
// Now abstract from player 2 and player 1 variables. // Now abstract from player 2 and player 1 variables.
@ -59,6 +64,35 @@ namespace storm {
return xCopy; return xCopy;
} }
template<storm::dd::DdType Type, typename ValueType>
void SymbolicGameSolver<Type, ValueType>::setGeneratePlayer1Strategy(bool value) {
generatePlayer1Strategy = value;
}
template<storm::dd::DdType Type, typename ValueType>
void SymbolicGameSolver<Type, ValueType>::setGeneratePlayer2Strategy(bool value) {
generatePlayer2Strategy = value;
}
template<storm::dd::DdType Type, typename ValueType>
void SymbolicGameSolver<Type, ValueType>::setGeneratePlayerStrategies(bool value) {
setGeneratePlayer1Strategy(value);
setGeneratePlayer2Strategy(value);
}
template<storm::dd::DdType Type, typename ValueType>
storm::dd::Bdd<Type> const& SymbolicGameSolver<Type, ValueType>::getPlayer1Strategy() const {
STORM_LOG_THROW(player1Strategy, storm::exceptions::IllegalFunctionCallException, "Cannot retrieve player 1 strategy because none was generated.");
return player1Strategy.get();
}
template<storm::dd::DdType Type, typename ValueType>
storm::dd::Bdd<Type> const& SymbolicGameSolver<Type, ValueType>::getPlayer2Strategy() const {
STORM_LOG_THROW(player2Strategy, storm::exceptions::IllegalFunctionCallException, "Cannot retrieve player 2 strategy because none was generated.");
return player2Strategy.get();
}
template class SymbolicGameSolver<storm::dd::DdType::CUDD, double>; template class SymbolicGameSolver<storm::dd::DdType::CUDD, double>;
template class SymbolicGameSolver<storm::dd::DdType::Sylvan, double>; template class SymbolicGameSolver<storm::dd::DdType::Sylvan, double>;

36
src/solver/SymbolicGameSolver.h

@ -68,12 +68,21 @@ namespace storm {
*/ */
virtual storm::dd::Add<Type, ValueType> solveGame(OptimizationDirection player1Goal, OptimizationDirection player2Goal, storm::dd::Add<Type, ValueType> const& x, storm::dd::Add<Type, ValueType> const& b) const; virtual storm::dd::Add<Type, ValueType> solveGame(OptimizationDirection player1Goal, OptimizationDirection player2Goal, storm::dd::Add<Type, ValueType> const& x, storm::dd::Add<Type, ValueType> const& b) const;
// Setters that enable the generation of the players' strategies.
void setGeneratePlayer1Strategy(bool value);
void setGeneratePlayer2Strategy(bool value);
void setGeneratePlayerStrategies(bool value);
// Getters to retrieve the players' strategies. Only legal if they were generated.
storm::dd::Bdd<Type> const& getPlayer1Strategy() const;
storm::dd::Bdd<Type> const& getPlayer2Strategy() const;
protected: protected:
// The matrix defining the coefficients of the linear equation system. // The matrix defining the coefficients of the linear equation system.
storm::dd::Add<Type, ValueType> const& gameMatrix;
storm::dd::Add<Type, ValueType> A;
// A BDD characterizing all rows of the equation system. // A BDD characterizing all rows of the equation system.
storm::dd::Bdd<Type> const& allRows;
storm::dd::Bdd<Type> allRows;
// An ADD that can be used to compensate for the illegal choices of player 1. // An ADD that can be used to compensate for the illegal choices of player 1.
storm::dd::Add<Type> illegalPlayer1Mask; storm::dd::Add<Type> illegalPlayer1Mask;
@ -82,19 +91,32 @@ namespace storm {
storm::dd::Add<Type> illegalPlayer2Mask; storm::dd::Add<Type> illegalPlayer2Mask;
// The row variables. // The row variables.
std::set<storm::expressions::Variable> const& rowMetaVariables;
std::set<storm::expressions::Variable> rowMetaVariables;
// The column variables. // The column variables.
std::set<storm::expressions::Variable> const& columnMetaVariables;
std::set<storm::expressions::Variable> columnMetaVariables;
// The pairs of meta variables used for renaming. // The pairs of meta variables used for renaming.
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs;
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> rowColumnMetaVariablePairs;
// The player 1 variables. // The player 1 variables.
std::set<storm::expressions::Variable> const& player1Variables;
std::set<storm::expressions::Variable> player1Variables;
// The player 2 variables. // The player 2 variables.
std::set<storm::expressions::Variable> const& player2Variables;
std::set<storm::expressions::Variable> player2Variables;
// A flag indicating whether a player 1 is to be generated.
bool generatePlayer1Strategy;
// A player 1 strategy if one was generated.
boost::optional<storm::dd::Bdd<Type>> player1Strategy;
// A flag indicating whether a player 2 is to be generated.
bool generatePlayer2Strategy;
// A player 1 strategy if one was generated.
boost::optional<storm::dd::Bdd<Type>> player2Strategy;
}; };
} // namespace solver } // namespace solver

8
src/solver/SymbolicMinMaxLinearEquationSolver.h

@ -91,10 +91,10 @@ namespace storm {
protected: protected:
// The matrix defining the coefficients of the linear equation system. // The matrix defining the coefficients of the linear equation system.
storm::dd::Add<DdType, ValueType> const& A;
storm::dd::Add<DdType, ValueType> A;
// A BDD characterizing all rows of the equation system. // A BDD characterizing all rows of the equation system.
storm::dd::Bdd<DdType> const& allRows;
storm::dd::Bdd<DdType> allRows;
// An ADD characterizing the illegal choices. // An ADD characterizing the illegal choices.
storm::dd::Add<DdType, ValueType> illegalMaskAdd; storm::dd::Add<DdType, ValueType> illegalMaskAdd;
@ -106,10 +106,10 @@ namespace storm {
std::set<storm::expressions::Variable> columnMetaVariables; std::set<storm::expressions::Variable> columnMetaVariables;
// The choice variables // The choice variables
std::set<storm::expressions::Variable> const& choiceVariables;
std::set<storm::expressions::Variable> choiceVariables;
// The pairs of meta variables used for renaming. // The pairs of meta variables used for renaming.
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs;
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> rowColumnMetaVariablePairs;
// The precision to achive. // The precision to achive.
double precision; double precision;

Loading…
Cancel
Save