#include "gtest/gtest.h" #include "storm-config.h" #include "src/storage/dd/CuddDdManager.h" #include "src/storage/dd/CuddAdd.h" #include "src/storage/dd/CuddBdd.h" #include "src/utility/solver.h" #include "src/settings/SettingsManager.h" #include "src/solver/SymbolicGameSolver.h" #include "src/settings/modules/NativeEquationSolverSettings.h" TEST(FullySymbolicGameSolverTest, Solve) { // Create some variables. std::shared_ptr> manager(new storm::dd::DdManager()); std::pair state = manager->addMetaVariable("x", 1, 4); std::pair pl1 = manager->addMetaVariable("a", 0, 1); std::pair pl2 = manager->addMetaVariable("b", 0, 1); storm::dd::Bdd allRows = manager->getBddZero(); std::set rowMetaVariables({state.first}); std::set columnMetaVariables({state.second}); std::vector> rowColumnMetaVariablePairs = {state}; std::set player1Variables({pl1.first}); std::set player2Variables({pl2.first}); // Construct simple game. storm::dd::Add matrix = manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 2).toAdd() * manager->getEncoding(pl1.first, 0).toAdd() * manager->getEncoding(pl2.first, 0).toAdd() * manager->getConstant(0.6); matrix += manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 1).toAdd() * manager->getEncoding(pl1.first, 0).toAdd() * manager->getEncoding(pl2.first, 0).toAdd() * manager->getConstant(0.4); matrix += manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 2).toAdd() * manager->getEncoding(pl1.first, 0).toAdd() * manager->getEncoding(pl2.first, 1).toAdd() * manager->getConstant(0.2); matrix += manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 3).toAdd() * manager->getEncoding(pl1.first, 0).toAdd() * manager->getEncoding(pl2.first, 1).toAdd() * manager->getConstant(0.8); matrix += manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 3).toAdd() * manager->getEncoding(pl1.first, 1).toAdd() * manager->getEncoding(pl2.first, 0).toAdd() * manager->getConstant(0.5); matrix += manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 4).toAdd() * manager->getEncoding(pl1.first, 1).toAdd() * manager->getEncoding(pl2.first, 0).toAdd() * manager->getConstant(0.5); matrix += manager->getEncoding(state.first, 1).toAdd() * manager->getEncoding(state.second, 1).toAdd() * manager->getEncoding(pl1.first, 1).toAdd() * manager->getEncoding(pl2.first, 1).toAdd() * manager->getConstant(1); std::unique_ptr> solverFactory(new storm::utility::solver::SymbolicGameSolverFactory()); std::unique_ptr> solver = solverFactory->create(matrix, allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs, player1Variables,player2Variables); // Create solution and target state vector. storm::dd::Add x = manager->getAddZero(); storm::dd::Add b = manager->getEncoding(state.first, 2).toAdd() + manager->getEncoding(state.first, 4).toAdd(); // Now solve the game with different strategies for the players. storm::dd::Add result = solver->solveGame(true, true, x, b); result *= manager->getEncoding(state.first, 1).toAdd(); result = result.sumAbstract({state.first}); EXPECT_NEAR(0, result.getValue(), storm::settings::nativeEquationSolverSettings().getPrecision()); x = manager->getAddZero(); result = solver->solveGame(true, false, x, b); result *= manager->getEncoding(state.first, 1).toAdd(); result = result.sumAbstract({state.first}); EXPECT_NEAR(0.5, result.getValue(), storm::settings::nativeEquationSolverSettings().getPrecision()); x = manager->getAddZero(); result = solver->solveGame(false, true, x, b); result *= manager->getEncoding(state.first, 1).toAdd(); result = result.sumAbstract({state.first}); EXPECT_NEAR(0.2, result.getValue(), storm::settings::nativeEquationSolverSettings().getPrecision()); x = manager->getAddZero(); result = solver->solveGame(false, false, x, b); result *= manager->getEncoding(state.first, 1).toAdd(); result = result.sumAbstract({state.first}); EXPECT_NEAR(0.99999892625817599, result.getValue(), storm::settings::nativeEquationSolverSettings().getPrecision()); }