diff options
Diffstat (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureDiversity.xtend')
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureDiversity.xtend | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureDiversity.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureDiversity.xtend new file mode 100644 index 00000000..70f7b033 --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasureDiversity.xtend | |||
@@ -0,0 +1,191 @@ | |||
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.HashMap | ||
16 | import java.util.LinkedList | ||
17 | import java.util.List | ||
18 | import org.eclipse.emf.ecore.EObject | ||
19 | import org.eclipse.emf.ecore.resource.Resource | ||
20 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
21 | import java.util.HashSet | ||
22 | import java.util.ArrayList | ||
23 | import java.util.Comparator | ||
24 | |||
25 | class MeasureDiversity { | ||
26 | static val partialInterpretation2Logic = new InstanceModel2PartialInterpretation | ||
27 | static val neiguboirhoodComputer = new PartialInterpretation2ImmutableTypeLattice | ||
28 | |||
29 | static val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
30 | |||
31 | static private def init() { | ||
32 | LogiclanguagePackage.eINSTANCE.class | ||
33 | LogicproblemPackage.eINSTANCE.class | ||
34 | PartialinterpretationPackage.eINSTANCE.class | ||
35 | Ecore2logicannotationsPackage.eINSTANCE.class | ||
36 | Viatra2LogicAnnotationsPackage.eINSTANCE.class | ||
37 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) | ||
38 | } | ||
39 | |||
40 | |||
41 | def static void main(String[] args) { | ||
42 | init() | ||
43 | val range = 20 | ||
44 | val path = '''D:/FASE18Meas/''' | ||
45 | val scenarios = #[ | ||
46 | "MetamodelOnly_Alloy_Symmetry0", | ||
47 | "MetamodelOnly_Alloy_Symmetry10", | ||
48 | //"MetamodelOnly_Alloy_Symmetry30", | ||
49 | "MetamodelOnly_Alloy_SymmetryDefault", | ||
50 | //"MetamodelOnly_VS_Fix_No", | ||
51 | "MetamodelOnly_VS_Fix_R1", | ||
52 | "MetamodelOnly_VS_Fix_R2", | ||
53 | "MetamodelOnly_VS_Fix_R3" | ||
54 | //,"RemoHF" | ||
55 | ] | ||
56 | |||
57 | println('''Scenario;Run;Model1;Model2;«FOR i: 0..<range SEPARATOR ';'»r«i»«ENDFOR»''') | ||
58 | for(scenario : scenarios) { | ||
59 | measureDiversity(scenario,path+"/"+scenario,range) | ||
60 | } | ||
61 | //println()println() | ||
62 | |||
63 | // println('''Scenario;Run;Model;«FOR i: 0..<range SEPARATOR ';'»r«i»«ENDFOR»;sn/gn''') | ||
64 | // for(scenario : scenarios) { | ||
65 | // MeasureInternalDiversity::run(path+"/"+scenario,scenario) | ||
66 | // } | ||
67 | } | ||
68 | |||
69 | def static void measureDiversity(String scenario, String path, int depth) { | ||
70 | val file = new File(path) | ||
71 | if(file.isDirectory) { | ||
72 | val subfiles = file.list | ||
73 | val xmiSubfiles = subfiles.filter[it.endsWith(".xmi")] | ||
74 | if(!xmiSubfiles.empty) { | ||
75 | measureDiversity(scenario, file,xmiSubfiles.map[new File(path+"/"+it)].toList,path,depth) | ||
76 | } else { | ||
77 | for(subfile : subfiles) { | ||
78 | measureDiversity(scenario, path+"/"+subfile,depth) | ||
79 | } | ||
80 | } | ||
81 | } else if(file.isFile) { | ||
82 | // Do nothing | ||
83 | } | ||
84 | } | ||
85 | |||
86 | def static void measureDiversity(String scenario, File parent, List<File> files, String path, int depth) { | ||
87 | val workspace = new FileSystemWorkspace(path, "") | ||
88 | //val file2Neighbourhood = new HashMap | ||
89 | |||
90 | files.sort(new FileComparator) | ||
91 | |||
92 | val neighbours = new ArrayList | ||
93 | for(i:0..<depth){ | ||
94 | neighbours.add(new HashSet) | ||
95 | } | ||
96 | |||
97 | for (file : files.filter[Integer.parseInt(it.name.runIndex) <= 20]) { | ||
98 | val MetamodelLoader loader = new YakinduLoader(workspace) => [ | ||
99 | it.useSynchronization = false | ||
100 | it.useComplexStates = true | ||
101 | ] | ||
102 | val metamodelTransformationOutput = ecore2Logic.transformMetamodel(loader.loadMetamodel, | ||
103 | new Ecore2LogicConfiguration) | ||
104 | |||
105 | val model = workspace.readModel(EObject, file.name) | ||
106 | val partialModel = partialInterpretation2Logic.transform(metamodelTransformationOutput, model.eResource, | ||
107 | false) | ||
108 | val list = representationList(partialModel, depth) | ||
109 | |||
110 | //file2Neighbourhood.put(file, list) | ||
111 | |||
112 | print('''«scenario»;«file.name.runIndex»;«file.name.modelIndex»''') | ||
113 | for (i : 0 ..< list.size) { | ||
114 | val s1 = list.get(i) | ||
115 | neighbours.get(i).addAll(s1) | ||
116 | print(";" + neighbours.get(i).size) | ||
117 | } | ||
118 | println() | ||
119 | } | ||
120 | } | ||
121 | |||
122 | |||
123 | // def static void measureDiversity(String scenario, File parent, List<File> files, String path, int depth) { | ||
124 | // val workspace = new FileSystemWorkspace(path,"") | ||
125 | // val file2Neighbourhood = new HashMap | ||
126 | // for(file : files) { | ||
127 | // val MetamodelLoader loader = new YakinduLoader(workspace) => [it.useSynchronization = false it.useComplexStates = true] | ||
128 | // val metamodelTransformationOutput = ecore2Logic.transformMetamodel(loader.loadMetamodel,new Ecore2LogicConfiguration) | ||
129 | // | ||
130 | // val model = workspace.readModel(EObject,file.name) | ||
131 | // val partialModel = partialInterpretation2Logic.transform(metamodelTransformationOutput,model.eResource,false) | ||
132 | // val list = representationList(partialModel,depth) | ||
133 | // | ||
134 | // file2Neighbourhood.put(file,list) | ||
135 | // } | ||
136 | // for(file1Index : 0..<files.size) { | ||
137 | // val file1 = files.get(file1Index) | ||
138 | // if(Integer.parseInt(file1.name.runIndex)<=20) { | ||
139 | // for(file2Index : 0..<file1Index) { | ||
140 | // val file2 = files.get(file2Index) | ||
141 | // val file1Representation = file2Neighbourhood.get(file1) | ||
142 | // val file2Representation = file2Neighbourhood.get(file2) | ||
143 | // print('''«scenario»;«file1.name.runIndex»;«file1.name.modelIndex»;«file2.name.modelIndex»''') | ||
144 | // if(file1Representation.size == file1Representation.size) { | ||
145 | // for(i : 0..<file1Representation.size) { | ||
146 | // val s1 = file1Representation.get(i) | ||
147 | // val s2 = file2Representation.get(i) | ||
148 | // | ||
149 | // val commonSet = new HashSet(s1) | ||
150 | // commonSet.addAll(s2) | ||
151 | // | ||
152 | // val diff = (commonSet.size-s1.size) + (commonSet.size-s2.size) | ||
153 | // print(";"+diff) | ||
154 | // } | ||
155 | // } else { | ||
156 | // throw new AssertionError('''length of representations is !=''') | ||
157 | // } | ||
158 | // println() | ||
159 | // } | ||
160 | // } | ||
161 | // } | ||
162 | // } | ||
163 | |||
164 | protected def static runIndex(String name) { | ||
165 | name.split("\\.").head.split('_').get(1) | ||
166 | } | ||
167 | protected def static modelIndex(String name) { | ||
168 | name.split("\\.").head.split('_').get(2) | ||
169 | } | ||
170 | |||
171 | protected def static representationList(PartialInterpretation partialModel, int depth) { | ||
172 | val list = new LinkedList | ||
173 | for(i : 0..<depth) { | ||
174 | val neighbourhood = neiguboirhoodComputer.createRepresentation(partialModel,i,0,0) | ||
175 | //val m = neighbourhood.modelRepresentation | ||
176 | //println(m) | ||
177 | list.add(neighbourhood.modelRepresentation.keySet.map[it.hashCode].toSet) | ||
178 | } | ||
179 | return list | ||
180 | } | ||
181 | } | ||
182 | |||
183 | class FileComparator implements Comparator<File> { | ||
184 | |||
185 | override compare(File arg0, File arg1) { | ||
186 | val a = Integer.parseInt(MeasureDiversity::modelIndex(arg0.name)) | ||
187 | val b = Integer.parseInt(MeasureDiversity::modelIndex(arg1.name)) | ||
188 | Integer.compare(a,b) | ||
189 | } | ||
190 | |||
191 | } \ No newline at end of file | ||