Browse Source

some more work, not fully working again (yet)

Former-commit-id: 32c8c6eb7e
tempestpy_adaptions
dehnert 9 years ago
parent
commit
7a4d3740de
  1. 2
      src/abstraction/AbstractionInformation.cpp
  2. 7
      src/abstraction/StateSetAbstractor.cpp
  3. 5
      src/abstraction/StateSetAbstractor.h
  4. 16
      src/abstraction/prism/AbstractModule.cpp
  5. 16
      src/abstraction/prism/AbstractModule.h
  6. 21
      src/abstraction/prism/AbstractProgram.cpp
  7. 6
      src/abstraction/prism/AbstractProgram.h

2
src/abstraction/AbstractionInformation.cpp

@ -9,7 +9,7 @@ namespace storm {
namespace abstraction {
template<storm::dd::DdType DdType>
AbstractionInformation<DdType>::AbstractionInformation(storm::expressions::ExpressionManager& expressionManager, std::shared_ptr<storm::dd::DdManager<DdType>> ddManager) : expressionManager(expressionManager), ddManager(ddManager) {
AbstractionInformation<DdType>::AbstractionInformation(storm::expressions::ExpressionManager& expressionManager, std::shared_ptr<storm::dd::DdManager<DdType>> ddManager) : expressionManager(expressionManager), ddManager(ddManager), allPredicateIdentities(ddManager->getBddZero()) {
// Intentionally left empty.
}

7
src/abstraction/StateSetAbstractor.cpp

@ -11,12 +11,7 @@ namespace storm {
namespace abstraction {
template <storm::dd::DdType DdType, typename ValueType>
StateSetAbstractor<DdType, ValueType>::StateSetAbstractor(AbstractionInformation<DdType>& abstractionInformation) : smtSolver(nullptr), abstractionInformation(abstractionInformation), localExpressionInformation(), relevantPredicatesAndVariables(), concretePredicateVariables(), decisionVariables(), needsRecomputation(false), cachedBdd(), constraint() {
// Intentionally left empty.
}
template <storm::dd::DdType DdType, typename ValueType>
StateSetAbstractor<DdType, ValueType>::StateSetAbstractor(AbstractionInformation<DdType>& abstractionInformation, std::vector<storm::expressions::Expression> const& statePredicates, storm::utility::solver::SmtSolverFactory const& smtSolverFactory) : smtSolver(smtSolverFactory.create(abstractionInformation.getExpressionManager())), abstractionInformation(abstractionInformation), localExpressionInformation(abstractionInformation.getExpressionVariables()), relevantPredicatesAndVariables(), concretePredicateVariables(), needsRecomputation(false), cachedBdd(abstractionInformation.getDdManager().getBddZero()), constraint(abstractionInformation.getDdManager().getBddOne()) {
StateSetAbstractor<DdType, ValueType>::StateSetAbstractor(AbstractionInformation<DdType>& abstractionInformation, std::set<storm::expressions::Variable> const& allVariables, std::vector<storm::expressions::Expression> const& statePredicates, storm::utility::solver::SmtSolverFactory const& smtSolverFactory) : smtSolver(smtSolverFactory.create(abstractionInformation.getExpressionManager())), abstractionInformation(abstractionInformation), localExpressionInformation(allVariables), relevantPredicatesAndVariables(), concretePredicateVariables(), needsRecomputation(false), cachedBdd(abstractionInformation.getDdManager().getBddZero()), constraint(abstractionInformation.getDdManager().getBddOne()) {
// Assert all constraints to enforce legal variable values.
for (auto const& constraint : abstractionInformation.getConstraints()) {

5
src/abstraction/StateSetAbstractor.h

@ -34,8 +34,6 @@ namespace storm {
template <storm::dd::DdType DdType, typename ValueType>
class StateSetAbstractor {
public:
StateSetAbstractor(AbstractionInformation<DdType>& abstractionInformation);
StateSetAbstractor(StateSetAbstractor const& other) = default;
StateSetAbstractor& operator=(StateSetAbstractor const& other) = default;
@ -48,11 +46,12 @@ namespace storm {
* Creates a state set abstractor.
*
* @param abstractionInformation An object storing information about the abstraction such as predicates and BDDs.
* @param allVariables All variables that appear in the predicates.
* @param statePredicates A set of predicates that have to hold in the concrete states this abstractor is
* supposed to abstract.
* @param smtSolverFactory A factory that can create new SMT solvers.
*/
StateSetAbstractor(AbstractionInformation<DdType>& abstractionInformation, std::vector<storm::expressions::Expression> const& statePredicates, storm::utility::solver::SmtSolverFactory const& smtSolverFactory);
StateSetAbstractor(AbstractionInformation<DdType>& abstractionInformation, std::set<storm::expressions::Variable> const& allVariables, std::vector<storm::expressions::Expression> const& statePredicates, storm::utility::solver::SmtSolverFactory const& smtSolverFactory);
/*!
* Refines the abstractor by making the given predicates new abstract predicates.

16
src/abstraction/prism/AbstractModule.cpp

@ -27,6 +27,11 @@ namespace storm {
}
}
template <storm::dd::DdType DdType, typename ValueType>
AbstractModule<DdType, ValueType>::~AbstractModule() {
std::cout << "destructing abs module at " << this << std::endl;
}
template <storm::dd::DdType DdType, typename ValueType>
std::pair<storm::dd::Bdd<DdType>, uint_fast64_t> AbstractModule<DdType, ValueType>::getAbstractBdd() {
// First, we retrieve the abstractions of all commands.
@ -39,22 +44,27 @@ namespace storm {
// Then, we build the module BDD by adding the single command DDs. We need to make sure that all command
// DDs use the same amount DD variable encoding the choices of player 2.
storm::dd::Bdd<DdType> result = abstractionInformation.getDdManager().getBddZero();
storm::dd::Bdd<DdType> result = this->getAbstractionInformation().getDdManager().getBddZero();
for (auto const& commandDd : commandDdsAndUsedOptionVariableCounts) {
result |= commandDd.first && abstractionInformation.getPlayer2ZeroCube(maximalNumberOfUsedOptionVariables, commandDd.second);
result |= commandDd.first && this->getAbstractionInformation().getPlayer2ZeroCube(maximalNumberOfUsedOptionVariables, commandDd.second);
}
return std::make_pair(result, maximalNumberOfUsedOptionVariables);
}
template <storm::dd::DdType DdType, typename ValueType>
storm::dd::Add<DdType, ValueType> AbstractModule<DdType, ValueType>::getCommandUpdateProbabilitiesAdd() const {
storm::dd::Add<DdType, ValueType> result = abstractionInformation.getDdManager().template getAddZero<ValueType>();
storm::dd::Add<DdType, ValueType> result = this->getAbstractionInformation().getDdManager().template getAddZero<ValueType>();
for (auto const& command : commands) {
result += command.getCommandUpdateProbabilitiesAdd();
}
return result;
}
template <storm::dd::DdType DdType, typename ValueType>
AbstractionInformation<DdType> const& AbstractModule<DdType, ValueType>::getAbstractionInformation() const {
return abstractionInformation.get();
}
template class AbstractModule<storm::dd::DdType::CUDD, double>;
template class AbstractModule<storm::dd::DdType::Sylvan, double>;
}

16
src/abstraction/prism/AbstractModule.h

@ -31,6 +31,13 @@ namespace storm {
*/
AbstractModule(storm::prism::Module const& module, AbstractionInformation<DdType>& abstractionInformation, storm::utility::solver::SmtSolverFactory const& smtSolverFactory);
AbstractModule(AbstractModule const&) = delete;
AbstractModule& operator=(AbstractModule const&) = delete;
AbstractModule(AbstractModule&&) = default;
AbstractModule& operator=(AbstractModule&&) = default;
~AbstractModule();
/*!
* Refines the abstract module with the given predicates.
*
@ -53,11 +60,18 @@ namespace storm {
storm::dd::Add<DdType, ValueType> getCommandUpdateProbabilitiesAdd() const;
private:
/*!
* Retrieves the abstraction information.
*
* @return The abstraction information.
*/
AbstractionInformation<DdType> const& getAbstractionInformation() const;
// A factory that can be used to create new SMT solvers.
storm::utility::solver::SmtSolverFactory const& smtSolverFactory;
// The DD-related information.
AbstractionInformation<DdType> const& abstractionInformation;
std::reference_wrapper<AbstractionInformation<DdType> const> abstractionInformation;
// The abstract commands of the abstract module.
std::vector<AbstractCommand<DdType, ValueType>> commands;

21
src/abstraction/prism/AbstractProgram.cpp

@ -16,12 +16,17 @@ namespace storm {
namespace abstraction {
namespace prism {
template <storm::dd::DdType DdType, typename ValueType>
AbstractProgram<DdType, ValueType>::~AbstractProgram() {
std::cout << "destructing abs program" << std::endl;
}
template <storm::dd::DdType DdType, typename ValueType>
AbstractProgram<DdType, ValueType>::AbstractProgram(storm::expressions::ExpressionManager& expressionManager, storm::prism::Program const& program,
std::vector<storm::expressions::Expression> const& initialPredicates,
std::unique_ptr<storm::utility::solver::SmtSolverFactory>&& smtSolverFactory,
bool addAllGuards)
: program(program), smtSolverFactory(std::move(smtSolverFactory)), modules(), abstractionInformation(expressionManager), initialStateAbstractor(), addedAllGuards(addAllGuards), bottomStateAbstractor(), currentGame(nullptr) {
: program(program), smtSolverFactory(std::move(smtSolverFactory)), modules(), abstractionInformation(expressionManager), initialStateAbstractor(abstractionInformation, program.getAllExpressionVariables(), {program.getInitialConstruct().getInitialStatesExpression()}, *this->smtSolverFactory), addedAllGuards(addAllGuards), bottomStateAbstractor(abstractionInformation, program.getAllExpressionVariables(), program.getAllGuards(true), *this->smtSolverFactory), currentGame(nullptr) {
// For now, we assume that there is a single module. If the program has more than one module, it needs
// to be flattened before the procedure.
@ -50,7 +55,7 @@ namespace storm {
totalNumberOfCommands += module.getNumberOfCommands();
}
// NOTE: currently we assume that 100 player 2variables suffice, which corresponds to 2^100 possible
// NOTE: currently we assume that 100 player 2 variables suffice, which corresponds to 2^100 possible
// choices. If for some reason this should not be enough, we could grow this vector dynamically, but
// odds are that it's impossible to treat such models in any event.
abstractionInformation.createEncodingVariables(static_cast<uint_fast64_t>(std::ceil(std::log2(totalNumberOfCommands))), 100, static_cast<uint_fast64_t>(std::ceil(std::log2(maximalUpdateCount))));
@ -67,18 +72,16 @@ namespace storm {
// For each module of the concrete program, we create an abstract counterpart.
for (auto const& module : program.getModules()) {
modules.emplace_back(module, abstractionInformation, *this->smtSolverFactory);
this->modules.emplace_back(module, abstractionInformation, *this->smtSolverFactory);
}
// Retrieve the command-update probability ADD, so we can multiply it with the abstraction BDD later.
commandUpdateProbabilitiesAdd = modules.front().getCommandUpdateProbabilitiesAdd();
// Create the state set abstractors.
initialStateAbstractor = storm::abstraction::StateSetAbstractor<DdType, ValueType>(abstractionInformation, {program.getInitialConstruct().getInitialStatesExpression()}, *this->smtSolverFactory);
bottomStateAbstractor = storm::abstraction::StateSetAbstractor<DdType, ValueType>(abstractionInformation, program.getAllGuards(true), *this->smtSolverFactory);
// Finally, we build the game the first time.
currentGame = buildGame();
std::cout << "abs module at " << &modules.front() << std::endl;
}
template <storm::dd::DdType DdType, typename ValueType>
@ -153,7 +156,7 @@ namespace storm {
if (!deadlockStates.isZero()) {
deadlockTransitions = (deadlockStates && abstractionInformation.getAllPredicateIdentities() && abstractionInformation.encodePlayer1Choice(0, abstractionInformation.getPlayer1VariableCount()) && abstractionInformation.encodePlayer2Choice(0, gameBdd.second) && abstractionInformation.encodeProbabilisticChoice(0, abstractionInformation.getProbabilisticBranchingVariableCount())).template toAdd<ValueType>();
}
// Construct the transition matrix by cutting away the transitions of unreachable states.
storm::dd::Add<DdType> transitionMatrix = (gameBdd.first && reachableStates).template toAdd<ValueType>() * commandUpdateProbabilitiesAdd + deadlockTransitions;
@ -161,7 +164,7 @@ namespace storm {
std::set<storm::expressions::Variable> allNondeterminismVariables = usedPlayer2Variables;
allNondeterminismVariables.insert(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end());
return std::make_unique<MenuGame<DdType, ValueType>>(abstractionInformation.getDdManagerAsSharedPointer(), reachableStates, initialStates, abstractionInformation.getDdManager().getBddZero(), transitionMatrix, bottomStates, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables(), abstractionInformation.getSourceSuccessorVariablePairs(), std::set<storm::expressions::Variable>(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end()), usedPlayer2Variables, allNondeterminismVariables, std::set<storm::expressions::Variable>(abstractionInformation.getProbabilisticBranchingVariables().begin(), abstractionInformation.getProbabilisticBranchingVariables().end()), abstractionInformation.getPredicateToBddMap());
}

6
src/abstraction/prism/AbstractProgram.h

@ -45,6 +45,12 @@ namespace storm {
*/
AbstractProgram(storm::expressions::ExpressionManager& expressionManager, storm::prism::Program const& program, std::vector<storm::expressions::Expression> const& initialPredicates, std::unique_ptr<storm::utility::solver::SmtSolverFactory>&& smtSolverFactory = std::make_unique<storm::utility::solver::SmtSolverFactory>(), bool addAllGuards = false);
AbstractProgram(AbstractProgram const&) = default;
AbstractProgram& operator=(AbstractProgram const&) = default;
AbstractProgram(AbstractProgram&&) = default;
AbstractProgram& operator=(AbstractProgram&&) = default;
~AbstractProgram();
/*!
* Uses the current set of predicates to derive the abstract menu game in the form of an ADD.
*

Loading…
Cancel
Save