aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszka@SEMERATH-LAPTOP>2017-10-17 20:56:18 +0200
committerLibravatar OszkarSemerath <oszka@SEMERATH-LAPTOP>2017-10-17 20:56:18 +0200
commitbd37465f3463af055ee274d9f44641ee93bd4312 (patch)
tree57d23275d866776e5979dec93ed80e4133d03aec
parentmeasurement and mutant coverage (diff)
downloadVIATRA-Generator-bd37465f3463af055ee274d9f44641ee93bd4312.tar.gz
VIATRA-Generator-bd37465f3463af055ee274d9f44641ee93bd4312.tar.zst
VIATRA-Generator-bd37465f3463af055ee274d9f44641ee93bd4312.zip
Runners
-rw-r--r--Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend170
-rw-r--r--Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/DiverseMeasurementRunner.xtend8
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 @@
1package hu.bme.mit.inf.dslreasoner.run
2
3import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage
4import hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated
5import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace
6import java.io.File
7import java.util.ArrayList
8import java.util.Collection
9import java.util.Comparator
10import java.util.HashMap
11import java.util.List
12import java.util.Map
13import java.util.TreeSet
14import org.eclipse.emf.ecore.EObject
15import org.eclipse.emf.ecore.resource.Resource
16import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
17import org.eclipse.viatra.query.runtime.api.IPatternMatch
18import org.eclipse.viatra.query.runtime.api.IQuerySpecification
19import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
20import org.eclipse.viatra.query.runtime.emf.EMFScope
21
22class QueryComparator implements Comparator<IQuerySpecification<?>>{
23
24 override compare(IQuerySpecification<?> arg0, IQuerySpecification<?> arg1) {
25 arg0.fullyQualifiedName.compareTo(arg1.fullyQualifiedName)
26 }
27}
28
29class 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
157class 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
318class DiverseMeasurementRunner { 319class 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 }