diff options
author | 2020-11-03 22:52:26 -0500 | |
---|---|---|
committer | 2020-11-03 22:52:26 -0500 | |
commit | 945f487a08b643392a5d5918c631640b9a0e4605 (patch) | |
tree | b537c456e395950ce98daaabb9468c7c17d5a72b /Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java | |
parent | Fix numeric-solver-at-end (diff) | |
download | VIATRA-Generator-945f487a08b643392a5d5918c631640b9a0e4605.tar.gz VIATRA-Generator-945f487a08b643392a5d5918c631640b9a0e4605.tar.zst VIATRA-Generator-945f487a08b643392a5d5918c631640b9a0e4605.zip |
add realistic solver
Diffstat (limited to 'Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java')
-rw-r--r-- | Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java new file mode 100644 index 00000000..e4e5b61f --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java | |||
@@ -0,0 +1,203 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.runner; | ||
2 | |||
3 | import java.io.File; | ||
4 | import java.io.FileNotFoundException; | ||
5 | import java.io.PrintStream; | ||
6 | import java.util.ArrayList; | ||
7 | import java.util.Map; | ||
8 | import java.util.Scanner; | ||
9 | |||
10 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain; | ||
11 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance; | ||
12 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph; | ||
13 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter; | ||
14 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.GraphReader; | ||
15 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.RepMetricsReader; | ||
16 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup; | ||
17 | import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor; | ||
18 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage; | ||
19 | import socialnetwork.Person; | ||
20 | |||
21 | public class Main { | ||
22 | |||
23 | private static String runWithPath(String path) { | ||
24 | String message = StandaloneScriptExecutor.executeScript(path); | ||
25 | return message; | ||
26 | } | ||
27 | |||
28 | private static String configFolder = "yakinduum/config22/"; | ||
29 | private static String configFileName = configFolder + "info_old_metric.csv"; | ||
30 | private static String aggregateViolationMeasureFileName = configFolder + "aggregateInfo.csv"; | ||
31 | private static String fileReadFolder = "output/Ecore_100/"; | ||
32 | |||
33 | public static void main(String args[]) { | ||
34 | String ecoreFile = args[0]; | ||
35 | System.out.println("Generation Started"); | ||
36 | |||
37 | System.out.println(System.getProperty("java.library.path")); | ||
38 | |||
39 | long begin = System.currentTimeMillis(); | ||
40 | String message = runWithPath(ecoreFile); | ||
41 | long elapsed = System.currentTimeMillis() - begin; | ||
42 | |||
43 | if(message != null) { | ||
44 | System.out.println(message); | ||
45 | return; | ||
46 | } | ||
47 | // ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | ||
48 | // String time = formatTime(elapsed); | ||
49 | // ArrayList<String> infoOutput = new ArrayList<String>(); | ||
50 | // infoOutput.add(time); | ||
51 | // output.add(infoOutput); | ||
52 | // System.out.println(time); | ||
53 | // CsvFileWriter.write(output, configFileName); | ||
54 | // | ||
55 | // | ||
56 | // output = new ArrayList<ArrayList<String>>(); | ||
57 | // output.add(prepareInfo()); | ||
58 | // CsvFileWriter.append(output, configFileName); | ||
59 | // | ||
60 | // for(int i = 0; i < 50; i++) { | ||
61 | // generateModel(i+1); | ||
62 | // } | ||
63 | // aggregateViolationMeasure(50); | ||
64 | System.out.println("Finished"); | ||
65 | } | ||
66 | |||
67 | // public static void generateModel(int run) { | ||
68 | // String filename = run+"_1.xmi"; | ||
69 | // //prepare initial info | ||
70 | // ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | ||
71 | // ArrayList<String> infoOutput = new ArrayList<String>(); | ||
72 | // infoOutput.add(run+ ""); | ||
73 | // infoOutput.addAll(calculateMetric(run)); | ||
74 | // | ||
75 | // YakinduumModel model = new YakinduumModel(fileReadFolder +"run" +run + "/" + filename); | ||
76 | // int violationCount = ViolationCheck.calculateViolationCounts(model.yakinduum); | ||
77 | // infoOutput.add(violationCount + ""); | ||
78 | // | ||
79 | // | ||
80 | // | ||
81 | // //save model to another directory | ||
82 | // model.save(configFolder + run + ".xmi"); | ||
83 | // output.add(infoOutput); | ||
84 | // CsvFileWriter.append(output, configFileName); | ||
85 | // } | ||
86 | // | ||
87 | // public static void singleModelViolationMeasure(int run) { | ||
88 | // String filename = run+"_1.xmi"; | ||
89 | // //prepare initial info | ||
90 | // ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | ||
91 | // ArrayList<String> infoOutput = new ArrayList<String>(); | ||
92 | // infoOutput.add(run+ ""); | ||
93 | // | ||
94 | // YakinduumModel model = new YakinduumModel(fileReadFolder+"/run"+run+"/"+ filename); | ||
95 | // | ||
96 | // //parse map of violation counts to two list and add them to the result list | ||
97 | // Map<String, Integer> map = ViolationCheck.violationMaps(model.yakinduum); | ||
98 | // ArrayList<String> counts = new ArrayList<String>(); | ||
99 | // ArrayList<String> violationNames = new ArrayList<String>(map.keySet()); | ||
100 | // for(int i = 0; i < violationNames.size(); i++) { | ||
101 | // String name = violationNames.get(i); | ||
102 | // int total = map.get(name); | ||
103 | // counts.add(total + ""); | ||
104 | // } | ||
105 | // output.add(infoOutput); | ||
106 | // output.add(violationNames); | ||
107 | // output.add(counts); | ||
108 | // | ||
109 | // CsvFileWriter.append(output, configFileName); | ||
110 | // } | ||
111 | // | ||
112 | // public static void aggregateViolationMeasure(int size) { | ||
113 | // ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | ||
114 | // ArrayList<String> counts = new ArrayList<String>(); | ||
115 | // ArrayList<String> violationNames = null; | ||
116 | // for(int run = 1; run < size+1; run++) { | ||
117 | // String filename = run+"_1.xmi"; | ||
118 | // YakinduumModel model = new YakinduumModel(fileReadFolder+"/run"+run+"/"+ filename); | ||
119 | // | ||
120 | // Map<String, Integer> map = ViolationCheck.violationMaps(model.yakinduum); | ||
121 | // if(run == 1) { | ||
122 | // violationNames = new ArrayList<String>(map.keySet()); | ||
123 | // for(int i = 0; i < violationNames.size(); i++) { | ||
124 | // String name = violationNames.get(i); | ||
125 | // int total = map.get(name); | ||
126 | // counts.add(total + ""); | ||
127 | // } | ||
128 | // }else { | ||
129 | // for(int i = 0; i < violationNames.size(); i++) { | ||
130 | // int count = Integer.parseInt(counts.get(i)); | ||
131 | // String name = violationNames.get(i); | ||
132 | // int total = count + map.get(name); | ||
133 | // counts.set(i, total + ""); | ||
134 | // } | ||
135 | // } | ||
136 | // } | ||
137 | // | ||
138 | // for(int i = 0; i < counts.size(); i++) { | ||
139 | // double count = Integer.parseInt(counts.get(i)) / (double) size; | ||
140 | // counts.set(i, count + ""); | ||
141 | // } | ||
142 | // | ||
143 | // output.add(violationNames); | ||
144 | // output.add(counts); | ||
145 | // CsvFileWriter.write(output, aggregateViolationMeasureFileName); | ||
146 | // } | ||
147 | // | ||
148 | public static ArrayList<String> calculateMetric(int run) { | ||
149 | //read model and metric | ||
150 | ArrayList<String> output = new ArrayList<String>(); | ||
151 | GraphReader reader = new GraphReader(YakindummPackage.eINSTANCE, ".xmi"); | ||
152 | EMFGraph graph = reader.readModel(fileReadFolder+"/run"+run, run + "_1.xmi"); | ||
153 | MetricSampleGroup metrics = RepMetricsReader.read(Domain.Yakindumm); | ||
154 | //KS distance | ||
155 | KSDistance ks = new KSDistance(metrics); | ||
156 | |||
157 | //calculate and put metric data to output array | ||
158 | MetricSampleGroup samples = graph.evaluateAllMetricsToSamples(); | ||
159 | output.add(graph.getStatistic().getAllNodes().size() + ""); | ||
160 | output.add(ks.outDegreeDistance(samples.outDegreeSamples) + ""); | ||
161 | output.add(ks.naDistance(samples.naSamples)+ ""); | ||
162 | output.add(ks.mpcDistance(samples.mpcSamples) + ""); | ||
163 | output.add(ks.typedOutDegreeDistance(samples.typedOutDegreeSamples) + ""); | ||
164 | return output; | ||
165 | } | ||
166 | |||
167 | public static ArrayList<String> prepareInfo() { | ||
168 | ArrayList<String> info = new ArrayList<String>(); | ||
169 | info.add("ID"); | ||
170 | info.add("# of Nodes"); | ||
171 | info.add("Out Degree"); | ||
172 | info.add("Node Activity"); | ||
173 | info.add("MPC"); | ||
174 | info.add("Typed Out Degree"); | ||
175 | info.add("Violations"); | ||
176 | return info; | ||
177 | } | ||
178 | |||
179 | public static String formatTime(long time) { | ||
180 | long mili = time % 1000; | ||
181 | long second = (time / 1000) % 60; | ||
182 | long minute = (time / (1000 * 60)); | ||
183 | return String.format("%d : %d.%d", minute, second, mili); | ||
184 | } | ||
185 | |||
186 | public static void statistics() { | ||
187 | String uri = "output/1.xmi"; | ||
188 | SocialNetworkModel socialNetwork = new SocialNetworkModel(uri); | ||
189 | System.out.println(socialNetwork.getPersons().size()); | ||
190 | |||
191 | File file = new File("model/statistics/output.txt"); | ||
192 | try { | ||
193 | @SuppressWarnings("resource") | ||
194 | PrintStream out = new PrintStream(file); | ||
195 | for(Person p : socialNetwork.getPersons()) { | ||
196 | out.println(p.getFriends().size()); | ||
197 | } | ||
198 | } catch (FileNotFoundException e) { | ||
199 | e.printStackTrace(); | ||
200 | } | ||
201 | System.out.println("Output Finished"); | ||
202 | } | ||
203 | } | ||