Browse Source

Changed nodes implementation in Lattice

tempestpy_adaptions
Jip Spel 6 years ago
parent
commit
b782d80a26
  1. 35
      src/storm-pars/analysis/Lattice.cpp

35
src/storm-pars/analysis/Lattice.cpp

@ -8,17 +8,28 @@ namespace storm {
namespace analysis { namespace analysis {
Lattice::Lattice(storm::storage::BitVector topStates, Lattice::Lattice(storm::storage::BitVector topStates,
storm::storage::BitVector bottomStates, uint_fast64_t numberOfStates) { storm::storage::BitVector bottomStates, uint_fast64_t numberOfStates) {
Node *top = new Node(); Node *top = new Node();
top->states = topStates; top->states = topStates;
Node *bottom = new Node(); Node *bottom = new Node();
bottom->states = bottomStates; bottom->states = bottomStates;
top->below.push_back(bottom); top->below.push_back(bottom);
bottom->above.push_back(top); bottom->above.push_back(top);
nodes = std::vector<Node *>({top, bottom});
nodes = std::vector<Node *>(numberOfStates);
for (auto i = topStates.getNextSetIndex(0); i < numberOfStates; i = topStates.getNextSetIndex(i+1)) {
nodes.at(i) = top;
}
for (auto i = bottomStates.getNextSetIndex(0); i < numberOfStates; i = bottomStates.getNextSetIndex(i+1)) {
nodes.at(i) = bottom;
}
this->numberOfStates = numberOfStates; this->numberOfStates = numberOfStates;
} }
void Lattice::addBetween(uint_fast64_t state, Node *above, Node *below) { void Lattice::addBetween(uint_fast64_t state, Node *above, Node *below) {
std::cout << "Adding: " << state << std::endl;
Node *newNode = new Node(); Node *newNode = new Node();
newNode->states = storm::storage::BitVector(numberOfStates); newNode->states = storm::storage::BitVector(numberOfStates);
newNode->states.set(state); newNode->states.set(state);
@ -28,11 +39,12 @@ namespace storm {
remove(&(above->below), below); remove(&(above->below), below);
(below->above).push_back(newNode); (below->above).push_back(newNode);
above->below.push_back(newNode); above->below.push_back(newNode);
nodes.push_back(newNode);
nodes.at(state) = newNode;
} }
void Lattice::addToNode(uint_fast64_t state, Node *node) { void Lattice::addToNode(uint_fast64_t state, Node *node) {
node->states.set(state); node->states.set(state);
nodes.at(state) = node;
} }
int Lattice::compare(uint_fast64_t state1, uint_fast64_t state2) { int Lattice::compare(uint_fast64_t state1, uint_fast64_t state2) {
@ -57,23 +69,21 @@ namespace storm {
} }
Lattice::Node *Lattice::getNode(uint_fast64_t stateNumber) { Lattice::Node *Lattice::getNode(uint_fast64_t stateNumber) {
Node *node;
for (auto itr = nodes.begin(); itr != nodes.end(); ++itr) {
storm::storage::BitVector states = (*itr)->states;
if (states[stateNumber]) return (*itr);
}
return node;
return nodes.at(stateNumber);
} }
void Lattice::toString(std::ostream &out) { void Lattice::toString(std::ostream &out) {
std::vector<Node*> printedNodes = std::vector<Node*>({});
for (auto itr = nodes.begin(); itr != nodes.end(); ++itr) { for (auto itr = nodes.begin(); itr != nodes.end(); ++itr) {
if (std::find(printedNodes.begin(), printedNodes.end(), (*itr)) == printedNodes.end()) {
Node *node = *itr; Node *node = *itr;
printedNodes.push_back(*itr);
out << "Node: {"; out << "Node: {";
uint_fast64_t index = node->states.getNextSetIndex(0); uint_fast64_t index = node->states.getNextSetIndex(0);
while (index < numberOfStates) { while (index < numberOfStates) {
out << index; out << index;
index = node->states.getNextSetIndex(index+1);
index = node->states.getNextSetIndex(index + 1);
if (index < numberOfStates) { if (index < numberOfStates) {
out << ", "; out << ", ";
} }
@ -87,7 +97,7 @@ namespace storm {
index = above->states.getNextSetIndex(0); index = above->states.getNextSetIndex(0);
while (index < numberOfStates) { while (index < numberOfStates) {
out << index; out << index;
index = above->states.getNextSetIndex(index+1);
index = above->states.getNextSetIndex(index + 1);
if (index < numberOfStates) { if (index < numberOfStates) {
out << ", "; out << ", ";
} }
@ -107,7 +117,7 @@ namespace storm {
index = below->states.getNextSetIndex(0); index = below->states.getNextSetIndex(0);
while (index < numberOfStates) { while (index < numberOfStates) {
out << index; out << index;
index = below->states.getNextSetIndex(index+1);
index = below->states.getNextSetIndex(index + 1);
if (index < numberOfStates) { if (index < numberOfStates) {
out << ", "; out << ", ";
} }
@ -121,6 +131,7 @@ namespace storm {
out << "}" << "\n"; out << "}" << "\n";
} }
} }
}
bool Lattice::above(Node *node1, Node *node2) { bool Lattice::above(Node *node1, Node *node2) {
bool result = !node1->below.empty() && std::find(node1->below.begin(), node1->below.end(), node2) != node1->below.end(); bool result = !node1->below.empty() && std::find(node1->below.begin(), node1->below.end(), node2) != node1->below.end();

Loading…
Cancel
Save