|
|
@ -11,7 +11,7 @@ |
|
|
|
#include <pantheios/pantheios.hpp> |
|
|
|
#include <pantheios/inserters/integer.hpp> |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <ostream> |
|
|
|
|
|
|
|
#include "single_atomic_proposition_labeling.h" |
|
|
|
|
|
|
@ -51,115 +51,131 @@ class AtomicPropositionsLabeling { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
/*! Constructor creating an object of class labeling. |
|
|
|
* @param nodeCount The number of nodes; necessary for class AtomicProposition. |
|
|
|
* @param propositionCount The number of atomic propositions. |
|
|
|
//! Constructor |
|
|
|
/*! |
|
|
|
* Constructs an empty atomic propositions labeling for the given number |
|
|
|
* of states and amount of atomic propositions. |
|
|
|
* @param state_count The number of states of the model. |
|
|
|
* @param ap_count The number of atomic propositions. |
|
|
|
*/ |
|
|
|
AtomicPropositionsLabeling(const uint_fast32_t nodeCount, |
|
|
|
const uint_fast32_t propositionCount) { |
|
|
|
AtomicPropositionsLabeling(const uint_fast32_t state_count, |
|
|
|
const uint_fast32_t ap_count) { |
|
|
|
// add one for 1-bound indices |
|
|
|
node_count = nodeCount + 1; |
|
|
|
proposition_count = propositionCount; |
|
|
|
propositions_current = 0; |
|
|
|
propositions = new SingleAtomicPropositionLabeling*[proposition_count]; |
|
|
|
for (uint_fast32_t i = 0; i < proposition_count; ++i) { |
|
|
|
propositions[i] = new SingleAtomicPropositionLabeling(node_count); |
|
|
|
this->state_count = state_count + 1; |
|
|
|
this->ap_count = ap_count; |
|
|
|
this->aps_current = 0; |
|
|
|
this->single_labelings = new SingleAtomicPropositionLabeling*[ap_count]; |
|
|
|
for (uint_fast32_t i = 0; i < ap_count; ++i) { |
|
|
|
this->single_labelings[i] = new SingleAtomicPropositionLabeling(state_count); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//! Copy Constructor |
|
|
|
/*! Copy Constructor. Performs a deep copy of this Labeling object. |
|
|
|
* |
|
|
|
/*! |
|
|
|
* Copy Constructor. Performs a deep copy of the given atomic proposition |
|
|
|
* labeling. |
|
|
|
*/ |
|
|
|
AtomicPropositionsLabeling(const AtomicPropositionsLabeling& atomic_propositions_labeling) : |
|
|
|
node_count(atomic_propositions_labeling.node_count), proposition_count( |
|
|
|
atomic_propositions_labeling.proposition_count), propositions_current( |
|
|
|
atomic_propositions_labeling.propositions_current), proposition_map( |
|
|
|
atomic_propositions_labeling.proposition_map) { |
|
|
|
propositions = new SingleAtomicPropositionLabeling*[proposition_count]; |
|
|
|
for (uint_fast32_t i = 0; i < proposition_count; ++i) { |
|
|
|
propositions[i] = new SingleAtomicPropositionLabeling( |
|
|
|
*atomic_propositions_labeling.propositions[i]); |
|
|
|
state_count(atomic_propositions_labeling.state_count), |
|
|
|
ap_count(atomic_propositions_labeling.ap_count), |
|
|
|
aps_current(atomic_propositions_labeling.aps_current), |
|
|
|
name_to_labeling_map(atomic_propositions_labeling.name_to_labeling_map) { |
|
|
|
this->single_labelings = new SingleAtomicPropositionLabeling*[ap_count]; |
|
|
|
for (uint_fast32_t i = 0; i < ap_count; ++i) { |
|
|
|
this->single_labelings[i] = new SingleAtomicPropositionLabeling( |
|
|
|
*atomic_propositions_labeling.single_labelings[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//! Destructor |
|
|
|
/* |
|
|
|
* Destructor. Needs to take care of deleting all single labelings. |
|
|
|
*/ |
|
|
|
virtual ~AtomicPropositionsLabeling() { |
|
|
|
//deleting all the labeling vectors in the map. |
|
|
|
// delete all the single atomic proposition labelings in the map |
|
|
|
MAP<std::string, SingleAtomicPropositionLabeling*>::iterator it; |
|
|
|
for (uint_fast32_t i = 0; i < proposition_count; ++i) { |
|
|
|
delete propositions[i]; |
|
|
|
propositions[i] = NULL; |
|
|
|
for (uint_fast32_t i = 0; i < ap_count; ++i) { |
|
|
|
delete this->single_labelings[i]; |
|
|
|
this->single_labelings[i] = NULL; |
|
|
|
} |
|
|
|
delete[] propositions; |
|
|
|
propositions = NULL; |
|
|
|
delete[] this->single_labelings; |
|
|
|
this->single_labelings = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
/*! Registers the name of a proposition. |
|
|
|
* Will throw an error if more propositions are added than were initialized, |
|
|
|
* or if a proposition is registered twice. |
|
|
|
* @param proposition The name of the proposition to add. |
|
|
|
/*! |
|
|
|
* 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. |
|
|
|
* @param ap The name of the atomic proposition to add. |
|
|
|
* @return The index of the new proposition. |
|
|
|
*/ |
|
|
|
uint_fast32_t addProposition(std::string proposition) { |
|
|
|
if (proposition_map.count(proposition) != 0) { |
|
|
|
throw std::out_of_range("Proposition does already exist."); |
|
|
|
uint_fast32_t addAtomicProposition(std::string ap) { |
|
|
|
if (name_to_labeling_map.count(ap) != 0) { |
|
|
|
throw std::out_of_range("Atomic Proposition already exists."); |
|
|
|
} |
|
|
|
if (propositions_current >= proposition_count) { |
|
|
|
throw std::out_of_range("Added more propositions than initialized for"); |
|
|
|
if (aps_current >= ap_count) { |
|
|
|
throw std::out_of_range("Added more atomic propositions than" |
|
|
|
"previously declared."); |
|
|
|
} |
|
|
|
proposition_map[proposition] = propositions_current; |
|
|
|
name_to_labeling_map[ap] = aps_current; |
|
|
|
|
|
|
|
uint_fast32_t returnValue = propositions_current++; |
|
|
|
//pantheios::log_INFO("returning ", pantheios::integer(returnValue), " for position "); |
|
|
|
uint_fast32_t returnValue = aps_current++; |
|
|
|
return returnValue; |
|
|
|
} |
|
|
|
|
|
|
|
/*! Checks whether the name of a proposition is already registered with the labeling. |
|
|
|
/*! |
|
|
|
* Checks whether the name of an atomic proposition is already registered |
|
|
|
* within this labeling. |
|
|
|
* @return True if the proposition was added to the labeling, false otherwise. |
|
|
|
*/ |
|
|
|
bool containsProposition(std::string proposition) { |
|
|
|
return (proposition_map.count(proposition) != 0); |
|
|
|
bool containsAtomicProposition(std::string proposition) { |
|
|
|
return (name_to_labeling_map.count(proposition) != 0); |
|
|
|
} |
|
|
|
|
|
|
|
/*! Labels a node with an atomic proposition. |
|
|
|
* @param proposition The name of the proposition |
|
|
|
* @param node The index of the node to label |
|
|
|
/*! |
|
|
|
* Adds an atomic proposition to a given state. |
|
|
|
* @param ap The name of the atomic proposition. |
|
|
|
* @param node The index of the state to label. |
|
|
|
*/ |
|
|
|
void addLabelToNode(std::string proposition, const uint_fast32_t node) { |
|
|
|
//TODO (Thomas Heinemann): Differentiate exceptions? |
|
|
|
if (proposition_map.count(proposition) == 0) { |
|
|
|
throw std::out_of_range("Proposition does not exist."); |
|
|
|
void addAtomicPropositionToState(std::string ap, const uint_fast32_t state_index) { |
|
|
|
if (name_to_labeling_map.count(ap) == 0) { |
|
|
|
throw std::out_of_range("Atomic Proposition '" + ap + "' unknown."); |
|
|
|
} |
|
|
|
if (node >= node_count) { |
|
|
|
throw std::out_of_range("Node number out of range"); |
|
|
|
if (state_index >= state_count) { |
|
|
|
throw std::out_of_range("State index out of range."); |
|
|
|
} |
|
|
|
propositions[proposition_map[proposition]]->addLabelToNode(node); |
|
|
|
this->single_labelings[name_to_labeling_map[ap]]->addLabelToState(state_index); |
|
|
|
} |
|
|
|
|
|
|
|
/*! Checks whether a node is labeled with a proposition. |
|
|
|
* @param proposition The name of the proposition |
|
|
|
* @param node The index of the node |
|
|
|
* @return True if the node is labeled with the proposition, false otherwise. |
|
|
|
/*! |
|
|
|
* Checks whether a given state is labeled with the given atomic proposition. |
|
|
|
* @param ap The name of the atomic proposition. |
|
|
|
* @param state_index The index of the state to check. |
|
|
|
* @return True if the node is labeled with the atomic proposition, false |
|
|
|
* otherwise. |
|
|
|
*/ |
|
|
|
bool nodeHasProposition(std::string proposition, const uint_fast32_t node) { |
|
|
|
return propositions[proposition_map[proposition]]->hasNodeLabel(node); |
|
|
|
bool stateHasAtomicProposition(std::string ap, |
|
|
|
const uint_fast32_t state_index) { |
|
|
|
return this->single_labelings[name_to_labeling_map[ap]]->hasLabel(state_index); |
|
|
|
} |
|
|
|
|
|
|
|
/*! Returns the number of propositions managed by this object (which was set in the initialization) |
|
|
|
* @return The number of propositions. |
|
|
|
/*! |
|
|
|
* Returns the number of atomic propositions managed by this object (set in |
|
|
|
* the initialization). |
|
|
|
* @return The number of atomic propositions. |
|
|
|
*/ |
|
|
|
uint_fast32_t getNumberOfAtomicPropositions() { |
|
|
|
return proposition_count; |
|
|
|
return ap_count; |
|
|
|
} |
|
|
|
|
|
|
|
/*! This function provides direct access to an atomic_proposition class object |
|
|
|
* by its string identifier. This object manages the nodes that are labeled with the |
|
|
|
* respective atomic proposition. |
|
|
|
* @param proposition The name of the proposition. |
|
|
|
* @return A pointer to the atomic_proposition object of the proposition. |
|
|
|
/*! |
|
|
|
* Returns the labeling of states associated with the given atomic proposition. |
|
|
|
* @param ap The name of the atomic proposition. |
|
|
|
* @return A pointer to an instance of SingleAtomicPropositionLabeling that |
|
|
|
* represents the labeling of the states with the given atomic proposition. |
|
|
|
*/ |
|
|
|
SingleAtomicPropositionLabeling* getAtomicProposition(std::string proposition) { |
|
|
|
return (propositions[proposition_map[proposition]]); |
|
|
|
SingleAtomicPropositionLabeling* getAtomicProposition(std::string ap) { |
|
|
|
return (this->single_labelings[name_to_labeling_map[ap]]); |
|
|
|
} |
|
|
|
|
|
|
|
/*! |
|
|
@ -168,28 +184,59 @@ public: |
|
|
|
*/ |
|
|
|
uint_fast64_t getSizeInMemory() { |
|
|
|
uint_fast64_t size = sizeof(*this); |
|
|
|
for (uint_fast32_t i = 0; i < proposition_count; i++) { |
|
|
|
size += propositions[i]->getSizeInMemory(); // count sizes of bit vectors |
|
|
|
// add sizes of all single labelings |
|
|
|
for (uint_fast32_t i = 0; i < ap_count; i++) { |
|
|
|
size += this->single_labelings[i]->getSizeInMemory(); |
|
|
|
} |
|
|
|
return size; |
|
|
|
} |
|
|
|
|
|
|
|
void printAtomicPropositionsInformation() { |
|
|
|
std::cout << "Atomic Propositions: \t" << this->getNumberOfAtomicPropositions() << std::endl; |
|
|
|
for(auto ap : this->proposition_map) { |
|
|
|
std::cout << "\t * " << ap.first << " -> " << propositions[ap.second]->getNumberOfLabeledStates(); |
|
|
|
std::cout << " state(s)" << std::endl; |
|
|
|
/*! |
|
|
|
* Prints information about the labeling to the specified stream. |
|
|
|
* @param out The stream the information is to be printed to. |
|
|
|
*/ |
|
|
|
void printAtomicPropositionsInformationToStream(std::ostream& out) { |
|
|
|
out << "Atomic Propositions: \t" << this->getNumberOfAtomicPropositions() |
|
|
|
<< std::endl; |
|
|
|
for(auto ap : this->name_to_labeling_map) { |
|
|
|
out << "\t * " << ap.first << " -> " |
|
|
|
<< this->single_labelings[ap.second]->getNumberOfLabeledStates(); |
|
|
|
out << " state(s)" << std::endl; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
uint_fast32_t node_count, proposition_count, propositions_current; |
|
|
|
MAP<std::string, uint_fast32_t> proposition_map; |
|
|
|
SingleAtomicPropositionLabeling** propositions; |
|
|
|
|
|
|
|
/*! The number of states whose labels are to be stored by this object. */ |
|
|
|
uint_fast32_t state_count; |
|
|
|
|
|
|
|
/*! The number of different atomic propositions this object can store. */ |
|
|
|
uint_fast32_t ap_count; |
|
|
|
|
|
|
|
/*! |
|
|
|
* The number of different atomic propositions currently associated with |
|
|
|
* this labeling. Used to prevent too many atomic propositions from being |
|
|
|
* added to this object. |
|
|
|
*/ |
|
|
|
uint_fast32_t aps_current; |
|
|
|
|
|
|
|
/*! |
|
|
|
* Associates a name of an atomic proposition to its corresponding labeling |
|
|
|
* by mapping the name to a specific index in the array of all |
|
|
|
* individual labelings. |
|
|
|
*/ |
|
|
|
MAP<std::string, uint_fast32_t> name_to_labeling_map; |
|
|
|
|
|
|
|
/*! |
|
|
|
* Stores all individual labelings. To find the labeling associated with |
|
|
|
* a particular atomic proposition, the map from names to indices in this |
|
|
|
* array has to be used. |
|
|
|
*/ |
|
|
|
SingleAtomicPropositionLabeling** single_labelings; |
|
|
|
}; |
|
|
|
|
|
|
|
} //namespace models |
|
|
|
} // namespace models |
|
|
|
|
|
|
|
} //namespace mrmc |
|
|
|
} // namespace mrmc |
|
|
|
|
|
|
|
#endif /* MRMC_MODELS_ATOMIC_PROPOSITIONS_LABELING_H_ */ |