aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca
diff options
context:
space:
mode:
Diffstat (limited to 'Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca')
-rw-r--r--Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/plugin/Queries.vql54
-rw-r--r--Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java128
-rw-r--r--Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java63
-rw-r--r--Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/RunnerTests.java18
-rw-r--r--Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/SocialNetworkModel.java62
-rw-r--r--Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/YakinduumModel.java52
6 files changed, 377 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 @@
1package ca.mcgill.ecse.socialnetwork.plugin
2
3import 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})
15pattern 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})
26pattern 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})
38pattern selfFriend(p: Person){
39 Person.friends(p,p);
40}
41
42pattern 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..72ea45d1
--- /dev/null
+++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Main.java
@@ -0,0 +1,128 @@
1package ca.mcgill.ecse.socialnetwork.runner;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.PrintStream;
6import java.util.ArrayList;
7
8import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain;
9import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance;
10import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph;
11import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter;
12import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.GraphReader;
13import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup;
14import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor;
15import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.validation.ViolationCheck;
16import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage;
17import socialnetwork.Person;
18
19public class Main {
20
21 private static String runWithPath(String path) {
22 String message = StandaloneScriptExecutor.executeScript(path);
23 return message;
24 }
25
26 public static void main(String args[]) {
27// try {
28
29 ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>();
30 output.add(prepareInfo());
31 CsvFileWriter.write(output, "yakinduum/info.csv");
32 //YakinduumModel.init();
33 generateModel(1);
34// }catch(Exception e) {
35// e.printStackTrace();
36// }finally {
37// outDegreeStatistic();
38// }
39// outDegreeStatistic();
40
41 }
42
43 public static void generateModel(int run) {
44 //prepare initial info
45 long begin = System.currentTimeMillis();
46 String message = runWithPath("yakinduGeneration.vsconfig");
47
48
49
50 if(message == null) {
51 ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>();
52 long elapsed = System.currentTimeMillis() - begin;
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 }
71
72 }
73
74 public static ArrayList<String> calculateMetric() {
75 //read model and metric
76 ArrayList<String> output = new ArrayList<String>();
77 GraphReader reader = new GraphReader(YakindummPackage.eINSTANCE);
78 EMFGraph graph = reader.readModels("output/Viatra_100/").get(0);
79
80 //KS distance
81 KSDistance ks = new KSDistance(Domain.Yakinduum);
82
83 //calculate and put metric data to output array
84 MetricSampleGroup samples = graph.evaluateAllMetricsToSamples();
85 output.add(graph.getStatistic().getAllNodes().size() + "");
86 output.add(ks.outDegreeDistance(samples.outDegreeSamples) + "");
87 output.add(ks.naDistance(samples.naSamples)+ "");
88 output.add(ks.mpcDistance(samples.mpcSamples) + "");
89 return output;
90 }
91
92 public static ArrayList<String> prepareInfo() {
93 ArrayList<String> info = new ArrayList<String>();
94 info.add("ID");
95 info.add("Time");
96 info.add("# of Nodes");
97 info.add("Out Degree");
98 info.add("Node Activity");
99 info.add("MPC");
100 info.add("Violations");
101 return info;
102 }
103
104 public static String formatTime(long time) {
105 long mili = time % 1000;
106 long second = (time / 1000) % 60;
107 long minute = (time / (1000 * 60));
108 return String.format("%d : %d.%d", minute, second, mili);
109 }
110
111 public static void statistics() {
112 String uri = "output/1.xmi";
113 SocialNetworkModel socialNetwork = new SocialNetworkModel(uri);
114 System.out.println(socialNetwork.getPersons().size());
115
116 File file = new File("model/statistics/output.txt");
117 try {
118 @SuppressWarnings("resource")
119 PrintStream out = new PrintStream(file);
120 for(Person p : socialNetwork.getPersons()) {
121 out.println(p.getFriends().size());
122 }
123 } catch (FileNotFoundException e) {
124 e.printStackTrace();
125 }
126 System.out.println("Output Finished");
127 }
128}
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 @@
1package ca.mcgill.ecse.socialnetwork.runner;
2import java.io.IOException;
3import java.util.Collections;
4import java.util.Map;
5
6import org.eclipse.emf.common.util.URI;
7import org.eclipse.emf.ecore.EObject;
8import org.eclipse.emf.ecore.resource.Resource;
9import org.eclipse.emf.ecore.resource.ResourceSet;
10import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
11import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
12
13public 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 @@
1package ca.mcgill.ecse.socialnetwork.runner;
2
3import org.junit.Test;
4
5import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor;
6
7public 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 @@
1package ca.mcgill.ecse.socialnetwork.runner;
2
3import org.eclipse.emf.common.util.EList;
4
5import socialnetwork.Person;
6import socialnetwork.SocialNetwork;
7import socialnetwork.SocialnetworkFactory;
8import socialnetwork.SocialnetworkPackage;
9import socialnetwork.impl.SocialnetworkFactoryImpl;
10
11
12
13public 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 @@
1package ca.mcgill.ecse.socialnetwork.runner;
2
3import javax.annotation.Resource;
4
5import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.Statechart;
6import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummFactory;
7import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage;
8import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.impl.YakindummFactoryImpl;
9import socialnetwork.SocialNetwork;
10import socialnetwork.SocialnetworkFactory;
11
12public 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}