Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstink committed Aug 5, 2023
1 parent 669e19e commit 4001960
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 121 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build
install
docs/html
.vscode
examples/flight/mermaid.html

# Prerequisites
*.d
Expand Down
1 change: 1 addition & 0 deletions examples/flight/flight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "symmetri/parsers.h"
#include "symmetri/symmetri.h"
#include "symmetri/utilities.hpp"
#include "transition.hpp"

using namespace symmetri;
Expand Down
1 change: 1 addition & 0 deletions examples/hello_world/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <thread>

#include "symmetri/symmetri.h"
#include "symmetri/utilities.hpp"

// Before main, we define a bunch of functions that can be bound to
// transitions in the petri net.
Expand Down
1 change: 1 addition & 0 deletions examples/model_benchmark/model_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "symmetri/parsers.h"
#include "symmetri/symmetri.h"
#include "symmetri/utilities.hpp"

int main(int, char *argv[]) {
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%f] [%^%l%$] [thread %t] %v");
Expand Down
68 changes: 0 additions & 68 deletions symmetri/include/symmetri/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,72 +60,4 @@ using PriorityTable =
std::vector<std::pair<Transition, int8_t>>; ///< Priority is limited from
///< -128 to 127

/**
* @brief Checks if the markings are exactly the same. Note that this uses a
* different type for Marking compared to the Marking type used to
* construct a net (an unordered map of strings). In this format the amount of
* tokens in a particular place is represented by how often that place occurs in
* the vector. For example: {"A","A","B"} is a marking with two tokens in place
* "A" and one token in place "B". This format does not have the overhead of
* mentioning all empty places.
*
* @tparam T
* @param m1
* @param m2
* @return true
* @return false
*/
template <typename T>
bool MarkingEquality(const std::vector<T>& m1, const std::vector<T>& m2);

/**
* @brief Checks if marking is at least a subset of final_marking. Note
* that this uses a different type for Marking compared to the Marking
* type used to construct a net (an unordered map of strings). In this
* format the amount of tokens in a particular place is represented by how often
* that place occurs in the vector. For example: {"A","A","B"} is a marking with
* two tokens in place "A" and one token in place "B". This format does not have
* the overhead of mentioning all empty places.
*
* @tparam T
* @param marking
* @param final_marking
* @return true
* @return false
*/
template <typename T>
bool MarkingReached(const std::vector<T>& marking,
const std::vector<T>& final_marking);

/**
* @brief Checks if two petri-nets have equal amount of arcs between places
* and transitions of the same name.
*
* @param net1
* @param net2
* @return true
* @return false
*/
bool stateNetEquality(const Net& net1, const Net& net2);

/**
* @brief Calculates a hash given an event log. This hash is only influenced by
* the order of the completions of transitions and if the output of those
* transitions is Completed, or something else.
*
* @param event_log An eventlog, can both be from a terminated or a still active
* net.
* @return size_t The hashed result.
*/
size_t calculateTrace(const Eventlog& event_log) noexcept;

/**
* @brief A convenience function to get a string representation of the
* state-enum.
*
* @param s The State
* @return std::string The State as a human readable string.
*/
std::string printState(State s) noexcept;

} // namespace symmetri
93 changes: 93 additions & 0 deletions symmetri/include/symmetri/utilities.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#pragma once
#include "symmetri/types.h"

