1
/* PeTe - Petri Engine exTremE
2
* Copyright (C) 2011 Jonas Finnemann Jensen <jopsen@gmail.com>,
3
* Thomas Søndersø Nielsen <primogens@gmail.com>,
4
* Lars Kærlund Østergaard <larsko@gmail.com>,
5
* Peter Gjøl Jensen <root@petergjoel.dk>
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
30
#include "../PetriNet.h"
31
#include "PetriEngine/Simplification/LPCache.h"
33
#include "../NetStructures.h"
35
namespace PetriEngine {
38
/** Context provided for context analysis */
39
class AnalysisContext {
41
const unordered_map<std::string, uint32_t>& _placeNames;
42
const unordered_map<std::string, uint32_t>& _transitionNames;
44
std::vector<ExprError> _errors;
47
/** A resolution result */
48
struct ResolutionResult {
49
/** Offset in relevant vector */
51
/** True, if the resolution was successful */
55
AnalysisContext(const std::unordered_map<std::string, uint32_t>& places, const std::unordered_map<std::string, uint32_t>& tnames, const PetriNet* net)
56
: _placeNames(places), _transitionNames(tnames), _net(net) {
60
virtual void setHasDeadlock(){};
62
const PetriNet* net() const
67
/** Resolve an identifier */
68
virtual ResolutionResult resolve(const std::string& identifier, bool place = true) {
69
ResolutionResult result;
71
result.success = false;
72
auto& map = place ? _placeNames : _transitionNames;
73
auto it = map.find(identifier);
76
result.offset = (int)it->second;
77
result.success = true;
84
void reportError(const ExprError& error) {
85
_errors.push_back(error);
88
/** Get list of errors */
89
const std::vector<ExprError>& errors() const {
94
class ColoredAnalysisContext : public AnalysisContext {
96
const std::unordered_map<std::string, std::unordered_map<uint32_t , std::string>>& _coloredPlaceNames;
97
const std::unordered_map<std::string, std::vector<std::string>>& _coloredTransitionNames;
102
ColoredAnalysisContext(const std::unordered_map<std::string, uint32_t>& places,
103
const std::unordered_map<std::string, uint32_t>& tnames,
105
const std::unordered_map<std::string, std::unordered_map<uint32_t , std::string>>& cplaces,
106
const std::unordered_map<std::string, std::vector<std::string>>& ctnames,
108
: AnalysisContext(places, tnames, net),
109
_coloredPlaceNames(cplaces),
110
_coloredTransitionNames(ctnames),
114
bool resolvePlace(const std::string& place, std::unordered_map<uint32_t,std::string>& out) {
115
auto it = _coloredPlaceNames.find(place);
116
if (it != _coloredPlaceNames.end()) {
123
bool resolveTransition(const std::string& transition, std::vector<std::string>& out) {
124
auto it = _coloredTransitionNames.find(transition);
125
if (it != _coloredTransitionNames.end()) {
132
bool isColored() const {
137
/** Context provided for evalation */
138
class EvaluationContext {
141
/** Create evaluation context, this doesn't take ownership */
142
EvaluationContext(const MarkVal* marking,
143
const PetriNet* net) {
148
EvaluationContext() {};
150
const MarkVal* marking() const {
154
void setMarking(MarkVal* marking) {
158
const PetriNet* net() const {
162
const MarkVal* _marking = nullptr;
163
const PetriNet* _net = nullptr;
166
/** Context for distance computation */
167
class DistanceContext : public EvaluationContext {
170
DistanceContext(const PetriNet* net,
171
const MarkVal* marking)
172
: EvaluationContext(marking, net) {
178
_negated = !_negated;
181
bool negated() const {
189
/** Context for condition to TAPAAL export */
190
class TAPAALConditionExportContext {
196
class SimplificationContext {
199
SimplificationContext(const MarkVal* marking,
200
const PetriNet* net, uint32_t queryTimeout, uint32_t lpTimeout,
202
: _queryTimeout(queryTimeout), _lpTimeout(lpTimeout) {
206
_start = std::chrono::high_resolution_clock::now();
210
const MarkVal* marking() const {
214
const PetriNet* net() const {
219
_negated = !_negated;
222
bool negated() const {
226
void setNegate(bool b){
230
double getReductionTime(){
231
// duration in seconds
232
auto end = std::chrono::high_resolution_clock::now();
233
return (std::chrono::duration_cast<std::chrono::microseconds>(end - _start).count())*0.000001;
236
bool timeout() const {
237
auto end = std::chrono::high_resolution_clock::now();
238
auto diff = std::chrono::duration_cast<std::chrono::seconds>(end - _start);
239
return (diff.count() >= _queryTimeout);
242
uint32_t getLpTimeout() const {
246
LPCache* cache() const
253
const MarkVal* _marking;
254
const PetriNet* _net;
255
uint32_t _queryTimeout, _lpTimeout;
256
std::chrono::high_resolution_clock::time_point _start;