27
27
import hu .bme .mit .delta .java .mdd .MddVariableOrder ;
28
28
import hu .bme .mit .delta .mdd .MddInterpreter ;
29
29
import hu .bme .mit .delta .mdd .MddVariableDescriptor ;
30
+ import hu .bme .mit .theta .analysis .Trace ;
30
31
import hu .bme .mit .theta .analysis .algorithm .SafetyChecker ;
31
32
import hu .bme .mit .theta .analysis .algorithm .SafetyResult ;
32
33
import hu .bme .mit .theta .analysis .algorithm .bounded .MonolithicExpr ;
33
34
import hu .bme .mit .theta .analysis .algorithm .mdd .ansd .AbstractNextStateDescriptor ;
34
- import hu .bme .mit .theta .analysis .algorithm .mdd .ansd .impl .MddNodeInitializer ;
35
- import hu .bme .mit .theta .analysis .algorithm .mdd .ansd .impl .MddNodeNextStateDescriptor ;
36
- import hu .bme .mit .theta .analysis .algorithm .mdd .ansd .impl .OnTheFlyReachabilityNextStateDescriptor ;
35
+ import hu .bme .mit .theta .analysis .algorithm .mdd .ansd .impl .*;
37
36
import hu .bme .mit .theta .analysis .algorithm .mdd .expressionnode .ExprLatticeDefinition ;
37
+ import hu .bme .mit .theta .analysis .algorithm .mdd .expressionnode .MddExplicitRepresentationExtractor ;
38
38
import hu .bme .mit .theta .analysis .algorithm .mdd .expressionnode .MddExpressionTemplate ;
39
- import hu .bme .mit .theta .analysis .algorithm .mdd .fixedpoint .BfsProvider ;
40
- import hu .bme .mit .theta .analysis .algorithm .mdd .fixedpoint .GeneralizedSaturationProvider ;
41
- import hu .bme .mit .theta .analysis .algorithm .mdd .fixedpoint .SimpleSaturationProvider ;
42
- import hu .bme .mit .theta .analysis .algorithm .mdd .fixedpoint .StateSpaceEnumerationProvider ;
39
+ import hu .bme .mit .theta .analysis .algorithm .mdd .fixedpoint .*;
43
40
import hu .bme .mit .theta .analysis .expr .ExprAction ;
41
+ import hu .bme .mit .theta .analysis .expr .ExprState ;
44
42
import hu .bme .mit .theta .analysis .unit .UnitPrec ;
45
43
import hu .bme .mit .theta .common .container .Containers ;
46
44
import hu .bme .mit .theta .common .logging .Logger ;
47
45
import hu .bme .mit .theta .common .logging .Logger .Level ;
48
46
import hu .bme .mit .theta .core .decl .Decl ;
49
47
import hu .bme .mit .theta .core .decl .VarDecl ;
48
+ import hu .bme .mit .theta .core .model .Valuation ;
50
49
import hu .bme .mit .theta .core .type .Expr ;
51
50
import hu .bme .mit .theta .core .type .booltype .BoolType ;
52
51
import hu .bme .mit .theta .core .utils .PathUtils ;
53
52
import hu .bme .mit .theta .core .utils .indexings .VarIndexingFactory ;
54
53
import hu .bme .mit .theta .solver .SolverPool ;
55
54
import java .util .ArrayList ;
56
55
import java .util .List ;
56
+ import java .util .function .BiFunction ;
57
+ import java .util .function .Function ;
57
58
58
- public class MddChecker <A extends ExprAction > implements SafetyChecker <MddProof , MddCex , UnitPrec > {
59
+ public class MddChecker <S extends ExprState , A extends ExprAction >
60
+ implements SafetyChecker <MddProof , Trace <S , A >, UnitPrec > {
59
61
60
62
private final MonolithicExpr monolithicExpr ;
61
63
private final List <VarDecl <?>> variableOrdering ;
62
64
private final SolverPool solverPool ;
63
65
private final Logger logger ;
64
- private IterationStrategy iterationStrategy = IterationStrategy .GSAT ;
66
+ private final IterationStrategy iterationStrategy ;
67
+ private final Function <Valuation , S > valToState ;
68
+ private final BiFunction <Valuation , Valuation , A > biValToAction ;
65
69
66
70
public enum IterationStrategy {
67
71
BFS ,
@@ -74,35 +78,55 @@ private MddChecker(
74
78
List <VarDecl <?>> variableOrdering ,
75
79
SolverPool solverPool ,
76
80
Logger logger ,
77
- IterationStrategy iterationStrategy ) {
81
+ IterationStrategy iterationStrategy ,
82
+ Function <Valuation , S > valToState ,
83
+ BiFunction <Valuation , Valuation , A > biValToAction ) {
78
84
this .monolithicExpr = monolithicExpr ;
79
85
this .variableOrdering = variableOrdering ;
80
86
this .solverPool = solverPool ;
81
87
this .logger = logger ;
82
88
this .iterationStrategy = iterationStrategy ;
89
+ this .valToState = valToState ;
90
+ this .biValToAction = biValToAction ;
83
91
}
84
92
85
- public static <A extends ExprAction > MddChecker <A > create (
93
+ public static <S extends ExprState , A extends ExprAction > MddChecker <S , A > create (
86
94
MonolithicExpr monolithicExpr ,
87
95
List <VarDecl <?>> variableOrdering ,
88
96
SolverPool solverPool ,
89
- Logger logger ) {
90
- return new MddChecker <A >(
91
- monolithicExpr , variableOrdering , solverPool , logger , IterationStrategy .GSAT );
97
+ Logger logger ,
98
+ Function <Valuation , S > valToState ,
99
+ BiFunction <Valuation , Valuation , A > biValToAction ) {
100
+ return new MddChecker <S , A >(
101
+ monolithicExpr ,
102
+ variableOrdering ,
103
+ solverPool ,
104
+ logger ,
105
+ IterationStrategy .GSAT ,
106
+ valToState ,
107
+ biValToAction );
92
108
}
93
109
94
- public static <A extends ExprAction > MddChecker <A > create (
110
+ public static <S extends ExprState , A extends ExprAction > MddChecker <S , A > create (
95
111
MonolithicExpr monolithicExpr ,
96
112
List <VarDecl <?>> variableOrdering ,
97
113
SolverPool solverPool ,
98
114
Logger logger ,
99
- IterationStrategy iterationStrategy ) {
100
- return new MddChecker <A >(
101
- monolithicExpr , variableOrdering , solverPool , logger , iterationStrategy );
115
+ IterationStrategy iterationStrategy ,
116
+ Function <Valuation , S > valToState ,
117
+ BiFunction <Valuation , Valuation , A > biValToAction ) {
118
+ return new MddChecker <S , A >(
119
+ monolithicExpr ,
120
+ variableOrdering ,
121
+ solverPool ,
122
+ logger ,
123
+ iterationStrategy ,
124
+ valToState ,
125
+ biValToAction );
102
126
}
103
127
104
128
@ Override
105
- public SafetyResult <MddProof , MddCex > check (UnitPrec prec ) {
129
+ public SafetyResult <MddProof , Trace < S , A > > check (UnitPrec prec ) {
106
130
107
131
final MddGraph <Expr > mddGraph =
108
132
JavaMddFactory .getDefault ().createMddGraph (ExprLatticeDefinition .forExpr ());
@@ -223,11 +247,39 @@ public SafetyResult<MddProof, MddCex> check(UnitPrec prec) {
223
247
// var explTrans = MddExplicitRepresentationExtractor.INSTANCE.transform(transitionNode,
224
248
// transSig.getTopVariableHandle());
225
249
226
- final SafetyResult <MddProof , MddCex > result ;
250
+ final SafetyResult <MddProof , Trace < S , A > > result ;
227
251
if (violatingSize != 0 ) {
252
+ final var explTrans =
253
+ MddExplicitRepresentationExtractor .INSTANCE .transform (
254
+ transitionNode , transSig .getTopVariableHandle ());
255
+ final var reversed = ReverseNextStateDescriptor .of (stateSpace , explTrans );
256
+
257
+ final TraceProvider traceProvider = new TraceProvider (stateSig .getVariableOrder ());
258
+ final var mddTrace =
259
+ traceProvider .compute (
260
+ propViolating , reversed , initNode , stateSig .getTopVariableHandle ());
261
+ final var valuations =
262
+ mddTrace .stream ()
263
+ .map (
264
+ it ->
265
+ PathUtils .extractValuation (
266
+ MddValuationCollector .collect (it ).stream ()
267
+ .findFirst ()
268
+ .orElseThrow (),
269
+ 0 ))
270
+ .toList ();
271
+ final List <S > states = new ArrayList <>();
272
+ final List <A > actions = new ArrayList <>();
273
+ for (int i = 0 ; i < valuations .size (); ++i ) {
274
+ states .add (valToState .apply (valuations .get (i )));
275
+ if (i > 0 ) {
276
+ actions .add (biValToAction .apply (valuations .get (i - 1 ), valuations .get (i )));
277
+ }
278
+ }
279
+
228
280
result =
229
281
SafetyResult .unsafe (
230
- MddCex .of (propViolating ), MddProof .of (stateSpace ), statistics );
282
+ Trace .of (states , actions ), MddProof .of (stateSpace ), statistics );
231
283
} else {
232
284
result = SafetyResult .safe (MddProof .of (stateSpace ), statistics );
233
285
}
0 commit comments