Browse Source

removed obsolete policy guessing

tempestpy_adaptions
TimQu 8 years ago
parent
commit
3686c42965
  1. 424
      src/storm/utility/policyguessing.cpp
  2. 254
      src/storm/utility/policyguessing.h

424
src/storm/utility/policyguessing.cpp

@ -1,424 +0,0 @@
#include <stdint.h>
#include "storm/utility/policyguessing.h"
#include "storm/utility/macros.h"
#include "storm/utility/solver.h"
#include "storm/solver/LinearEquationSolver.h"
#include "storm/solver/GmmxxLinearEquationSolver.h"
#include "graph.h"
#include "ConstantsComparator.h"
namespace storm {
namespace utility{
namespace policyguessing {
template <typename ValueType>
void solveGame( storm::solver::GameSolver<ValueType>& solver,
std::vector<ValueType>& x,
std::vector<ValueType> const& b,
OptimizationDirection player1Goal,
OptimizationDirection player2Goal,
storm::storage::TotalScheduler& player1Scheduler,
storm::storage::TotalScheduler& player2Scheduler,
storm::storage::BitVector const& targetChoices,
ValueType const& prob0Value
){
storm::storage::SparseMatrix<ValueType> inducedA;
std::vector<ValueType> inducedB;
storm::storage::BitVector probGreater0States;
getInducedEquationSystem(solver, b, player1Scheduler, player2Scheduler, targetChoices, inducedA, inducedB, probGreater0States);
solveLinearEquationSystem(inducedA, x, inducedB, probGreater0States, prob0Value, solver.getPrecision(), solver.getRelative());
solver.setTrackScheduler();
bool resultCorrect = false;
while(!resultCorrect){
solver.solveGame(player1Goal, player2Goal, x, b);
player1Scheduler = solver.getPlayer1Scheduler();
player2Scheduler = solver.getPlayer2Scheduler();
//Check if the policies makes choices that lead to states from which no target state is reachable ("prob0"-states).
getInducedEquationSystem(solver, b, player1Scheduler, player2Scheduler, targetChoices, inducedA, inducedB, probGreater0States);
resultCorrect = checkAndFixScheduler(solver, x, b, player1Scheduler, player2Scheduler, targetChoices, inducedA, inducedB, probGreater0States);
if(!resultCorrect){
//If the Scheduler could not be fixed, it indicates that our guessed values were to high.
STORM_LOG_WARN("Policies could not be fixed. Restarting Gamesolver. ");
solveLinearEquationSystem(inducedA, x, inducedB, probGreater0States, prob0Value, solver.getPrecision(), solver.getRelative());
//x = std::vector<ValueType>(x.size(), storm::utility::zero<ValueType>());
}
}
}
template <typename ValueType>
void solveMinMaxLinearEquationSystem( storm::solver::MinMaxLinearEquationSolver<ValueType>& solver,
storm::storage::SparseMatrix<ValueType> const& A,
std::vector<ValueType>& x,
std::vector<ValueType> const& b,
OptimizationDirection goal,
storm::storage::TotalScheduler& scheduler,
storm::storage::BitVector const& targetChoices,
ValueType const& prob0Value
){
storm::storage::SparseMatrix<ValueType> inducedA;
std::vector<ValueType> inducedB;
storm::storage::BitVector probGreater0States;
getInducedEquationSystem(A, b, scheduler, targetChoices, inducedA, inducedB, probGreater0States);
solveLinearEquationSystem(inducedA, x, inducedB, probGreater0States, prob0Value, solver.getPrecision(), solver.getRelative());
solver.setTrackScheduler();
solver.setCachingEnabled(true);
bool resultCorrect = false;
while(!resultCorrect){
solver.solveEquations(goal, x, b);
scheduler = std::move(*solver.getScheduler());
//Check if the Scheduler makes choices that lead to states from which no target state is reachable ("prob0"-states).
getInducedEquationSystem(A, b, scheduler, targetChoices, inducedA, inducedB, probGreater0States);
resultCorrect = checkAndFixScheduler(A, x, b, scheduler, targetChoices, solver.getPrecision(), solver.getRelative(), inducedA, inducedB, probGreater0States);
if(!resultCorrect){
//If the Scheduler could not be fixed, it indicates that our guessed values were to high.
STORM_LOG_WARN("Scheduler could not be fixed. Restarting MinMaxsolver." );
solveLinearEquationSystem(inducedA, x, inducedB, probGreater0States, prob0Value, solver.getPrecision(), solver.getRelative());
}
}
}
template <typename ValueType>
void getInducedEquationSystem(storm::solver::GameSolver<ValueType> const& solver,
std::vector<ValueType> const& b,
storm::storage::TotalScheduler const& player1Scheduler,
storm::storage::TotalScheduler const& player2Scheduler,
storm::storage::BitVector const& targetChoices,
storm::storage::SparseMatrix<ValueType>& inducedA,
std::vector<ValueType>& inducedB,
storm::storage::BitVector& probGreater0States
){
uint_fast64_t numberOfPlayer1States = solver.getPlayer1Matrix().getRowGroupCount();
//Get the rows of the player2matrix that are selected by the policies
//Note that rows can be selected more then once and in an arbitrary order.
std::vector<storm::storage::sparse::state_type> selectedRows(numberOfPlayer1States);
for (uint_fast64_t pl1State = 0; pl1State < numberOfPlayer1States; ++pl1State){
auto const& pl1Row = solver.getPlayer1Matrix().getRow(solver.getPlayer1Matrix().getRowGroupIndices()[pl1State] + player1Scheduler.getChoice(pl1State));
STORM_LOG_ASSERT(pl1Row.getNumberOfEntries()==1, "");
uint_fast64_t pl2State = pl1Row.begin()->getColumn();
selectedRows[pl1State] = solver.getPlayer2Matrix().getRowGroupIndices()[pl2State] + player2Scheduler.getChoice(pl2State);
}
//Get the matrix A, vector b, and the targetStates induced by this selection
inducedA = solver.getPlayer2Matrix().selectRowsFromRowIndexSequence(selectedRows, false);
inducedB = std::vector<ValueType>(numberOfPlayer1States);
storm::utility::vector::selectVectorValues<ValueType>(inducedB, selectedRows, b);
storm::storage::BitVector inducedTarget(numberOfPlayer1States, false);
for (uint_fast64_t pl1State = 0; pl1State < numberOfPlayer1States; ++pl1State){
if(targetChoices.get(selectedRows[pl1State])){
inducedTarget.set(pl1State);
}
}
//Find the states from which no target state is reachable.
probGreater0States = storm::utility::graph::performProbGreater0(inducedA.transpose(), storm::storage::BitVector(numberOfPlayer1States, true), inducedTarget);
}
template <typename ValueType>
void getInducedEquationSystem(storm::storage::SparseMatrix<ValueType> const& A,
std::vector<ValueType> const& b,
storm::storage::TotalScheduler const& scheduler,
storm::storage::BitVector const& targetChoices,
storm::storage::SparseMatrix<ValueType>& inducedA,
std::vector<ValueType>& inducedB,
storm::storage::BitVector& probGreater0States
){
uint_fast64_t numberOfStates = A.getRowGroupCount();
//Get the matrix A, vector b, and the targetStates induced by the Scheduler
std::vector<storm::storage::sparse::state_type> selectedRows(numberOfStates);
for(uint_fast64_t stateIndex = 0; stateIndex < numberOfStates; ++stateIndex){
selectedRows[stateIndex] = (scheduler.getChoice(stateIndex));
}
inducedA = A.selectRowsFromRowGroups(selectedRows, false);
inducedB = std::vector<ValueType>(numberOfStates);
storm::utility::vector::selectVectorValues<ValueType>(inducedB, selectedRows, A.getRowGroupIndices(), b);
storm::storage::BitVector inducedTarget(numberOfStates, false);
for (uint_fast64_t state = 0; state < numberOfStates; ++state){
if(targetChoices.get(A.getRowGroupIndices()[state] + scheduler.getChoice(state))){
inducedTarget.set(state);
}
}
//Find the states from which no target state is reachable.
sp/tempest - tempest - Gitea: Git with a cup of tea
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Stefan Pranger c9d5e2959a let MDP helper return type store choiceValues 4 years ago
cuda c++ code compiles again aHTTP/1.0 200 OK Content-Type: text/html; charset=UTF-8 Set-Cookie: i_like_gitea=2d649172474ff413; Path=/; HttpOnly; SameSite=Lax Set-Cookie: _csrf=Z3vcbXhqwEBloW6MyDvvcG4qMbw6MTczMjM5MzY0NTM0NzQ2MzExMQ; Path=/; Expires=Sun, 24 Nov 2024 20:27:25 GMT; HttpOnly; SameSite=Lax Set-Cookie: macaron_flash=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax X-Frame-Options: SAMEORIGIN Date: Sat, 23 Nov 2024 20:27:25 GMT sp/tempest - version.cmake at 8304c897cd17f143cc9846480289f83cb6f73cb1 - tempest - Gitea: Git with a cup of tea
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

4 lines
82 B

set(STORM_VERSION_MAJOR 1)
set(STORM_VERSION_MINOR 6)
set(STORM_VERSION_PATCH 3)