2
* File: ColoredPetriNetBuilder.h
5
* Created on 17. februar 2018, 16:25
1
/* Copyright (C) 2020 Alexander Bilgram <alexander@bilgram.dk>,
2
* Peter Haar Taankvist <ptaankvist@gmail.com>,
3
* Thomas Pedersen <thomas.pedersen@stofanet.dk>
4
* Andreas H. Klostergaard
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
8
20
#ifndef COLOREDPETRINETBUILDER_H
12
24
#include <unordered_map>
14
#include "ColoredNetStructures.h"
15
26
#include "../AbstractPetriNetBuilder.h"
16
27
#include "../PetriNetBuilder.h"
28
#include "BindingGenerator.h"
29
#include "IntervalGenerator.h"
30
#include "ArcIntervals.h"
18
32
namespace PetriEngine {
19
34
class ColoredPetriNetBuilder : public AbstractPetriNetBuilder {
21
typedef std::unordered_map<std::string, Colored::ColorType*> ColorTypeMap;
22
36
typedef std::unordered_map<std::string, std::unordered_map<uint32_t , std::string>> PTPlaceMap;
23
37
typedef std::unordered_map<std::string, std::vector<std::string>> PTTransitionMap;
110
133
PetriNetBuilder& unfold();
111
134
PetriNetBuilder& stripColors();
135
void computePlaceColorFixpoint(uint32_t maxIntervals, uint32_t maxIntervalsReduced, int32_t timeout);
113
138
std::unordered_map<std::string,uint32_t> _placenames;
114
139
std::unordered_map<std::string,uint32_t> _transitionnames;
140
std::unordered_map<uint32_t, std::unordered_map<uint32_t, Colored::ArcIntervals>> _arcIntervals;
141
std::unordered_map<uint32_t,std::vector<uint32_t>> _placePostTransitionMap;
142
std::unordered_map<uint32_t,FixpointBindingGenerator> _bindings;
115
143
PTPlaceMap _ptplacenames;
116
144
PTTransitionMap _pttransitionnames;
117
145
uint32_t _nptplaces = 0;
118
146
uint32_t _npttransitions = 0;
119
147
uint32_t _nptarcs = 0;
148
uint32_t _maxIntervals = 0;
149
PetriEngine::IntervalGenerator intervalGenerator;
121
151
std::vector<Colored::Place> _places;
122
152
std::vector<Colored::Transition> _transitions;
123
153
std::vector<Colored::Arc> _arcs;
154
std::vector<Colored::ColorFixpoint> _placeColorFixpoints;
124
155
ColorTypeMap _colors;
125
156
PetriNetBuilder _ptBuilder;
126
157
bool _unfolded = false;
127
158
bool _stripped = false;
160
std::vector<uint32_t> _placeFixpointQueue;
163
double _fixPointCreationTime;
131
167
std::string arcToString(Colored::Arc& arc) const ;
169
void printPlaceTable();
171
std::unordered_map<uint32_t, Colored::ArcIntervals> setupTransitionVars(Colored::Transition transition);
133
173
void addArc(const std::string& place,
134
174
const std::string& transition,
135
175
const Colored::ArcExpression_ptr& expr,
179
void getArcIntervals(Colored::Transition& transition, bool &transitionActivated, uint32_t max_intervals, uint32_t transitionId);
180
void processInputArcs(Colored::Transition& transition, uint32_t currentPlaceId, uint32_t transitionId, bool &transitionActivated, uint32_t max_intervals);
181
void processOutputArcs(Colored::Transition& transition);
138
void unfoldPlace(Colored::Place& place);
183
void unfoldPlace(const Colored::Place* place, const PetriEngine::Colored::Color *color);
139
184
void unfoldTransition(Colored::Transition& transition);
140
void unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& name);
185
void handleOrphanPlace(Colored::Place& place, std::unordered_map<std::string, uint32_t> unfoldedPlaceMap);
187
void unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& name, bool input);
143
class BindingGenerator {
147
BindingGenerator* _generator;
150
Iterator(BindingGenerator* generator);
152
bool operator==(Iterator& other);
153
bool operator!=(Iterator& other);
154
Iterator& operator++();
155
const Colored::ExpressionContext::BindingMap operator++(int);
156
Colored::ExpressionContext::BindingMap& operator*();
159
Colored::GuardExpression_ptr _expr;
160
Colored::ExpressionContext::BindingMap _bindings;
161
ColoredPetriNetBuilder::ColorTypeMap& _colorTypes;
166
BindingGenerator(Colored::Transition& transition,
167
const std::vector<Colored::Arc>& arcs,
168
ColoredPetriNetBuilder::ColorTypeMap& colorTypes);
190
//Used for checking if a variable is inside either a succ or pred expression
191
enum ExpressionType {
170
Colored::ExpressionContext::BindingMap& nextBinding();
171
Colored::ExpressionContext::BindingMap& currentBinding();
172
bool isInitial() const;
178
200
#endif /* COLOREDPETRINETBUILDER_H */