diff options
author | 2019-07-10 10:56:00 -0400 | |
---|---|---|
committer | 2019-07-10 10:56:00 -0400 | |
commit | 991dacefdb8f78fccc359d3d2ec836dc2e7fc80a (patch) | |
tree | 6b18aa59c5f711a845aa9e3e5cf3fd3632ad7a33 /Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io | |
parent | add sample domain for measuring realistic metrics (diff) | |
download | VIATRA-Generator-991dacefdb8f78fccc359d3d2ec836dc2e7fc80a.tar.gz VIATRA-Generator-991dacefdb8f78fccc359d3d2ec836dc2e7fc80a.tar.zst VIATRA-Generator-991dacefdb8f78fccc359d3d2ec836dc2e7fc80a.zip |
measurements for the different violation types, comparison for differenct generation config
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io')
2 files changed, 35 insertions, 60 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend index fc56e142..8f1feb9d 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend | |||
@@ -17,10 +17,18 @@ import org.eclipse.emf.ecore.resource.Resource | |||
17 | import org.eclipse.emf.ecore.resource.ResourceSet | 17 | import org.eclipse.emf.ecore.resource.ResourceSet |
18 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | 18 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl |
19 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | 19 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl |
20 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeTypeMetric | ||
21 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.EdgeTypeMetric | ||
22 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.TypedOutDegree | ||
23 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage | ||
20 | 24 | ||
21 | class GraphReader{ | 25 | class GraphReader{ |
22 | val ResourceSet resSet = new ResourceSetImpl(); | 26 | val ResourceSet resSet = new ResourceSetImpl(); |
23 | val referenceTypes = new ArrayList<String>(); | 27 | val referenceTypes = new ArrayList<EReference>(); |
28 | |||
29 | def static void main(String[] args){ | ||
30 | var g = new GraphReader(YakindummPackage.eINSTANCE); | ||
31 | } | ||
24 | 32 | ||
25 | new(EPackage metaModel) { | 33 | new(EPackage metaModel) { |
26 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) | 34 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) |
@@ -28,7 +36,7 @@ class GraphReader{ | |||
28 | //find all reference types in the meta model | 36 | //find all reference types in the meta model |
29 | metaModel.eAllContents.forEach[ | 37 | metaModel.eAllContents.forEach[ |
30 | if(it instanceof EReference){ | 38 | if(it instanceof EReference){ |
31 | referenceTypes.add(it.name); | 39 | referenceTypes.add(it); |
32 | } | 40 | } |
33 | ] | 41 | ] |
34 | } | 42 | } |
@@ -45,7 +53,10 @@ class GraphReader{ | |||
45 | metrics.add(new OutDegreeMetric()); | 53 | metrics.add(new OutDegreeMetric()); |
46 | metrics.add(new NodeActivityMetric()); | 54 | metrics.add(new NodeActivityMetric()); |
47 | metrics.add(new MultiplexParticipationCoefficientMetric()); | 55 | metrics.add(new MultiplexParticipationCoefficientMetric()); |
48 | 56 | metrics.add(new TypedOutDegree()); | |
57 | metrics.add(new NodeTypeMetric()); | ||
58 | metrics.add(new EdgeTypeMetric()); | ||
59 | |||
49 | //check all files in the directory with xmi | 60 | //check all files in the directory with xmi |
50 | for(String name : dir.list.filter[it| it.endsWith(".xmi")]){ | 61 | for(String name : dir.list.filter[it| it.endsWith(".xmi")]){ |
51 | val file = new File(name); | 62 | val file = new File(name); |
@@ -71,7 +82,7 @@ class GraphReader{ | |||
71 | } | 82 | } |
72 | } catch(Exception e) { | 83 | } catch(Exception e) { |
73 | e.printStackTrace(); | 84 | e.printStackTrace(); |
74 | throw new FileNotFoundException(getURI(path, name).toString + "reason: " + e.message) | 85 | throw new Exception(getURI(path, name).toString()); |
75 | } | 86 | } |
76 | } | 87 | } |
77 | 88 | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend index 867ddd1a..2ea12581 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend | |||
@@ -1,79 +1,43 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain |
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
7 | import java.io.File | ||
8 | import java.util.List | ||
9 | import java.util.Scanner | ||
10 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup | 4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup |
5 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.impl.YakindummPackageImpl | ||
11 | 6 | ||
12 | /** | 7 | /** |
13 | * Read the sample of the distribution of a metric provided the csv file of the metric | 8 | * Read the sample of the distribution of a metric provided the csv file of the metric |
14 | */ | 9 | */ |
15 | class RepMetricsReader { | 10 | class RepMetricsReader { |
16 | static def read(Domain d){ | 11 | static def read(Domain d){ |
17 | var domainRepPath = CsvDataName.REP_PATH + d.name + '/'; | 12 | var reader = new GraphReader(YakindummPackageImpl.eINSTANCE); |
13 | |||
14 | |||
15 | var domainRepPath = DataName.REP_PATH + d.name + '/'; | ||
18 | var rep = new MetricSampleGroup() | 16 | var rep = new MetricSampleGroup() |
19 | rep.mpcSamples = readFile(domainRepPath + CsvDataName.MPC_REP, MultiplexParticipationCoefficientMetric.valueName, | 17 | var out_d = readMetrics(reader, domainRepPath + DataName.OUT_D_REP); |
20 | MultiplexParticipationCoefficientMetric.countName).map[Double.parseDouble(it)]; | 18 | rep.mpcSamples = readMetrics(reader, domainRepPath + DataName.MPC_REP).mpcSamples; |
21 | rep.naSamples = readFile(domainRepPath+CsvDataName.NA_REP, NodeActivityMetric.valueName, NodeActivityMetric.countName | 19 | rep.outDegreeSamples = out_d.outDegreeSamples; |
22 | ).map[Double.parseDouble(it)]; | 20 | rep.naSamples = readMetrics(reader, domainRepPath + DataName.NA_REP).naSamples; |
23 | rep.outDegreeSamples = readFile(domainRepPath+CsvDataName.OUT_D_REP, OutDegreeMetric.valueName, OutDegreeMetric.countName | 21 | rep.typedOutDegreeSamples = out_d.typedOutDegreeSamples; |
24 | ).map[Double.parseDouble(it)]; | 22 | rep.edgeTypeSamples = out_d.edgeTypeSamples; |
23 | rep.nodeTypeSamples = out_d.nodeTypeSamples; | ||
25 | return rep; | 24 | return rep; |
26 | } | 25 | } |
27 | 26 | ||
28 | /** | 27 | /** |
29 | * read metric data and parse it to samples | 28 | * Read representative model |
30 | */ | 29 | */ |
31 | private static def List<String> readFile(String filename, String valueDataName, String countDataName){ | 30 | private static def readMetrics(GraphReader r, String path){ |
32 | var s = new Scanner(new File(filename)); | 31 | var model = r.readModels(path).head; |
33 | val counts = newArrayList(); | 32 | return model.evaluateAllMetricsToSamples(); |
34 | val values = newArrayList(); | ||
35 | //read data from csv | ||
36 | while(s.hasNext()){ | ||
37 | var data = s.nextLine().split(','); | ||
38 | |||
39 | if(data.size >= 1){ | ||
40 | if(data.get(0).equals(countDataName)){ | ||
41 | //add all data with parsing them as integers | ||
42 | counts.addAll(data.subList(1, data.size()).map[Integer.parseInt(it)]); | ||
43 | }else if(data.get(0).equals(valueDataName)){ | ||
44 | //add all data without parsing (there can be either double or string, to be parsed later) | ||
45 | values.addAll(data.subList(1, data.size())); | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | return createSamples(counts, values); | ||
51 | } | 33 | } |
52 | 34 | ||
53 | // create samples from values and counts | ||
54 | private static def List<String> createSamples(List<Integer> counts, List<String> values){ | ||
55 | val samples = newArrayList(); | ||
56 | |||
57 | if(counts.size() != values.size()){ | ||
58 | throw new RuntimeException("counts and values should have the same size!"); | ||
59 | } | ||
60 | |||
61 | for(var i = 0; i < counts.size(); i++){ | ||
62 | for(var j = 0; j < counts.get(i); j++){ | ||
63 | samples.add(values.get(i)); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return samples; | ||
68 | } | ||
69 | |||
70 | |||
71 | } | 35 | } |
72 | 36 | ||
73 | class CsvDataName{ | 37 | class DataName{ |
74 | public static val REP_PATH = 'data/'; | 38 | public static val REP_PATH = 'data/'; |
75 | public static val MPC_REP = 'mpc_rep.csv'; | 39 | public static val MPC_REP = 'mpc_rep'; |
76 | public static val NA_REP = 'na_rep.csv'; | 40 | public static val NA_REP = 'na_rep'; |
77 | public static val OUT_D_REP = 'out_d_rep.csv'; | 41 | public static val OUT_D_REP = 'out_d_rep'; |
78 | } | 42 | } |
79 | 43 | ||