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

Cpn unfolding - fix 2081147 #174

Merged
merged 9 commits into from
Nov 14, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/PetriEngine/Colored/ArcIntervals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() << ") ";
Expand Down
30 changes: 26 additions & 4 deletions include/PetriEngine/Colored/Expressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -85,6 +89,7 @@ namespace PetriEngine {
return _variable->colorType;
}

bool is_variable() const override { return true; }
};

class UserOperatorExpression : public ColorExpression {
Expand Down Expand Up @@ -113,6 +118,8 @@ namespace PetriEngine {
return _color;
}

bool is_successor() const override { return true; }

SuccessorExpression(ColorExpression_ptr&& color)
: _color(std::move(color)) {}

Expand All @@ -131,6 +138,8 @@ namespace PetriEngine {
return _color;
}

bool is_predecessor() const override { return true; }

PredecessorExpression(ColorExpression_ptr&& color)
: _color(std::move(color)) {}

Expand All @@ -151,6 +160,8 @@ namespace PetriEngine {
return _colors.size();
}

bool is_tuple() const override { return true; }

auto begin() const {
return _colors.begin();
}
Expand Down Expand Up @@ -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> ArcExpression_ptr;
Expand Down Expand Up @@ -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;
}
Expand All @@ -346,6 +360,10 @@ namespace PetriEngine {
return _color.end();
}

auto& back() const {
return _color.back();
}

NumberOfExpression(std::vector<ColorExpression_ptr>&& color, uint32_t number = 1)
: _number(number), _color(std::move(color)) {}
NumberOfExpression(AllExpression_ptr&& all, uint32_t number = 1)
Expand All @@ -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();
}

Expand All @@ -388,6 +406,10 @@ namespace PetriEngine {
return _constituents.end();
}

auto& back() const {
return _constituents.back();
}

AddExpression(std::vector<ArcExpression_ptr> &&constituents)
: _constituents(std::move(constituents)) {}

Expand All @@ -404,7 +426,7 @@ namespace PetriEngine {
return _left->weight() - _right->weight();
}

bool is_single_color() const {
bool is_single_color() const override {
return false;
}

Expand Down Expand Up @@ -434,7 +456,7 @@ namespace PetriEngine {
return _scalar * _expr->weight();
}

bool is_single_color() const {
bool is_single_color() const override {
return _expr->is_single_color();
}

Expand Down
58 changes: 55 additions & 3 deletions include/PetriEngine/Colored/VariableVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#ifndef VARIABLESVISITOR_H
#define VARIABLESVISITOR_H

#include <stack>

#include "Expressions.h"
#include "Colors.h"

Expand Down Expand Up @@ -206,23 +208,47 @@ namespace PetriEngine {
virtual void accept(const AddExpression* add)
{
for (const auto& elem : *add) {
for(auto& pair : _varModifiers){
std::unordered_map<uint32_t, int32_t> newMap;
pair.second.push_back(newMap);
for (auto& pair : _varModifiers) {
pair.second.emplace_back();
}

_index = 0;
elem->visit(*this);
}

if (add->back()->is_number_of()) {
const auto& numberOfExpr = std::static_pointer_cast<const NumberOfExpression>(add->back());
if (is_last_variable_expr(*numberOfExpr->back())) {
for (auto& pair : _varModifiers) {
pair.second.emplace_back();
}
}
}
}

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;
(*sub)[1]->visit(*this);

if ((*sub)[1]->is_number_of()) {
const auto& numberOfExpr = std::static_pointer_cast<const NumberOfExpression>((*sub)[1]);
if (is_last_variable_expr(*numberOfExpr->back())) {
for (auto& pair : _varModifiers) {
pair.second.emplace_back();
}
}
}
}
}

Expand Down Expand Up @@ -262,6 +288,32 @@ namespace PetriEngine {

get_variables(e, variables, varPositions, varModifierMap, tuples, false);
}

private:
bool is_last_variable_expr(const ColorExpression& expr) const {
std::stack<const ColorExpression*> stack;
stack.push(&expr);

while (!stack.empty()) {
const auto* currentExpr = stack.top();
stack.pop();

if (currentExpr->is_variable()) {
return true;
} else if (currentExpr->is_predecessor()) {
stack.push(static_cast<const PredecessorExpression*>(currentExpr)->child().get());
} else if (currentExpr->is_successor()) {
stack.push(static_cast<const SuccessorExpression*>(currentExpr)->child().get());
} else if (currentExpr->is_tuple()) {
const auto* tupleExpr = static_cast<const TupleExpression*>(currentExpr);
for (const auto& tupleElem : *tupleExpr) {
stack.push(tupleElem.get());
}
}
}

return false;
}
};
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/PetriEngine/Colored/EvaluationVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
srba marked this conversation as resolved.
Show resolved Hide resolved
_mres = lhs - _mres;
}

Expand Down
7 changes: 5 additions & 2 deletions src/PetriEngine/Colored/IntervalGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace PetriEngine {

std::vector<interval_t> IntervalGenerator::getIntervalsFromInterval(const interval_t &interval, uint32_t varPosition, int32_t varModifier, const std::vector<const ColorType*> &varColorTypes) {
std::vector<interval_t> varIntervals;
interval_t firstVarInterval;
varIntervals.push_back(firstVarInterval);
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();
int32_t lower_val = ctSize + (interval[i]._lower + varModifier);
Expand Down Expand Up @@ -89,6 +89,7 @@ namespace PetriEngine {
interval_vector_t varIntervals;
std::vector<const ColorType*> varColorTypes;
pair.first->colorType->getColortypes(varColorTypes);
assert(pair.second.size() > tuplePos);

getArcVarIntervals(varIntervals, pair.second[tuplePos], interval, varColorTypes);

Expand Down Expand Up @@ -131,6 +132,8 @@ namespace PetriEngine {
interval_vector_t varIntervals;
std::vector<const ColorType*> 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()){
Expand Down
3 changes: 1 addition & 2 deletions src/PetriEngine/Colored/PartitionBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ namespace PetriEngine {
const VariableModifierMap &varModifierMap,
const EquivalenceClass& eqClass , const Arc *arc, uint32_t placeId){
std::vector<VariableIntervalMap> varMaps;
VariableIntervalMap varMap;
varMaps.push_back(varMap);
varMaps.emplace_back();
std::unordered_map<uint32_t, ArcIntervals> placeArcIntervals;
ColorFixpoint postPlaceFixpoint;
postPlaceFixpoint.constraints = eqClass.intervals();
Expand Down
Loading