From eab03396392edcd43efb0aebd0af123711461e56 Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Mon, 7 Oct 2024 19:10:26 +0200 Subject: [PATCH 1/9] fixed unfolding --- .gitignore | 1 + include/PetriEngine/Colored/ArcIntervalVisitor.h | 8 +++++--- include/PetriEngine/Colored/ArcIntervals.h | 2 +- src/PetriEngine/Colored/IntervalGenerator.cpp | 5 +++-- src/PetriEngine/Colored/PartitionBuilder.cpp | 3 +-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8d835a83a..19716c6a4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ nbproject/ cmake-build-* .idea/ +.vscode src/PetriEngine/PQL/PQLQueryParser.parser.cpp src/PetriEngine/PQL/PQLQueryParser.parser.hpp src/PetriEngine/PQL/PQLQueryTokens.lexer.cpp diff --git a/include/PetriEngine/Colored/ArcIntervalVisitor.h b/include/PetriEngine/Colored/ArcIntervalVisitor.h index 4c5c1ce38..6a9d962e1 100644 --- a/include/PetriEngine/Colored/ArcIntervalVisitor.h +++ b/include/PetriEngine/Colored/ArcIntervalVisitor.h @@ -195,10 +195,12 @@ namespace PetriEngine { return; } - old_intervals._intervalTupleVec.insert( - old_intervals._intervalTupleVec.end(), - _arcIntervals._intervalTupleVec.begin(), _arcIntervals._intervalTupleVec.end()); } + + old_intervals._intervalTupleVec.insert( + old_intervals._intervalTupleVec.end(), + _arcIntervals._intervalTupleVec.begin(), _arcIntervals._intervalTupleVec.end()); + std::swap(old_intervals, _arcIntervals); } diff --git a/include/PetriEngine/Colored/ArcIntervals.h b/include/PetriEngine/Colored/ArcIntervals.h index b382c1d4e..d950e1dc6 100644 --- a/include/PetriEngine/Colored/ArcIntervals.h +++ b/include/PetriEngine/Colored/ArcIntervals.h @@ -39,7 +39,7 @@ namespace PetriEngine { : _varIndexModMap(std::move(varIndexModMap)), _intervalTupleVec(std::move(ranges)) { }; - void print() { + void print() const { std::cout << "[ "; for(auto& varModifierPair : _varIndexModMap){ std::cout << "(" << varModifierPair.first->name << ", " << varModifierPair.first->colorType->productSize() << ") "; diff --git a/src/PetriEngine/Colored/IntervalGenerator.cpp b/src/PetriEngine/Colored/IntervalGenerator.cpp index 042996ccc..76982053d 100644 --- a/src/PetriEngine/Colored/IntervalGenerator.cpp +++ b/src/PetriEngine/Colored/IntervalGenerator.cpp @@ -23,8 +23,7 @@ namespace PetriEngine { std::vector IntervalGenerator::getIntervalsFromInterval(const interval_t &interval, uint32_t varPosition, int32_t varModifier, const std::vector &varColorTypes) { std::vector varIntervals; - interval_t firstVarInterval; - varIntervals.push_back(firstVarInterval); + varIntervals.emplace_back(); for(uint32_t i = varPosition; i < varPosition + varColorTypes.size(); i++){ auto ctSize = varColorTypes[i - varPosition]->size(); int32_t lower_val = ctSize + (interval[i]._lower + varModifier); @@ -131,6 +130,8 @@ namespace PetriEngine { interval_vector_t varIntervals; std::vector varColorTypes; pair.first->colorType->getColortypes(varColorTypes); + + assert(pair.second.size() > tuplePos); getArcVarIntervals(varIntervals, pair.second[tuplePos], interval, varColorTypes); if(arcIntervals._intervalTupleVec.size() > 1 && pair.second[tuplePos].empty()){ diff --git a/src/PetriEngine/Colored/PartitionBuilder.cpp b/src/PetriEngine/Colored/PartitionBuilder.cpp index 451dc6553..06a40ab74 100644 --- a/src/PetriEngine/Colored/PartitionBuilder.cpp +++ b/src/PetriEngine/Colored/PartitionBuilder.cpp @@ -422,8 +422,7 @@ namespace PetriEngine { const VariableModifierMap &varModifierMap, const EquivalenceClass& eqClass , const Arc *arc, uint32_t placeId){ std::vector varMaps; - VariableIntervalMap varMap; - varMaps.push_back(varMap); + varMaps.emplace_back(); std::unordered_map placeArcIntervals; ColorFixpoint postPlaceFixpoint; postPlaceFixpoint.constraints = eqClass.intervals(); From f9b444727691a845c2b8acbf67dd73333c74b0db Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Fri, 11 Oct 2024 14:59:41 +0200 Subject: [PATCH 2/9] fixed unfolding --- include/PetriEngine/Colored/ArcIntervalVisitor.h | 7 +++---- src/PetriEngine/Colored/IntervalGenerator.cpp | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/PetriEngine/Colored/ArcIntervalVisitor.h b/include/PetriEngine/Colored/ArcIntervalVisitor.h index 6a9d962e1..64d5f8ee2 100644 --- a/include/PetriEngine/Colored/ArcIntervalVisitor.h +++ b/include/PetriEngine/Colored/ArcIntervalVisitor.h @@ -195,11 +195,10 @@ namespace PetriEngine { return; } + old_intervals._intervalTupleVec.insert( + old_intervals._intervalTupleVec.end(), + _arcIntervals._intervalTupleVec.begin(), _arcIntervals._intervalTupleVec.end()); } - - old_intervals._intervalTupleVec.insert( - old_intervals._intervalTupleVec.end(), - _arcIntervals._intervalTupleVec.begin(), _arcIntervals._intervalTupleVec.end()); std::swap(old_intervals, _arcIntervals); } diff --git a/src/PetriEngine/Colored/IntervalGenerator.cpp b/src/PetriEngine/Colored/IntervalGenerator.cpp index 76982053d..f0d5e27ce 100644 --- a/src/PetriEngine/Colored/IntervalGenerator.cpp +++ b/src/PetriEngine/Colored/IntervalGenerator.cpp @@ -26,6 +26,7 @@ namespace PetriEngine { varIntervals.emplace_back(); for(uint32_t i = varPosition; i < varPosition + varColorTypes.size(); i++){ auto ctSize = varColorTypes[i - varPosition]->size(); + assert(i < interval.size()); int32_t lower_val = ctSize + (interval[i]._lower + varModifier); int32_t upper_val = ctSize + (interval[i]._upper + varModifier); uint32_t lower = lower_val % ctSize; From 994a40e69b428cff510c1f1708dafd80a2e239d0 Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Fri, 11 Oct 2024 15:02:41 +0200 Subject: [PATCH 3/9] fixed unfolding --- include/PetriEngine/Colored/VariableVisitor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/PetriEngine/Colored/VariableVisitor.h b/include/PetriEngine/Colored/VariableVisitor.h index 9afbe7eca..6b7bb3e42 100644 --- a/include/PetriEngine/Colored/VariableVisitor.h +++ b/include/PetriEngine/Colored/VariableVisitor.h @@ -206,12 +206,12 @@ namespace PetriEngine { virtual void accept(const AddExpression* add) { for (const auto& elem : *add) { - for(auto& pair : _varModifiers){ - std::unordered_map newMap; - pair.second.push_back(newMap); - } _index = 0; + size_t _modifierSizeBefore = _varModifiers.size(); elem->visit(*this); + for (auto it = std::next(_varModifiers.begin(), _modifierSizeBefore); it != _varModifiers.end(); ++it){ + it->second.emplace_back(); + } } } From a79ed67a93229febf4b92c833c77ae78bcd24a1c Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Fri, 11 Oct 2024 15:04:37 +0200 Subject: [PATCH 4/9] revert --- include/PetriEngine/Colored/ArcIntervalVisitor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/PetriEngine/Colored/ArcIntervalVisitor.h b/include/PetriEngine/Colored/ArcIntervalVisitor.h index 64d5f8ee2..4c5c1ce38 100644 --- a/include/PetriEngine/Colored/ArcIntervalVisitor.h +++ b/include/PetriEngine/Colored/ArcIntervalVisitor.h @@ -199,7 +199,6 @@ namespace PetriEngine { old_intervals._intervalTupleVec.end(), _arcIntervals._intervalTupleVec.begin(), _arcIntervals._intervalTupleVec.end()); } - std::swap(old_intervals, _arcIntervals); } From 1fef11343100bd0d855a5539b6dea1fff6b9ae40 Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Fri, 11 Oct 2024 17:53:58 +0200 Subject: [PATCH 5/9] fixed test failing --- include/PetriEngine/Colored/VariableVisitor.h | 17 ++++++++++++++--- src/PetriEngine/Colored/IntervalGenerator.cpp | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/PetriEngine/Colored/VariableVisitor.h b/include/PetriEngine/Colored/VariableVisitor.h index 6b7bb3e42..f8a15e514 100644 --- a/include/PetriEngine/Colored/VariableVisitor.h +++ b/include/PetriEngine/Colored/VariableVisitor.h @@ -205,12 +205,23 @@ namespace PetriEngine { virtual void accept(const AddExpression* add) { + bool lastIsVarExpr = false; for (const auto& elem : *add) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } + _index = 0; - size_t _modifierSizeBefore = _varModifiers.size(); + size_t sizeBefore = _varModifiers.size(); elem->visit(*this); - for (auto it = std::next(_varModifiers.begin(), _modifierSizeBefore); it != _varModifiers.end(); ++it){ - it->second.emplace_back(); + size_t sizeAfter = _varModifiers.size(); + + lastIsVarExpr = sizeBefore != sizeAfter; + } + + if (lastIsVarExpr) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); } } } diff --git a/src/PetriEngine/Colored/IntervalGenerator.cpp b/src/PetriEngine/Colored/IntervalGenerator.cpp index f0d5e27ce..d1b5f05e2 100644 --- a/src/PetriEngine/Colored/IntervalGenerator.cpp +++ b/src/PetriEngine/Colored/IntervalGenerator.cpp @@ -24,9 +24,9 @@ namespace PetriEngine { std::vector IntervalGenerator::getIntervalsFromInterval(const interval_t &interval, uint32_t varPosition, int32_t varModifier, const std::vector &varColorTypes) { std::vector varIntervals; varIntervals.emplace_back(); + assert(varPosition + varColorTypes.size() <= interval.size()); for(uint32_t i = varPosition; i < varPosition + varColorTypes.size(); i++){ auto ctSize = varColorTypes[i - varPosition]->size(); - assert(i < interval.size()); int32_t lower_val = ctSize + (interval[i]._lower + varModifier); int32_t upper_val = ctSize + (interval[i]._upper + varModifier); uint32_t lower = lower_val % ctSize; @@ -89,6 +89,7 @@ namespace PetriEngine { interval_vector_t varIntervals; std::vector varColorTypes; pair.first->colorType->getColortypes(varColorTypes); + assert(pair.second.size() > tuplePos); getArcVarIntervals(varIntervals, pair.second[tuplePos], interval, varColorTypes); From 59344215d92ccef33d586c140c617f25e835e25b Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Sat, 19 Oct 2024 16:56:20 +0200 Subject: [PATCH 6/9] Fixed river, and now ignores redundant subtractions instead of throwing error --- include/PetriEngine/Colored/VariableVisitor.h | 16 ++++++++++++++++ src/PetriEngine/Colored/EvaluationVisitor.cpp | 2 -- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/PetriEngine/Colored/VariableVisitor.h b/include/PetriEngine/Colored/VariableVisitor.h index f8a15e514..48e3e9a12 100644 --- a/include/PetriEngine/Colored/VariableVisitor.h +++ b/include/PetriEngine/Colored/VariableVisitor.h @@ -228,12 +228,28 @@ namespace PetriEngine { virtual void accept(const SubtractExpression* sub) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } _index = 0; (*sub)[0]->visit(*this); //We ignore the restrictions imposed by the subtraction for now if(_include_subtracts){ + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } _index = 0; + size_t sizeBefore = _varModifiers.size(); (*sub)[1]->visit(*this); + size_t sizeAfter = _varModifiers.size(); + + bool lastIsVarExpr = sizeBefore != sizeAfter; + + if (lastIsVarExpr) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } + } } } diff --git a/src/PetriEngine/Colored/EvaluationVisitor.cpp b/src/PetriEngine/Colored/EvaluationVisitor.cpp index f7ac8a6a1..d94292d37 100644 --- a/src/PetriEngine/Colored/EvaluationVisitor.cpp +++ b/src/PetriEngine/Colored/EvaluationVisitor.cpp @@ -129,8 +129,6 @@ namespace PetriEngine { (*sub)[0]->visit(*this); auto lhs = _mres; (*sub)[1]->visit(*this); - if (!_mres.isSubsetOf(lhs)) - throw base_error("RHS of subtraction is not a subset of LHS"); _mres = lhs - _mres; } From 8f259ad801fe2785efa348edb5028d087ed52200 Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Tue, 29 Oct 2024 00:32:59 +0100 Subject: [PATCH 7/9] Updated to now correctly check if right most element is a var or if its a tuple including a var --- include/PetriEngine/Colored/Expressions.h | 26 +++++-- include/PetriEngine/Colored/VariableVisitor.h | 72 +++++++++++++------ 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/include/PetriEngine/Colored/Expressions.h b/include/PetriEngine/Colored/Expressions.h index 35cdd738c..5d12dec99 100644 --- a/include/PetriEngine/Colored/Expressions.h +++ b/include/PetriEngine/Colored/Expressions.h @@ -55,6 +55,10 @@ namespace PetriEngine { ColorExpression() {} virtual ~ColorExpression() {} virtual const ColorType* getColorType(const ColorTypeMap& colorTypes) const = 0; + virtual bool is_variable() const { return false; } + virtual bool is_predecessor() const { return false; } + virtual bool is_successor() const { return false; } + virtual bool is_tuple() const { return false; } }; class DotConstantExpression : public ColorExpression { @@ -85,6 +89,7 @@ namespace PetriEngine { return _variable->colorType; } + bool is_variable() const override { return true; } }; class UserOperatorExpression : public ColorExpression { @@ -113,6 +118,8 @@ namespace PetriEngine { return _color; } + bool is_successor() const override { return true; } + SuccessorExpression(ColorExpression_ptr&& color) : _color(std::move(color)) {} @@ -131,6 +138,8 @@ namespace PetriEngine { return _color; } + bool is_predecessor() const override { return true; } + PredecessorExpression(ColorExpression_ptr&& color) : _color(std::move(color)) {} @@ -151,6 +160,8 @@ namespace PetriEngine { return _colors.size(); } + bool is_tuple() const override { return true; } + auto begin() const { return _colors.begin(); } @@ -285,6 +296,7 @@ namespace PetriEngine { virtual void visit(ColorExpressionVisitor& visitor) const = 0; virtual uint32_t weight() const = 0; virtual bool is_single_color() const = 0; + virtual bool is_number_of() const { return false; } }; typedef std::shared_ptr ArcExpression_ptr; @@ -322,10 +334,12 @@ namespace PetriEngine { return _number * _color.size(); } - bool is_single_color() const { + bool is_single_color() const override { return _color.size() == 1; } + bool is_number_of() const override { return true; } + uint32_t number() const { return _number; } @@ -346,6 +360,10 @@ namespace PetriEngine { return _color.end(); } + auto back() const { + return _color.back(); + } + NumberOfExpression(std::vector&& color, uint32_t number = 1) : _number(number), _color(std::move(color)) {} NumberOfExpression(AllExpression_ptr&& all, uint32_t number = 1) @@ -368,7 +386,7 @@ namespace PetriEngine { return res; } - bool is_single_color() const { + bool is_single_color() const override { return _constituents.size() == 1 && _constituents[0]->is_single_color(); } @@ -404,7 +422,7 @@ namespace PetriEngine { return _left->weight() - _right->weight(); } - bool is_single_color() const { + bool is_single_color() const override { return false; } @@ -434,7 +452,7 @@ namespace PetriEngine { return _scalar * _expr->weight(); } - bool is_single_color() const { + bool is_single_color() const override { return _expr->is_single_color(); } diff --git a/include/PetriEngine/Colored/VariableVisitor.h b/include/PetriEngine/Colored/VariableVisitor.h index 48e3e9a12..56e0491ed 100644 --- a/include/PetriEngine/Colored/VariableVisitor.h +++ b/include/PetriEngine/Colored/VariableVisitor.h @@ -29,6 +29,8 @@ #ifndef VARIABLESVISITOR_H #define VARIABLESVISITOR_H +#include + #include "Expressions.h" #include "Colors.h" @@ -205,23 +207,28 @@ namespace PetriEngine { virtual void accept(const AddExpression* add) { - bool lastIsVarExpr = false; - for (const auto& elem : *add) { - for (auto& pair : _varModifiers) { - pair.second.emplace_back(); - } + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } - _index = 0; - size_t sizeBefore = _varModifiers.size(); - elem->visit(*this); - size_t sizeAfter = _varModifiers.size(); + _index = 0; + (*add)[0]->visit(*this); - lastIsVarExpr = sizeBefore != sizeAfter; + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); } + + if (add->size() < 2) return; - if (lastIsVarExpr) { - for (auto& pair : _varModifiers) { - pair.second.emplace_back(); + _index = 0; + (*add)[1]->visit(*this); + + if ((*add)[1]->is_number_of()) { + auto numberOfExpr = std::static_pointer_cast((*add)[1]); + if (is_last_variable_expr(numberOfExpr->back())) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } } } } @@ -239,15 +246,14 @@ namespace PetriEngine { pair.second.emplace_back(); } _index = 0; - size_t sizeBefore = _varModifiers.size(); (*sub)[1]->visit(*this); - size_t sizeAfter = _varModifiers.size(); - - bool lastIsVarExpr = sizeBefore != sizeAfter; - if (lastIsVarExpr) { - for (auto& pair : _varModifiers) { - pair.second.emplace_back(); + if ((*sub)[1]->is_number_of()) { + auto numberOfExpr = std::static_pointer_cast((*sub)[1]); + if (is_last_variable_expr(numberOfExpr->back())) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } } } } @@ -289,6 +295,32 @@ namespace PetriEngine { get_variables(e, variables, varPositions, varModifierMap, tuples, false); } + + private: + bool is_last_variable_expr(const std::shared_ptr expr) const { + std::stack> stack; + stack.push(expr); + + while (!stack.empty()) { + auto currentExpr = stack.top(); + stack.pop(); + + if (currentExpr->is_variable()) { + return true; + } else if (currentExpr->is_predecessor()) { + stack.push(std::static_pointer_cast(currentExpr)->child()); + } else if (currentExpr->is_successor()) { + stack.push(std::static_pointer_cast(currentExpr)->child()); + } else if (currentExpr->is_tuple()) { + auto tupleExpr = std::static_pointer_cast(currentExpr); + for (const auto& tupleElem : *tupleExpr) { + stack.push(tupleElem); + } + } + } + + return false; + } }; } } From de885ef6711b3637a499ff64a114bc0f9bf2a467 Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Tue, 29 Oct 2024 14:24:27 +0100 Subject: [PATCH 8/9] now works for lamport test net --- include/PetriEngine/Colored/Expressions.h | 4 +++ include/PetriEngine/Colored/VariableVisitor.h | 25 +++++++------------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/PetriEngine/Colored/Expressions.h b/include/PetriEngine/Colored/Expressions.h index 5d12dec99..74105433a 100644 --- a/include/PetriEngine/Colored/Expressions.h +++ b/include/PetriEngine/Colored/Expressions.h @@ -406,6 +406,10 @@ namespace PetriEngine { return _constituents.end(); } + auto back() const { + return _constituents.back(); + } + AddExpression(std::vector &&constituents) : _constituents(std::move(constituents)) {} diff --git a/include/PetriEngine/Colored/VariableVisitor.h b/include/PetriEngine/Colored/VariableVisitor.h index 56e0491ed..249ec6da3 100644 --- a/include/PetriEngine/Colored/VariableVisitor.h +++ b/include/PetriEngine/Colored/VariableVisitor.h @@ -207,24 +207,17 @@ namespace PetriEngine { virtual void accept(const AddExpression* add) { - for (auto& pair : _varModifiers) { - pair.second.emplace_back(); - } - - _index = 0; - (*add)[0]->visit(*this); - - for (auto& pair : _varModifiers) { - pair.second.emplace_back(); + for (const auto& elem : *add) { + for (auto& pair : _varModifiers) { + pair.second.emplace_back(); + } + + _index = 0; + elem->visit(*this); } - - if (add->size() < 2) return; - - _index = 0; - (*add)[1]->visit(*this); - if ((*add)[1]->is_number_of()) { - auto numberOfExpr = std::static_pointer_cast((*add)[1]); + if (add->back()->is_number_of()) { + auto numberOfExpr = std::static_pointer_cast(add->back()); if (is_last_variable_expr(numberOfExpr->back())) { for (auto& pair : _varModifiers) { pair.second.emplace_back(); From e3a19fedc21ab40acce0fab8ad8330eb5d4395e0 Mon Sep 17 00:00:00 2001 From: Mikkel Tygesen Date: Wed, 6 Nov 2024 16:38:10 +0100 Subject: [PATCH 9/9] Optimizations to avoid unnecessary copies and ownership transfers --- include/PetriEngine/Colored/Expressions.h | 4 ++-- include/PetriEngine/Colored/VariableVisitor.h | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/PetriEngine/Colored/Expressions.h b/include/PetriEngine/Colored/Expressions.h index 74105433a..25ece30ec 100644 --- a/include/PetriEngine/Colored/Expressions.h +++ b/include/PetriEngine/Colored/Expressions.h @@ -360,7 +360,7 @@ namespace PetriEngine { return _color.end(); } - auto back() const { + auto& back() const { return _color.back(); } @@ -406,7 +406,7 @@ namespace PetriEngine { return _constituents.end(); } - auto back() const { + auto& back() const { return _constituents.back(); } diff --git a/include/PetriEngine/Colored/VariableVisitor.h b/include/PetriEngine/Colored/VariableVisitor.h index 249ec6da3..04e0aa573 100644 --- a/include/PetriEngine/Colored/VariableVisitor.h +++ b/include/PetriEngine/Colored/VariableVisitor.h @@ -217,8 +217,8 @@ namespace PetriEngine { } if (add->back()->is_number_of()) { - auto numberOfExpr = std::static_pointer_cast(add->back()); - if (is_last_variable_expr(numberOfExpr->back())) { + const auto& numberOfExpr = std::static_pointer_cast(add->back()); + if (is_last_variable_expr(*numberOfExpr->back())) { for (auto& pair : _varModifiers) { pair.second.emplace_back(); } @@ -242,8 +242,8 @@ namespace PetriEngine { (*sub)[1]->visit(*this); if ((*sub)[1]->is_number_of()) { - auto numberOfExpr = std::static_pointer_cast((*sub)[1]); - if (is_last_variable_expr(numberOfExpr->back())) { + const auto& numberOfExpr = std::static_pointer_cast((*sub)[1]); + if (is_last_variable_expr(*numberOfExpr->back())) { for (auto& pair : _varModifiers) { pair.second.emplace_back(); } @@ -290,24 +290,24 @@ namespace PetriEngine { } private: - bool is_last_variable_expr(const std::shared_ptr expr) const { - std::stack> stack; - stack.push(expr); + bool is_last_variable_expr(const ColorExpression& expr) const { + std::stack stack; + stack.push(&expr); while (!stack.empty()) { - auto currentExpr = stack.top(); + const auto* currentExpr = stack.top(); stack.pop(); if (currentExpr->is_variable()) { return true; } else if (currentExpr->is_predecessor()) { - stack.push(std::static_pointer_cast(currentExpr)->child()); + stack.push(static_cast(currentExpr)->child().get()); } else if (currentExpr->is_successor()) { - stack.push(std::static_pointer_cast(currentExpr)->child()); + stack.push(static_cast(currentExpr)->child().get()); } else if (currentExpr->is_tuple()) { - auto tupleExpr = std::static_pointer_cast(currentExpr); + const auto* tupleExpr = static_cast(currentExpr); for (const auto& tupleElem : *tupleExpr) { - stack.push(tupleElem); + stack.push(tupleElem.get()); } } }