Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add failure tokens to marking incase transitions fail with such a case #54

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions symmetri/petri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ void Petri::fireSynchronous(const size_t t) {
switch (result) {
case Color::Scheduled:
case Color::Started:
case Color::Deadlocked:
case Color::Canceled:
case Color::Paused:
case Color::Failed:
break;
default: {
tokens.reserve(tokens.size() + lookup_t.size());
Expand Down
3 changes: 0 additions & 3 deletions symmetri/petri_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ Reducer createReducerForCallback(const size_t t_i, const Token result,
switch (result) {
case Color::Scheduled:
case Color::Started:
case Color::Deadlocked:
case Color::Canceled:
case Color::Paused:
case Color::Failed:
break;
default: {
const auto &place_list = model.net.output_n[t_i];
Expand Down
34 changes: 34 additions & 0 deletions symmetri/tests/symmetri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@ TEST_CASE("Can not reuse an active application with a new case_id.") {
fire(app);
}

TEST_CASE("Deadlocked transition shows up in marking") {
auto [net, priority, initial_marking] = SymmetriTestNet();
Marking goal_marking = {};
const auto initial_id = "deadlock transition";
auto threadpool = std::make_shared<TaskSystem>(1);
PetriNet app(net, initial_id, threadpool, initial_marking, goal_marking,
priority);
app.registerCallback("t0", [] { return Color::Deadlocked; });
fire(app);
const auto marking = app.getMarking();
const bool has_deadlock_token =
std::find_if(marking.cbegin(), marking.cend(), [=](const auto& pc) {
return Color::Deadlocked == pc.second && pc.first == "Pc";
}) != marking.end();
CHECK(has_deadlock_token);
}

TEST_CASE("Error'd transition shows up in marking") {
auto [net, priority, initial_marking] = SymmetriTestNet();
Marking goal_marking = {};
const auto initial_id = "deadlock transition";
auto threadpool = std::make_shared<TaskSystem>(1);
PetriNet app(net, initial_id, threadpool, initial_marking, goal_marking,
priority);
app.registerCallback("t0", [] { return Color::Failed; });
fire(app);
const auto marking = app.getMarking();
const bool has_failed_token =
std::find_if(marking.cbegin(), marking.cend(), [=](const auto& pc) {
return Color::Failed == pc.second && pc.first == "Pc";
}) != marking.end();
CHECK(has_failed_token);
}

TEST_CASE("Test pause and resume") {
std::atomic<int> i = 0;
Net net = {{"t0", {{{"Pa", Color::Success}}, {{"Pa", Color::Success}}}},
Expand Down