Merge lp:~tapaal-contributor/tapaal/Net-statistics-should-display-orphan-places-1879127 into lp:tapaal
- Net-statistics-should-display-orphan-places-1879127
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jiri Srba | ||||
Approved revision: | 1063 | ||||
Merged at revision: | 1062 | ||||
Proposed branch: | lp:~tapaal-contributor/tapaal/Net-statistics-should-display-orphan-places-1879127 | ||||
Merge into: | lp:tapaal | ||||
Diff against target: |
619 lines (+260/-104) 8 files modified
src/dk/aau/cs/gui/TabContent.java (+1/-1) src/dk/aau/cs/gui/components/StatisticsPanel.java (+147/-78) src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java (+9/-4) src/dk/aau/cs/model/tapn/SharedPlace.java (+7/-2) src/dk/aau/cs/model/tapn/TimedArcPetriNet.java (+37/-13) src/dk/aau/cs/model/tapn/TimedPlace.java (+56/-3) src/dk/aau/cs/model/tapn/TimedTransition.java (+2/-2) src/pipe/gui/GuiFrame.java (+1/-1) |
||||
To merge this branch: | bzr merge lp:~tapaal-contributor/tapaal/Net-statistics-should-display-orphan-places-1879127 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Lena Ernstsen (community) | Needs Resubmitting | ||
Kenneth Yrke Jørgensen | Approve | ||
Review via email: mp+385044@code.launchpad.net |
Commit message
Added to the statistics tab the 'Remove orphan places' button and statistics of number of orphan places.
Fixed the wrong behaviour of the 'Remove orphan transitions' button.
Description of the change
- 1062. By Lena Ernstsen
-
Removed unused method
Jiri Srba (srba) wrote : | # |
Tested and it works very nicely. When I open the dialog, move it to the corner of the screen and click remove transitions/places (assuming there are some), it will reset the dialog position to the center of the screen again. Would it be possible that it stays where it currently is?
Kenneth Yrke Jørgensen (yrke) wrote : | # |
I think for now merge the change, and then lets make a new request for keeping location, I will require some changes in how the update is handled.
Jiri Srba (srba) wrote : | # |
There is a bug when removing orphan transitions (not introduced in the branch I guess).
Make a place and a transition and connect them by inhibitor arcs. Then the transition is marked
as orphan and when it is removed the arcs remains there and there is exception thrown.
Also, if possible not to reset the dialog position after removal already in this branch before merge, this would be nice.
- 1063. By Lena Ernstsen
-
Fixed bug with orphan transitions and inhibitor arcs
Lena Ernstsen (lsaid) wrote : | # |
Fixed bug with orphan transitions and inhibitor arcs
Jiri Srba (srba) : | # |
Preview Diff
1 | === modified file 'src/dk/aau/cs/gui/TabContent.java' |
2 | --- src/dk/aau/cs/gui/TabContent.java 2020-06-17 20:30:35 +0000 |
3 | +++ src/dk/aau/cs/gui/TabContent.java 2020-06-18 20:57:23 +0000 |
4 | @@ -1085,7 +1085,7 @@ |
5 | |
6 | @Override |
7 | public void showStatistics() { |
8 | - StatisticsPanel.showStatisticsPanel(drawingSurface().getModel().getStatistics()); |
9 | + StatisticsPanel.showStatisticsPanel(drawingSurface().getModel().getStatistics()); |
10 | } |
11 | |
12 | @Override |
13 | |
14 | === modified file 'src/dk/aau/cs/gui/components/StatisticsPanel.java' |
15 | --- src/dk/aau/cs/gui/components/StatisticsPanel.java 2020-04-18 12:27:02 +0000 |
16 | +++ src/dk/aau/cs/gui/components/StatisticsPanel.java 2020-06-18 20:57:23 +0000 |
17 | @@ -17,8 +17,11 @@ |
18 | import javax.swing.JPanel; |
19 | import javax.swing.JSeparator; |
20 | |
21 | +import dk.aau.cs.model.tapn.TimedPlace; |
22 | import pipe.gui.*; |
23 | +import pipe.gui.graphicElements.tapn.TimedPlaceComponent; |
24 | import pipe.gui.graphicElements.tapn.TimedTransitionComponent; |
25 | +import pipe.gui.undo.DeleteTimedPlaceCommand; |
26 | import pipe.gui.undo.DeleteTimedTransitionCommand; |
27 | import pipe.gui.undo.UndoManager; |
28 | import pipe.dataLayer.*; |
29 | @@ -32,8 +35,10 @@ |
30 | private final int topBottomMargin = 3; |
31 | private final int rightMargin = 10; |
32 | |
33 | - private JButton removeOrphans; |
34 | - private static final String REMOVE_ORPHANS_TOOL_TIP = "<html>Remove all orphan transitions<br /> (transitions with no arcs attached)<br /> in all components</html>"; |
35 | + private JButton removeOrphanTransitions; |
36 | + private JButton removeOrphanPlaces; |
37 | + private static final String REMOVE_ORPHAN_TRANSITIONS_TOOL_TIP = "<html>Remove all orphan transitions<br /> (transitions with no arcs attached)<br /> in all components</html>"; |
38 | + private static final String REMOVE_ORPHAN_PLACES_TOOL_TIP = "<html>Remove all orphan places<br /> (transitions with no arcs attached)<br /> in all components</html>"; |
39 | private static final String DIALOG_TITLE = "Statistics"; |
40 | |
41 | String[] headLines = {"", "Shown component", "Active components", "All components"}; |
42 | @@ -50,8 +55,8 @@ |
43 | } |
44 | |
45 | public static void showStatisticsPanel(Object[][] statistics){ |
46 | - StatisticsPanel panel = new StatisticsPanel(statistics); |
47 | - |
48 | + StatisticsPanel panel = new StatisticsPanel(statistics); |
49 | + |
50 | JOptionPane optionPane = new JOptionPane(panel, JOptionPane.INFORMATION_MESSAGE); |
51 | |
52 | dialog = optionPane.createDialog(DIALOG_TITLE); |
53 | @@ -61,11 +66,10 @@ |
54 | } |
55 | |
56 | private JPanel init() { |
57 | - |
58 | addRow(headLines, 0, true); |
59 | |
60 | - //Add the content - make space for separators (except the orphan transitions |
61 | - for(int i = 0; i < contents.length - 1; i++){ |
62 | + //Add the content - make space for separators (except the orphan transitions) |
63 | + for(int i = 0; i < contents.length - 2; i++){ |
64 | addRow(contents[i], (i+1)*2, false); |
65 | } |
66 | |
67 | @@ -83,27 +87,11 @@ |
68 | gbc.gridy = i; |
69 | this.add(jSep, gbc); |
70 | } |
71 | - |
72 | - //If any orphan transitions - add them |
73 | - boolean orphanTransitions = false; |
74 | - for(int i = 1; i< contents[contents.length-1].length; i++){ |
75 | - if(!contents[contents.length-1][i].toString().equals("0")){ |
76 | - orphanTransitions = true; |
77 | - } |
78 | - } |
79 | - |
80 | - if(orphanTransitions){ |
81 | - jSep = new JSeparator(); |
82 | - jSep.setPreferredSize(new Dimension(1, 3)); |
83 | - gbc.gridy = contents.length*2-1; |
84 | - this.add(jSep, gbc); |
85 | - addRow(contents[contents.length-1], contents.length*2, false); |
86 | - jSep = new JSeparator(); |
87 | - jSep.setPreferredSize(new Dimension(1, 3)); |
88 | - gbc.gridy = contents.length*2+1; |
89 | - this.add(jSep, gbc); |
90 | - addButtons(headLines.length, contents.length*2); |
91 | - } |
92 | + |
93 | + addOrphanButtons(gbc); |
94 | + |
95 | + this.setVisible(true); |
96 | + |
97 | return null; |
98 | } |
99 | |
100 | @@ -128,61 +116,142 @@ |
101 | } |
102 | } |
103 | } |
104 | + |
105 | + private boolean checkIfOrphan(int contentNumber, GridBagConstraints gbc, boolean orphanTransitions) { |
106 | + boolean isOrphan = false; |
107 | + int rowNumber; |
108 | + |
109 | + for (int i = 1; i < contents[contents.length - contentNumber].length; i++) { |
110 | + if (!contents[contents.length - contentNumber][i].toString().equals("0")) { |
111 | + isOrphan = true; |
112 | + } |
113 | + } |
114 | + |
115 | + if (isOrphan) { |
116 | + if (contentNumber == 1 && orphanTransitions) { |
117 | + rowNumber = contents.length * 2 - 2; |
118 | + } |
119 | + else { |
120 | + rowNumber = contents.length * 2; |
121 | + } |
122 | + JSeparator jSep = new JSeparator(); |
123 | + jSep.setPreferredSize(new Dimension(1, 3)); |
124 | + gbc.gridy = contents.length * 2 - 1; |
125 | + this.add(jSep, gbc); |
126 | + addRow(contents[contents.length - contentNumber], rowNumber, false); |
127 | + |
128 | + jSep = new JSeparator(); |
129 | + jSep.setPreferredSize(new Dimension(1, 3)); |
130 | + gbc.gridy = contents.length * 2 + 1; |
131 | + this.add(jSep, gbc); |
132 | + } |
133 | + return isOrphan; |
134 | + } |
135 | |
136 | - private void addButtons(int gridWidth, int gridHeight){ |
137 | - removeOrphans = new JButton("Remove orphan transitions"); |
138 | - removeOrphans.setToolTipText(REMOVE_ORPHANS_TOOL_TIP); |
139 | + private void addOrphanButtons(GridBagConstraints gbc) { |
140 | + boolean orphanTransition = checkIfOrphan(2, gbc, false); |
141 | + boolean orphanPlace = checkIfOrphan(1, gbc, orphanTransition); |
142 | + |
143 | + removeOrphanTransitions = new JButton("Remove orphan transitions"); |
144 | + removeOrphanTransitions.setToolTipText(REMOVE_ORPHAN_TRANSITIONS_TOOL_TIP); |
145 | + removeOrphanPlaces = new JButton("Remove orphan places"); |
146 | + removeOrphanPlaces.setToolTipText(REMOVE_ORPHAN_PLACES_TOOL_TIP); |
147 | + |
148 | final JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
149 | - removeOrphans.addActionListener(new ActionListener() { |
150 | - |
151 | - |
152 | - public void actionPerformed(ActionEvent e) { |
153 | - TabContent tab = CreateGui.getCurrentTab(); |
154 | - Iterable<Template> templates = tab.allTemplates(); |
155 | - |
156 | - UndoManager undoManager = CreateGui.getCurrentTab().getUndoManager(); |
157 | - boolean first = true; |
158 | - for(Template template : templates){ |
159 | - List<TimedTransition> orphans = template.model().getOrphanTransitions(); |
160 | - for(TimedTransition trans : orphans){ |
161 | - TimedTransitionComponent t = (TimedTransitionComponent)template.guiModel().getTransitionByName(trans.name()); |
162 | - Command cmd = new DeleteTimedTransitionCommand(t, t.underlyingTransition().model(), template.guiModel()); |
163 | - |
164 | - if(first){ |
165 | - undoManager.addNewEdit(cmd); |
166 | - first = false; |
167 | - } else { |
168 | - undoManager.addEdit(cmd); |
169 | - } |
170 | - cmd.redo(); |
171 | - } |
172 | - } |
173 | - |
174 | - |
175 | - tab.drawingSurface().repaint(); |
176 | - |
177 | - StatisticsPanel.this.removeAll(); |
178 | - StatisticsPanel.this.init(); |
179 | - |
180 | - JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE); |
181 | - |
182 | - dialog.dispose(); |
183 | - |
184 | - dialog = optionPane.createDialog(DIALOG_TITLE); |
185 | - |
186 | - dialog.pack(); |
187 | - dialog.setVisible(true); |
188 | - } |
189 | - }); |
190 | - |
191 | - buttonsPanel.add(removeOrphans); |
192 | - |
193 | - GridBagConstraints gbc = new GridBagConstraints(); |
194 | + |
195 | + if (orphanTransition) { |
196 | + addTransitionAction(); |
197 | + buttonsPanel.add(removeOrphanTransitions); |
198 | + } |
199 | + if (orphanPlace) { |
200 | + addPlaceAction(); |
201 | + buttonsPanel.add(removeOrphanPlaces); |
202 | + } |
203 | + |
204 | + gbc = new GridBagConstraints(); |
205 | gbc.gridx = 0; |
206 | - gbc.gridy = gridHeight + 2; |
207 | + gbc.gridy = contents.length * 2 + 2; |
208 | gbc.anchor = GridBagConstraints.EAST; |
209 | gbc.fill = GridBagConstraints.HORIZONTAL; |
210 | - gbc.gridwidth = gridWidth; |
211 | + gbc.gridwidth = headLines.length; |
212 | this.add(buttonsPanel, gbc); |
213 | } |
214 | + |
215 | + private void addTransitionAction() { |
216 | + removeOrphanTransitions.addActionListener(new ActionListener() { |
217 | + public void actionPerformed(ActionEvent e) { |
218 | + TabContent tab = CreateGui.getCurrentTab(); |
219 | + Iterable<Template> templates = tab.allTemplates(); |
220 | + |
221 | + UndoManager undoManager = tab.getUndoManager(); |
222 | + boolean first = true; |
223 | + for (Template template : templates) { |
224 | + List<TimedTransition> orphans = template.model().getOrphanTransitions(); |
225 | + for (TimedTransition trans : orphans) { |
226 | + TimedTransitionComponent t = (TimedTransitionComponent)template.guiModel().getTransitionByName(trans.name()); |
227 | + Command cmd = new DeleteTimedTransitionCommand(t, t.underlyingTransition().model(), template.guiModel()); |
228 | + |
229 | + if (first) { |
230 | + undoManager.addNewEdit(cmd); |
231 | + first = false; |
232 | + } else { |
233 | + undoManager.addEdit(cmd); |
234 | + } |
235 | + cmd.redo(); |
236 | + } |
237 | + contents = template.model().getStatistics(); |
238 | + } |
239 | + tab.drawingSurface().repaint(); |
240 | + |
241 | + StatisticsPanel.this.removeAll(); |
242 | + StatisticsPanel.this.init(); |
243 | + |
244 | + JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE); |
245 | + |
246 | + dialog.dispose(); |
247 | + dialog = optionPane.createDialog(DIALOG_TITLE); |
248 | + dialog.pack(); |
249 | + dialog.setVisible(true); |
250 | + } |
251 | + }); |
252 | + } |
253 | + |
254 | + private void addPlaceAction() { |
255 | + removeOrphanPlaces.addActionListener(new ActionListener() { |
256 | + public void actionPerformed(ActionEvent e) { |
257 | + TabContent tab = CreateGui.getCurrentTab(); |
258 | + Iterable<Template> templates = tab.allTemplates(); |
259 | + |
260 | + UndoManager undoManager = tab.getUndoManager(); |
261 | + boolean first = true; |
262 | + for (Template template : templates) { |
263 | + List<TimedPlace> orphans = template.model().getOrphanPlaces(); |
264 | + for (TimedPlace place : orphans) { |
265 | + TimedPlaceComponent timedPlace = (TimedPlaceComponent)template.guiModel().getPlaceByName(place.name()); |
266 | + Command cmd = new DeleteTimedPlaceCommand(timedPlace, template.model(), template.guiModel()); |
267 | + |
268 | + if (first) { |
269 | + undoManager.addNewEdit(cmd); |
270 | + first = false; |
271 | + } else { |
272 | + undoManager.addEdit(cmd); |
273 | + } |
274 | + cmd.redo(); |
275 | + } |
276 | + contents = template.model().getStatistics(); |
277 | + } |
278 | + tab.drawingSurface().repaint(); |
279 | + |
280 | + StatisticsPanel.this.removeAll(); |
281 | + StatisticsPanel.this.init(); |
282 | + |
283 | + JOptionPane optionPane = new JOptionPane(StatisticsPanel.this, JOptionPane.INFORMATION_MESSAGE); |
284 | + |
285 | + dialog.dispose(); |
286 | + dialog = optionPane.createDialog(DIALOG_TITLE); |
287 | + dialog.pack(); |
288 | + dialog.setVisible(true); |
289 | + } |
290 | + }); |
291 | + } |
292 | } |
293 | |
294 | === modified file 'src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java' |
295 | --- src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java 2020-04-18 14:41:05 +0000 |
296 | +++ src/dk/aau/cs/gui/undo/MakePlaceSharedCommand.java 2020-06-18 20:57:23 +0000 |
297 | @@ -75,29 +75,34 @@ |
298 | for(TimedInputArc arc : tapn.inputArcs()){ |
299 | if(arc.source().equals(toReplace)){ |
300 | arc.setSource(replacement); |
301 | + replacement.addInputArc(arc); |
302 | } |
303 | } |
304 | |
305 | for(TimedInhibitorArc arc : tapn.inhibitorArcs()){ |
306 | if(arc.source().equals(toReplace)){ |
307 | arc.setSource(replacement); |
308 | - } |
309 | + replacement.addInhibitorArc(arc); |
310 | + } |
311 | } |
312 | |
313 | for(TransportArc arc : tapn.transportArcs()){ |
314 | if(arc.source().equals(toReplace)){ |
315 | arc.setSource(replacement); |
316 | - } |
317 | + replacement.addTransportArc(arc); |
318 | + } |
319 | |
320 | if(arc.destination().equals(toReplace)){ |
321 | arc.setDestination(replacement); |
322 | - } |
323 | + replacement.addTransportArc(arc); |
324 | + } |
325 | } |
326 | |
327 | for(TimedOutputArc arc : tapn.outputArcs()){ |
328 | if(arc.destination().equals(toReplace)){ |
329 | arc.setDestination(replacement); |
330 | - } |
331 | + replacement.addOutputArc(arc); |
332 | + } |
333 | } |
334 | } |
335 | |
336 | |
337 | === modified file 'src/dk/aau/cs/model/tapn/SharedPlace.java' |
338 | --- src/dk/aau/cs/model/tapn/SharedPlace.java 2019-11-26 13:59:12 +0000 |
339 | +++ src/dk/aau/cs/model/tapn/SharedPlace.java 2020-06-18 20:57:23 +0000 |
340 | @@ -15,8 +15,9 @@ |
341 | private static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); |
342 | |
343 | private String name; |
344 | - private TimeInvariant invariant; |
345 | - |
346 | + private List<TimedPlace> places = new ArrayList<TimedPlace>(); |
347 | + private TimeInvariant invariant; |
348 | + |
349 | private TimedArcPetriNetNetwork network; |
350 | private TimedMarking currentMarking; |
351 | private Tuple<PlaceType, Integer> extrapolation = new Tuple<TimedPlace.PlaceType, Integer>(PlaceType.Dead, -2); |
352 | @@ -213,4 +214,8 @@ |
353 | |
354 | return new Tuple<TimedPlace.PlaceType, Integer>(type, cmax); |
355 | } |
356 | + |
357 | + public List<TimedPlace> getPlaces() { |
358 | + return places; |
359 | + } |
360 | } |
361 | |
362 | === modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNet.java' |
363 | --- src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2020-04-18 13:33:48 +0000 |
364 | +++ src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2020-06-18 20:57:23 +0000 |
365 | @@ -75,6 +75,7 @@ |
366 | |
367 | arc.setModel(this); |
368 | inputArcs.add(arc); |
369 | + arc.source().addInputArc(arc); |
370 | arc.destination().addToPreset(arc); |
371 | } |
372 | |
373 | @@ -90,7 +91,8 @@ |
374 | arc.setModel(this); |
375 | outputArcs.add(arc); |
376 | arc.source().addToPostset(arc); |
377 | - } |
378 | + arc.destination().addOutputArc(arc); |
379 | + } |
380 | |
381 | public void add(TimedInhibitorArc arc) { |
382 | Require.that(arc != null, "Argument must be a non-null output arc."); |
383 | @@ -102,6 +104,7 @@ |
384 | arc.setModel(this); |
385 | inhibitorArcs.add(arc); |
386 | arc.destination().addInhibitorArc(arc); |
387 | + arc.source().addInhibitorArc(arc); |
388 | } |
389 | |
390 | public void add(TransportArc arc) { |
391 | @@ -116,6 +119,8 @@ |
392 | arc.setModel(this); |
393 | transportArcs.add(arc); |
394 | arc.transition().addTransportArcGoingThrough(arc); |
395 | + arc.source().addTransportArc(arc); |
396 | + arc.destination().addTransportArc(arc); |
397 | } |
398 | |
399 | public void addToken(TimedToken token) { |
400 | @@ -146,15 +151,17 @@ |
401 | boolean removed = inputArcs.remove(arc); |
402 | if (removed) { |
403 | arc.setModel(null); |
404 | - arc.destination().removeFromPreset(arc); |
405 | - } |
406 | + arc.source().removeInputArc(arc); |
407 | + arc.destination().removeFromPreset(arc); |
408 | + } |
409 | } |
410 | |
411 | public void remove(TransportArc arc) { |
412 | boolean removed = transportArcs.remove(arc); |
413 | if (removed) { |
414 | arc.setModel(null); |
415 | - arc.transition().removeTransportArcGoingThrough(arc); |
416 | + arc.destination().removeTransportArc(arc); |
417 | + arc.transition().removeTransportArcGoingThrough(arc); |
418 | } |
419 | } |
420 | |
421 | @@ -162,7 +169,8 @@ |
422 | boolean removed = outputArcs.remove(arc); |
423 | if (removed) { |
424 | arc.setModel(null); |
425 | - arc.source().removeFromPostset(arc); |
426 | + arc.source().removeFromPostset(arc); |
427 | + arc.destination().removeOutputArc(arc); |
428 | } |
429 | } |
430 | |
431 | @@ -170,7 +178,8 @@ |
432 | boolean removed = inhibitorArcs.remove(arc); |
433 | if (removed) { |
434 | arc.setModel(null); |
435 | - arc.destination().removeInhibitorArc(arc); |
436 | + arc.destination().removeInhibitorArc(arc); |
437 | + arc.source().removeInhibitorArc(arc); |
438 | } |
439 | } |
440 | |
441 | @@ -386,8 +395,9 @@ |
442 | int numberOfTransportArcs = 0; |
443 | int numberOfTotalNumberOfArcs = 0; |
444 | int numberOfTokens = 0; |
445 | - int numberOfOrphans = 0; |
446 | - boolean networkUntimed = true; |
447 | + int numberOfOrphanTransitions = 0; |
448 | + int numberOfOrphanPlaces = 0; |
449 | + boolean networkUntimed = true; |
450 | boolean networkWeighted = false; |
451 | int numberOfUntimedInputArcs = 0; |
452 | int numberOfUntimedTransportArcs = 0; |
453 | @@ -427,7 +437,8 @@ |
454 | numberOfOutputArcs += t.outputArcs.size(); |
455 | numberOfInhibitorArcs += t.inhibitorArcs.size(); |
456 | numberOfTransportArcs += t.transportArcs.size(); |
457 | - numberOfOrphans += t.getOrphanTransitions().size(); |
458 | + numberOfOrphanTransitions += t.getOrphanTransitions().size(); |
459 | + numberOfOrphanPlaces += t.getOrphanPlaces().size(); |
460 | //Test if all inputarcs is untimed and get the number of untimed input arcs |
461 | for(TimedInputArc in : t.inputArcs()){ |
462 | if(!((in.interval().lowerBound().value() == 0 && in.interval().IsLowerBoundNonStrict() && in.interval().upperBound().equals(Bound.Infinity)))){ |
463 | @@ -496,12 +507,13 @@ |
464 | rowNumber += 2; |
465 | array[rowNumber++][columnNumber] = networkUntimed ? "yes" : "no"; |
466 | array[rowNumber++][columnNumber] = networkWeighted ? "yes" : "no"; |
467 | - array[rowNumber++][columnNumber] = numberOfOrphans; |
468 | + array[rowNumber++][columnNumber] = numberOfOrphanTransitions; |
469 | + array[rowNumber++][columnNumber] = numberOfOrphanPlaces; |
470 | } |
471 | |
472 | public Object[][] getStatistics(){ |
473 | |
474 | - Object[][] result = new Object[16][4]; |
475 | + Object[][] result = new Object[17][4]; |
476 | int rowNumber = 0; |
477 | int columnNumber = 0; |
478 | result[rowNumber++][columnNumber] = "Number of components considered: "; |
479 | @@ -520,8 +532,9 @@ |
480 | result[rowNumber++][columnNumber] = "The network is untimed: "; |
481 | result[rowNumber++][columnNumber] = "The network is weighted: "; |
482 | result[rowNumber++][columnNumber] = "Number of orphan transitions: "; |
483 | - |
484 | - fillStatistics(Arrays.asList(new TimedArcPetriNet[] {this}), result, 1); |
485 | + result[rowNumber++][columnNumber] = "Number of orphan places: "; |
486 | + |
487 | + fillStatistics(Arrays.asList(new TimedArcPetriNet[] {this}), result, 1); |
488 | fillStatistics(this.parentNetwork().activeTemplates(), result, 2); |
489 | fillStatistics(this.parentNetwork().allTemplates(), result, 3); |
490 | |
491 | @@ -543,6 +556,17 @@ |
492 | |
493 | return orphans; |
494 | } |
495 | + |
496 | + public List<TimedPlace> getOrphanPlaces(){ |
497 | + List<TimedPlace> orphans = new ArrayList<TimedPlace>(); |
498 | + |
499 | + for (TimedPlace place : places) { |
500 | + if (place.isOrphan()) { |
501 | + orphans.add(place); |
502 | + } |
503 | + } |
504 | + return orphans; |
505 | + } |
506 | |
507 | public int getNumberOfTokensInNet(){ |
508 | int result = 0; |
509 | |
510 | === modified file 'src/dk/aau/cs/model/tapn/TimedPlace.java' |
511 | --- src/dk/aau/cs/model/tapn/TimedPlace.java 2020-03-29 12:40:43 +0000 |
512 | +++ src/dk/aau/cs/model/tapn/TimedPlace.java 2020-06-18 20:57:23 +0000 |
513 | @@ -4,10 +4,17 @@ |
514 | import java.util.List; |
515 | |
516 | import dk.aau.cs.model.tapn.event.TimedPlaceListener; |
517 | +import dk.aau.cs.util.Require; |
518 | import dk.aau.cs.util.Tuple; |
519 | |
520 | public abstract class TimedPlace { |
521 | - public enum PlaceType{ |
522 | + private SharedPlace sharedPlace; |
523 | + private List<TimedOutputArc> postset = new ArrayList<TimedOutputArc>(); |
524 | + private List<TimedInputArc> preset = new ArrayList<TimedInputArc>(); |
525 | + private List<TransportArc> transportArcs = new ArrayList<TransportArc>(); |
526 | + private List<TimedInhibitorArc> inhibitorArcs = new ArrayList<TimedInhibitorArc>(); |
527 | + |
528 | + public enum PlaceType{ |
529 | Standard, Invariant, Dead |
530 | } |
531 | |
532 | @@ -57,8 +64,54 @@ |
533 | TimedPlace other = (TimedPlace) obj; |
534 | return name() == other.name(); |
535 | } |
536 | - |
537 | - |
538 | + |
539 | + public boolean isOrphan() { |
540 | + return presetSize() == 0 && postsetSize() == 0; |
541 | + } |
542 | + |
543 | + public void addInputArc(TimedInputArc arc) { |
544 | + Require.that(arc != null, "Cannot add null to preset"); |
545 | + preset.add(arc); |
546 | + } |
547 | + |
548 | + public void addOutputArc(TimedOutputArc arc) { |
549 | + Require.that(arc != null, "Cannot add null to postset"); |
550 | + postset.add(arc); |
551 | + } |
552 | + |
553 | + public void removeInputArc(TimedInputArc arc) { |
554 | + preset.remove(arc); |
555 | + } |
556 | + |
557 | + public void removeOutputArc(TimedOutputArc arc) { |
558 | + postset.remove(arc); |
559 | + } |
560 | + |
561 | + public void addTransportArc(TransportArc arc) { |
562 | + Require.that(arc != null, "Cannot add null to preset"); |
563 | + transportArcs.add(arc); |
564 | + } |
565 | + |
566 | + public void removeTransportArc(TransportArc arc) { |
567 | + transportArcs.remove(arc); |
568 | + } |
569 | + |
570 | + public void addInhibitorArc(TimedInhibitorArc arc) { |
571 | + inhibitorArcs.add(arc); |
572 | + } |
573 | + |
574 | + public void removeInhibitorArc(TimedInhibitorArc arc) { |
575 | + inhibitorArcs.remove(arc); |
576 | + } |
577 | + |
578 | + public int presetSize() { |
579 | + return preset.size() + transportArcs.size() + inhibitorArcs.size(); |
580 | + } |
581 | + |
582 | + public int postsetSize() { |
583 | + return postset.size() + transportArcs.size() + inhibitorArcs.size(); |
584 | + } |
585 | + |
586 | // public abstract void addInhibitorArc(TimedInhibitorArc arc); |
587 | // public abstract void addToPreset(TransportArc arc); |
588 | // public abstract void addToPreset(TimedOutputArc arc); |
589 | |
590 | === modified file 'src/dk/aau/cs/model/tapn/TimedTransition.java' |
591 | --- src/dk/aau/cs/model/tapn/TimedTransition.java 2020-04-18 13:33:48 +0000 |
592 | +++ src/dk/aau/cs/model/tapn/TimedTransition.java 2020-06-18 20:57:23 +0000 |
593 | @@ -186,11 +186,11 @@ |
594 | } |
595 | |
596 | public int presetSize() { |
597 | - return preset.size() + transportArcsGoingThrough.size(); |
598 | + return preset.size() + transportArcsGoingThrough.size() + inhibitorArcs.size(); |
599 | } |
600 | |
601 | public int postsetSize() { |
602 | - return postset.size() + transportArcsGoingThrough.size(); |
603 | + return postset.size() + transportArcsGoingThrough.size() + inhibitorArcs.size(); |
604 | } |
605 | |
606 | public boolean isDEnabled(){ |
607 | |
608 | === modified file 'src/pipe/gui/GuiFrame.java' |
609 | --- src/pipe/gui/GuiFrame.java 2020-06-15 14:04:25 +0000 |
610 | +++ src/pipe/gui/GuiFrame.java 2020-06-18 20:57:23 +0000 |
611 | @@ -669,7 +669,7 @@ |
612 | |
613 | netStatisticsAction = new GuiAction("Net statistics", "Shows information about the number of transitions, places, arcs, etc.", KeyStroke.getKeyStroke(KeyEvent.VK_I, shortcutkey)) { |
614 | public void actionPerformed(ActionEvent e) { |
615 | - currentTab.ifPresent(TabContentActions::showStatistics); |
616 | + currentTab.ifPresent(TabContentActions::showStatistics); |
617 | } |
618 | }; |
619 | toolsMenu.add(netStatisticsAction).setMnemonic('i'); |
Think it looks great, a few comments for future work, but don't think they need be changed for this.