~tapaal-contributor/tapaal/display-shared-places-transitions-1879126

« back to all changes in this revision

Viewing changes to src/net/tapaal/TAPAAL.java

  • Committer: Jiri Srba
  • Date: 2020-04-28 19:15:28 UTC
  • mfrom: (998.2.376 testbranch)
  • Revision ID: srba@cs.aau.dk-20200428191528-3xxjqa1r4jcob5ur
merged in lp:~yrke/tapaal/testbranch doing majour refactoring of the GUI

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package net.tapaal;
2
2
 
3
3
import java.io.File;
 
4
import java.io.FileInputStream;
4
5
import java.net.MalformedURLException;
5
6
import java.net.URI;
6
7
import java.net.URISyntaxException;
7
8
import java.net.URL;
 
9
import java.util.List;
 
10
import java.util.stream.Collectors;
 
11
import java.util.stream.StreamSupport;
8
12
 
 
13
import dk.aau.cs.gui.TabContent;
 
14
import dk.aau.cs.gui.components.BatchProcessingResultsTableModel;
 
15
import dk.aau.cs.io.batchProcessing.BatchProcessingResultsExporter;
 
16
import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;
 
17
import dk.aau.cs.model.tapn.simulation.TAPNNetworkTrace;
 
18
import dk.aau.cs.translations.ReductionOption;
 
19
import dk.aau.cs.util.MemoryMonitor;
 
20
import dk.aau.cs.util.VerificationCallback;
 
21
import dk.aau.cs.verification.*;
 
22
import dk.aau.cs.verification.batchProcessing.BatchProcessingVerificationResult;
9
23
import org.apache.commons.cli.CommandLine;
10
24
import org.apache.commons.cli.CommandLineParser;
11
25
import org.apache.commons.cli.Options;
12
26
import org.apache.commons.cli.ParseException;
13
27
import org.apache.commons.cli.PosixParser;
14
28
 
 
29
import pipe.dataLayer.TAPNQuery;
15
30
import pipe.gui.CreateGui;
16
31
import dk.aau.cs.debug.Logger;
 
32
import pipe.gui.GuiFrame;
 
33
import pipe.gui.Verifier;
17
34
 
 
35
/**
 
36
 * Main class for lunching TAPAAL
 
37
 *
 
38
 * @author Kenneth Yrke Joergensen (kenneth@yrke.dk)
 
39
 */
18
40
public class TAPAAL {
19
 
        
20
 
        /**
21
 
         * Main class for lunching TAPAAL
22
 
         * 
23
 
         * @author Kenneth Yrke Joergensen (kenneth@yrke.dk)
24
 
         */
25
 
        
 
41
 
26
42
        public static final String TOOLNAME = "TAPAAL";
27
43
        public static final String VERSION = "DEV"; 
28
44
 
31
47
        }
32
48
 
33
49
        
