diff options
Diffstat (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureInternalDiversity.xtend')
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureInternalDiversity.xtend | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureInternalDiversity.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureInternalDiversity.xtend new file mode 100644 index 00000000..c4737672 --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureInternalDiversity.xtend | |||
@@ -0,0 +1,107 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.run | ||
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.ecore2logicannotations.Ecore2logicannotationsPackage | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage | ||
8 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2PartialInterpretation | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | ||
13 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
14 | import java.io.File | ||
15 | import java.util.LinkedList | ||
16 | import java.util.List | ||
17 | import org.eclipse.emf.ecore.EObject | ||
18 | import org.eclipse.emf.ecore.resource.Resource | ||
19 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
20 | |||
21 | class MeasureInternalDiversity { | ||
22 | static val partialInterpretation2Logic = new InstanceModel2PartialInterpretation | ||
23 | static val neiguboirhoodComputer = new PartialInterpretation2ImmutableTypeLattice | ||
24 | |||
25 | static val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
26 | |||
27 | static private def init() { | ||
28 | LogiclanguagePackage.eINSTANCE.class | ||
29 | LogicproblemPackage.eINSTANCE.class | ||
30 | PartialinterpretationPackage.eINSTANCE.class | ||
31 | Ecore2logicannotationsPackage.eINSTANCE.class | ||
32 | Viatra2LogicAnnotationsPackage.eINSTANCE.class | ||
33 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) | ||
34 | } | ||
35 | |||
36 | |||
37 | def static void main(String[] args) { | ||
38 | init() | ||
39 | |||
40 | } | ||
41 | |||
42 | def static run(String path, String scenario) { | ||
43 | val range = 20 | ||
44 | |||
45 | measureDiversity(scenario,path,range) | ||
46 | } | ||
47 | |||
48 | def static void measureDiversity(String scenario, String path, int depth) { | ||
49 | val file = new File(path) | ||
50 | if(file.isDirectory) { | ||
51 | val subfiles = file.list | ||
52 | val xmiSubfiles = subfiles.filter[it.endsWith(".xmi")] | ||
53 | if(!xmiSubfiles.empty) { | ||
54 | measureDiversity(scenario,file,xmiSubfiles.map[new File(path+"/"+it)].toList,path,depth) | ||
55 | } else { | ||
56 | for(subfile : subfiles) { | ||
57 | measureDiversity(scenario,path+"/"+subfile,depth) | ||
58 | } | ||
59 | } | ||
60 | } else if(file.isFile) { | ||
61 | // Do nothing | ||
62 | } | ||
63 | } | ||
64 | |||
65 | def static void measureDiversity(String scenario, File parent, List<File> files, String path, int depth) { | ||
66 | val workspace = new FileSystemWorkspace(path,"") | ||
67 | //val file2Neighbourhood = new HashMap<File,List<?>> | ||
68 | for(file : files) { | ||
69 | val MetamodelLoader loader = new YakinduLoader(workspace) => [it.useSynchronization = false it.useComplexStates = true] | ||
70 | val metamodelTransformationOutput = ecore2Logic.transformMetamodel(loader.loadMetamodel,new Ecore2LogicConfiguration) | ||
71 | |||
72 | val model = workspace.readModel(EObject,file.name) | ||
73 | val partialModel = partialInterpretation2Logic.transform(metamodelTransformationOutput,model.eResource,false) | ||
74 | val list = representationList(partialModel,depth) | ||
75 | try { | ||
76 | val runIndex = file.name.runIndex | ||
77 | val modelIndex = file.name.modelIndex | ||
78 | print('''«scenario»;«runIndex»;«modelIndex»''') | ||
79 | } catch (Exception e) { | ||
80 | print('''«scenario»;0;«file.name»''') | ||
81 | } | ||
82 | for(i : 0..<list.size) { | ||
83 | print(''';«list.get(i).keySet.size»''') | ||
84 | } | ||
85 | print(";"+(list.last.keySet.size*1.0 /partialModel.newElements.size)) | ||
86 | println | ||
87 | } | ||
88 | } | ||
89 | |||
90 | protected def static runIndex(String name) { | ||
91 | name.split("\\.").head.split('_').get(1) | ||
92 | } | ||
93 | protected def static modelIndex(String name) { | ||
94 | name.split("\\.").head.split('_').get(2) | ||
95 | } | ||
96 | |||
97 | protected def static representationList(PartialInterpretation partialModel, int depth) { | ||
98 | val list = new LinkedList | ||
99 | for(i : 0..<depth) { | ||
100 | val neighbourhood = neiguboirhoodComputer.createRepresentation(partialModel,i,0,0) | ||
101 | //val m = neighbourhood.modelRepresentation | ||
102 | //println(m) | ||
103 | list.add(neighbourhood.modelRepresentation) | ||
104 | } | ||
105 | return list | ||
106 | } | ||
107 | } \ No newline at end of file | ||