diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse')
6 files changed, 452 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/plugin/Queries.vql b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/plugin/Queries.vql new file mode 100644 index 00000000..3e7fc68c --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/plugin/Queries.vql | |||
@@ -0,0 +1,54 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.plugin | ||
2 | |||
3 | import epackage "http://ecse.mcgill.ca/socialnetwork" | ||
4 | |||
5 | //@Constraint(message="terminatorAndInformation", severity="error", key={T}) | ||
6 | //pattern terminatorAndInformation(T : FAMTerminator, I : InformationLink) = { | ||
7 | // FunctionalOutput.outgoingLinks(Out,I); | ||
8 | // FunctionalOutput.terminator(Out,T); | ||
9 | //} or { | ||
10 | // InformationLink.to(I,In); | ||
11 | // FunctionalInput.terminator(In,T); | ||
12 | //} | ||
13 | |||
14 | @Constraint(message="singleFriendship", severity="error", key={p1}) | ||
15 | pattern singleFriendship(p1: Person) { | ||
16 | find friendship(p1, p); | ||
17 | neg find friendship(p, p1); | ||
18 | } | ||
19 | |||
20 | //@Constraint(message="cycle", severity="error", key={p}) | ||
21 | //pattern cycleInParenthood(p: Person) { | ||
22 | // find isAncestor(p, p); | ||
23 | //} | ||
24 | |||
25 | @Constraint(message="noFriend", severity="error", key={p}) | ||
26 | pattern noFriend(p: Person){ | ||
27 | neg find friendship(p, _); | ||
28 | } | ||
29 | |||
30 | //@Constraint(message="brothhoodParent", severity="error", key={p1,p2}) | ||
31 | //pattern brothhoodParent(p1: Person, p2: Person){ | ||
32 | // Person.parents(p1, parent1); | ||
33 | // Person.parents(p2, parent2); | ||
34 | // parent1 == parent2; | ||
35 | // find isAncestor(p1, p2); | ||
36 | //} | ||
37 | @Constraint(message="selfFriend", severity="error", key={p}) | ||
38 | pattern selfFriend(p: Person){ | ||
39 | Person.friends(p,p); | ||
40 | } | ||
41 | |||
42 | pattern friendship(p1: Person, p2: Person){ | ||
43 | Person.friends(p1,p2); | ||
44 | } | ||
45 | |||
46 | //pattern isAncestor(person : Person, ancestor : Person){ | ||
47 | // Person.parents(person, ancestor); | ||
48 | //} or { | ||
49 | // Person.parents(person, parent); | ||
50 | // find isAncestor(parent, ancestor); | ||
51 | //} | ||
52 | |||
53 | |||
54 | |||
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 | } | ||
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java new file mode 100644 index 00000000..3ebede25 --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java | |||
@@ -0,0 +1,63 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.runner; | ||
2 | import java.io.IOException; | ||
3 | import java.util.Collections; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.eclipse.emf.common.util.URI; | ||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | import org.eclipse.emf.ecore.resource.Resource; | ||
9 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
10 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
11 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
12 | |||
13 | public class Persisitence<G extends EObject> { | ||
14 | private String uri; | ||
15 | |||
16 | public Persisitence (String suffix, String uri){ | ||
17 | //prepare to save | ||
18 | Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; | ||
19 | Map<String, Object> m = reg.getExtensionToFactoryMap(); | ||
20 | m.put(suffix, new XMIResourceFactoryImpl()); | ||
21 | this.uri = uri; | ||
22 | } | ||
23 | |||
24 | |||
25 | /** | ||
26 | * Save the model | ||
27 | * @return whether the model has saved successfully | ||
28 | */ | ||
29 | public boolean save(G model) { | ||
30 | //create resource | ||
31 | ResourceSet resSet = new ResourceSetImpl(); | ||
32 | Resource resource = resSet.createResource(URI.createURI(uri)); | ||
33 | resource.getContents().add(model); | ||
34 | try { | ||
35 | resource.save(Collections.EMPTY_MAP); | ||
36 | return true; | ||
37 | }catch(IOException e) { | ||
38 | e.printStackTrace(); | ||
39 | return false; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * load the model from persistent | ||
45 | * @return: the model loaded | ||
46 | */ | ||
47 | @SuppressWarnings("unchecked") | ||
48 | public G load() { | ||
49 | G model = null; | ||
50 | // try { | ||
51 | ResourceSet resSet = new ResourceSetImpl(); | ||
52 | Resource resource = resSet.getResource(URI.createURI(uri), true); | ||
53 | model = (G) resource.getContents().get(0); | ||
54 | // }catch (org.eclipse.emf.common.util.WrappedException e) { | ||
55 | // // if the file cannot be found then return null | ||
56 | // if(e.getCause().getClass() == java.io.FileNotFoundException.class) { | ||
57 | // return null; | ||
58 | // } | ||
59 | // } | ||
60 | |||
61 | return model; | ||
62 | } | ||
63 | } | ||
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/RunnerTests.java b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/RunnerTests.java new file mode 100644 index 00000000..c09c55be --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/RunnerTests.java | |||
@@ -0,0 +1,18 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.runner; | ||
2 | |||
3 | import org.junit.Test; | ||
4 | |||
5 | import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor; | ||
6 | |||
7 | public class RunnerTests { | ||
8 | private static String runWithPath(String path) { | ||
9 | String message = StandaloneScriptExecutor.executeScript(path); | ||
10 | return message; | ||
11 | } | ||
12 | |||
13 | @Test | ||
14 | public void generateModel() { | ||
15 | String message = runWithPath("SocialNetworkGeneration.vsconfig"); | ||
16 | System.out.println(message); | ||
17 | } | ||
18 | } | ||
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/SocialNetworkModel.java b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/SocialNetworkModel.java new file mode 100644 index 00000000..51c50b11 --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/SocialNetworkModel.java | |||
@@ -0,0 +1,62 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.runner; | ||
2 | |||
3 | import org.eclipse.emf.common.util.EList; | ||
4 | |||
5 | import socialnetwork.Person; | ||
6 | import socialnetwork.SocialNetwork; | ||
7 | import socialnetwork.SocialnetworkFactory; | ||
8 | import socialnetwork.SocialnetworkPackage; | ||
9 | import socialnetwork.impl.SocialnetworkFactoryImpl; | ||
10 | |||
11 | |||
12 | |||
13 | public class SocialNetworkModel { | ||
14 | private final static String SUFFIX = "xmi"; | ||
15 | |||
16 | private static boolean isInit = false; | ||
17 | |||
18 | public static void init() { | ||
19 | SocialnetworkFactory.eINSTANCE.eClass(); | ||
20 | SocialnetworkPackage.eINSTANCE.eClass(); | ||
21 | SocialnetworkFactoryImpl.init(); | ||
22 | } | ||
23 | |||
24 | // container for the social network model | ||
25 | public SocialNetwork socialNetwork; | ||
26 | |||
27 | // factory for social network model | ||
28 | SocialnetworkFactory factory; | ||
29 | |||
30 | // persistent | ||
31 | Persisitence<SocialNetwork> persistence; | ||
32 | |||
33 | |||
34 | public SocialNetworkModel(String uri){ | ||
35 | if(!isInit) { | ||
36 | init(); | ||
37 | } | ||
38 | |||
39 | //create persistence | ||
40 | persistence = new Persisitence<SocialNetwork>(SUFFIX, uri); | ||
41 | factory = SocialnetworkFactory.eINSTANCE; | ||
42 | // try load the model | ||
43 | this.socialNetwork = persistence.load(); | ||
44 | if(this.socialNetwork == null) { | ||
45 | this.socialNetwork = factory.createSocialNetwork(); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | public Person createPerson() { | ||
50 | Person p = factory.createPerson(); | ||
51 | socialNetwork.getPersons().add(p); | ||
52 | return p; | ||
53 | } | ||
54 | |||
55 | public EList<Person> getPersons(){ | ||
56 | return socialNetwork.getPersons(); | ||
57 | } | ||
58 | |||
59 | public boolean save() { | ||
60 | return persistence.save(socialNetwork); | ||
61 | } | ||
62 | } | ||
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/YakinduumModel.java b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/YakinduumModel.java new file mode 100644 index 00000000..803daff4 --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/YakinduumModel.java | |||
@@ -0,0 +1,52 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.runner; | ||
2 | |||
3 | import javax.annotation.Resource; | ||
4 | |||
5 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.Statechart; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummFactory; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.impl.YakindummFactoryImpl; | ||
9 | import socialnetwork.SocialNetwork; | ||
10 | import socialnetwork.SocialnetworkFactory; | ||
11 | |||
12 | public class YakinduumModel { | ||
13 | private final static String SUFFIX = "xmi"; | ||
14 | |||
15 | private static boolean isInit = false; | ||
16 | |||
17 | private String uri; | ||
18 | |||
19 | public static void init() { | ||
20 | YakindummFactory.eINSTANCE.eClass(); | ||
21 | YakindummPackage.eINSTANCE.eClass(); | ||
22 | YakindummFactoryImpl.init(); | ||
23 | } | ||
24 | |||
25 | // container for the social network model | ||
26 | public Statechart yakinduum; | ||
27 | |||
28 | |||
29 | // persistent | ||
30 | Persisitence<Statechart> persistence; | ||
31 | |||
32 | |||
33 | public YakinduumModel(String uri){ | ||
34 | if(!isInit) { | ||
35 | init(); | ||
36 | } | ||
37 | this.uri = uri; | ||
38 | //create persistence | ||
39 | persistence = new Persisitence<Statechart>(SUFFIX, uri); | ||
40 | // try load the model | ||
41 | this.yakinduum = persistence.load(); | ||
42 | } | ||
43 | |||
44 | public boolean save(String uri) { | ||
45 | if(this.uri.equals(uri)) { | ||
46 | return persistence.save(yakinduum); | ||
47 | }else { | ||
48 | persistence = new Persisitence<Statechart>(SUFFIX, uri); | ||
49 | return persistence.save(yakinduum); | ||
50 | } | ||
51 | } | ||
52 | } | ||