Merge lp:~tapaal-contributor/tapaal/boundedness-check into lp:tapaal
- boundedness-check
- Merge into trunk
Proposed by
Lena Ernstsen
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 1140 | ||||
Proposed branch: | lp:~tapaal-contributor/tapaal/boundedness-check | ||||
Merge into: | lp:tapaal | ||||
Diff against target: |
311 lines (+118/-33) 5 files modified
src/dk/aau/cs/verification/VerifyTAPN/VerifyPNOptions.java (+2/-1) src/pipe/gui/KBoundAnalyzer.java (+66/-15) src/pipe/gui/RunKBoundAnalysis.java (+29/-6) src/pipe/gui/RunVerification.java (+3/-2) src/pipe/gui/RunVerificationBase.java (+18/-9) |
||||
To merge this branch: | bzr merge lp:~tapaal-contributor/tapaal/boundedness-check | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Needs Fixing | ||
Review via email: mp+407668@code.launchpad.net |
Commit message
Boundedness check for verifypn uses different query and minimizing extra tokens is optional
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/dk/aau/cs/verification/VerifyTAPN/VerifyPNOptions.java' |
2 | --- src/dk/aau/cs/verification/VerifyTAPN/VerifyPNOptions.java 2021-03-02 16:02:35 +0000 |
3 | +++ src/dk/aau/cs/verification/VerifyTAPN/VerifyPNOptions.java 2021-08-25 10:24:16 +0000 |
4 | @@ -84,7 +84,8 @@ |
5 | result.append(" -a 10 "); |
6 | } |
7 | if (this.queryReductionTime == QueryReductionTime.NoTime) { |
8 | - result.append(" -q 0 "); |
9 | + result.append( |
10 | + " -q 0 "); |
11 | } else if (this.queryReductionTime == QueryReductionTime.ShortestTime) { |
12 | //Run query reduction for 1 second, to avoid conflict with -s OverApprox argument, but also still not run the verification. |
13 | result.append(" -q 1"); |
14 | |
15 | === modified file 'src/pipe/gui/KBoundAnalyzer.java' |
16 | --- src/pipe/gui/KBoundAnalyzer.java 2021-02-07 11:09:51 +0000 |
17 | +++ src/pipe/gui/KBoundAnalyzer.java 2021-08-25 10:24:16 +0000 |
18 | @@ -2,15 +2,18 @@ |
19 | |
20 | import javax.swing.JSpinner; |
21 | |
22 | +import dk.aau.cs.TCTL.*; |
23 | +import dk.aau.cs.model.tapn.TimedArcPetriNet; |
24 | +import dk.aau.cs.model.tapn.TimedPlace; |
25 | +import dk.aau.cs.util.Tuple; |
26 | +import dk.aau.cs.verification.NameMapping; |
27 | +import dk.aau.cs.verification.TAPNComposer; |
28 | import pipe.dataLayer.TAPNQuery.SearchOption; |
29 | import pipe.dataLayer.TAPNQuery.TraceOption; |
30 | import pipe.dataLayer.TAPNQuery.AlgorithmOption; |
31 | import pipe.dataLayer.TAPNQuery.QueryCategory; |
32 | import pipe.gui.widgets.RunningVerificationDialog; |
33 | import dk.aau.cs.Messenger; |
34 | -import dk.aau.cs.TCTL.TCTLAGNode; |
35 | -import dk.aau.cs.TCTL.TCTLAbstractProperty; |
36 | -import dk.aau.cs.TCTL.TCTLTrueNode; |
37 | import dk.aau.cs.model.tapn.TAPNQuery; |
38 | import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork; |
39 | import dk.aau.cs.verification.ModelChecker; |
40 | @@ -22,6 +25,8 @@ |
41 | import dk.aau.cs.verification.VerifyTAPN.VerifyTAPNDiscreteVerification; |
42 | import dk.aau.cs.verification.VerifyTAPN.VerifyTAPNOptions; |
43 | |
44 | +import java.util.ArrayList; |
45 | + |
46 | public class KBoundAnalyzer { |
47 | protected TimedArcPetriNetNetwork tapnNetwork; |
48 | protected int k; |
49 | @@ -40,16 +45,24 @@ |
50 | } |
51 | |
52 | public void analyze() { |
53 | - TAPNQuery query = getBoundednessQuery(); |
54 | - VerifyTAPNOptions options = verificationOptions(); |
55 | - |
56 | - RunKBoundAnalysis analyzer = new RunKBoundAnalysis(modelChecker, messenger, spinner); |
57 | - RunningVerificationDialog dialog = new RunningVerificationDialog(CreateGui.getApp(), analyzer); |
58 | - |
59 | - analyzer.execute(options, tapnNetwork, query, null); |
60 | - dialog.setVisible(true); |
61 | + analyze(verificationOptions()); |
62 | } |
63 | |
64 | + public void analyze(VerifyTAPNOptions options) { |
65 | + TAPNQuery query; |
66 | + if (modelChecker instanceof VerifyPN) { |
67 | + query = getPNBoundednessQuery(); |
68 | + } else { |
69 | + query = getBoundednessQuery(); |
70 | + } |
71 | + |
72 | + RunKBoundAnalysis analyzer = new RunKBoundAnalysis(modelChecker, messenger, spinner); |
73 | + RunningVerificationDialog dialog = new RunningVerificationDialog(CreateGui.getApp(), analyzer); |
74 | + |
75 | + analyzer.execute(options, tapnNetwork, query, null); |
76 | + dialog.setVisible(true); |
77 | + } |
78 | + |
79 | protected VerifyTAPNOptions verificationOptions() { |
80 | if(modelChecker instanceof VerifyPN){ |
81 | return new VerifyPNOptions(k, TraceOption.NONE, SearchOption.BFS, false, ModelReduction.BOUNDPRESERVING, false, false, 1, QueryCategory.Default, AlgorithmOption.CERTAIN_ZERO, false, pipe.dataLayer.TAPNQuery.QueryReductionTime.UnlimitedTime, false, null, false); |
82 | @@ -62,10 +75,48 @@ |
83 | } |
84 | |
85 | protected TAPNQuery getBoundednessQuery() { |
86 | - TCTLAbstractProperty property = null; |
87 | - |
88 | - property = new TCTLAGNode(new TCTLTrueNode()); |
89 | - |
90 | + TCTLAbstractProperty property = new TCTLAGNode(new TCTLTrueNode()); |
91 | return new TAPNQuery(property, k); |
92 | } |
93 | + |
94 | + protected TAPNQuery getPNBoundednessQuery() { |
95 | + int totalTokens = k + tapnNetwork.marking().size(); |
96 | + |
97 | + TCTLAtomicPropositionNode child = new TCTLAtomicPropositionNode(new TCTLTermListNode(getFactors()), "<=", new TCTLConstNode(totalTokens)); |
98 | + TCTLAbstractProperty property = new TCTLAGNode(child); |
99 | + |
100 | + TAPNQuery query = new TAPNQuery(property, k); |
101 | + query.setCategory(QueryCategory.CTL); |
102 | + |
103 | + return query; |
104 | + } |
105 | + |
106 | + private ArrayList<TCTLAbstractStateProperty> getFactors() { |
107 | + TimedArcPetriNet net = mergeNetComponents(); |
108 | + ArrayList<TCTLAbstractStateProperty> factors = new ArrayList<>(); |
109 | + |
110 | + tapnNetwork.sharedPlaces().forEach(o -> { |
111 | + if (net.getPlaceByName(o.name()) != null && !net.getPlaceByName(o.name()).name().contains("Shared_")) { |
112 | + net.getPlaceByName(o.name()).setName("Shared_" + o.name()); |
113 | + } |
114 | + }); |
115 | + tapnNetwork.allTemplates().forEach(o -> o.places().forEach(x -> { |
116 | + if (net.getPlaceByName(x.name()) != null) net.getPlaceByName(x.name()).setName(o.name() + "_" + x.name()); |
117 | + })); |
118 | + |
119 | + for (TimedPlace place : net.places()) { |
120 | + factors.add(new TCTLPlaceNode(place.name())); |
121 | + factors.add(new AritmeticOperator("+")); |
122 | + } |
123 | + if (factors.get(factors.size()-1) instanceof AritmeticOperator) factors.remove(factors.size()-1); |
124 | + |
125 | + return factors; |
126 | + } |
127 | + |
128 | + private TimedArcPetriNet mergeNetComponents() { |
129 | + TAPNComposer composer = new TAPNComposer(new MessengerImpl(), CreateGui.getCurrentTab().getGuiModels(), true, true); |
130 | + Tuple<TimedArcPetriNet, NameMapping> transformedModel = composer.transformModel(tapnNetwork); |
131 | + |
132 | + return transformedModel.value1(); |
133 | + } |
134 | } |
135 | |
136 | === modified file 'src/pipe/gui/RunKBoundAnalysis.java' |
137 | --- src/pipe/gui/RunKBoundAnalysis.java 2020-05-27 12:59:31 +0000 |
138 | +++ src/pipe/gui/RunKBoundAnalysis.java 2021-08-25 10:24:16 +0000 |
139 | @@ -4,33 +4,47 @@ |
140 | import javax.swing.JSpinner; |
141 | |
142 | import dk.aau.cs.Messenger; |
143 | +import dk.aau.cs.verification.VerifyTAPN.VerifyPN; |
144 | import net.tapaal.resourcemanager.ResourceManager; |
145 | import dk.aau.cs.model.tapn.simulation.TAPNNetworkTrace; |
146 | import dk.aau.cs.verification.Boundedness; |
147 | import dk.aau.cs.verification.ModelChecker; |
148 | import dk.aau.cs.verification.VerificationResult; |
149 | |
150 | +import java.util.ArrayList; |
151 | + |
152 | public class RunKBoundAnalysis extends RunVerificationBase { |
153 | |
154 | private final JSpinner spinner; |
155 | |
156 | public RunKBoundAnalysis(ModelChecker modelChecker, Messenger messenger,JSpinner spinner) { |
157 | - super(modelChecker, messenger); |
158 | + super(modelChecker, messenger, spinner); |
159 | this.spinner = spinner; |
160 | } |
161 | |
162 | @Override |
163 | - protected void showResult(VerificationResult<TAPNNetworkTrace> result) { |
164 | + protected boolean showResult(VerificationResult<TAPNNetworkTrace> result) { |
165 | if(result != null && !result.error()) { |
166 | if (!result.getQueryResult().boundednessAnalysis().boundednessResult().equals(Boundedness.Bounded)) { |
167 | JOptionPane.showMessageDialog(CreateGui.getApp(), |
168 | getAnswerNotBoundedString(), "Analysis Result", |
169 | JOptionPane.INFORMATION_MESSAGE); |
170 | } else { |
171 | - spinner.setValue(result.getQueryResult().boundednessAnalysis().usedTokens() - result.getQueryResult().boundednessAnalysis().tokensInNet()); |
172 | - JOptionPane.showMessageDialog(CreateGui.getApp(), |
173 | - getAnswerBoundedString(), "Analysis Result", |
174 | - JOptionPane.INFORMATION_MESSAGE, ResourceManager.satisfiedIcon()); |
175 | + if (modelChecker instanceof VerifyPN && !result.getRawOutput().contains("max tokens:")) { |
176 | + Object[] options = {"Ok", "Minimize extra tokens"}; |
177 | + int answer = JOptionPane.showOptionDialog(CreateGui.getApp(), |
178 | + getPNAnswerBoundedString(), "Analysis Result,", |
179 | + JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, |
180 | + ResourceManager.satisfiedIcon(), options, JOptionPane.OK_OPTION); |
181 | + return answer != JOptionPane.OK_OPTION; |
182 | + } else if (modelChecker instanceof VerifyPN) { |
183 | + spinner.setValue(result.getQueryResult().boundednessAnalysis().usedTokens() - result.getQueryResult().boundednessAnalysis().tokensInNet()); |
184 | + } else { |
185 | + spinner.setValue(result.getQueryResult().boundednessAnalysis().usedTokens() - result.getQueryResult().boundednessAnalysis().tokensInNet()); |
186 | + JOptionPane.showMessageDialog(CreateGui.getApp(), |
187 | + getAnswerBoundedString(), "Analysis Result", |
188 | + JOptionPane.INFORMATION_MESSAGE, ResourceManager.satisfiedIcon()); |
189 | + } |
190 | } |
191 | } else { |
192 | String message = "An error occured during the verification." + |
193 | @@ -40,6 +54,7 @@ |
194 | |
195 | messenger.displayWrappedErrorMessage(message,"Error during verification"); |
196 | } |
197 | + return false; |
198 | } |
199 | |
200 | protected String getAnswerNotBoundedString() { |
201 | @@ -58,4 +73,12 @@ |
202 | + "The number of extra tokens was automatically lowered to the\n" |
203 | + "minimum number of tokens needed for an exact analysis."; |
204 | } |
205 | + |
206 | + protected String getPNAnswerBoundedString() { |
207 | + return "The net with the specified extra number of tokens is bounded.\n\n" |
208 | + + "This means that the analysis will be exact and always give \n" |
209 | + + "the correct answer.\n\n" |
210 | + + "The number of extra tokens can be lowered to the minimum number\n" |
211 | + + "of tokens needed for an exact analysis."; |
212 | + } |
213 | } |
214 | |
215 | === modified file 'src/pipe/gui/RunVerification.java' |
216 | --- src/pipe/gui/RunVerification.java 2021-02-22 22:56:50 +0000 |
217 | +++ src/pipe/gui/RunVerification.java 2021-08-25 10:24:16 +0000 |
218 | @@ -31,7 +31,7 @@ |
219 | private final IconSelector iconSelector; |
220 | private final VerificationCallback callback; |
221 | public RunVerification(ModelChecker modelChecker, IconSelector selector, Messenger messenger, VerificationCallback callback, String reducedNetFilePath, boolean reduceNetOnly) { |
222 | - super(modelChecker, messenger, reducedNetFilePath, reduceNetOnly); |
223 | + super(modelChecker, messenger, reducedNetFilePath, reduceNetOnly, null); |
224 | iconSelector = selector; |
225 | this.callback = callback; |
226 | } |
227 | @@ -45,7 +45,7 @@ |
228 | } |
229 | |
230 | @Override |
231 | - protected void showResult(VerificationResult<TAPNNetworkTrace> result) { |
232 | + protected boolean showResult(VerificationResult<TAPNNetworkTrace> result) { |
233 | if (result != null && !result.error()) { |
234 | if(callback != null){ |
235 | callback.run(result); |
236 | @@ -98,6 +98,7 @@ |
237 | messenger.displayWrappedErrorMessage(message,"Error during verification"); |
238 | |
239 | } |
240 | + return false; |
241 | } |
242 | |
243 | private String toHTML(String string){ |
244 | |
245 | === modified file 'src/pipe/gui/RunVerificationBase.java' |
246 | --- src/pipe/gui/RunVerificationBase.java 2021-02-07 11:09:51 +0000 |
247 | +++ src/pipe/gui/RunVerificationBase.java 2021-08-25 10:24:16 +0000 |
248 | @@ -3,9 +3,9 @@ |
249 | import java.io.File; |
250 | import java.util.concurrent.ExecutionException; |
251 | |
252 | -import javax.swing.SwingUtilities; |
253 | -import javax.swing.SwingWorker; |
254 | +import javax.swing.*; |
255 | |
256 | +import dk.aau.cs.verification.VerifyTAPN.VerifyTAPNOptions; |
257 | import pipe.dataLayer.TAPNQuery.SearchOption; |
258 | import dk.aau.cs.Messenger; |
259 | import dk.aau.cs.TCTL.visitors.RenameAllPlacesVisitor; |
260 | @@ -43,20 +43,25 @@ |
261 | protected String reducedNetFilePath; |
262 | protected boolean reduceNetOnly; |
263 | protected boolean reducedNetOpened = false; |
264 | - |
265 | - |
266 | + protected JSpinner spinner; |
267 | + |
268 | protected Messenger messenger; |
269 | |
270 | - public RunVerificationBase(ModelChecker modelChecker, Messenger messenger, String reducedNetFilePath, boolean reduceNetOnly) { |
271 | + public RunVerificationBase(ModelChecker modelChecker, Messenger messenger, String reducedNetFilePath, boolean reduceNetOnly, JSpinner spinner) { |
272 | super(); |
273 | this.modelChecker = modelChecker; |
274 | this.messenger = messenger; |
275 | this.reducedNetFilePath = reducedNetFilePath; |
276 | this.reduceNetOnly = reduceNetOnly; |
277 | - } |
278 | + this.spinner = spinner; |
279 | + } |
280 | |
281 | public RunVerificationBase(ModelChecker modelChecker, Messenger messenger) { |
282 | - this(modelChecker, messenger, null, false); |
283 | + this(modelChecker, messenger, null, false, null); |
284 | + } |
285 | + |
286 | + public RunVerificationBase(ModelChecker modelChecker, Messenger messenger, JSpinner spinner) { |
287 | + this(modelChecker, messenger, null, false, spinner); |
288 | } |
289 | |
290 | |
291 | @@ -212,8 +217,12 @@ |
292 | return; |
293 | } |
294 | firePropertyChange("state", StateValue.PENDING, StateValue.DONE); |
295 | - showResult(result); |
296 | |
297 | + if (showResult(result) && spinner != null) { |
298 | + options = new VerifyPNOptions(options.extraTokens(), pipe.dataLayer.TAPNQuery.TraceOption.NONE, SearchOption.BFS, false, ModelReduction.BOUNDPRESERVING, false, false, 1, pipe.dataLayer.TAPNQuery.QueryCategory.Default, pipe.dataLayer.TAPNQuery.AlgorithmOption.CERTAIN_ZERO, false, pipe.dataLayer.TAPNQuery.QueryReductionTime.NoTime, false, null, false); |
299 | + KBoundAnalyzer optimizer = new KBoundAnalyzer(model, options.extraTokens(), modelChecker, new MessengerImpl(), spinner); |
300 | + optimizer.analyze((VerifyTAPNOptions) options); |
301 | + } |
302 | } else { |
303 | modelChecker.kill(); |
304 | messenger.displayInfoMessage("Verification was interrupted by the user. No result found!", "Verification Cancelled"); |
305 | @@ -231,5 +240,5 @@ |
306 | }); |
307 | } |
308 | |
309 | - protected abstract void showResult(VerificationResult<TAPNNetworkTrace> result); |
310 | + protected abstract boolean showResult(VerificationResult<TAPNNetworkTrace> result); |
311 | } |
Open the game-harddisk example and check for boundedness, it is broken.