Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Marking.cpp
Go to the documentation of this file.
1#include "Marking.h"
2
3#include <stdint.h>
4
5namespace storm {
6namespace gspn {
7Marking::Marking(uint_fast64_t const& numberOfPlaces, std::map<uint_fast64_t, uint_fast64_t> const& numberOfBits, uint_fast64_t const& numberOfTotalBits) {
8 this->numberOfPlaces = numberOfPlaces;
9 this->numberOfBits = numberOfBits;
10 this->marking = storm::storage::BitVector(numberOfTotalBits);
11}
12
13Marking::Marking(uint_fast64_t const& numberOfPlaces, std::map<uint_fast64_t, uint_fast64_t> const& numberOfBits, storm::storage::BitVector const& bitvector) {
14 this->numberOfPlaces = numberOfPlaces;
15 this->numberOfBits = numberOfBits;
16 this->marking = bitvector;
17}
18
19uint_fast64_t Marking::getNumberOfPlaces() const {
20 return this->numberOfPlaces;
21}
22
23void Marking::setNumberOfTokensAt(uint_fast64_t const& place, uint_fast64_t const& numberOfTokens) {
24 uint_fast64_t index = 0;
25 for (uint_fast64_t i = 0; i < place; ++i) {
26 index += numberOfBits[i];
27 }
28 marking.setFromInt(index, numberOfBits[place], numberOfTokens);
29}
30
31uint_fast64_t Marking::getNumberOfTokensAt(uint_fast64_t const& place) const {
32 uint_fast64_t index = 0;
33 for (uint_fast64_t i = 0; i < place; ++i) {
34 index += numberOfBits.at(i);
35 }
36 return marking.getAsInt(index, numberOfBits.at(place));
37}
38
39std::shared_ptr<storm::storage::BitVector> Marking::getBitVector() const {
40 auto result = std::make_shared<storm::storage::BitVector>();
41 *result = storm::storage::BitVector(marking);
42 return result;
43}
44
45bool Marking::operator==(const Marking& other) const {
46 if (getNumberOfPlaces() != other.getNumberOfPlaces()) {
47 return false;
48 }
49 if (&numberOfBits == &other.numberOfBits) {
50 return marking == other.marking;
51 }
52 for (uint_fast64_t i = 0; i < getNumberOfPlaces(); ++i) {
53 if (getNumberOfTokensAt(i) != other.getNumberOfTokensAt(i)) {
54 return false;
55 }
56 }
57 return true;
58}
59} // namespace gspn
60} // namespace storm
std::shared_ptr< storm::storage::BitVector > getBitVector() const
Returns a copy of the bitvector.
Definition Marking.cpp:39
uint_fast64_t getNumberOfPlaces() const
Retrieves the number of places for which the tokens are stored.
Definition Marking.cpp:19
Marking(uint_fast64_t const &numberOfPlaces, std::map< uint_fast64_t, uint_fast64_t > const &numberOfBits, uint_fast64_t const &numberOfTotalBits)
Creates an empty marking (at all places contain 0 tokens).
Definition Marking.cpp:7
bool operator==(const Marking &other) const
Overload equality operator.
Definition Marking.cpp:45
void setNumberOfTokensAt(uint_fast64_t const &place, uint_fast64_t const &numberOfTokens)
Set the number of tokens for the given place to the given amount.
Definition Marking.cpp:23
uint_fast64_t getNumberOfTokensAt(uint_fast64_t const &place) const
Get the number of tokens for the given place.
Definition Marking.cpp:31
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void setFromInt(uint_fast64_t bitIndex, uint_fast64_t numberOfBits, uint64_t value)
Sets the selected number of lowermost bits of the provided value at the given bit index.
uint_fast64_t getAsInt(uint_fast64_t bitIndex, uint_fast64_t numberOfBits) const
Retrieves the content of the current bit vector at the given index for the given number of bits as an...
LabParser.cpp.
Definition cli.cpp:18