From bd37465f3463af055ee274d9f44641ee93bd4312 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 17 Oct 2017 20:56:18 +0200 Subject: Runners --- .../bme/mit/inf/dslreasoner/run/CountMatches.xtend | 170 +++++++++++++++++++++ .../dslreasoner/run/DiverseMeasurementRunner.xtend | 8 +- 2 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf') 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 @@ +package hu.bme.mit.inf.dslreasoner.run + +import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage +import hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated +import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace +import java.io.File +import java.util.ArrayList +import java.util.Collection +import java.util.Comparator +import java.util.HashMap +import java.util.List +import java.util.Map +import java.util.TreeSet +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl +import org.eclipse.viatra.query.runtime.api.IPatternMatch +import org.eclipse.viatra.query.runtime.api.IQuerySpecification +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.query.runtime.emf.EMFScope + +class QueryComparator implements Comparator>{ + + override compare(IQuerySpecification arg0, IQuerySpecification arg1) { + arg0.fullyQualifiedName.compareTo(arg1.fullyQualifiedName) + } +} + +class CountMatches { + var static List> wfPatterns; + var static Map,IQuerySpecification> query2Reference + + def static void main(String[] args) { + YakindummPackage.eINSTANCE.eClass + Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) + + wfPatterns = Mutated.instance.specifications.toList; + //wfPatterns = wfPatterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toList + wfPatterns.sort(new QueryComparator) + + val groupName2Representant = new HashMap + query2Reference = new HashMap + for(wfPattern : wfPatterns) { + val groupName = wfPattern.groupName + if(groupName2Representant.containsKey(groupName)) { + val representant = groupName2Representant.get(groupName) + query2Reference.put(wfPattern,representant) + } else { + groupName2Representant.put(groupName,wfPattern) + } + } + + + println('''modelpath;run;model;« + FOR wfPattern:wfPatterns SEPARATOR ";"»#(« + wfPattern.fullyQualifiedName.split("\\.").last»);hash(« + wfPattern.fullyQualifiedName.split("\\.").last»)«ENDFOR»;« + FOR mutant : wfPatterns.filter[query2Reference.keySet.contains(it)] SEPARATOR ';'»diff(« + mutant.fullyQualifiedName.split("\\.").last»)«ENDFOR»''' + ) + countMatches('''D:/FASE18Meas/MetamodelOnly_Alloy_Symmetry30''') + } + + def private static simpleName(IQuerySpecification wfPattern) { + wfPattern.fullyQualifiedName.split("\\.").last + } + def private static groupName(IQuerySpecification wfPattern) { + wfPattern.simpleName.split('_').head + } + + def static void countMatches(String path) { + val file = new File(path) + if(file.isDirectory) { + for(subFileName : file.list) { + (path + "/" + subFileName).countMatches + } + } else if(file.isFile) { + if(path.endsWith("xmi")) { + countMatches(file,path) + } + } + } + + def static void countMatches(File file, String path) { + val parent = file.parent + + val pathSegments = path.split("/") + val groupName = pathSegments.get(pathSegments.size-2).split("\\.").last.split("_").get(0) + print(groupName +";") + val nameExtension = pathSegments.get(pathSegments.size-1).split("\\.").get(0).split("_") + val runNumber = nameExtension.get(1) + val modelNumber = nameExtension.get(2) + print('''«runNumber»;«modelNumber»''') + val workspace = new FileSystemWorkspace(parent,"") + val model = workspace.readModel(EObject,file.name) + + val engine = ViatraQueryEngine.on(new EMFScope(model)) + val objectCode = model.eResource.calculateObjectCode + + val pattern2Hash = new HashMap + for(pattern : wfPatterns) { + val matcher = pattern.getMatcher(engine) + val matches = matcher.allMatches + val hash = matches.getMatchSetDescriptor(objectCode) + pattern2Hash.put(pattern,hash) + print(''';«matcher.countMatches»;«hash»''') + } + var mutantsKilled = 0 + for(mutant : wfPatterns.filter[query2Reference.keySet.contains(it)]) { + val equals = pattern2Hash.get(mutant) == pattern2Hash.get(query2Reference.get(mutant)) + print(''';''') + if(equals) { + print('0') + } else { + print('1') + mutantsKilled++ + } + } + //print(''';«mutantsKilled»''') + println() + } + + def static Map calculateObjectCode(Resource resource) { + val res = new HashMap + val iterator = resource.allContents + var index = 1 + while(iterator.hasNext) { + res.put(iterator.next,index++) + } + return res + } + + def static getMatchSetDescriptor(Collection matchSet, Map objectCode) { + val set = new TreeSet(new ArrayComparator) + for(match: matchSet) { + val size = match.parameterNames.size + val idArray = new ArrayList(size) + for(i:0..> { + + override compare(List arg0, List arg1) { + if(arg0.size === arg1.size) { + for(i : 0.. [ it.runtimeLimit = 300 @@ -226,6 +226,7 @@ class ScenarioRunner { it.solutionScope.numberOfRequiredSolution = scenario.number it.typeScopes.maxNewIntegers = 0 it.writeToFile=true + it.randomise = run-1 ] } @@ -317,7 +318,8 @@ class ScenarioRunner { class DiverseMeasurementRunner { def static void main(String[] args) { - val scenario = new Scenario(30,29,Metamodel::YakinduWOSynch,Constraints.Metamodel,StateCoder.R1,20,Solver::Alloy) + val scenario = new Scenario(30,29,Metamodel::YakinduWOSynch,Constraints.Metamodel,StateCoder.R3,20,Solver::Alloy + ) val scenarioRunner = new ScenarioRunner scenarioRunner.runScenario(scenario) } -- cgit v1.2.3-54-g00ecf