diff options
Diffstat (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit')
2 files changed, 175 insertions, 3 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend new file mode 100644 index 00000000..f9086683 --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend | |||
@@ -0,0 +1,170 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage | ||
4 | import hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated | ||
5 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
6 | import java.io.File | ||
7 | import java.util.ArrayList | ||
8 | import java.util.Collection | ||
9 | import java.util.Comparator | ||
10 | import java.util.HashMap | ||
11 | import java.util.List | ||
12 | import java.util.Map | ||
13 | import java.util.TreeSet | ||
14 | import org.eclipse.emf.ecore.EObject | ||
15 | import org.eclipse.emf.ecore.resource.Resource | ||
16 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
17 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
18 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
19 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | ||
20 | import org.eclipse.viatra.query.runtime.emf.EMFScope | ||
21 | |||
22 | class QueryComparator implements Comparator<IQuerySpecification<?>>{ | ||
23 | |||
24 | override compare(IQuerySpecification<?> arg0, IQuerySpecification<?> arg1) { | ||
25 | arg0.fullyQualifiedName.compareTo(arg1.fullyQualifiedName) | ||
26 | } | ||
27 | } | ||
28 | |||
29 | class CountMatches { | ||
30 | var static List<IQuerySpecification<?>> wfPatterns; | ||
31 | var static Map<IQuerySpecification<?>,IQuerySpecification<?>> query2Reference | ||
32 | |||
33 | def static void main(String[] args) { | ||
34 | YakindummPackage.eINSTANCE.eClass | ||
35 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) | ||
36 | |||
37 | wfPatterns = Mutated.instance.specifications.toList; | ||
38 | //wfPatterns = wfPatterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toList | ||
39 | wfPatterns.sort(new QueryComparator) | ||
40 | |||
41 | val groupName2Representant = new HashMap | ||
42 | query2Reference = new HashMap | ||
43 | for(wfPattern : wfPatterns) { | ||
44 | val groupName = wfPattern.groupName | ||
45 | if(groupName2Representant.containsKey(groupName)) { | ||
46 | val representant = groupName2Representant.get(groupName) | ||
47 | query2Reference.put(wfPattern,representant) | ||
48 | } else { | ||
49 | groupName2Representant.put(groupName,wfPattern) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | |||
54 | println('''modelpath;run;model;« | ||
55 | FOR wfPattern:wfPatterns SEPARATOR ";"»#(« | ||
56 | wfPattern.fullyQualifiedName.split("\\.").last»);hash(« | ||
57 | wfPattern.fullyQualifiedName.split("\\.").last»)«ENDFOR»;« | ||
58 | FOR mutant : wfPatterns.filter[query2Reference.keySet.contains(it)] SEPARATOR ';'»diff(« | ||
59 | mutant.fullyQualifiedName.split("\\.").last»)«ENDFOR»''' | ||
60 | ) | ||
61 | countMatches('''D:/FASE18Meas/MetamodelOnly_Alloy_Symmetry30''') | ||
62 | } | ||
63 | |||
64 | def private static simpleName(IQuerySpecification<?> wfPattern) { | ||
65 | wfPattern.fullyQualifiedName.split("\\.").last | ||
66 | } | ||
67 | def private static groupName(IQuerySpecification<?> wfPattern) { | ||
68 | wfPattern.simpleName.split('_').head | ||
69 | } | ||
70 | |||
71 | def static void countMatches(String path) { | ||
72 | val file = new File(path) | ||
73 | if(file.isDirectory) { | ||
74 | for(subFileName : file.list) { | ||
75 | (path + "/" + subFileName).countMatches | ||
76 | } | ||
77 | } else if(file.isFile) { | ||
78 | if(path.endsWith("xmi")) { | ||
79 | countMatches(file,path) | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | def static void countMatches(File file, String path) { | ||
85 | val parent = file.parent | ||
86 | |||
87 | val pathSegments = path.split("/") | ||
88 | val groupName = pathSegments.get(pathSegments.size-2).split("\\.").last.split("_").get(0) | ||
89 | print(groupName +";") | ||
90 | val nameExtension = pathSegments.get(pathSegments.size-1).split("\\.").get(0).split("_") | ||
91 | val runNumber = nameExtension.get(1) | ||
92 | val modelNumber = nameExtension.get(2) | ||
93 | print('''«runNumber»;«modelNumber»''') | ||
94 | val workspace = new FileSystemWorkspace(parent,"") | ||
95 | val model = workspace.readModel(EObject,file.name) | ||
96 | |||
97 | val engine = ViatraQueryEngine.on(new EMFScope(model)) | ||
98 | val objectCode = model.eResource.calculateObjectCode | ||
99 | |||
100 | val pattern2Hash = new HashMap | ||
101 | for(pattern : wfPatterns) { | ||
102 | val matcher = pattern.getMatcher(engine) | ||
103 | val matches = matcher.allMatches | ||
104 | val hash = matches.getMatchSetDescriptor(objectCode) | ||
105 | pattern2Hash.put(pattern,hash) | ||
106 | print(''';«matcher.countMatches»;«hash»''') | ||
107 | } | ||
108 | var mutantsKilled = 0 | ||
109 | for(mutant : wfPatterns.filter[query2Reference.keySet.contains(it)]) { | ||
110 | val equals = pattern2Hash.get(mutant) == pattern2Hash.get(query2Reference.get(mutant)) | ||
111 | print(''';''') | ||
112 | if(equals) { | ||
113 | print('0') | ||
114 | } else { | ||
115 | print('1') | ||
116 | mutantsKilled++ | ||
117 | } | ||
118 | } | ||
119 | //print(''';«mutantsKilled»''') | ||
120 | println() | ||
121 | } | ||
122 | |||
123 | def static Map<EObject,Integer> calculateObjectCode(Resource resource) { | ||
124 | val res = new HashMap | ||
125 | val iterator = resource.allContents | ||
126 | var index = 1 | ||
127 | while(iterator.hasNext) { | ||
128 | res.put(iterator.next,index++) | ||
129 | } | ||
130 | return res | ||
131 | } | ||
132 | |||
133 | def static getMatchSetDescriptor(Collection<? extends IPatternMatch> matchSet, Map<EObject,Integer> objectCode) { | ||
134 | val set = new TreeSet(new ArrayComparator) | ||
135 | for(match: matchSet) { | ||
136 | val size = match.parameterNames.size | ||
137 | val idArray = new ArrayList<Integer>(size) | ||
138 | for(i:0..<size) { | ||
139 | val objectInMatch = match.get(i) | ||
140 | if(objectInMatch instanceof EObject) { | ||
141 | val id = objectCode.get(objectInMatch) | ||
142 | if(id!== null) { | ||
143 | idArray+= id | ||
144 | } else { | ||
145 | throw new IllegalArgumentException('''Unindexed object in match: «objectInMatch»''') | ||
146 | } | ||
147 | } else { | ||
148 | throw new IllegalArgumentException('''Unknown type object in match: "«objectInMatch.class.simpleName»"''') | ||
149 | } | ||
150 | } | ||
151 | set += idArray | ||
152 | } | ||
153 | return '''«FOR match : set SEPARATOR ','»[«FOR index : match SEPARATOR ','»«index»«ENDFOR»]«ENDFOR»'''.toString.hashCode | ||
154 | } | ||
155 | } | ||
156 | |||
157 | class ArrayComparator implements Comparator<List<Integer>> { | ||
158 | |||
159 | override compare(List<Integer> arg0, List<Integer> arg1) { | ||
160 | if(arg0.size === arg1.size) { | ||
161 | for(i : 0..<arg0.size) { | ||
162 | val comparison = arg0.get(i).compareTo(arg1.get(i)) | ||
163 | if(comparison !== 0) return comparison | ||
164 | } | ||
165 | return 0 | ||
166 | } else { | ||
167 | throw new IllegalArgumentException('''the arrays need to be in the same size''') | ||
168 | } | ||
169 | } | ||
170 | } \ No newline at end of file | ||
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/DiverseMeasurementRunner.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/DiverseMeasurementRunner.xtend index 12fe775a..702b1740 100644 --- a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/DiverseMeasurementRunner.xtend +++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/DiverseMeasurementRunner.xtend | |||
@@ -135,7 +135,7 @@ class ScenarioRunner { | |||
135 | 135 | ||
136 | var FileSystemWorkspace workspace = new FileSystemWorkspace('''output_«id»/''',"") | 136 | var FileSystemWorkspace workspace = new FileSystemWorkspace('''output_«id»/''',"") |
137 | workspace.initAndClear | 137 | workspace.initAndClear |
138 | val config = getSolverConfiguration(scenario,vq) | 138 | val config = getSolverConfiguration(scenario,vq,run) |
139 | 139 | ||
140 | // Execute | 140 | // Execute |
141 | val solution = getSolver(scenario).solve(problem,config,workspace) | 141 | val solution = getSolver(scenario).solve(problem,config,workspace) |
@@ -181,7 +181,7 @@ class ScenarioRunner { | |||
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | def private getSolverConfiguration(Scenario scenario, ViatraQuerySetDescriptor vq) { | 184 | def private getSolverConfiguration(Scenario scenario, ViatraQuerySetDescriptor vq, int run) { |
185 | if(scenario.solver == Solver.ViatraSolver) { | 185 | if(scenario.solver == Solver.ViatraSolver) { |
186 | val viatraConfig = new ViatraReasonerConfiguration => [ | 186 | val viatraConfig = new ViatraReasonerConfiguration => [ |
187 | it.runtimeLimit = 300 | 187 | it.runtimeLimit = 300 |
@@ -226,6 +226,7 @@ class ScenarioRunner { | |||
226 | it.solutionScope.numberOfRequiredSolution = scenario.number | 226 | it.solutionScope.numberOfRequiredSolution = scenario.number |
227 | it.typeScopes.maxNewIntegers = 0 | 227 | it.typeScopes.maxNewIntegers = 0 |
228 | it.writeToFile=true | 228 | it.writeToFile=true |
229 | it.randomise = run-1 | ||
229 | ] | 230 | ] |
230 | } | 231 | } |
231 | 232 | ||
@@ -317,7 +318,8 @@ class ScenarioRunner { | |||
317 | 318 | ||
318 | class DiverseMeasurementRunner { | 319 | class DiverseMeasurementRunner { |
319 | def static void main(String[] args) { | 320 | def static void main(String[] args) { |
320 | val scenario = new Scenario(30,29,Metamodel::YakinduWOSynch,Constraints.Metamodel,StateCoder.R1,20,Solver::Alloy) | 321 | val scenario = new Scenario(30,29,Metamodel::YakinduWOSynch,Constraints.Metamodel,StateCoder.R3,20,Solver::Alloy |
322 | ) | ||
321 | val scenarioRunner = new ScenarioRunner | 323 | val scenarioRunner = new ScenarioRunner |
322 | scenarioRunner.runScenario(scenario) | 324 | scenarioRunner.runScenario(scenario) |
323 | } | 325 | } |