diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca')
-rw-r--r-- | Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java | 143 |
1 files changed, 108 insertions, 35 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 index 72ea45d1..e1698e5b 100644 --- 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 | |||
@@ -4,6 +4,10 @@ import java.io.File; | |||
4 | import java.io.FileNotFoundException; | 4 | import java.io.FileNotFoundException; |
5 | import java.io.PrintStream; | 5 | import java.io.PrintStream; |
6 | import java.util.ArrayList; | 6 | import java.util.ArrayList; |
7 | import java.util.List; | ||
8 | import java.util.Map; | ||
9 | |||
10 | import org.eclipse.viatra.query.runtime.matchers.aggregators.count; | ||
7 | 11 | ||
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain; | 12 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain; |
9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance; | 13 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance; |
@@ -23,59 +27,127 @@ public class Main { | |||
23 | return message; | 27 | return message; |
24 | } | 28 | } |
25 | 29 | ||
30 | private static String configFolder = "yakinduum/"; | ||
31 | private static String configFileName = configFolder + "info.csv"; | ||
32 | private static String aggregateViolationMeasureFileName = configFolder + "aggregateInfo2.csv"; | ||
33 | |||
26 | public static void main(String args[]) { | 34 | public static void main(String args[]) { |
27 | // try { | 35 | // try { |
28 | 36 | ||
37 | |||
38 | long begin = System.currentTimeMillis(); | ||
39 | String message = null;//runWithPath("yakinduGeneration.vsconfig"); | ||
40 | long elapsed = System.currentTimeMillis() - begin; | ||
41 | |||
42 | if(message != null) { | ||
43 | return; | ||
44 | } | ||
29 | ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | 45 | ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); |
46 | String time = formatTime(elapsed); | ||
47 | ArrayList<String> infoOutput = new ArrayList<String>(); | ||
48 | infoOutput.add(time); | ||
49 | output.add(infoOutput); | ||
50 | System.out.println(time); | ||
51 | //CsvFileWriter.write(output, configFileName); | ||
52 | |||
53 | |||
54 | output = new ArrayList<ArrayList<String>>(); | ||
30 | output.add(prepareInfo()); | 55 | output.add(prepareInfo()); |
31 | CsvFileWriter.write(output, "yakinduum/info.csv"); | 56 | //CsvFileWriter.append(output, configFileName); |
32 | //YakinduumModel.init(); | 57 | |
33 | generateModel(1); | 58 | // for(int i = 0; i < 50; i++) { |
34 | // }catch(Exception e) { | 59 | // singleModelViolationMeasure(i+1); |
35 | // e.printStackTrace(); | ||
36 | // }finally { | ||
37 | // outDegreeStatistic(); | ||
38 | // } | 60 | // } |
39 | // outDegreeStatistic(); | 61 | aggregateViolationMeasure(50); |
40 | 62 | System.out.println("Finished"); | |
41 | } | 63 | } |
42 | 64 | ||
43 | public static void generateModel(int run) { | 65 | public static void generateModel(int run) { |
66 | String filename = run+"_1.xmi"; | ||
44 | //prepare initial info | 67 | //prepare initial info |
45 | long begin = System.currentTimeMillis(); | 68 | ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); |
46 | String message = runWithPath("yakinduGeneration.vsconfig"); | 69 | ArrayList<String> infoOutput = new ArrayList<String>(); |
70 | infoOutput.add(run+ ""); | ||
71 | infoOutput.addAll(calculateMetric(run)); | ||
72 | |||
73 | YakinduumModel model = new YakinduumModel("output/Viatra_100/run"+run+"/"+ filename); | ||
74 | int violationCount = ViolationCheck.calculateViolationCounts(model.yakinduum); | ||
75 | infoOutput.add(violationCount + ""); | ||
76 | |||
77 | |||
78 | |||
79 | //save model to another directory | ||
80 | model.save(configFolder + run + ".xmi"); | ||
81 | |||
82 | CsvFileWriter.append(output, configFileName); | ||
83 | } | ||
47 | 84 | ||
85 | public static void singleModelViolationMeasure(int run) { | ||
86 | String filename = run+".xmi"; | ||
87 | //prepare initial info | ||
88 | ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | ||
89 | ArrayList<String> infoOutput = new ArrayList<String>(); | ||
90 | infoOutput.add(run+ ""); | ||
91 | |||
92 | YakinduumModel model = new YakinduumModel("yakinduum\\config8\\"+ filename); | ||
48 | 93 | ||
94 | //parse map of violation counts to two list and add them to the result list | ||
95 | Map<String, Integer> map = ViolationCheck.violationMaps(model.yakinduum); | ||
96 | ArrayList<String> counts = new ArrayList<String>(); | ||
97 | ArrayList<String> violationNames = new ArrayList<String>(map.keySet()); | ||
98 | for(int i = 0; i < violationNames.size(); i++) { | ||
99 | String name = violationNames.get(i); | ||
100 | int total = map.get(name); | ||
101 | counts.add(total + ""); | ||
102 | } | ||
103 | output.add(infoOutput); | ||
104 | output.add(violationNames); | ||
105 | output.add(counts); | ||
106 | |||
107 | CsvFileWriter.append(output, configFileName); | ||
108 | } | ||
109 | |||
110 | public static void aggregateViolationMeasure(int size) { | ||
111 | ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | ||
112 | ArrayList<String> counts = new ArrayList<String>(); | ||
113 | ArrayList<String> violationNames = null; | ||
114 | for(int run = 1; run < size+1; run++) { | ||
115 | String filename = run+".xmi"; | ||
116 | YakinduumModel model = new YakinduumModel("yakinduum\\config8\\"+ filename); | ||
117 | |||
118 | Map<String, Integer> map = ViolationCheck.violationMaps(model.yakinduum); | ||
119 | if(run == 1) { | ||
120 | violationNames = new ArrayList<String>(map.keySet()); | ||
121 | for(int i = 0; i < violationNames.size(); i++) { | ||
122 | String name = violationNames.get(i); | ||
123 | int total = map.get(name); | ||
124 | counts.add(total + ""); | ||
125 | } | ||
126 | }else { | ||
127 | for(int i = 0; i < violationNames.size(); i++) { | ||
128 | int count = Integer.parseInt(counts.get(i)); | ||
129 | String name = violationNames.get(i); | ||
130 | int total = count + map.get(name); | ||
131 | counts.set(i, total + ""); | ||
132 | } | ||
133 | } | ||
134 | } | ||
49 | 135 | ||
50 | if(message == null) { | 136 | for(int i = 0; i < counts.size(); i++) { |
51 | ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>(); | 137 | double count = Integer.parseInt(counts.get(i)) / (double) size; |
52 | long elapsed = System.currentTimeMillis() - begin; | 138 | counts.set(i, count + ""); |
53 | String time = formatTime(elapsed); | ||
54 | |||
55 | ArrayList<String> infoOutput = new ArrayList<String>(); | ||
56 | infoOutput.add(run+ ""); | ||
57 | infoOutput.add(time); | ||
58 | infoOutput.addAll(calculateMetric()); | ||
59 | |||
60 | YakinduumModel model = new YakinduumModel("output/Viatra_100/1.xmi"); | ||
61 | int violationCount = ViolationCheck.calculateViolationCounts(model.yakinduum); | ||
62 | infoOutput.add(violationCount + ""); | ||
63 | |||
64 | //save model to another directory | ||
65 | model.save("yakinduum/" + run + ".xmi"); | ||
66 | |||
67 | output.add(infoOutput); | ||
68 | CsvFileWriter.append(output, "yakinduum/info.csv"); | ||
69 | System.out.println("Finished"); | ||
70 | } | 139 | } |
71 | 140 | ||
141 | output.add(violationNames); | ||
142 | output.add(counts); | ||
143 | CsvFileWriter.write(output, aggregateViolationMeasureFileName); | ||
72 | } | 144 | } |
73 | 145 | ||
74 | public static ArrayList<String> calculateMetric() { | 146 | public static ArrayList<String> calculateMetric(int run) { |
75 | //read model and metric | 147 | //read model and metric |
76 | ArrayList<String> output = new ArrayList<String>(); | 148 | ArrayList<String> output = new ArrayList<String>(); |
77 | GraphReader reader = new GraphReader(YakindummPackage.eINSTANCE); | 149 | GraphReader reader = new GraphReader(YakindummPackage.eINSTANCE); |
78 | EMFGraph graph = reader.readModels("output/Viatra_100/").get(0); | 150 | EMFGraph graph = reader.readModels("output/Viatra_100/run"+run+"/").get(0); |
79 | 151 | ||
80 | //KS distance | 152 | //KS distance |
81 | KSDistance ks = new KSDistance(Domain.Yakinduum); | 153 | KSDistance ks = new KSDistance(Domain.Yakinduum); |
@@ -86,17 +158,18 @@ public class Main { | |||
86 | output.add(ks.outDegreeDistance(samples.outDegreeSamples) + ""); | 158 | output.add(ks.outDegreeDistance(samples.outDegreeSamples) + ""); |
87 | output.add(ks.naDistance(samples.naSamples)+ ""); | 159 | output.add(ks.naDistance(samples.naSamples)+ ""); |
88 | output.add(ks.mpcDistance(samples.mpcSamples) + ""); | 160 | output.add(ks.mpcDistance(samples.mpcSamples) + ""); |
161 | output.add(ks.typedOutDegreeDistance(samples.typedOutDegreeSamples) + ""); | ||
89 | return output; | 162 | return output; |
90 | } | 163 | } |
91 | 164 | ||
92 | public static ArrayList<String> prepareInfo() { | 165 | public static ArrayList<String> prepareInfo() { |
93 | ArrayList<String> info = new ArrayList<String>(); | 166 | ArrayList<String> info = new ArrayList<String>(); |
94 | info.add("ID"); | 167 | info.add("ID"); |
95 | info.add("Time"); | ||
96 | info.add("# of Nodes"); | 168 | info.add("# of Nodes"); |
97 | info.add("Out Degree"); | 169 | info.add("Out Degree"); |
98 | info.add("Node Activity"); | 170 | info.add("Node Activity"); |
99 | info.add("MPC"); | 171 | info.add("MPC"); |
172 | info.add("Typed Out Degree"); | ||
100 | info.add("Violations"); | 173 | info.add("Violations"); |
101 | return info; | 174 | return info; |
102 | } | 175 | } |