Browse Source

Changed nodes implementation in Lattice

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

29
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,18 +69,16 @@ 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) {
@ -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