Skip to content
Snippets Groups Projects
Commit a865d755 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Exploration(.*): Fix containment relations.

When using a non-z3 backend (here: the unofficial MOEA backend) that makes a more extensive use of the ExplorationSolution, invalid models can be produced. The reason for this behavior are faulty containment relations since the produced model fragments of the DSE were not contained in any other EObject. Here, it shall be noted that the SuperSets themselves are not intended as containers as of now since they are also used to pass around references to the relevant elements of a DSE.

Furthermore, one warning was produced due to an EAttribute not being set (noticeable on the console).

Technical details:

* getCastedType(...): Used to avoid ugly casting in client code. The DSE language is based on generic IModelElements, whereas the Sets/SuperSets are strict w.r.t. to the types to provide guarantess for the DSE I/O.
* The ExplorationSpecification now contains the the map of input parameters passed to the DSE (Tracing), but not its elements (!).
* ExplorationSolution: 
* * Contains the returned SuperSetMap.
* * Added a "pool" for SuperSets: They are accessible via the SuperSetMap.
* * Added a element "pool" for the generated elements referenced by the returned SuperSets.
* DSMLModelElementFactory: Creating Sets now requires a reference to the SuperSet (reduced code redundancy; can be used for robustness checking later).
* Adapt to the meta-model changes when using SuperSets/Sets (esp in the smt plugin).
refs 3353
parent 9bec3c26
No related branches found
No related tags found
No related merge requests found
Opt4JDseBackend.java 4f9559ae2dce6b0378ef936843f521d4b5993dde RED
Opt4JDseBackend.java f0485dc7fbc69c31f2f7fd15a7dad582ee5d7636 RED
......@@ -27,6 +27,7 @@ import java.util.Optional;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.swt.widgets.Display;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.exploration.alg.dse.CompositeExplorationSolution;
......@@ -66,7 +67,7 @@ public class Opt4JDseBackend implements IDseBackend {
private final Collection<Class<?>> requiredInputModels = Arrays.asList(
ComponentArchitecture.class, TaskArchitecture.class, PlatformArchitecture.class);
// TODO: Remove after migration to AF3 visiualization
// TODO: Remove after migration to AF3 visualization
/** Last {@link XYPlotter} (in order to close it before creating a new one. */
protected XYPlotter lastPlotter;
......@@ -94,10 +95,12 @@ public class Opt4JDseBackend implements IDseBackend {
// Input to DSE: {@link SystemModelAdapter} and {@link DesignSpaceExploration}.
// SystemModelAdapter systemModelAdapter;
systemModelAdapter = new AF3SystemModelAdapter(superSets.get(Task.class),
superSets.get(ComponentToTaskAllocationEntry.class),
superSets.get(ExecutionUnit.class), superSets.get(Signal.class));
DseSpecification dseSpec = createDefaultDesignSpaceExploration(expSpec, context);
systemModelAdapter =
new AF3SystemModelAdapter(superSets.get(Task.class),
superSets.get(ComponentToTaskAllocationEntry.class),
superSets.get(ExecutionUnit.class), superSets.get(Signal.class));
DseSpecification dseSpec =
createDefaultDesignSpaceExploration(EcoreUtil.copy(expSpec), context);
// Set the requested solutions.
Set<Class<?>> solutionTypes = new HashSet<>();
......@@ -145,8 +148,8 @@ public class Opt4JDseBackend implements IDseBackend {
* Temporary helper method to extract the architecture model from a {@link SuperSet} provided in
* the {@link SuperSetMap} to the DSE.
*/
private <T extends IModelElement, S extends IModelElement> T getArchModel(SuperSetMap superSets,
Class<T> archModelType, Class<S> elementType) throws Exception {
private <T extends IModelElement, S extends IModelElement> T getArchModel(
SuperSetMap superSets, Class<T> archModelType, Class<S> elementType) throws Exception {
Optional<S> anyElem = getFirst(superSets.get(elementType).getEntries());
if(!anyElem.isPresent()) {
throw new Exception("No " + elementType.getSimpleName() +
......@@ -170,8 +173,9 @@ public class Opt4JDseBackend implements IDseBackend {
// draw figure
// FIXME: Unchecked cast to ExplorationSolutionSet
XYPlotter plotter = new XYPlotter(solutionSet.getExplorationSpec(), solutionSet,
"Design Space Exploration Result (generations: " + "N/A" + ")");
XYPlotter plotter =
new XYPlotter(solutionSet.getExplorationSpec(), solutionSet,
"Design Space Exploration Result (generations: " + "N/A" + ")");
plotter.createPlot();
plotter.pack();
RefineryUtilities.centerFrameOnScreen(plotter);
......
CompositeExplorationSolution.java c35b0b0cf5658300b5e8c4f2cc9e217c29ae37a3 RED
CompositeExplorationSolution.java 88849af9f8a52684cc523f89e235599e16dd9ac3 RED
DSEFactory.java 0a2f2cc6a197e760c1f8223339ffa5f16856b184 RED
Explorer.java 2194a74cbe51ca9e7dafb008dcefb51a54064dc8 RED
ImplicitExplorationTargetFactory.java 6c16c6712886b549dda0a73aef4a4c3fe18c1850 RED
......
......@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.InstantiatedTaskMappingEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.IExplorationSolution;
......@@ -179,10 +178,13 @@ public class CompositeExplorationSolution<P extends Phenotype> {
outputTypes.add(SuperSetMap.class);
ExplorationTransformationInputs inputs =
new ExplorationTransformationInputs(null, internalSolutions);
Map<Class<EObject>, ?> solutionModels =
Map<Class<IModelElement>, IModelElement> solutionModels =
getService(IExplorationTransformationService.class).getTransformedModels(
DSE_INTERNAL, null, inputs, outputTypes, "");
singleExpSolution.setSolutionSets((SuperSetMap)solutionModels.get(SuperSetMap.class));
SuperSetMap transformedSuperSets = (SuperSetMap)solutionModels.get(SuperSetMap.class);
transformedSuperSets.keySet().forEach(
k -> singleExpSolution.putSolutionModel((Class<IModelElement>)k,
transformedSuperSets.get((Class<IModelElement>)k)));
// Invalid solutions are filtered before.
singleExpSolution.setSolutionState(SolutionState.OPTIMIZED);
......
......@@ -4,4 +4,4 @@ ScheduleLabelGenerator.java 0ceecedfec9802bbcaa33525d61e1a60a70d3841 RED
SchedulePlotter.java 29b1156c9419d4ff3314c4b2c932aeb46f4749f8 RED
ScheduleToolTipGenerator.java cedfa0dd7ebc7b48d7cc70e966eebaeee9636caf RED
TaskSeriesCollectionFromSchedule.java b53b7af649c48980520ad572da8c7bbdbae0aed5 RED
XYPlotter.java b8abd061e80509c7c8af83baf584e9549c98a4d9 RED
XYPlotter.java a70c65b6138805d91ad1db551bcc4e7cfc1dc200 RED
......@@ -22,7 +22,6 @@ import static org.fortiss.af3.exploration.alg.service.IExplorationTransformation
import static org.fortiss.af3.exploration.util.DesignSpaceExplorationModelElementFactory.createSuperSetMap;
import static org.fortiss.af3.exploration.util.ExplorationUtils.createExceptionStatus;
import static org.fortiss.af3.project.utils.ProjectUtils.getFileProject;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElements;
import java.awt.Color;
import java.awt.GridBagConstraints;
......@@ -66,6 +65,7 @@ import org.fortiss.af3.exploration.model.solutions.ExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.partition.model.allocation.PartitionToExecutionUnitAllocationEntry;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.common.util.LambdaUtils;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
......@@ -613,9 +613,9 @@ public class XYPlotter extends JFrame implements ChartMouseListener, ActionListe
*
* @throws Exception
*/
private AllocationTableCollection transformSingleDeployment(
SingleExplorationSolution solutionMap, String deploymentName, boolean generateSCSpec)
throws Exception {
@SuppressWarnings("unchecked")
private AllocationTableCollection transformSingleDeployment(SingleExplorationSolution solution,
String deploymentName, boolean generateSCSpec) throws Exception {
// Deployment generation has NOT been cancelled.
if(deploymentName.isEmpty()) {
deploymentName = "_Deployment";
......@@ -641,7 +641,7 @@ public class XYPlotter extends JFrame implements ChartMouseListener, ActionListe
// TODO: The context must be an export here. In a future version, it must be
// possible to specify, how the transformed model can be injected / exported.
SuperSet<PartitionToExecutionUnitAllocationEntry> partToExU =
solutionMap.getSolutionSets().get(PartitionToExecutionUnitAllocationEntry.class);
solution.getSolutionModel(PartitionToExecutionUnitAllocationEntry.class);
PartitionToExecutionUnitAllocationEntry entry =
LambdaUtils.getFirst(partToExU.getEntries()).get();
ITopLevelElement modelContext =
......@@ -657,13 +657,16 @@ public class XYPlotter extends JFrame implements ChartMouseListener, ActionListe
// TODO: clearer separation between In- and output models.
// Create a new SuperSet Map that combines in and outputs.
SuperSetMap solutionSuperSets = solutionMap.getSolutionSets();
Collection<Class<? extends IModelElement>> solutionSuperSetTypes =
solution.getAvailableSolutionModels();
SuperSetMap superSetMap = createSuperSetMap();
for(Class<?> setType : solutionSuperSets.keySet()) {
superSetMap.put((Class)setType, solutionSuperSets.get((Class)setType));
for(Class<? extends IModelElement> setType : solutionSuperSetTypes) {
superSetMap.put((Class<IModelElement>)setType,
solution.getSolutionModel((Class<IModelElement>)setType));
}
for(Class<?> setType : expSpec.getSearchSpace().keySet()) {
superSetMap.put((Class)setType, expSpec.getSearchSpace().get((Class)setType));
superSetMap.put((Class<IModelElement>)setType,
expSpec.getSearchSpace().get((Class<IModelElement>)setType));
}
ExplorationTransformationInputs inputs =
new ExplorationTransformationInputs(superSetMap, null);
......@@ -747,21 +750,4 @@ public class XYPlotter extends JFrame implements ChartMouseListener, ActionListe
fp.getRootElements().add(deployment);
fp.getRootElements().add(deployment);
}
/**
* Actually generates the an AF3 deployment model from a given solution in the provided model
* context and registers the resulting deployment (and a possibly generated
* {@link ComponentArchitecture}) in the {@link FileProject} of the DSE.
*/
private <S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>>
void addDeploymentToProject(Deployment deployment) {
ComponentArchitecture deployedArchitecture =
(ComponentArchitecture)deployment.getComponentArchitectureReference()
.getReference();
FileProject fp = getFileProject(expSpec);
if(!getRootElements(expSpec, ComponentArchitecture.class).contains(deployedArchitecture)) {
fp.getRootElements().add(deployedArchitecture);
}
fp.getRootElements().add(deployment);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment