Browse Source

Make cyclic part faster

tempestpy_adaptions
Jip Spel 6 years ago
parent
commit
f41b61fb7b
  1. 12
      src/storm-pars-cli/storm-pars.cpp
  2. 93
      src/storm-pars/analysis/LatticeExtender.cpp
  3. 2
      src/storm-pars/analysis/LatticeExtender.h
  4. 1
      src/storm-pars/analysis/MonotonicityChecker.cpp
  5. 2
      src/storm-pars/analysis/MonotonicityChecker.h

12
src/storm-pars-cli/storm-pars.cpp

@ -563,6 +563,7 @@ namespace storm {
} }
if (parSettings.isSccEliminationSet()) { if (parSettings.isSccEliminationSet()) {
storm::utility::Stopwatch eliminationWatch(true);
// TODO: check for correct Model type // TODO: check for correct Model type
STORM_PRINT("Applying scc elimination" << std::endl); STORM_PRINT("Applying scc elimination" << std::endl);
auto sparseModel = model->as<storm::models::sparse::Model<ValueType>>(); auto sparseModel = model->as<storm::models::sparse::Model<ValueType>>();
@ -617,16 +618,11 @@ namespace storm {
auto keptRows = matrix.getRowFilter(selectedStates); auto keptRows = matrix.getRowFilter(selectedStates);
storm::storage::SparseMatrix<ValueType> newTransitionMatrix = flexibleMatrix.createSparseMatrix(keptRows, selectedStates); storm::storage::SparseMatrix<ValueType> newTransitionMatrix = flexibleMatrix.createSparseMatrix(keptRows, selectedStates);
// TODO: rewards get lost // TODO: rewards get lost
// obtain the reward model for the resulting system
// std::unordered_map<std::string, RewardModelType> rewardModels;
// if(rewardModelName) {
// storm::utility::vector::filterVectorInPlace(actionRewards, keptRows);
// rewardModels.insert(std::make_pair(*rewardModelName, RewardModelType(boost::none, std::move(actionRewards))));
// }
model = std::make_shared<storm::models::sparse::Dtmc<ValueType>>(std::move(newTransitionMatrix), sparseModel->getStateLabeling().getSubLabeling(selectedStates)); model = std::make_shared<storm::models::sparse::Dtmc<ValueType>>(std::move(newTransitionMatrix), sparseModel->getStateLabeling().getSubLabeling(selectedStates));
STORM_PRINT("SCC Elimination applied" << std::endl);
eliminationWatch.stop();
STORM_PRINT(std::endl << "Time for scc elimination: " << eliminationWatch << "." << std::endl << std::endl);
model->printModelInformationToStream(std::cout);
} }
if (parSettings.isMonotonicityAnalysisSet()) { if (parSettings.isMonotonicityAnalysisSet()) {

93
src/storm-pars/analysis/LatticeExtender.cpp

@ -112,6 +112,8 @@ namespace storm {
} }
} }
statesToHandle = initialMiddleStates;
// Create the Lattice // Create the Lattice
Lattice *lattice = new Lattice(topStates, bottomStates, initialMiddleStates, numberOfStates); Lattice *lattice = new Lattice(topStates, bottomStates, initialMiddleStates, numberOfStates);
@ -325,57 +327,70 @@ namespace storm {
} else if (!acyclic) { } else if (!acyclic) {
// TODO: kan dit niet efficienter // TODO: kan dit niet efficienter
for (auto stateNumber = 0; stateNumber < numberOfStates; stateNumber++) {
auto addedStates = lattice->getAddedStates();
// Iterate over all states
// auto stateNumber = i;
auto addedStates = lattice->getAddedStates();
if (assumptionSeen) {
statesToHandle = addedStates;
}
auto stateNumber = statesToHandle.getNextSetIndex(0);
while (stateNumber != numberOfStates) {
addedStates = lattice->getAddedStates();
storm::storage::BitVector successors = stateMap[stateNumber]; storm::storage::BitVector successors = stateMap[stateNumber];
// Checking for states which are already added to the lattice, and only have one successor left which haven't been added yet
auto succ1 = successors.getNextSetIndex(0);
auto succ2 = successors.getNextSetIndex(succ1 + 1);
// Check if current state has not been added yet, and all successors have
bool check = !addedStates[stateNumber];
for (auto succIndex = successors.getNextSetIndex(0);
check && succIndex != successors.size(); succIndex = successors.getNextSetIndex(
++succIndex)) {
// if the stateNumber equals succIndex we have a self-loop, ignoring selfloop as seenStates[stateNumber] = false
if (succIndex != stateNumber) {
check &= addedStates[succIndex];
assert (addedStates[stateNumber]);
if (successors.getNumberOfSetBits() == 2
&& ((addedStates[succ1] && !addedStates[succ2])
|| (!addedStates[succ1] && addedStates[succ2]))) {
if (!addedStates[succ1]) {
std::swap(succ1, succ2);
} }
}
if (check) {
auto result = extendAllSuccAdded(lattice, stateNumber, successors);
if (std::get<1>(result) != successors.size()) {
return result;
auto compare = lattice->compare(stateNumber, succ1);
if (compare == Lattice::ABOVE) {
lattice->addBetween(succ2, lattice->getTop(), lattice->getNode(stateNumber));
} else if (compare == Lattice::BELOW) {
lattice->addBetween(succ2, lattice->getNode(stateNumber), lattice->getBottom());
} else {
assert(false);
} }
statesToHandle.set(succ2);
statesToHandle.set(stateNumber, false);
stateNumber = statesToHandle.getNextSetIndex(0);
} else if (!((addedStates[succ1] && !addedStates[succ2])
|| (!addedStates[succ1] && addedStates[succ2]))) {
stateNumber = statesToHandle.getNextSetIndex(stateNumber + 1);
} else { } else {
// Checking for states which are already added to the lattice, and only have one successor left which haven't been added yet
auto succ1 = successors.getNextSetIndex(0);
auto succ2 = successors.getNextSetIndex(succ1 + 1);
if (addedStates[stateNumber] && successors.getNumberOfSetBits() == 2
&& ((addedStates[succ1] && !addedStates[succ2])
||(!addedStates[succ1] && addedStates[succ2]))) {
assert (successors.getNumberOfSetBits() == 2);
statesToHandle.set(stateNumber, false);
stateNumber = statesToHandle.getNextSetIndex(0);
}
}
if (!addedStates[succ1]) {
std::swap(succ1, succ2);
}
addedStates = lattice->getAddedStates();
for (auto stateNumber = addedStates.getNextUnsetIndex(0); stateNumber < numberOfStates; stateNumber = addedStates.getNextUnsetIndex(stateNumber + 1)) {
// Iterate over all not yet added states
storm::storage::BitVector successors = stateMap[stateNumber];
auto compare = lattice->compare(stateNumber, succ1);
if (compare == Lattice::ABOVE) {
lattice->addBetween(succ2, lattice->getTop(), lattice->getNode(stateNumber));
} else if (compare == Lattice::BELOW) {
lattice->addBetween(succ2, lattice->getNode(stateNumber), lattice->getBottom());
} else {
assert(false);
}
// Check if current state has not been added yet, and all successors have, ignore selfloop in this
successors.set(stateNumber, false);
if ((successors & addedStates) == successors) {
auto result = extendAllSuccAdded(lattice, stateNumber, successors);
if (std::get<1>(result) != successors.size()) {
return result;
} }
statesToHandle.set(stateNumber);
} }
} }
// if nothing changed, then add a state between top and bottom
// if nothing changed and there are states left, then add a state between top and bottom
if (oldNumberSet == lattice->getAddedStates().getNumberOfSetBits() && oldNumberSet != numberOfStates) { if (oldNumberSet == lattice->getAddedStates().getNumberOfSetBits() && oldNumberSet != numberOfStates) {
lattice->add(lattice->getAddedStates().getNextUnsetIndex(0));
auto stateNumber = lattice->getAddedStates().getNextUnsetIndex(0);
lattice->add(stateNumber);
statesToHandle.set(stateNumber);
} }
} }
} }

2
src/storm-pars/analysis/LatticeExtender.h

@ -60,6 +60,8 @@ namespace storm {
bool assumptionSeen; bool assumptionSeen;
storm::storage::BitVector statesToHandle;
void handleAssumption(Lattice* lattice, std::shared_ptr<storm::expressions::BinaryRelationExpression> assumption); void handleAssumption(Lattice* lattice, std::shared_ptr<storm::expressions::BinaryRelationExpression> assumption);
std::tuple<Lattice*, uint_fast64_t, uint_fast64_t> extendAllSuccAdded(Lattice* lattice, uint_fast64_t stateNumber, storm::storage::BitVector successors); std::tuple<Lattice*, uint_fast64_t, uint_fast64_t> extendAllSuccAdded(Lattice* lattice, uint_fast64_t stateNumber, storm::storage::BitVector successors);

1
src/storm-pars/analysis/MonotonicityChecker.cpp

@ -35,7 +35,6 @@ namespace storm {
this->model = model; this->model = model;
this->formulas = formulas; this->formulas = formulas;
this->validate = validate; this->validate = validate;
this->sccElimination = sccElimination;
this->resultCheckOnSamples = std::map<carl::Variable, std::pair<bool, bool>>(); this->resultCheckOnSamples = std::map<carl::Variable, std::pair<bool, bool>>();
if (model != nullptr) { if (model != nullptr) {
std::shared_ptr<storm::models::sparse::Model<ValueType>> sparseModel = model->as<storm::models::sparse::Model<ValueType>>(); std::shared_ptr<storm::models::sparse::Model<ValueType>> sparseModel = model->as<storm::models::sparse::Model<ValueType>>();

2
src/storm-pars/analysis/MonotonicityChecker.h

@ -72,8 +72,6 @@ namespace storm {
bool validate; bool validate;
bool sccElimination;
std::map<carl::Variable, std::pair<bool, bool>> resultCheckOnSamples; std::map<carl::Variable, std::pair<bool, bool>> resultCheckOnSamples;
storm::analysis::LatticeExtender<ValueType> *extender; storm::analysis::LatticeExtender<ValueType> *extender;

Loading…
Cancel
Save