Browse Source

Made several changes.

- Fixed the infinite loop bug that occured when giving a filepath pointing to a directory instead of a file.
- The BitVector to Dtmc subsystem converter now supports an optional choice labeling.
- The output of the modelchecker to the log file is now suppressed while doing a counterexample generation.
- It is now possible to add more atomic propositions to the AtomicPropositionLabeling than previously declared (at the cost of one reserve per added ap beyond the maximum).
  The maximum is then increased accordingly.
|-> As a result the state added for the Dtmc subsystem has now its own label.

Next up: Merge.)


Former-commit-id: 74c92aaea1
tempestpy_adaptions
masawei 11 years ago
parent
commit
af0601c453
  1. 10
      src/counterexamples/PathBasedSubsystemGenerator.h
  2. 9
      src/models/AbstractModel.h
  3. 20
      src/models/AtomicPropositionsLabeling.h
  4. 30
      src/models/Dtmc.h
  5. 21
      src/parser/PrctlFileParser.cpp
  6. 6
      src/storm.cpp

10
src/counterexamples/PathBasedSubsystemGenerator.h

@ -524,11 +524,11 @@ public:
#endif
LOG4CPLUS_INFO(logger, "Start finding critical subsystem.");
//make model checker
//TODO: Implement and use generic Model Checker factory.
// make model checker
// TODO: Implement and use generic Model Checker factory.
storm::modelchecker::prctl::SparseDtmcPrctlModelChecker<T> modelCheck {model, new storm::solver::GmmxxLinearEquationSolver<T>()};
//init bit vector to contain the subsystem
// init bit vector to contain the subsystem
storm::storage::BitVector subSys(model.getNumberOfStates());
storm::property::prctl::AbstractPathFormula<T> const* pathFormulaPtr;
@ -550,7 +550,9 @@ public:
storm::storage::BitVector initStates = model.getLabeledStates("init");
//get real prob for formula
logger.getAppender("mainFileAppender")->setThreshold(log4cplus::WARN_LOG_LEVEL);
std::vector<T> trueProbs = pathFormulaPtr->check(modelCheck, false);
logger.getAppender("mainFileAppender")->setThreshold(log4cplus::INFO_LOG_LEVEL);
T trueProb = 0;
for(auto index : initStates) {
@ -667,7 +669,9 @@ public:
if((pathCount % precision == 0) && subSysProb >= bound) {
//get probabilities
logger.getAppender("mainFileAppender")->setThreshold(log4cplus::WARN_LOG_LEVEL);
subSysProbs = modelCheck.checkUntil(allowedStates & subSys, targetStates & subSys, false);
logger.getAppender("mainFileAppender")->setThreshold(log4cplus::INFO_LOG_LEVEL);
//T diff = subSysProb;
//std::cout << "Est. prob: " << diff << std::endl;

9
src/models/AbstractModel.h

@ -65,8 +65,8 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalChoiceLabeling A vector that represents the labels associated with the choices of each state.
*/
AbstractModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
@ -90,8 +90,9 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalChoiceLabeling A vector that represents the labels associated with the choices of each state.
*/
AbstractModel(storm::storage::SparseMatrix<T>&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,

20
src/models/AtomicPropositionsLabeling.h

@ -27,7 +27,7 @@ namespace storm {
namespace models {
/*!
* This class manages the labeling of the state space with a fixed number of
* This class manages the labeling of the state space with a number of
* atomic propositions.
*/
class AtomicPropositionsLabeling {
@ -130,8 +130,9 @@ public:
/*!
* Registers the name of a proposition.
* Will throw an error if more atomic propositions are added than were originally declared or if an atomic
* proposition is registered twice.
* Will throw an error if an atomic proposition is registered twice.
* If more atomic propositions are added than previously declared, the maximum number of propositions
* is increased and the capacity of the singleLabelings vector is matched with the new maximum.
*
* @param ap The name of the atomic proposition to add.
* @return The index of the new proposition.
@ -142,9 +143,8 @@ public:
throw storm::exceptions::OutOfRangeException("Atomic Proposition already exists.");
}
if (apsCurrent >= apCountMax) {
LOG4CPLUS_ERROR(logger, "Added more atomic propositions than previously declared.");
throw storm::exceptions::OutOfRangeException("Added more atomic propositions than"
"previously declared.");
apCountMax++;
singleLabelings.reserve(apCountMax);
}
nameToLabelingMap[ap] = apsCurrent;
singleLabelings.push_back(storm::storage::BitVector(stateCount));
@ -226,9 +226,9 @@ public:
}
/*!
* Returns the number of atomic propositions managed by this object (set in the initialization).
*
* @return The number of atomic propositions.
* Returns the internal index of a given atomic proposition.
*
* @return The index of the atomic proposition.
*/
uint_fast64_t getIndexOfProposition(std::string const& ap) const {
if (!this->containsAtomicProposition(ap)) {
@ -300,7 +300,7 @@ public:
}
/*!
* Calculates a hash over all values contained in this Sparse Matrix.
* Calculates a hash over all values contained in this Atomic Proposition Labeling.
* @return size_t A Hash Value
*/
std::size_t getHash() const {

30
src/models/Dtmc.h

@ -39,8 +39,9 @@ public:
* @param probabilityMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalChoiceLabeling A vector that represents the labels associated with the choices of each state.
*/
Dtmc(storm::storage::SparseMatrix<T> const& probabilityMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
@ -65,8 +66,9 @@ public:
* @param probabilityMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalChoiceLabeling A vector that represents the labels associated with the choices of each state.
*/
Dtmc(storm::storage::SparseMatrix<T>&& probabilityMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
@ -224,6 +226,10 @@ public:
// 3. Take care of the labeling.
storm::models::AtomicPropositionsLabeling newLabeling = storm::models::AtomicPropositionsLabeling(this->getStateLabeling(), subSysStates);
newLabeling.addState();
if(!newLabeling.containsAtomicProposition("s_b")) {
newLabeling.addAtomicProposition("s_b");
}
newLabeling.addAtomicPropositionToState("s_b", newStateCount - 1);
// 4. Handle the optionals
@ -270,14 +276,26 @@ public:
newTransitionRewards = newTransRewards;
}
//What about choice labeling?? Not documented, not parsed, not used, but there?
boost::optional<std::vector<std::set<uint_fast64_t>>> newChoiceLabels;
if(this->hasChoiceLabels()) {
// Get the choice label sets and move the needed values to the front.
std::vector<std::set<uint_fast64_t>> newChoice(this->getChoiceLabeling());
storm::utility::vector::selectVectorValues(newChoice, subSysStates, newChoice);
// Throw away all values after the last state and set the choice label set for s_b as empty.
newChoice.resize(newStateCount);
newChoice[newStateCount - 1] = std::set<uint_fast64_t>();
newChoiceLabels = newChoice;
}
// 5. Make Dtmc from its parts and return it
return storm::models::Dtmc<T>(newMat,
newLabeling,
newStateRewards,
newTransitionRewards,
boost::optional<std::vector<std::set<uint_fast64_t>>>()
newChoiceLabels
);
}

21
src/parser/PrctlFileParser.cpp

@ -15,7 +15,8 @@ namespace parser {
std::list<storm::property::prctl::AbstractPrctlFormula<double>*> PrctlFileParser(std::string filename) {
// Open file
std::ifstream inputFileStream(filename, std::ios::in);
std::ifstream inputFileStream;
inputFileStream.open(filename, std::ios::in);
if (!inputFileStream.is_open()) {
std::string message = "Error while opening file ";
@ -24,16 +25,14 @@ std::list<storm::property::prctl::AbstractPrctlFormula<double>*> PrctlFileParser
std::list<storm::property::prctl::AbstractPrctlFormula<double>*> result;
while(!inputFileStream.eof()) {
std::string line;
//The while loop reads the input file line by line
while (std::getline(inputFileStream, line)) {
PrctlParser parser(line);
if (!parser.parsedComment()) {
//lines containing comments will be skipped.
LOG4CPLUS_INFO(logger, "Parsed formula \"" + line + "\" into \"" + parser.getFormula()->toString() + "\"");
result.push_back(parser.getFormula());
}
std::string line;
//The while loop reads the input file line by line
while (std::getline(inputFileStream, line)) {
PrctlParser parser(line);
if (!parser.parsedComment()) {
//lines containing comments will be skipped.
LOG4CPLUS_INFO(logger, "Parsed formula \"" + line + "\" into \"" + parser.getFormula()->toString() + "\"");
result.push_back(parser.getFormula());
}
}

6
src/storm.cpp

@ -337,7 +337,13 @@ void checkPrctlFormulae(storm::modelchecker::prctl::AbstractModelChecker<double>
// Now check if the model does not satisfy the formula.
// That is if there is at least one initial state of the model that does not.
// Also raise the logger threshold for the log file, so that the model check infos aren't logged (useless and there are lots of them)
// Lower it again after the model check.
logger.getAppender("mainFileAppender")->setThreshold(log4cplus::WARN_LOG_LEVEL);
storm::storage::BitVector result = stateForm.check(*createPrctlModelChecker(model));
logger.getAppender("mainFileAppender")->setThreshold(log4cplus::INFO_LOG_LEVEL);
if((result & model.getInitialStates()).getNumberOfSetBits() == model.getInitialStates().getNumberOfSetBits()) {
std::cout << "Formula is satisfied. Can not generate counterexample.\n\n" << std::endl;
LOG4CPLUS_INFO(logger, "Formula is satisfied. Can not generate counterexample.");

Loading…
Cancel
Save