From 34404d03bc70647b55daf0d4378410629d548578 Mon Sep 17 00:00:00 2001 From: "S.John" Date: Thu, 1 Mar 2018 16:14:36 +0100 Subject: [PATCH 1/4] added schema location to output files --- .../src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend b/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend index ada9e66af..36e6ea65c 100644 --- a/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend +++ b/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend @@ -18,6 +18,8 @@ import java.util.TimeZone import java.util.HashMap import com.google.common.io.Files import java.nio.charset.Charset +import org.eclipse.emf.ecore.xmi.XMIResource +import java.util.Map class MDEOResultsOutput { @@ -148,7 +150,12 @@ class MDEOResultsOutput { resource.contents.clear } resource.contents.add(model) - resource.save(Collections.EMPTY_MAP) + + // Keep schema location in output models + val Map options = new HashMap(); + options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); + + resource.save(options) } private def storeSolutionData(PrintWriter infoWriter, String modelPath, MoeaOptimisationSolution solution){ From 1cc6f34652c719114c10d9c9c66d4eb1a3790574 Mon Sep 17 00:00:00 2001 From: "S.John" Date: Wed, 14 Mar 2018 14:05:38 +0100 Subject: [PATCH 2/4] added copy of meta model to experiments folder; before result is saved, URI of referenced package is changed to point to copy of meta model --- .../ac/kcl/ui/output/MDEOResultsOutput.xtend | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend b/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend index 36e6ea65c..595f1f948 100644 --- a/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend +++ b/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/output/MDEOResultsOutput.xtend @@ -1,25 +1,24 @@ package uk.ac.kcl.ui.output +import com.google.common.io.Files +import java.io.File +import java.io.PrintWriter +import java.nio.charset.Charset +import java.text.SimpleDateFormat import java.util.Date -import java.util.List +import java.util.HashMap import java.util.LinkedList +import java.util.List +import java.util.Map +import java.util.TimeZone +import org.eclipse.core.runtime.IPath +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.resource.ResourceSet -import uk.ac.kcl.mdeoptimise.Optimisation import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl -import org.eclipse.emf.ecore.EObject -import java.util.Collections -import java.text.SimpleDateFormat -import uk.ac.kcl.optimisation.moea.MoeaOptimisationSolution -import java.io.PrintWriter -import java.io.File -import org.eclipse.emf.common.util.URI -import org.eclipse.core.runtime.IPath -import java.util.TimeZone -import java.util.HashMap -import com.google.common.io.Files -import java.nio.charset.Charset import org.eclipse.emf.ecore.xmi.XMIResource -import java.util.Map +import uk.ac.kcl.mdeoptimise.Optimisation +import uk.ac.kcl.optimisation.moea.MoeaOptimisationSolution class MDEOResultsOutput { @@ -44,7 +43,7 @@ class MDEOResultsOutput { batches.add(batch); } - def String outputBatchSummary(MDEOBatch batch, IPath outcomePath) { + def String outputBatchSummary(MDEOBatch batch, IPath outcomePath, IPath metaModelOutputPath) { var batchOutputPath = outcomePath.append(String.format("batch-%s/", batch.id)) var batchInfoPath = batchOutputPath.append("outcome.txt") @@ -71,7 +70,7 @@ class MDEOResultsOutput { val solution = batch.solutions.get(i); val modelPath = batchOutputPath + String.format("%08X", solution.model.hashCode) + ".xmi" - solution.model.writeModel(modelPath) + solution.model.writeModel(modelPath, metaModelOutputPath.toPortableString) storeSolutionData(batchWriter, modelPath, solution) } @@ -132,25 +131,42 @@ class MDEOResultsOutput { } } + def IPath copyMetaModel(IPath outcomePath){ + val metaModelInputPath = projectRoot.append(moptConfiguration.basepath.location).append(moptConfiguration.metamodel.location) + val metaModelOutputPath = outcomePath.append(metaModelInputPath.lastSegment) + + if (!metaModelInputPath.empty) { + val outputFile = metaModelOutputPath.toFile + Files.createParentDirs(outputFile) + Files.copy(metaModelInputPath.toFile, outputFile) + } + return metaModelOutputPath + } + def void saveOutcome(){ val experimentDate = new SimpleDateFormat("yyMMdd-HHmmss").format(experimentStartTime); val outcomePath = projectRoot.append(String.format("mdeo-results/experiment-%s/", experimentDate)); + + val metaModelOutputPath = copyMetaModel(outcomePath) val batchesOutput = new StringBuilder(); - batches.forEach[ batch | batchesOutput.append(outputBatchSummary(batch, outcomePath))] + batches.forEach[ batch | batchesOutput.append(outputBatchSummary(batch, outcomePath, metaModelOutputPath))] outputExperimentSummary(batches, outcomePath, moptFile, batchesOutput) } - def writeModel(EObject model, String path) { - val resource = resourceSet.createResource(URI.createFileURI(path)) + def writeModel(EObject model, String path, String metaModelPath) { + val resource = resourceSet.createResource(URI.createFileURI(new File(path).absolutePath)) if (resource.loaded) { resource.contents.clear } resource.contents.add(model) + // Change URI of model package to reference the meta model copied to output location + model.eClass.EPackage.eResource.URI = URI.createFileURI(metaModelPath) + // Keep schema location in output models val Map options = new HashMap(); options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); From 14789967de105a7a26cf64eda6e43b171cff2944 Mon Sep 17 00:00:00 2001 From: "S.John" Date: Wed, 9 May 2018 09:45:32 +0200 Subject: [PATCH 3/4] moved MDEOResultsOutput init after null check --- .../src/uk/ac/kcl/ui/launch/RunOptimisation.xtend | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/launch/RunOptimisation.xtend b/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/launch/RunOptimisation.xtend index bac5989b0..2365d0814 100644 --- a/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/launch/RunOptimisation.xtend +++ b/src/plugins/uk.ac.kcl.mdeoptimise.ui/src/uk/ac/kcl/ui/launch/RunOptimisation.xtend @@ -56,11 +56,10 @@ class RunOptimisation { val resource = resourceSetProvider.get().getResource(URI.createFileURI(moptFile.getAbsolutePath()), true) val optimisationModel = resource.contents.head as Optimisation - val mdeoResultsOutput = new MDEOResultsOutput(new Date(), new Path(moptProjectPath), - new Path(configuredMoptFilePath), optimisationModel - ); - if(optimisationModel !== null){ + + val mdeoResultsOutput = new MDEOResultsOutput(new Date(), new Path(moptProjectPath), + new Path(configuredMoptFilePath), optimisationModel); var experimentId = 0; do { From f94bba0f5c9410d7e7ccad2cb6c5c6ec3aad51ee Mon Sep 17 00:00:00 2001 From: "S.John" Date: Wed, 9 May 2018 16:31:28 +0200 Subject: [PATCH 4/4] fixed offspring of crossover being returned even when they are not mutated --- .../kcl/optimisation/moea/MoeaProbabilisticVariation.xtend | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/plugins/uk.ac.kcl.mdeoptimise/src/uk/ac/kcl/optimisation/moea/MoeaProbabilisticVariation.xtend b/src/plugins/uk.ac.kcl.mdeoptimise/src/uk/ac/kcl/optimisation/moea/MoeaProbabilisticVariation.xtend index b47d10a3d..6c1fbc4a3 100644 --- a/src/plugins/uk.ac.kcl.mdeoptimise/src/uk/ac/kcl/optimisation/moea/MoeaProbabilisticVariation.xtend +++ b/src/plugins/uk.ac.kcl.mdeoptimise/src/uk/ac/kcl/optimisation/moea/MoeaProbabilisticVariation.xtend @@ -45,20 +45,18 @@ class MoeaProbabilisticVariation implements Variation { println("Not running crossover this run") } - var solutions = new LinkedList(); - for(var i = 0; i < result.length; i++){ var mutationProbability = random.nextDouble if(mutationProbability <= mutationRate){ println("Running mutation with probability: " + mutationProbability) - solutions.addAll(mutationOperator.evolve(#[result.get(i)])) + result.set(i, mutationOperator.evolve(#[result.get(i)]).get(0)) } else { println("Not running mutation this run") } } - return solutions; + return result; }