namespace symmetri {

/**
* @brief Checks if the markings are exactly the same. Note that this uses a
* different type for Marking compared to the Marking type used to
* construct a net (an unordered map of strings). In this format the amount of
* tokens in a particular place is represented by how often that place occurs in
* the vector. For example: {"A","A","B"} is a marking with two tokens in place
* "A" and one token in place "B". This format does not have the overhead of
* mentioning all empty places.
*
* @tparam T
* @param m1
* @param m2
* @return true
* @return false
*/
template <typename T>
bool MarkingEquality(const std::vector<T>& m1, const std::vector<T>& m2) {
auto m1_sorted = m1;
auto m2_sorted = m2;
std::sort(m1_sorted.begin(), m1_sorted.end());
std::sort(m2_sorted.begin(), m2_sorted.end());
return m1_sorted == m2_sorted;
}

/**
* @brief Checks if marking is at least a subset of final_marking. Note
* that this uses a different type for Marking compared to the Marking
* type used to construct a net (an unordered map of strings). In this
* format the amount of tokens in a particular place is represented by how often
* that place occurs in the vector. For example: {"A","A","B"} is a marking with
* two tokens in place "A" and one token in place "B". This format does not have
* the overhead of mentioning all empty places.
*
* @tparam T
* @param marking
* @param final_marking
* @return true
* @return false
*/
template <typename T>
bool MarkingReached(const std::vector<T>& marking,
const std::vector<T>& final_marking) {
if (final_marking.empty()) {
return false;
}
auto unique = final_marking;
std::sort(unique.begin(), unique.end());
auto last = std::unique(unique.begin(), unique.end());
unique.erase(last, unique.end());

return std::all_of(std::begin(unique), std::end(unique), [&](const auto& p) {
return std::count(marking.begin(), marking.end(), p) ==
std::count(final_marking.begin(), final_marking.end(), p);
});
}

/**
* @brief Checks if two petri-nets have equal amount of arcs between places
* and transitions of the same name.
*
* @param net1
* @param net2
* @return true
* @return false
*/
bool stateNetEquality(const Net& net1, const Net& net2);

/**
* @brief Calculates a hash given an event log. This hash is only influenced by
* the order of the completions of transitions and if the output of those
* transitions is Completed, or something else.
*
* @param event_log An eventlog, can both be from a terminated or a still active
* net.
* @return size_t The hashed result.
*/
size_t calculateTrace(const Eventlog& event_log) noexcept;

/**
* @brief A convenience function to get a string representation of the
* state-enum.
*
* @param s The State
* @return std::string The State as a human readable string.
*/
std::string printState(State s) noexcept;

} // namespace symmetri
1 change: 1 addition & 0 deletions symmetri/symmetri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "model.h"
#include "symmetri/parsers.h"
#include "symmetri/utilities.hpp"

namespace symmetri {

Expand Down
1 change: 1 addition & 0 deletions symmetri/tests/test_bugs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <condition_variable>

#include "model.h"
#include "symmetri/utilities.hpp"

using namespace symmetri;

Expand Down
2 changes: 2 additions & 0 deletions symmetri/tests/test_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <map>

#include "model.h"
#include "symmetri/utilities.hpp"

using namespace symmetri;
using namespace moodycamel;

Expand Down
2 changes: 2 additions & 0 deletions symmetri/tests/test_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <iostream>

#include "symmetri/parsers.h"
#include "symmetri/utilities.hpp"

using namespace symmetri;

TEST_CASE("Load p1.pnml net") {
Expand Down
2 changes: 2 additions & 0 deletions symmetri/tests/test_priorities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <list>

#include "model.h"
#include "symmetri/utilities.hpp"

using namespace symmetri;
using namespace moodycamel;

Expand Down
1 change: 1 addition & 0 deletions symmetri/tests/test_types.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp>

#include "symmetri/types.h"
#include "symmetri/utilities.hpp"

using namespace symmetri;

Expand Down
53 changes: 0 additions & 53 deletions symmetri/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,6 @@
#include <numeric>
namespace symmetri {

template <>
bool MarkingEquality<size_t>(const std::vector<size_t>& m1,
const std::vector<size_t>& m2) {
auto m1_sorted = m1;
auto m2_sorted = m2;
std::sort(m1_sorted.begin(), m1_sorted.end());
std::sort(m2_sorted.begin(), m2_sorted.end());
return m1_sorted == m2_sorted;
}
template <>
bool MarkingReached<size_t>(const std::vector<size_t>& marking,
const std::vector<size_t>& final_marking) {
if (final_marking.empty()) {
return false;
}
auto unique = final_marking;
std::sort(unique.begin(), unique.end());
auto last = std::unique(unique.begin(), unique.end());
unique.erase(last, unique.end());

return std::all_of(std::begin(unique), std::end(unique), [&](const auto& p) {
return std::count(marking.begin(), marking.end(), p) ==
std::count(final_marking.begin(), final_marking.end(), p);
});
}

template <>
bool MarkingEquality<std::string>(const std::vector<std::string>& m1,
const std::vector<std::string>& m2) {
auto m1_sorted = m1;
auto m2_sorted = m2;
std::sort(m1_sorted.begin(), m1_sorted.end());
std::sort(m2_sorted.begin(), m2_sorted.end());
return m1_sorted == m2_sorted;
}
template <>
bool MarkingReached<std::string>(
const std::vector<std::string>& marking,
const std::vector<std::string>& final_marking) {
if (final_marking.empty()) {
return false;
}
auto unique = final_marking;
std::sort(unique.begin(), unique.end());
auto last = std::unique(unique.begin(), unique.end());
unique.erase(last, unique.end());

return std::all_of(std::begin(unique), std::end(unique), [&](const auto& p) {
return std::count(marking.begin(), marking.end(), p) ==
std::count(final_marking.begin(), final_marking.end(), p);
});
}

bool stateNetEquality(const Net& net1, const Net& net2) {
if (net1.size() != net2.size()) {
return false;
Expand Down

0 comments on commit 4001960

Please sign in to comment.