34
 
        public static void main(String[] args) {
 
50
        public static void main(String[] args) throws Exception {
35
51
                // Create a CommandLineParser using Posix Style
36
52
                CommandLineParser parser = new PosixParser();
37
53
 
49
65
                        System.err.println("Unexpected exception:" + exp.getMessage());
50
66
                }
51
67
 
52
 
                // Create the TAPAAL GUI
53
 
                CreateGui.init();
54
 
 
55
68
                // Enable debug
56
69
                if (commandline.hasOption("debug")) {
57
70
                        Logger.enableLogging(true);
62
75
                        Logger.log("Debug logging is enabled by default in DEV branch");
63
76
                }
64
77
 
 
78
                if (commandline.hasOption("batch")) {
 
79
 
 
80
                        String[] files = commandline.getArgs();
 
81
                        //String [] files = new String[] {"C:\\kyrke\\tapaal\\3.6\\src\\resources\\Example nets"};
 
82
 
 
83
                        //String [] files = new String[] {"C:\\kyrke\\tapaal\\testmodels-tapaal"};
 
84
                        //String [] files = new String[] {"C:\\tmp\\subset2"};
 
85
                        File batchFolder = new File(files[0]);
 
86
 
 
87
                        batchProcessing(batchFolder);
 
88
 
 
89
 
 
90
                        return;
 
91
                }
 
92
 
 
93
                // Create the TAPAAL GUI
 
94
                CreateGui.init();
 
95
 
65
96
                // Open files
66
97
                String[] files = commandline.getArgs();
 
98
                Logger.log("Opening #files: " + files.length);
67
99
                for (String f : files) {
68
100
                        File file = new File(f);
69
101
 
70
102
                        if (file.exists()) { // Open the file
71
103
                                if (file.canRead()) {
72
104
                                        try {
73
 
                                                CreateGui.getAppGui().createNewTabFromFile(file);
 
105
                        CreateGui.getAppGuiController().openTab(TabContent.createNewTabFromFile(file));
74
106
                                        } catch (Exception e) {
75
107
                                                // TODO Auto-generated catch block
76
108
                                                e.printStackTrace();
88
120
                }
89
121
 
90
122
        }
91
 
        
 
123
 
 
124
        private static void batchProcessing(File batchFolder) throws Exception {
 
125
                //Sadly needs to create the gui
 
126
                CreateGui.init();
 
127
                CreateGui.getApp().setVisible(false);
 
128
 
 
129
                System.out.println("=============================================================");
 
130
                System.out.println("Batch Porcessing");
 
131
                System.out.println("=============================================================");
 
132
 
 
133
                System.out.println("Running in batch mode for " + batchFolder.getAbsolutePath());
 
134
 
 
135
                BatchProcessingResultsTableModel results = new BatchProcessingResultsTableModel();
 
136
 
 
137
                for (File f : batchFolder.listFiles()) {
 
138
                        if (f.getName().toLowerCase().endsWith(".tapn") || f.getName().toLowerCase().endsWith(".xml")) {
 
139
                                System.out.println("Processing File: " + f);
 
140
 
 
141
                                TabContent tab = TabContent.createNewTabFromInputStream(new FileInputStream(f), f.getName());
 
142
                                TimedArcPetriNetNetwork network = tab.network();
 
143
                                List<TAPNQuery> queries = StreamSupport
 
144
                                                .stream(tab.queries().spliterator(), false)
 
145
                                                .collect(Collectors.toList());
 
146
 
 
147
                                for (TAPNQuery query : queries) {
 
148
 
 
149
                                        System.out.println("    | Running query: " + query.getName());
 
150
 
 
151
                                        if(query.getReductionOption() == ReductionOption.VerifyTAPN || query.getReductionOption() == ReductionOption.VerifyTAPNdiscreteVerification || query.getReductionOption() == ReductionOption.VerifyPN) {
 
152
                                                Verifier.runVerifyTAPNVerification(network, query, new VerificationCallback() {
 
153
                                                        @Override
 
154
                                                        public void run(VerificationResult<TAPNNetworkTrace> result) {
 
155
 
 
156
                                                                String resultString = result.getQueryResult().isQuerySatisfied() ? "Satisfied" : "Not Satisfied";
 
157
                                                                System.out.println("    | Result: " + resultString);
 
158
 
 
159
                                                                results.addResult(new BatchProcessingVerificationResult(
 
160
                                                                                f.toString(), query,resultString ,result.verificationTime(), MemoryMonitor.getPeakMemory(),result.stats()
 
161
                                                                ));
 
162
                                                        }
 
163
 
 
164
                                                });
 
165
                                        } else {
 
166
                                                System.out.println("    | Skipped");
 
167
                                                //Verifier.runUppaalVerification(network, query);
 
168
                                        }
 
169
 
 
170
                                }
 
171
 
 
172
                        }
 
173
                }
 
174
 
 
175
                System.out.println("===========================================");
 
176
                System.out.println("===========================================");
 
177
 
 
178
                BatchProcessingResultsExporter exporter = new BatchProcessingResultsExporter();
 
179
                exporter.exportToCSV(results.getResults(), System.out);
 
180
                System.out.println("Done" + results.getRowCount());
 
181
        }
 
182
 
92
183
        public static File getInstallDir() {
93
184
                
94
185
                String str = ClassLoader.getSystemResource("TAPAAL.class").getPath();
142
233
                        
143
234
                        return installdir;
144
235
                        
145
 
                } catch (MalformedURLException e) {
146
 
                        e.printStackTrace();
147
 
                } catch (URISyntaxException e) {
 
236
                } catch (MalformedURLException | URISyntaxException e) {
148
237
                        e.printStackTrace();
149
238
                }
150
239
                return null;