diff options
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator')
10 files changed, 614 insertions, 0 deletions
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.FileComparator.java._trace b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.FileComparator.java._trace new file mode 100644 index 00000000..66809531 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.FileComparator.java._trace | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureDiversity.java._trace b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureDiversity.java._trace new file mode 100644 index 00000000..87a0a021 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureDiversity.java._trace | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureDiversity.xtendbin b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureDiversity.xtendbin new file mode 100644 index 00000000..b2685222 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureDiversity.xtendbin | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureInternalDiversity.java._trace b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureInternalDiversity.java._trace new file mode 100644 index 00000000..f9773278 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureInternalDiversity.java._trace | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureInternalDiversity.xtendbin b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureInternalDiversity.xtendbin new file mode 100644 index 00000000..1ffee322 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.MeasureInternalDiversity.xtendbin | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.PatternWithMatches.java._trace b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.PatternWithMatches.java._trace new file mode 100644 index 00000000..f8d273ed --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/.PatternWithMatches.java._trace | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/FileComparator.java b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/FileComparator.java new file mode 100644 index 00000000..d3992d29 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/FileComparator.java | |||
@@ -0,0 +1,27 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.diversitycalculator; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.diversitycalculator.MeasureDiversity; | ||
4 | import java.io.File; | ||
5 | import java.util.Comparator; | ||
6 | |||
7 | @SuppressWarnings("all") | ||
8 | public class FileComparator implements Comparator<File> { | ||
9 | @Override | ||
10 | public int compare(final File arg0, final File arg1) { | ||
11 | int _xblockexpression = (int) 0; | ||
12 | { | ||
13 | final int r1 = Integer.parseInt(MeasureDiversity.runIndex(arg0.getName())); | ||
14 | final int r2 = Integer.parseInt(MeasureDiversity.runIndex(arg1.getName())); | ||
15 | final int runRes = Integer.compare(r1, r2); | ||
16 | if ((runRes == 0)) { | ||
17 | final int a = Integer.parseInt(MeasureDiversity.modelIndex(arg0.getName())); | ||
18 | final int b = Integer.parseInt(MeasureDiversity.modelIndex(arg1.getName())); | ||
19 | Integer.compare(a, b); | ||
20 | } else { | ||
21 | return runRes; | ||
22 | } | ||
23 | _xblockexpression = arg0.getName().compareTo(arg1.getName()); | ||
24 | } | ||
25 | return _xblockexpression; | ||
26 | } | ||
27 | } | ||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/MeasureDiversity.java b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/MeasureDiversity.java new file mode 100644 index 00000000..bbf46409 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/MeasureDiversity.java | |||
@@ -0,0 +1,350 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.diversitycalculator; | ||
2 | |||
3 | import TaxationWithRoot.TaxationWithRootPackage; | ||
4 | import com.google.common.collect.Iterables; | ||
5 | import familytree.FamilytreePackage; | ||
6 | import hu.bme.mit.inf.dslreasoner.diversitycalculator.FileComparator; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
9 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
10 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
11 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage; | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement; | ||
14 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage; | ||
15 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage; | ||
17 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage; | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2PartialInterpretation; | ||
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.AbstractNodeDescriptor; | ||
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodWithTraces; | ||
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice; | ||
22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage; | ||
24 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
25 | import java.io.File; | ||
26 | import java.io.PrintWriter; | ||
27 | import java.util.ArrayList; | ||
28 | import java.util.Collections; | ||
29 | import java.util.HashMap; | ||
30 | import java.util.HashSet; | ||
31 | import java.util.LinkedList; | ||
32 | import java.util.List; | ||
33 | import java.util.Map; | ||
34 | import java.util.Set; | ||
35 | import java.util.function.Consumer; | ||
36 | import org.eclipse.emf.common.util.EList; | ||
37 | import org.eclipse.emf.ecore.EAttribute; | ||
38 | import org.eclipse.emf.ecore.EClass; | ||
39 | import org.eclipse.emf.ecore.EEnum; | ||
40 | import org.eclipse.emf.ecore.EEnumLiteral; | ||
41 | import org.eclipse.emf.ecore.EObject; | ||
42 | import org.eclipse.emf.ecore.EPackage; | ||
43 | import org.eclipse.emf.ecore.EReference; | ||
44 | import org.eclipse.emf.ecore.EcorePackage; | ||
45 | import org.eclipse.emf.ecore.resource.Resource; | ||
46 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
47 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; | ||
48 | import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory; | ||
49 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory; | ||
50 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
51 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
52 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
53 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
54 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
55 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
56 | import org.eclipse.xtext.xbase.lib.Functions.Function2; | ||
57 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
58 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
59 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
60 | import satellite.SatellitePackage; | ||
61 | |||
62 | @SuppressWarnings("all") | ||
63 | public class MeasureDiversity { | ||
64 | public static class BenchmarkConfig { | ||
65 | private int range; | ||
66 | |||
67 | private int size; | ||
68 | |||
69 | private PrintWriter writer; | ||
70 | |||
71 | private String scenario; | ||
72 | } | ||
73 | |||
74 | private static final InstanceModel2PartialInterpretation partialInterpretation2Logic = new InstanceModel2PartialInterpretation(); | ||
75 | |||
76 | private static final PartialInterpretation2ImmutableTypeLattice neiguboirhoodComputer = new PartialInterpretation2ImmutableTypeLattice(); | ||
77 | |||
78 | private static final Ecore2Logic ecore2Logic = new Ecore2Logic(); | ||
79 | |||
80 | private static void init() { | ||
81 | LogiclanguagePackage.eINSTANCE.getClass(); | ||
82 | LogicproblemPackage.eINSTANCE.getClass(); | ||
83 | PartialinterpretationPackage.eINSTANCE.getClass(); | ||
84 | Ecore2logicannotationsPackage.eINSTANCE.getClass(); | ||
85 | Viatra2LogicAnnotationsPackage.eINSTANCE.getClass(); | ||
86 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
87 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
88 | _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); | ||
89 | ViatraQueryEngineOptions.setSystemDefaultBackends(ReteBackendFactory.INSTANCE, ReteBackendFactory.INSTANCE, LocalSearchEMFBackendFactory.INSTANCE); | ||
90 | } | ||
91 | |||
92 | public static void main(final String[] args) { | ||
93 | try { | ||
94 | MeasureDiversity.init(); | ||
95 | StringConcatenation _builder = new StringConcatenation(); | ||
96 | _builder.append("inputs"); | ||
97 | final String path = _builder.toString(); | ||
98 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
99 | _builder_1.append("FamilyTree"); | ||
100 | StringConcatenation _builder_2 = new StringConcatenation(); | ||
101 | _builder_2.append("Satellite"); | ||
102 | StringConcatenation _builder_3 = new StringConcatenation(); | ||
103 | _builder_3.append("Taxation"); | ||
104 | StringConcatenation _builder_4 = new StringConcatenation(); | ||
105 | _builder_4.append("FamilyTreeNoNum"); | ||
106 | StringConcatenation _builder_5 = new StringConcatenation(); | ||
107 | _builder_5.append("SatelliteNoNum"); | ||
108 | StringConcatenation _builder_6 = new StringConcatenation(); | ||
109 | _builder_6.append("TaxationNoNum"); | ||
110 | final List<String> scenarios = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_builder_1.toString(), _builder_2.toString(), _builder_3.toString(), _builder_4.toString(), _builder_5.toString(), _builder_6.toString())); | ||
111 | final PrintWriter writer = new PrintWriter((path + "/diversity.csv"), "UTF-8"); | ||
112 | for (final String scenario : scenarios) { | ||
113 | { | ||
114 | final MeasureDiversity.BenchmarkConfig config = new MeasureDiversity.BenchmarkConfig(); | ||
115 | config.writer = writer; | ||
116 | config.range = 3; | ||
117 | config.scenario = scenario; | ||
118 | MeasureDiversity.measureDiversity(scenario, ((path + "/") + scenario), config); | ||
119 | InputOutput.<String>println((scenario + " finished")); | ||
120 | } | ||
121 | } | ||
122 | writer.close(); | ||
123 | } catch (Throwable _e) { | ||
124 | throw Exceptions.sneakyThrow(_e); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | public static void measureDiversity(final String scenario, final String path, final MeasureDiversity.BenchmarkConfig config) { | ||
129 | final File file = new File(path); | ||
130 | boolean _isDirectory = file.isDirectory(); | ||
131 | if (_isDirectory) { | ||
132 | final String[] subfiles = file.list(); | ||
133 | final Function1<String, Boolean> _function = (String it) -> { | ||
134 | return Boolean.valueOf(it.endsWith(".xmi")); | ||
135 | }; | ||
136 | final Iterable<String> xmiSubfiles = IterableExtensions.<String>filter(((Iterable<String>)Conversions.doWrapArray(subfiles)), _function); | ||
137 | boolean _isEmpty = IterableExtensions.isEmpty(xmiSubfiles); | ||
138 | boolean _not = (!_isEmpty); | ||
139 | if (_not) { | ||
140 | final Function1<String, File> _function_1 = (String it) -> { | ||
141 | return new File(((path + "/") + it)); | ||
142 | }; | ||
143 | MeasureDiversity.measureDiversity(scenario, file, IterableExtensions.<File>toList(IterableExtensions.<String, File>map(xmiSubfiles, _function_1)), path, config); | ||
144 | } else { | ||
145 | for (final String subfile : subfiles) { | ||
146 | MeasureDiversity.measureDiversity(scenario, ((path + "/") + subfile), config); | ||
147 | } | ||
148 | } | ||
149 | } else { | ||
150 | boolean _isFile = file.isFile(); | ||
151 | if (_isFile) { | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | public static void measureDiversity(final String scenario, final File parent, final List<File> files, final String path, final MeasureDiversity.BenchmarkConfig config) { | ||
157 | final int depth = config.range; | ||
158 | final FileSystemWorkspace workspace = new FileSystemWorkspace(path, ""); | ||
159 | EcorePackage.eINSTANCE.eClass(); | ||
160 | TaxationWithRootPackage.eINSTANCE.eClass(); | ||
161 | SatellitePackage.eINSTANCE.eClass(); | ||
162 | FamilytreePackage.eINSTANCE.eClass(); | ||
163 | FileComparator _fileComparator = new FileComparator(); | ||
164 | files.sort(_fileComparator); | ||
165 | final HashMap<File, List<Map<? extends AbstractNodeDescriptor, Integer>>> modelShapeLists = new HashMap<File, List<Map<? extends AbstractNodeDescriptor, Integer>>>(); | ||
166 | final HashMap<File, Map<? extends AbstractNodeDescriptor, Integer>> modelShapes = new HashMap<File, Map<? extends AbstractNodeDescriptor, Integer>>(); | ||
167 | for (final File file : files) { | ||
168 | { | ||
169 | final EObject model = workspace.<EObject>readModel(EObject.class, file.getName()); | ||
170 | final EPackage pckg = model.eClass().getEPackage(); | ||
171 | List<EClass> _list = IterableExtensions.<EClass>toList(Iterables.<EClass>filter(pckg.getEClassifiers(), EClass.class)); | ||
172 | Set<EClass> _emptySet = Collections.<EClass>emptySet(); | ||
173 | List<EEnum> _list_1 = IterableExtensions.<EEnum>toList(Iterables.<EEnum>filter(pckg.getEClassifiers(), EEnum.class)); | ||
174 | final Function1<EEnum, EList<EEnumLiteral>> _function = (EEnum it) -> { | ||
175 | return it.getELiterals(); | ||
176 | }; | ||
177 | List<EEnumLiteral> _list_2 = IterableExtensions.<EEnumLiteral>toList(Iterables.<EEnumLiteral>concat(IterableExtensions.<EEnum, EList<EEnumLiteral>>map(Iterables.<EEnum>filter(pckg.getEClassifiers(), EEnum.class), _function))); | ||
178 | final Function1<EClass, EList<EReference>> _function_1 = (EClass it) -> { | ||
179 | return it.getEReferences(); | ||
180 | }; | ||
181 | List<EReference> _list_3 = IterableExtensions.<EReference>toList(Iterables.<EReference>concat(IterableExtensions.<EClass, EList<EReference>>map(Iterables.<EClass>filter(pckg.getEClassifiers(), EClass.class), _function_1))); | ||
182 | final Function1<EClass, EList<EAttribute>> _function_2 = (EClass it) -> { | ||
183 | return it.getEAttributes(); | ||
184 | }; | ||
185 | List<EAttribute> _list_4 = IterableExtensions.<EAttribute>toList(Iterables.<EAttribute>concat(IterableExtensions.<EClass, EList<EAttribute>>map(Iterables.<EClass>filter(pckg.getEClassifiers(), EClass.class), _function_2))); | ||
186 | final EcoreMetamodelDescriptor metamodel = new EcoreMetamodelDescriptor(_list, _emptySet, | ||
187 | false, _list_1, _list_2, _list_3, _list_4); | ||
188 | Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); | ||
189 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTransformationOutput = MeasureDiversity.ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); | ||
190 | final PartialInterpretation partialModelOutput = MeasureDiversity.partialInterpretation2Logic.transform(metamodelTransformationOutput, model.eResource(), | ||
191 | false); | ||
192 | final List<Map<? extends AbstractNodeDescriptor, Integer>> list = MeasureDiversity.shapeList(partialModelOutput, depth); | ||
193 | modelShapes.put(file, list.get((depth - 1))); | ||
194 | } | ||
195 | } | ||
196 | final PrintWriter writer = config.writer; | ||
197 | InputOutput.<String>println("Printing internal diversity of models"); | ||
198 | for (final File model : files) { | ||
199 | { | ||
200 | final Map<? extends AbstractNodeDescriptor, Integer> modelshape = modelShapes.get(model); | ||
201 | final Function2<Integer, Integer, Integer> _function = (Integer a, Integer b) -> { | ||
202 | return Integer.valueOf(((a).intValue() + (b).intValue())); | ||
203 | }; | ||
204 | final Integer amounts = IterableExtensions.<Integer>reduce(modelshape.values(), _function); | ||
205 | int _size = modelshape.size(); | ||
206 | final double shapes = ((double) _size); | ||
207 | writer.println(((((config.scenario + ",") + model) + ",") + Double.valueOf((shapes / (amounts).intValue())))); | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | public static ArrayList<List<File>> getRandomOrders(final List<File> files, final int number) { | ||
213 | final ArrayList<List<File>> sequences = new ArrayList<List<File>>(); | ||
214 | for (int i = 0; (i < number); i++) { | ||
215 | { | ||
216 | final ArrayList<File> seq = new ArrayList<File>(files); | ||
217 | Collections.shuffle(seq); | ||
218 | sequences.add(seq); | ||
219 | } | ||
220 | } | ||
221 | return sequences; | ||
222 | } | ||
223 | |||
224 | public static void printShapeNumbersOnRandomOrders(final List<File> files, final HashMap<File, Map<? extends AbstractNodeDescriptor, Integer>> shapes, final int number) { | ||
225 | final ArrayList<List<File>> sequences = new ArrayList<List<File>>(); | ||
226 | InputOutput.<String>println("Printing generated random orders (models apper in original order)"); | ||
227 | for (int i = 0; (i < number); i++) { | ||
228 | { | ||
229 | final ArrayList<File> seq = new ArrayList<File>(files); | ||
230 | Collections.shuffle(seq); | ||
231 | sequences.add(seq); | ||
232 | InputOutput.<String>println("Model;NewIndex"); | ||
233 | for (final File model : files) { | ||
234 | String _plus = (model + ","); | ||
235 | int _indexOf = seq.indexOf(model); | ||
236 | String _plus_1 = (_plus + Integer.valueOf(_indexOf)); | ||
237 | InputOutput.<String>println(_plus_1); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | InputOutput.<String>println("Printing generated random orders (models apper in original order)"); | ||
242 | InputOutput.<String>println("SeqNo;Index;Model;NewShapes;AllShapes"); | ||
243 | int seqindx = 0; | ||
244 | for (final List<File> seq : sequences) { | ||
245 | { | ||
246 | final HashSet<AbstractNodeDescriptor> currshapes = new HashSet<AbstractNodeDescriptor>(); | ||
247 | int indx = 0; | ||
248 | for (final File model : seq) { | ||
249 | { | ||
250 | final int beforesize = currshapes.size(); | ||
251 | currshapes.addAll(shapes.get(model).keySet()); | ||
252 | final int aftersize = currshapes.size(); | ||
253 | final int diff = (aftersize - beforesize); | ||
254 | String _plus = (Integer.valueOf(seqindx) + ","); | ||
255 | String _plus_1 = (_plus + Integer.valueOf(indx)); | ||
256 | String _plus_2 = (_plus_1 + ","); | ||
257 | String _plus_3 = (_plus_2 + model); | ||
258 | String _plus_4 = (_plus_3 + ","); | ||
259 | String _plus_5 = (_plus_4 + Integer.valueOf(diff)); | ||
260 | String _plus_6 = (_plus_5 + ","); | ||
261 | int _size = currshapes.size(); | ||
262 | String _plus_7 = (_plus_6 + Integer.valueOf(_size)); | ||
263 | InputOutput.<String>println(_plus_7); | ||
264 | indx++; | ||
265 | } | ||
266 | } | ||
267 | seqindx++; | ||
268 | } | ||
269 | } | ||
270 | } | ||
271 | |||
272 | public static void printShapeNumbers(final List<File> order, final Map<File, Map<? extends AbstractNodeDescriptor, Integer>> shapes) { | ||
273 | InputOutput.<String>println("Model;InternalDiversity;NewShapes;AllCurrentShapes"); | ||
274 | final HashSet<AbstractNodeDescriptor> currshapes = new HashSet<AbstractNodeDescriptor>(); | ||
275 | for (final File file : order) { | ||
276 | { | ||
277 | final int beforesize = currshapes.size(); | ||
278 | currshapes.addAll(shapes.get(file).keySet()); | ||
279 | final int aftersize = currshapes.size(); | ||
280 | final int diff = (aftersize - beforesize); | ||
281 | String _plus = (file + ","); | ||
282 | int _size = shapes.get(file).size(); | ||
283 | String _plus_1 = (_plus + Integer.valueOf(_size)); | ||
284 | String _plus_2 = (_plus_1 + ","); | ||
285 | String _plus_3 = (_plus_2 + Integer.valueOf(diff)); | ||
286 | String _plus_4 = (_plus_3 + ","); | ||
287 | int _size_1 = currshapes.size(); | ||
288 | String _plus_5 = (_plus_4 + Integer.valueOf(_size_1)); | ||
289 | InputOutput.<String>println(_plus_5); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | |||
294 | protected static String runIndex(final String name) { | ||
295 | final String res = IterableExtensions.<String>head(((Iterable<String>)Conversions.doWrapArray(name.split("\\.")))).split("_")[0]; | ||
296 | boolean _startsWith = res.startsWith("result"); | ||
297 | if (_startsWith) { | ||
298 | return res.substring(6); | ||
299 | } else { | ||
300 | return res; | ||
301 | } | ||
302 | } | ||
303 | |||
304 | protected static String modelIndex(final String name) { | ||
305 | return IterableExtensions.<String>head(((Iterable<String>)Conversions.doWrapArray(name.split("\\.")))).split("_")[1]; | ||
306 | } | ||
307 | |||
308 | protected static LinkedList<Set<Integer>> representationList(final PartialInterpretation partialModel, final int depth) { | ||
309 | final LinkedList<Set<Integer>> list = new LinkedList<Set<Integer>>(); | ||
310 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, depth, true); | ||
311 | for (final Integer i : _doubleDotLessThan) { | ||
312 | { | ||
313 | final NeighbourhoodWithTraces<Map<? extends AbstractNodeDescriptor, Integer>, AbstractNodeDescriptor> neighbourhood = MeasureDiversity.neiguboirhoodComputer.createRepresentation(partialModel, (i).intValue(), 0, 0); | ||
314 | final Function1<AbstractNodeDescriptor, Integer> _function = (AbstractNodeDescriptor it) -> { | ||
315 | return Integer.valueOf(it.hashCode()); | ||
316 | }; | ||
317 | list.add(IterableExtensions.<Integer>toSet(IterableExtensions.map(neighbourhood.getModelRepresentation().keySet(), _function))); | ||
318 | } | ||
319 | } | ||
320 | return list; | ||
321 | } | ||
322 | |||
323 | protected static List<Map<? extends AbstractNodeDescriptor, Integer>> shapeList(final PartialInterpretation partialModel, final int depth) { | ||
324 | final LinkedList<Map<? extends AbstractNodeDescriptor, Integer>> list = new LinkedList<Map<? extends AbstractNodeDescriptor, Integer>>(); | ||
325 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, depth, true); | ||
326 | for (final Integer i : _doubleDotLessThan) { | ||
327 | { | ||
328 | final NeighbourhoodWithTraces<Map<? extends AbstractNodeDescriptor, Integer>, AbstractNodeDescriptor> neighbourhood = MeasureDiversity.neiguboirhoodComputer.createRepresentation(partialModel, (i).intValue(), Integer.MAX_VALUE, Integer.MAX_VALUE); | ||
329 | final EList<DefinedElement> openWorldElements = partialModel.getOpenWorldElements(); | ||
330 | final Function1<DefinedElement, AbstractNodeDescriptor> _function = (DefinedElement it) -> { | ||
331 | return neighbourhood.getNodeRepresentations().get(it); | ||
332 | }; | ||
333 | final Set<AbstractNodeDescriptor> representationsOfOpenElements = IterableExtensions.<AbstractNodeDescriptor>toSet(ListExtensions.<DefinedElement, AbstractNodeDescriptor>map(openWorldElements, _function)); | ||
334 | Map<? extends AbstractNodeDescriptor, Integer> _modelRepresentation = neighbourhood.getModelRepresentation(); | ||
335 | final HashMap<AbstractNodeDescriptor, Integer> allElementRepresentation = new HashMap<AbstractNodeDescriptor, Integer>(_modelRepresentation); | ||
336 | final Consumer<AbstractNodeDescriptor> _function_1 = (AbstractNodeDescriptor it) -> { | ||
337 | allElementRepresentation.remove(it); | ||
338 | }; | ||
339 | representationsOfOpenElements.forEach(_function_1); | ||
340 | final Map<Integer, Integer> hashedRepresentation = new HashMap<Integer, Integer>(); | ||
341 | Set<Map.Entry<AbstractNodeDescriptor, Integer>> _entrySet = allElementRepresentation.entrySet(); | ||
342 | for (final Map.Entry<AbstractNodeDescriptor, Integer> entry : _entrySet) { | ||
343 | hashedRepresentation.put(Integer.valueOf(entry.getKey().getDataHash()), entry.getValue()); | ||
344 | } | ||
345 | list.add(allElementRepresentation); | ||
346 | } | ||
347 | } | ||
348 | return list; | ||
349 | } | ||
350 | } | ||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/MeasureInternalDiversity.java b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/MeasureInternalDiversity.java new file mode 100644 index 00000000..e1552b2f --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/MeasureInternalDiversity.java | |||
@@ -0,0 +1,165 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.diversitycalculator; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage; | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage; | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2PartialInterpretation; | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.AbstractNodeDescriptor; | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodWithTraces; | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice; | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage; | ||
19 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
20 | import java.io.File; | ||
21 | import java.util.LinkedList; | ||
22 | import java.util.List; | ||
23 | import java.util.Map; | ||
24 | import org.eclipse.emf.ecore.EObject; | ||
25 | import org.eclipse.emf.ecore.resource.Resource; | ||
26 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
27 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
28 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
29 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
30 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
31 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
32 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
33 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
34 | |||
35 | @SuppressWarnings("all") | ||
36 | public class MeasureInternalDiversity { | ||
37 | private static final InstanceModel2PartialInterpretation partialInterpretation2Logic = new InstanceModel2PartialInterpretation(); | ||
38 | |||
39 | private static final PartialInterpretation2ImmutableTypeLattice neiguboirhoodComputer = new PartialInterpretation2ImmutableTypeLattice(); | ||
40 | |||
41 | private static final Ecore2Logic ecore2Logic = new Ecore2Logic(); | ||
42 | |||
43 | private static Object init() { | ||
44 | Object _xblockexpression = null; | ||
45 | { | ||
46 | LogiclanguagePackage.eINSTANCE.getClass(); | ||
47 | LogicproblemPackage.eINSTANCE.getClass(); | ||
48 | PartialinterpretationPackage.eINSTANCE.getClass(); | ||
49 | Ecore2logicannotationsPackage.eINSTANCE.getClass(); | ||
50 | Viatra2LogicAnnotationsPackage.eINSTANCE.getClass(); | ||
51 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
52 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
53 | _xblockexpression = _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); | ||
54 | } | ||
55 | return _xblockexpression; | ||
56 | } | ||
57 | |||
58 | public static void main(final String[] args) { | ||
59 | MeasureInternalDiversity.init(); | ||
60 | } | ||
61 | |||
62 | public static void run(final EcoreMetamodelDescriptor metamodel, final String path, final String scenario) { | ||
63 | final int range = 20; | ||
64 | MeasureInternalDiversity.measureDiversity(metamodel, scenario, path, range); | ||
65 | } | ||
66 | |||
67 | public static void measureDiversity(final EcoreMetamodelDescriptor metamodel, final String scenario, final String path, final int depth) { | ||
68 | final File file = new File(path); | ||
69 | boolean _isDirectory = file.isDirectory(); | ||
70 | if (_isDirectory) { | ||
71 | final String[] subfiles = file.list(); | ||
72 | final Function1<String, Boolean> _function = (String it) -> { | ||
73 | return Boolean.valueOf(it.endsWith(".xmi")); | ||
74 | }; | ||
75 | final Iterable<String> xmiSubfiles = IterableExtensions.<String>filter(((Iterable<String>)Conversions.doWrapArray(subfiles)), _function); | ||
76 | boolean _isEmpty = IterableExtensions.isEmpty(xmiSubfiles); | ||
77 | boolean _not = (!_isEmpty); | ||
78 | if (_not) { | ||
79 | final Function1<String, File> _function_1 = (String it) -> { | ||
80 | return new File(((path + "/") + it)); | ||
81 | }; | ||
82 | MeasureInternalDiversity.measureDiversity(metamodel, scenario, file, IterableExtensions.<File>toList(IterableExtensions.<String, File>map(xmiSubfiles, _function_1)), path, depth); | ||
83 | } else { | ||
84 | for (final String subfile : subfiles) { | ||
85 | MeasureInternalDiversity.measureDiversity(metamodel, scenario, ((path + "/") + subfile), depth); | ||
86 | } | ||
87 | } | ||
88 | } else { | ||
89 | boolean _isFile = file.isFile(); | ||
90 | if (_isFile) { | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | public static void measureDiversity(final EcoreMetamodelDescriptor metamodel, final String scenario, final File parent, final List<File> files, final String path, final int depth) { | ||
96 | final FileSystemWorkspace workspace = new FileSystemWorkspace(path, ""); | ||
97 | for (final File file : files) { | ||
98 | { | ||
99 | Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); | ||
100 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTransformationOutput = MeasureInternalDiversity.ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); | ||
101 | final EObject model = workspace.<EObject>readModel(EObject.class, file.getName()); | ||
102 | final PartialInterpretation partialModel = MeasureInternalDiversity.partialInterpretation2Logic.transform(metamodelTransformationOutput, model.eResource(), false); | ||
103 | final LinkedList<Map<? extends AbstractNodeDescriptor, Integer>> list = MeasureInternalDiversity.representationList(partialModel, depth); | ||
104 | try { | ||
105 | final String runIndex = MeasureInternalDiversity.runIndex(file.getName()); | ||
106 | final String modelIndex = MeasureInternalDiversity.modelIndex(file.getName()); | ||
107 | StringConcatenation _builder = new StringConcatenation(); | ||
108 | _builder.append(scenario); | ||
109 | _builder.append(";"); | ||
110 | _builder.append(runIndex); | ||
111 | _builder.append(";"); | ||
112 | _builder.append(modelIndex); | ||
113 | InputOutput.<String>print(_builder.toString()); | ||
114 | } catch (final Throwable _t) { | ||
115 | if (_t instanceof Exception) { | ||
116 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
117 | _builder_1.append(scenario); | ||
118 | _builder_1.append(";0;"); | ||
119 | String _name = file.getName(); | ||
120 | _builder_1.append(_name); | ||
121 | InputOutput.<String>print(_builder_1.toString()); | ||
122 | } else { | ||
123 | throw Exceptions.sneakyThrow(_t); | ||
124 | } | ||
125 | } | ||
126 | int _size = list.size(); | ||
127 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); | ||
128 | for (final Integer i : _doubleDotLessThan) { | ||
129 | StringConcatenation _builder = new StringConcatenation(); | ||
130 | _builder.append(";"); | ||
131 | int _size_1 = list.get((i).intValue()).keySet().size(); | ||
132 | _builder.append(_size_1); | ||
133 | InputOutput.<String>print(_builder.toString()); | ||
134 | } | ||
135 | int _size_2 = list.getLast().keySet().size(); | ||
136 | double _multiply = (_size_2 * 1.0); | ||
137 | int _size_3 = partialModel.getNewElements().size(); | ||
138 | double _divide = (_multiply / _size_3); | ||
139 | String _plus = (";" + Double.valueOf(_divide)); | ||
140 | InputOutput.<String>print(_plus); | ||
141 | InputOutput.println(); | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | |||
146 | protected static String runIndex(final String name) { | ||
147 | return IterableExtensions.<String>head(((Iterable<String>)Conversions.doWrapArray(name.split("\\.")))).split("_")[1]; | ||
148 | } | ||
149 | |||
150 | protected static String modelIndex(final String name) { | ||
151 | return IterableExtensions.<String>head(((Iterable<String>)Conversions.doWrapArray(name.split("\\.")))).split("_")[2]; | ||
152 | } | ||
153 | |||
154 | protected static LinkedList<Map<? extends AbstractNodeDescriptor, Integer>> representationList(final PartialInterpretation partialModel, final int depth) { | ||
155 | final LinkedList<Map<? extends AbstractNodeDescriptor, Integer>> list = new LinkedList<Map<? extends AbstractNodeDescriptor, Integer>>(); | ||
156 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, depth, true); | ||
157 | for (final Integer i : _doubleDotLessThan) { | ||
158 | { | ||
159 | final NeighbourhoodWithTraces<Map<? extends AbstractNodeDescriptor, Integer>, AbstractNodeDescriptor> neighbourhood = MeasureInternalDiversity.neiguboirhoodComputer.createRepresentation(partialModel, (i).intValue(), 0, 0); | ||
160 | list.add(neighbourhood.getModelRepresentation()); | ||
161 | } | ||
162 | } | ||
163 | return list; | ||
164 | } | ||
165 | } | ||
diff --git a/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/PatternWithMatches.java b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/PatternWithMatches.java new file mode 100644 index 00000000..201269fd --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/models20.diversity-calculator/xtend-gen/hu/bme/mit/inf/dslreasoner/diversitycalculator/PatternWithMatches.java | |||
@@ -0,0 +1,72 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.diversitycalculator; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement; | ||
4 | import java.util.List; | ||
5 | import org.eclipse.xtend.lib.annotations.Data; | ||
6 | import org.eclipse.xtext.xbase.lib.Pure; | ||
7 | import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
8 | |||
9 | @Data | ||
10 | @SuppressWarnings("all") | ||
11 | public class PatternWithMatches { | ||
12 | private final String name; | ||
13 | |||
14 | private final List<List<DefinedElement>> matches; | ||
15 | |||
16 | public PatternWithMatches(final String name, final List<List<DefinedElement>> matches) { | ||
17 | super(); | ||
18 | this.name = name; | ||
19 | this.matches = matches; | ||
20 | } | ||
21 | |||
22 | @Override | ||
23 | @Pure | ||
24 | public int hashCode() { | ||
25 | final int prime = 31; | ||
26 | int result = 1; | ||
27 | result = prime * result + ((this.name== null) ? 0 : this.name.hashCode()); | ||
28 | return prime * result + ((this.matches== null) ? 0 : this.matches.hashCode()); | ||
29 | } | ||
30 | |||
31 | @Override | ||
32 | @Pure | ||
33 | public boolean equals(final Object obj) { | ||
34 | if (this == obj) | ||
35 | return true; | ||
36 | if (obj == null) | ||
37 | return false; | ||
38 | if (getClass() != obj.getClass()) | ||
39 | return false; | ||
40 | PatternWithMatches other = (PatternWithMatches) obj; | ||
41 | if (this.name == null) { | ||
42 | if (other.name != null) | ||
43 | return false; | ||
44 | } else if (!this.name.equals(other.name)) | ||
45 | return false; | ||
46 | if (this.matches == null) { | ||
47 | if (other.matches != null) | ||
48 | return false; | ||
49 | } else if (!this.matches.equals(other.matches)) | ||
50 | return false; | ||
51 | return true; | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | @Pure | ||
56 | public String toString() { | ||
57 | ToStringBuilder b = new ToStringBuilder(this); | ||
58 | b.add("name", this.name); | ||
59 | b.add("matches", this.matches); | ||
60 | return b.toString(); | ||
61 | } | ||
62 | |||
63 | @Pure | ||
64 | public String getName() { | ||
65 | return this.name; | ||
66 | } | ||
67 | |||
68 | @Pure | ||
69 | public List<List<DefinedElement>> getMatches() { | ||
70 | return this.matches; | ||
71 | } | ||
72 | } | ||