186
204
Member constraint(SimplificationContext& context) const override;
206
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const;
187
208
bool placeFree() const override { return true; }
214
class IdentifierExpr : public Expr {
216
IdentifierExpr(const std::string& name) : _name(name) {}
217
void analyze(AnalysisContext& context) override;
218
int evaluate(const EvaluationContext& context) override {
219
return _compiled->evaluate(context);
221
void toString(std::ostream& os) const override {
223
_compiled->toString(os);
227
Expr::Types type() const override {
228
if(_compiled) return _compiled->type();
229
return Expr::IdentifierExpr;
231
void toXML(std::ostream& os, uint32_t tabs, bool tokencount = false) const override {
232
_compiled->toXML(os, tabs, tokencount);
234
void incr(ReducingSuccessorGenerator& generator) const override {
235
_compiled->incr(generator);
237
void decr(ReducingSuccessorGenerator& generator) const override {
238
_compiled->decr(generator);
240
int formulaSize() const override {
241
if(_compiled) return _compiled->formulaSize();
244
virtual bool placeFree() const override {
245
if(_compiled) return _compiled->placeFree();
249
Member constraint(SimplificationContext& context) const override {
250
return _compiled->constraint(context);
253
void toBinary(std::ostream& s) const override {
254
_compiled->toBinary(s);
258
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const
260
return _compiled->encodeSat(net, context, uses, incremented);
192
268
/** Identifier expression */
193
class IdentifierExpr : public Expr {
269
class UnfoldedIdentifierExpr : public Expr {
195
IdentifierExpr(const std::string& name, int offest)
271
UnfoldedIdentifierExpr(const std::string& name, int offest)
196
272
: _offsetInMarking(offest), _name(name) {
199
IdentifierExpr(const std::string& name) : IdentifierExpr(name, -1) {
275
UnfoldedIdentifierExpr(const std::string& name) : UnfoldedIdentifierExpr(name, -1) {
202
278
void analyze(AnalysisContext& context) override;
203
int evaluate(const EvaluationContext& context) const override;
279
int evaluate(const EvaluationContext& context) override;
204
280
void toString(std::ostream&) const override;
205
281
Expr::Types type() const override;
206
282
void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override;
283
void toBinary(std::ostream&) const override;
207
284
void incr(ReducingSuccessorGenerator& generator) const override;
208
285
void decr(ReducingSuccessorGenerator& generator) const override;
209
286
int formulaSize() const override{
226
306
std::string _name;
229
/******************** TEMPORAL OPERATORS ********************/
310
class NotCondition : public Condition {
313
NotCondition(const Condition_ptr cond) {
315
_temporal = _cond->isTemporal();
316
_loop_sensitive = _cond->isLoopSensitive();
318
int formulaSize() const override{
319
return _cond->formulaSize() + 1;
321
void analyze(AnalysisContext& context) override;
322
Result evaluate(const EvaluationContext& context) override;
323
Result evalAndSet(const EvaluationContext& context) override;
324
uint32_t distance(DistanceContext& context) const override;
325
void toString(std::ostream&) const override;
326
void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override;
327
Retval simplify(SimplificationContext& context) const override;
328
bool isReachability(uint32_t depth) const override;
329
Condition_ptr prepareForReachability(bool negated) const override;
330
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
331
void toXML(std::ostream&, uint32_t tabs) const override;
332
void toBinary(std::ostream&) const override;
333
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
334
Quantifier getQuantifier() const override { return Quantifier::NEG; }
335
Path getPath() const override { return Path::pError; }
336
CTLType getQueryType() const override { return CTLType::LOPERATOR; }
337
const Condition_ptr& operator[](size_t i) const { return _cond; };
338
virtual bool isTemporal() const override { return _temporal;}
339
bool containsNext() const override { return _cond->containsNext(); }
341
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const;
345
bool _temporal = false;
349
/******************** TEMPORAL OPERATORS ********************/
231
351
class QuantifierCondition : public Condition
241
361
SimpleQuantifierCondition(const Condition_ptr cond) {
363
_loop_sensitive = cond->isLoopSensitive();
244
365
int formulaSize() const override{
245
366
return _cond->formulaSize() + 1;
248
369
void analyze(AnalysisContext& context) override;
249
Result evaluate(const EvaluationContext& context) const override;
370
Result evaluate(const EvaluationContext& context) override;
250
371
Result evalAndSet(const EvaluationContext& context) override;
251
372
void toString(std::ostream&) const override;
252
373
void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override;
253
bool isUpperBound() override;
374
void toBinary(std::ostream& out) const override;
254
375
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
255
376
virtual const Condition_ptr& operator[] (size_t i) const override { return _cond;}
256
377
virtual bool containsNext() const override { return _cond->containsNext(); }
379
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const
381
return _cond->encodeSat(net, context, uses, incremented);
258
385
virtual std::string op() const = 0;
368
499
UntilCondition(const Condition_ptr cond1, const Condition_ptr cond2) {
502
_loop_sensitive = _cond1->isLoopSensitive() || _cond2->isLoopSensitive();
372
504
int formulaSize() const override{
373
505
return _cond1->formulaSize() + _cond2->formulaSize() + 1;
376
508
void analyze(AnalysisContext& context) override;
377
Result evaluate(const EvaluationContext& context) const override;
509
Result evaluate(const EvaluationContext& context) override;
511
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const
513
return context.bool_val(true);
378
516
void toString(std::ostream&) const override;
379
517
void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override;
518
void toBinary(std::ostream& out) const override;
380
519
bool isReachability(uint32_t depth) const override;
381
bool isUpperBound() override;
382
520
Condition_ptr prepareForReachability(bool negated) const override;
383
521
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
384
522
Result evalAndSet(const EvaluationContext& context) override;
415
553
Quantifier getQuantifier() const override { return Quantifier::A; }
416
554
uint32_t distance(DistanceContext& context) const override;
417
555
void toXML(std::ostream&, uint32_t tabs) const override;
418
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
556
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
557
virtual bool isLoopSensitive() const override { return true; }
421
559
std::string op() const override;
424
562
/******************** CONDITIONS ********************/
426
/* Fireable Condition -- placeholder, needs to be unfolded */
427
class FireableCondition : public Condition {
565
class ExpandableCondition : public Condition {
429
FireableCondition(const std::string& tname) : _name(tname) {};
430
void analyze(AnalysisContext& context) override;
431
Result evaluate(const EvaluationContext& context) const override
567
ExpandableCondition(const std::string& tname) : _name(tname) {};
568
Result evaluate(const EvaluationContext& context) override
432
569
{ return _compiled->evaluate(context); }
433
570
Result evalAndSet(const EvaluationContext& context) override
434
571
{ return _compiled->evalAndSet(context); }
435
572
uint32_t distance(DistanceContext& context) const override
436
573
{ return _compiled->distance(context); }
437
574
void toString(std::ostream& ss) const override
438
{ _compiled->toString(ss); }
576
if(_compiled) _compiled->toString(ss);
439
579
void toTAPAALQuery(std::ostream& s,TAPAALConditionExportContext& context) const override
440
580
{ _compiled->toTAPAALQuery(s, context); }
581
void toBinary(std::ostream& out) const override
582
{ _compiled->toBinary(out); }
441
584
Retval simplify(SimplificationContext& context) const override
443
586
return _compiled->simplify(context);
445
588
bool isReachability(uint32_t depth) const override
446
{ return _compiled->isReachability(depth); }
447
bool isUpperBound() override
449
Condition_ptr prepareForReachability(bool negated) const override
450
{ return _compiled->prepareForReachability(negated); }
451
Condition_ptr pushNegation(negstat_t& stat, const EvaluationContext& context, bool nested, bool negated) const override
453
return _compiled->pushNegation(stat, context, nested, negated);
455
591
void toXML(std::ostream& ss, uint32_t tabs) const override
456
592
{ _compiled->toXML(ss, tabs);};
457
593
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override
458
594
{ _compiled->findInteresting(generator, negated); }
459
595
Quantifier getQuantifier() const override
460
{ return _compiled->getQuantifier(); }
597
if(_compiled) return _compiled->getQuantifier();
598
else return Quantifier::AND;
461
600
Path getPath() const override
462
601
{ return _compiled->getPath(); }
463
602
CTLType getQueryType() const override
466
605
{ return _compiled->formulaSize(); }
467
606
bool containsNext() const override
468
607
{ return false; }
609
z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const override
612
return context.bool_val(false);
471
617
std::string _name;
472
618
Condition_ptr _compiled;
621
/* Fireable Condition -- placeholder, needs to be unfolded */
622
class UnfoldedFireableCondition : public ExpandableCondition {
624
UnfoldedFireableCondition(const std::string& tname) : ExpandableCondition(tname) {};
625
void analyze(AnalysisContext& context) override;
626
Condition_ptr pushNegation(negstat_t& stat, const EvaluationContext& context, bool nested, bool negated, bool initrw) override
629
return _compiled->pushNegation(stat, context, nested, negated, initrw);
632
stat.negated_fireability = true;
633
return std::make_shared<NotCondition>(std::make_shared<UnfoldedFireableCondition>(_name));
636
return std::make_shared<UnfoldedFireableCondition>(_name);
639
Condition_ptr prepareForReachability(bool negated) const override
641
if(_compiled) return _compiled->prepareForReachability(negated);
642
return std::make_shared<UnfoldedFireableCondition>(_name);
647
class FireableCondition : public ExpandableCondition {
649
FireableCondition(const std::string& tname) : ExpandableCondition(tname) {};
650
void analyze(AnalysisContext& context) override;
651
Condition_ptr pushNegation(negstat_t& stat, const EvaluationContext& context, bool nested, bool negated, bool initrw) override
654
return _compiled->pushNegation(stat, context, nested, negated, initrw);
657
stat.negated_fireability = true;
658
return std::make_shared<NotCondition>(std::make_shared<FireableCondition>(_name));
661
return std::make_shared<FireableCondition>(_name);
664
Condition_ptr prepareForReachability(bool negated) const override
666
if(_compiled) return _compiled->prepareForReachability(negated);
667
return std::make_shared<FireableCondition>(_name);
477
672
/* Logical conditon */
478
673
class LogicalCondition : public Condition {
534
729
AndCondition(Condition_ptr left, Condition_ptr right);
536
731
Retval simplify(SimplificationContext& context) const override;
537
Result evaluate(const EvaluationContext& context) const override;
732
Result evaluate(const EvaluationContext& context) override;
538
733
Result evalAndSet(const EvaluationContext& context) override;
540
735
void toXML(std::ostream&, uint32_t tabs) const override;
541
736
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
542
737
Quantifier getQuantifier() const override { return Quantifier::AND; }
543
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
738
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
740
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const;
546
743
//int logicalOp() const;
547
744
uint32_t delta(uint32_t d1, uint32_t d2, const DistanceContext& context) const override;
559
756
OrCondition(Condition_ptr left, Condition_ptr right);
561
758
Retval simplify(SimplificationContext& context) const override;
562
Result evaluate(const EvaluationContext& context) const override;
759
Result evaluate(const EvaluationContext& context) override;
563
760
Result evalAndSet(const EvaluationContext& context) override;
565
762
void toXML(std::ostream&, uint32_t tabs) const override;
566
763
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
567
764
Quantifier getQuantifier() const override { return Quantifier::OR; }
568
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
765
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
767
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const;
570
770
//int logicalOp() const;
571
771
uint32_t delta(uint32_t d1, uint32_t d2, const DistanceContext& context) const override;
620
818
uint32_t distance(DistanceContext& context) const override;
621
819
void toString(std::ostream& stream) const override;
622
820
void toTAPAALQuery(std::ostream& stream,TAPAALConditionExportContext& context) const override;
821
void toBinary(std::ostream& out) const override;
623
822
bool isReachability(uint32_t depth) const override { return depth > 0; };
624
bool isUpperBound() override { return false; }
625
823
Condition_ptr prepareForReachability(bool negated) const override;
626
824
CTLType getQueryType() const override { return CTLType::LOPERATOR; }
627
825
Path getPath() const override { return Path::pError; }
628
826
virtual void toXML(std::ostream& stream, uint32_t tabs) const override;
629
827
Retval simplify(SimplificationContext& context) const override;
630
Result evaluate(const EvaluationContext& context) const override;
828
Result evaluate(const EvaluationContext& context) override;
631
829
Result evalAndSet(const EvaluationContext& context) override;
632
830
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
633
831
Quantifier getQuantifier() const override { return _negated ? Quantifier::OR : Quantifier::AND; }
634
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
832
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
635
833
bool isNegated() const { return _negated; }
636
834
bool singular() const
806
1019
std::string sopTAPAAL() const override;
810
class NotCondition : public Condition {
813
NotCondition(const Condition_ptr cond) {
815
_temporal = _cond->isTemporal();
817
int formulaSize() const override{
818
return _cond->formulaSize() + 1;
820
void analyze(AnalysisContext& context) override;
821
Result evaluate(const EvaluationContext& context) const override;
822
Result evalAndSet(const EvaluationContext& context) override;
823
uint32_t distance(DistanceContext& context) const override;
824
void toString(std::ostream&) const override;
825
void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override;
826
Retval simplify(SimplificationContext& context) const override;
827
bool isReachability(uint32_t depth) const override;
828
bool isUpperBound() override;
829
Condition_ptr prepareForReachability(bool negated) const override;
830
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
831
void toXML(std::ostream&, uint32_t tabs) const override;
832
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
833
Quantifier getQuantifier() const override { return Quantifier::NEG; }
834
Path getPath() const override { return Path::pError; }
835
CTLType getQueryType() const override { return CTLType::LOPERATOR; }
836
const Condition_ptr& operator[](size_t i) const { return _cond; };
837
virtual bool isTemporal() const override { return _temporal;}
838
bool containsNext() const override { return _cond->containsNext(); }
842
bool _temporal = false;
845
1022
/* Bool condition */
846
1023
class BooleanCondition : public Condition {
867
1044
static Condition_ptr getShared(bool val);
868
1045
Retval simplify(SimplificationContext& context) const override;
869
1046
bool isReachability(uint32_t depth) const override;
870
bool isUpperBound() override;
871
1047
Condition_ptr prepareForReachability(bool negated) const override;
872
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
1048
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
873
1049
void toXML(std::ostream&, uint32_t tabs) const override;
1050
void toBinary(std::ostream&) const override;
874
1051
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
875
1052
Quantifier getQuantifier() const override { return Quantifier::EMPTY; }
876
1053
Path getPath() const override { return Path::pError; }
877
1054
CTLType getQueryType() const override { return CTLType::EVAL; }
878
1055
bool containsNext() const override { return false; }
1057
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const
1059
return context.bool_val(_value);
880
1063
const bool _value;
887
1070
DeadlockCondition() {
1071
_loop_sensitive = true;
889
1073
int formulaSize() const override{
892
1076
void analyze(AnalysisContext& context) override;
893
Result evaluate(const EvaluationContext& context) const override;
1077
Result evaluate(const EvaluationContext& context) override;
894
1078
Result evalAndSet(const EvaluationContext& context) override;
895
1079
uint32_t distance(DistanceContext& context) const override;
896
1080
void toString(std::ostream&) const override;
897
1081
void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override;
898
1082
Retval simplify(SimplificationContext& context) const override;
899
1083
bool isReachability(uint32_t depth) const override;
900
bool isUpperBound() override;
901
1084
Condition_ptr prepareForReachability(bool negated) const override;
902
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated) const override;
1085
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
903
1086
void toXML(std::ostream&, uint32_t tabs) const override;
1087
void toBinary(std::ostream&) const override;
904
1088
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
905
1089
static Condition_ptr DEADLOCK;
906
1090
Quantifier getQuantifier() const override { return Quantifier::EMPTY; }
907
1091
Path getPath() const override { return Path::pError; }
908
1092
CTLType getQueryType() const override { return CTLType::EVAL; }
909
1093
bool containsNext() const override { return false; }
1095
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const;
1099
class UpperBoundsCondition : public Condition
1103
UpperBoundsCondition(const std::vector<std::string>& places) : _places(places)
1107
int formulaSize() const override{
1108
return _places.size();
1110
void analyze(AnalysisContext& context) override;
1111
Result evaluate(const EvaluationContext& context) override
1112
{ return _compiled->evaluate(context); }
1113
Result evalAndSet(const EvaluationContext& context) override
1114
{ return _compiled->evalAndSet(context); }
1115
uint32_t distance(DistanceContext& context) const override
1116
{ return _compiled->distance(context); }
1117
void toString(std::ostream& out) const override;
1118
void toTAPAALQuery(std::ostream& out,TAPAALConditionExportContext& context) const override
1119
{ _compiled->toTAPAALQuery(out, context); }
1120
void toBinary(std::ostream& out) const override
1121
{ return _compiled->toBinary(out); }
1122
Retval simplify(SimplificationContext& context) const override
1123
{ return _compiled->simplify(context); }
1124
bool isReachability(uint32_t depth) const override
1126
Condition_ptr prepareForReachability(bool negated) const override
1127
{ return _compiled->prepareForReachability(negated); }
1128
Condition_ptr pushNegation(negstat_t& neg, const EvaluationContext& context, bool nested, bool negated, bool initrw) override
1131
return _compiled->pushNegation(neg, context, nested, negated, initrw);
1133
return std::make_shared<UpperBoundsCondition>(_places);
1135
void toXML(std::ostream& out, uint32_t tabs) const override
1136
{ _compiled->toXML(out, tabs); }
1137
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override
1138
{ _compiled->findInteresting(generator, negated);}
1139
Quantifier getQuantifier() const override { return Quantifier::UPPERBOUNDS; }
1140
Path getPath() const override { return Path::pError; }
1141
CTLType getQueryType() const override { return CTLType::EVAL; }
1142
bool containsNext() const override { return false; }
1144
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const
1145
{ return _compiled->encodeSat(net, context, uses, incremented); }
1148
std::vector<std::string> _places;
1149
Condition_ptr _compiled;
1153
class UnfoldedUpperBoundsCondition : public Condition
1158
uint32_t _place = 0;
1159
place_t(const std::string& name)
1163
bool operator<(const place_t& other) const{
1164
return _place < other._place;
1168
UnfoldedUpperBoundsCondition(const std::vector<std::string>& places)
1170
for(auto& s : places) _places.push_back(s);
1172
UnfoldedUpperBoundsCondition(const std::vector<place_t>& places, size_t max)
1173
: _places(places), _max(max) {
1175
int formulaSize() const override{
1176
return _places.size();
1178
void analyze(AnalysisContext& context) override;
1179
Result evaluate(const EvaluationContext& context) override;
1180
Result evalAndSet(const EvaluationContext& context) override;
1181
uint32_t distance(DistanceContext& context) const override;
1182
void toString(std::ostream&) const override;
1183
void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override;
1184
void toBinary(std::ostream&) const override;
1185
Retval simplify(SimplificationContext& context) const override;
1186
bool isReachability(uint32_t depth) const override;
1187
Condition_ptr prepareForReachability(bool negated) const override;
1188
Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override;
1189
void toXML(std::ostream&, uint32_t tabs) const override;
1190
void findInteresting(ReducingSuccessorGenerator& generator, bool negated) const override;
1191
Quantifier getQuantifier() const override { return Quantifier::EMPTY; }
1192
Path getPath() const override { return Path::pError; }
1193
CTLType getQueryType() const override { return CTLType::EVAL; }
1194
bool containsNext() const override { return false; }
1195
size_t bounds() const { return _bound; }
1197
virtual z3::expr encodeSat(const PetriNet& net, z3::context& context, std::vector<int32_t>& uses, std::vector<bool>& incremented) const;
1199
virtual void setUpperBound(size_t bound)
1201
_bound = std::max(_bound, bound);
1204
std::vector<place_t> _places;
1206
size_t _max = std::numeric_limits<size_t>::max();