Commit c860e139 authored by Alexander Diewald's avatar Alexander Diewald

Exploration: DSE project MM improvements & DSE Backend Unification

=================
| Exploration

exploration.ecore
=================
- ExplorationSpecification
  - targets: non-contained (Migrator!)
  - Add superSet reference to pass required SuperSets to the DSE backend.
- Remove ExplorationSolution interface: No Migration needed.
- Rename ExplorationSolutionSet --> ExplorationSolution
  - Deprecated inputModelAdapter: No migration needed, only used in MOEA.
  - Renaming: targetSpecification --> explorationSpec
    - targetSpecification marked @deprecated
    - No mirgator needed: Class was not used in previous stable releases.
- Add EClass SuperSetMap: Relates types of elements to SuperSets
  - solution: EJavaClassToSuperSetMap (containment!)
- Add EClass EJavaClassToSuperSetMap: internal map of "SuperSetMap"
  - key: Class
  - Value: SuperSet (NO containment!)
- ExplorationSolution
  - Renamed solutionModelMap -> solutionSets
    (Type EJavaClassToEJavaObjectMap -> EJavaClassToSuperSetMap)
  - Adjust EOperations to modifications in backend map.
- SingleExplorationSolution
  - Add the solution state for single solutions.
  - Adjust EOperations to modifications in backend map.
- Removed EJavaClassToEJavaObjectMap

dseproject.ecore
================
- DSE:
  - Add EReference target: ExplorationTarget (containment)
  - Remove explorationSpecification (Migrator!)
- Add an ExplorationTargetPool that contains all ExplorationTargets of a DSE
  project.
- DSERun:
  - Add EReference explorationSolution (containment)
  - Remove EReference visualization (Migrator!)
  
dsl_v2.ecore
============
- Overwrite the accept method for the Sum expression: Do not return null if the
  associated set is empty, evaluate to Zero, instead.

New Migrators
=============
- DSEExplorationTargetContainmentMigrator
  Migrates the set of explorationTargets to the DSE project
- VisualizationToExpSolutionMigrator:
  Migrates the Visualization data to the ExplorationSolution representation that
  allows a better traceability.
  
Other Business
==============
- Adjust plugin.xml to account for recently removed Objective- and
  ConstraintExpression classes. Now, ExplorationObjective and
  ExplorationConstraint is used.
  
=================
| Exploration.alg

- Adjust the Opt4JBackend to be comply to the new DSE Backend Specification
- The output type detection in the base decoder is more robust.
- The ITaskAdapter temporally references its corresponding component to ease
  the refactoring of the DSE backend interface. This shall not be needed when
  the transformation framework is integrated again.
- Temporally transform the internal solutions to a superset of
  ComponentToExecutionUnitAllocations to create s solution model. Workaround
  until the transformation framework is integrated again.
- Misc adjustment for backend changes.

=================
| Exploration.smt

- Adjust the Z3Backend to be comply to the new DSE Backend Specification
- Base the results of the DeploymentRun2 and SolverRun2 on the
  ExplorationSolution (see above).

================
| Exploration.ui

- Adjust the GUI logic to account for the changed containment relations.
- Update the DSE project import wizard for the Meta-Model changes.
- Move the ExplorationSolutionVisualizationUtils class to the UI plugin (here).
  It is used to transform ExplorationSolutions to a Visualization representation
  (i.e., DataSetCollection).
- Use doubles instead of ints in the SpiderChartUtils. Although not a proper
  solution, this covers more cases... Instead the generic should be reflected.
refs 3273
parent f383b601
......@@ -21,7 +21,7 @@
</eAnnotations>
</eStructuralFeatures>
<eGenericSuperTypes eClassifier="ecore:EClass platform:/resource/org.fortiss.af3.exploration/model/exploration.ecore#//ExplorationObjective">
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBooleanObject"/>
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>
</eGenericSuperTypes>
<eGenericSuperTypes eClassifier="#//CustomDimension"/>
</eClassifiers>
......
......@@ -15,33 +15,23 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.smt.backend;
import static org.fortiss.af3.exploration.util.DesignSpaceExplorationModelElementFactory.createExplorationSpecification;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.exploration.backend.DseSolutionVisualization;
import org.fortiss.af3.exploration.backend.IDseBackend;
import org.fortiss.af3.exploration.backend.RuleSetContainer;
import org.fortiss.af3.exploration.backend.SuperSetMap;
import org.fortiss.af3.exploration.model.ExplorationSolution;
import org.fortiss.af3.exploration.model.ExplorationSpecification;
import org.fortiss.af3.exploration.model.IExplorationFeature;
import org.fortiss.af3.exploration.model.solutions.ExplorationSolutionSet;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolutionMap;
import org.fortiss.af3.exploration.model.solutions.SolutionState;
import org.fortiss.af3.exploration.model.solutions.SolutionsFactory;
import org.fortiss.af3.exploration.projectmodel.RuleSet;
import org.fortiss.af3.exploration.projectmodel.dseArtifacts.DSESuperSets;
import org.fortiss.af3.exploration.model.solutions.ExplorationSolution;
import org.fortiss.af3.exploration.smt.modeltransformation.rework.DeploymentRun2;
import org.fortiss.af3.exploration.smt.util.DeploymentSMTResult;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.TransmissionUnit;
import org.fortiss.af3.task.model.Signal;
import org.fortiss.af3.task.model.Task;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
/**
* DSE backend that uses Z3 to solve a given DSE problem. It translates a problem statement in form
......@@ -51,66 +41,26 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @author diewald
*/
public class Z3Backend implements IDseBackend {
/** Specifies the required input models from the DSE. */
private final Collection<Class<?>> requiredInputModels =
Arrays.asList(RuleSetContainer.class, DSESuperSets.class);
/** Caches the solution container (metrics/visualization + solution models. */
private DseSolutionVisualization<?> solutionVisualization;
/** {@inheritDoc} */
@Override
// TODO: Based on the requested solutions (Deployment, Scheduling) we need to return different
// input requirements.
public Collection<Class<?>> getRequiredInputSet() {
return requiredInputModels;
}
/** {@inheritDoc} */
@Override
// TODO: Currently, the DSE execute method is implemented using some Deployment synthesis
// specifics. These should be removed, as the method shall be generic.
public Optional<ExplorationSolution> executeDSE(RuleSetContainer spec,
Set<Class<? extends IModelElement>> solutionTypes, SuperSetMap superSetMap,
public Optional<ExplorationSolution> executeDSE(ExplorationSpecification spec,
Set<Class<? extends IModelElement>> solutionTypes,
Collection<IExplorationFeature> explorationModules, IProgressMonitor monitor,
int timeoutMS) throws Exception {
if(spec.size() < 1) {
if(spec.getTargets().isEmpty()) {
throw new Exception("No exploration targets defined. Cannot perform the DSE.");
}
DeploymentRun2 run = new DeploymentRun2();
DeploymentSMTResult isSolved = run.solveDeployment(spec, timeoutMS, monitor, superSetMap);
// spec will not be empty (see entry condition).
ITopLevelElement context =
IPersistencyService.getInstance().getTopLevelElementFor(spec.get(0));
ExplorationSpecification targetSpec = createExplorationSpecification();
for(RuleSet ruleSet : spec) {
context.runAsNonDirtyingCommand(
() -> targetSpec.getTargets().addAll(ruleSet.getExplorationTargets()));
}
// TODO: The metrics should be added to each solution as well.
ExplorationSolutionSet solution = SolutionsFactory.eINSTANCE.createExplorationSolutionSet();
solution.setTargetSpecification(targetSpec);
solution.setSolutionState(extractSolutionState(isSolved));
solution.getUnsatConstraints().addAll(run.getFailedConstraints());
ExplorationSolution expSolution = run.solveDeployment(spec, timeoutMS, monitor);
expSolution.getUnsatConstraints().addAll(run.getFailedConstraints());
// FIXME: The DeploymentSMTResult shall be converted to a ExplorationSolutionSet. The
// returned allocation lists from the solver are actually ExplorationSolutions. In order to
// support the UNSAT etc. states of the solver, an additional attribute has to be created. A
// simple enum can be used for that purpose.
for(Deployment solDeployment : isSolved.getDeployments()) {
SingleExplorationSolutionMap singleSol =
SolutionsFactory.eINSTANCE.createSingleExplorationSolutionMap();
singleSol.putSolutionModel(Deployment.class, solDeployment);
solution.getSolutions().add(singleSol);
}
solutionVisualization = run.getDeploymentVisModel();
return Optional.of(solution);
return Optional.of(expSolution);
}
/** Returns the cached solution representation (metrics/visualization + solution models). */
......@@ -118,17 +68,15 @@ public class Z3Backend implements IDseBackend {
return solutionVisualization;
}
/** Extractes the {@link SolutionState} of a {@link DeploymentSMTResult}. */
private SolutionState extractSolutionState(DeploymentSMTResult isSolved) {
if(isSolved.isUNSAT()) {
return SolutionState.UNSAT;
} else if(isSolved.isUNKNOWN() && !isSolved.getDeployments().isEmpty()) {
return SolutionState.OPTIMIZED;
} else if(isSolved.isSAT()) {
return SolutionState.OPTIMAL;
}
return SolutionState.UNKNOWN;
/** {@inheritDoc} */
@Override
public Collection<Class<?>> getRequiredInputSet() {
Collection<Class<?>> reqInputSet = new HashSet<>();
reqInputSet.add(Task.class);
reqInputSet.add(Signal.class);
reqInputSet.add(ExecutionUnit.class);
reqInputSet.add(TransmissionUnit.class);
return reqInputSet;
}
/** {@inheritDoc} */
......@@ -145,7 +93,7 @@ public class Z3Backend implements IDseBackend {
/** {@inheritDoc} */
@Override
public void plotResult(ExplorationSolutionSet solutionSet) {
public void plotResult(ExplorationSolution solutionSet) {
throw new UnsupportedOperationException(
"The Z3 backend uses the AF3 visualization engine.");
}
......
BasicDeploymentConstraint.java 20b61cba24661109cbffb2548042f54ae4c3d7e0 RED
ConstraintToNONQuantifiedSMT.java 99f852223c25442c395ff888cabbcc3b18694a5a RED
ConstraintToQuantifiedSMT.java 9cbb27b1ac997015a642a652351c96ec726a35d5 RED
DeploymentRun2.java 4eaef8648a4815b61cb89187cddb3181210f8da8 RED
DeploymentRun2.java 1e097286ea15d33b5349a297935d30700f1ce7db RED
ITransformationService.java fcddb7beb90eb693983babba30728d4600c15fc6 RED
LanguageTransformation.java 533f2d36fc76fbff13e7ee72da1eb47ea6d1c1a6 RED
LanguageTransformation.java 8354240819f62669b590dfc54fbc26ea8595e2c8 RED
SMTTransformationUtils.java c7a344d8141974b01dbcd6f9b89f8c4a4af668db RED
SolverRun2.java a00cf83a55691f64e3afd45b122b33103b884718 RED
TransformationService.java a31527200b832504dfa9dbfbe26ad19141046c68 RED
SolverRun2.java 877e3a5e04b8bcc0df20857d9fa447c3105ce480 RED
TransformationService.java 1dd5542305402ee2f0e28fd25350265251ad801f RED
......@@ -36,7 +36,6 @@ import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.deployment.model.Segment;
import org.fortiss.af3.deployment.model.VirtualLink;
import org.fortiss.af3.efficientdeployment.model.Hop;
import org.fortiss.af3.exploration.backend.SuperSetMap;
import org.fortiss.af3.exploration.dsl_v2.model.booleanp.And;
import org.fortiss.af3.exploration.dsl_v2.model.booleanp.Exists;
import org.fortiss.af3.exploration.dsl_v2.model.booleanp.ForAll;
......@@ -49,6 +48,7 @@ import org.fortiss.af3.exploration.dsl_v2.model.expression.SuperSet;
import org.fortiss.af3.exploration.dsl_v2.model.function.End;
import org.fortiss.af3.exploration.dsl_v2.model.function.FunctionFactory;
import org.fortiss.af3.exploration.dsl_v2.model.function.Start;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.exploration.projectmodel.dseArtifacts.DSEPlatformArtifact;
import org.fortiss.af3.exploration.smt.model.SMTConstraint;
import org.fortiss.af3.platform.model.ExecutionUnit;
......
......@@ -18,6 +18,8 @@ package org.fortiss.af3.exploration.smt.modeltransformation.rework;
import static com.microsoft.z3.Z3javaAPIWrapper.createBoolConst;
import static java.lang.System.currentTimeMillis;
import static org.fortiss.af3.exploration.smt.AF3ExplorationSMTActivator.getDefault;
import static org.fortiss.af3.exploration.util.DesignSpaceExplorationModelElementFactory.createExplorationResult;
import static org.fortiss.af3.exploration.util.DesignSpaceExplorationModelElementFactory.createSingleExplorationSolution;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.info;
import java.io.BufferedWriter;
......@@ -30,25 +32,39 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.management.modelmbean.InvalidTargetObjectTypeException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.fortiss.af3.exploration.model.ExplorationObjective;
import org.fortiss.af3.exploration.model.ExplorationSpecification;
import org.fortiss.af3.exploration.model.ExplorationTarget;
import org.fortiss.af3.exploration.model.solutions.ExplorationResult;
import org.fortiss.af3.exploration.model.solutions.ExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SolutionState;
import org.fortiss.af3.exploration.projectmodel.RuleSet;
import org.fortiss.af3.exploration.smt.AF3ExplorationSMTActivator;
import org.fortiss.af3.exploration.smt.model.SMTConstraint;
import org.fortiss.af3.exploration.smt.model.SMTObjective;
import org.fortiss.af3.exploration.smt.util.DeploymentSMTResult;
import org.fortiss.af3.exploration.util.DesignSpaceExplorationModelElementFactory;
import org.fortiss.af3.exploration.util.ExplorationUtils;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
import com.microsoft.z3.ArithExpr;
import com.microsoft.z3.BoolExpr;
import com.microsoft.z3.Context;
import com.microsoft.z3.Expr;
import com.microsoft.z3.IntNum;
import com.microsoft.z3.Model;
import com.microsoft.z3.Optimize;
import com.microsoft.z3.Params;
import com.microsoft.z3.RatNum;
import com.microsoft.z3.Solver;
import com.microsoft.z3.Status;
import com.microsoft.z3.Z3Exception;
......@@ -60,6 +76,8 @@ import com.microsoft.z3.Z3Exception;
* @author eder
*/
public abstract class SolverRun2 {
/** The solution found for the current DSE run. */
ExplorationSolution expSolution;
/** {@link Expr} to {@link SMTObjective} mapping */
protected HashMap<Expr, SMTObjective> objectiveMapping;
......@@ -68,7 +86,7 @@ public abstract class SolverRun2 {
protected HashMap<Expr, SMTConstraint> constraintMapping;
/** List of the latest generated z3 {@link Model}s */
protected List<Model> models;
Map<Model, SingleExplorationSolution> z3ModelSolutionAssocs = new HashMap<>();
/** List of the latest unsat cores. */
protected BoolExpr[] unsatCores;
......@@ -76,9 +94,11 @@ public abstract class SolverRun2 {
// TODO(AD): This is one of the main interfaces to the solver. Would it make sense to add the
// parameter description here? Feel free to reject.
/** Solves the given constraints. */
protected List<Model> solveOptimized(Context context, int numberOfRuns, int timeout,
LanguageTransformation transformation, DeploymentSMTResult resultObject,
protected void solveOptimized(Context context, int numberOfRuns, int timeout,
LanguageTransformation transformation, ExplorationSpecification expSpec,
IProgressMonitor monitor) throws Z3Exception {
expSolution = DesignSpaceExplorationModelElementFactory.createExplorationSolution();
expSolution.setExplorationSpec(expSpec);
// Parameters for optimizing solver.
Params params = context.mkParams();
......@@ -104,6 +124,7 @@ public abstract class SolverRun2 {
List<Model> models = new ArrayList<>();
Model model = null;
for(int i = 0; i < numberOfRuns; ++i) {
SingleExplorationSolution singleSolution = createSingleExplorationSolution();
// TODO(AD): Are the printlns needed? Below, the LoggingUtils are used.
System.out.println();
System.out.println();
......@@ -117,22 +138,33 @@ public abstract class SolverRun2 {
// optimize solver sometimes says unsat although it produces a result. because of this
// go on if the result list is not empty
if(check.equals(Status.UNSATISFIABLE) && models.isEmpty()) {
resultObject.setUNSAT(true);
singleSolution.setSolutionState(SolutionState.UNSAT);
continue;
}
if(check.equals(Status.UNKNOWN)) {
resultObject.setUNKNOWN(true);
singleSolution.setSolutionState(SolutionState.UNKNOWN);
} else {
resultObject.setSAT(true);
singleSolution.setSolutionState(SolutionState.OPTIMAL);
}
model = solver.getModel();
models.add(model);
z3ModelSolutionAssocs.put(model, singleSolution);
convertSolutionResults(model, singleSolution);
expSolution.getSolutions().add(singleSolution);
if(monitor != null) {
double worked = (1.0 / (numberOfRuns * 1.0)) * 100;
monitor.worked((int)worked);
}
}
return models;
// Set the overall state of the solution set.
if(z3ModelSolutionAssocs.isEmpty()) {
expSolution.setSolutionState(SolutionState.UNSAT);
} else {
expSolution.setSolutionState(SolutionState.OPTIMAL);
if(z3ModelSolutionAssocs.values().stream()
.allMatch(s -> s.getSolutionState() == SolutionState.UNKNOWN)) {
expSolution.setSolutionState(SolutionState.UNKNOWN);
}
}
}
/** Prints the given string to a smt2 file. */
......@@ -157,7 +189,8 @@ public abstract class SolverRun2 {
// TODO(AD): Consistently use the LoggingUtils in this method: Sometimes System.out is called
// (which shall not be used), sometimes LoggingUtils is called.
protected List<Model> solveNonOptimized(Context context, int timeout,
LanguageTransformation transformation, DeploymentSMTResult result) throws Z3Exception {
LanguageTransformation transformation, ExplorationSolution solutionSet)
throws Z3Exception {
unsatCores = null;
// TODO(AD): This should be the non-optimizing solver, correct?
......@@ -196,16 +229,17 @@ public abstract class SolverRun2 {
for(BoolExpr b : unsatCores) {
System.out.println(b);
}
result.setUNSAT(true);
solutionSet.setSolutionState(SolutionState.UNSAT);
} else if(check.equals(Status.SATISFIABLE)) {
model = solver.getModel();
System.out.println();
System.out.println(model);
models.add(model);
result.setSAT(true);
// TODO: Here, we would need a state "Feasible" or "Solved" (expressive name!)
solutionSet.setSolutionState(SolutionState.OPTIMIZED);
} else if(check.equals(Status.UNKNOWN)) {
System.err.println("Solver returned UNKNOWN. Reason: " + solver.getReasonUnknown());
result.setUNKNOWN(true);
solutionSet.setSolutionState(SolutionState.UNKNOWN);
}
long time = (currentTimeMillis() - currentTimeMillis) / 1000;
info(getDefault(), "[Z3] " + check + " Solved problem without optimizer with parameters " +
......@@ -246,9 +280,45 @@ public abstract class SolverRun2 {
return results;
}
// TODO(AD): Comment is unclear: What is meant by "optimizations" here?
/** Counts the optimizations in given sub set. */
protected static int countOptimzations(List<RuleSet> subSets) {
return getOptimzations(subSets).size();
/** Returns the deployment Visualization model of the latest generation. */
private void convertSolutionResults(Model z3Model, SingleExplorationSolution singleSolution) {
try {
for(Entry<Expr, SMTObjective> entry : objectiveMapping.entrySet()) {
Expr z3EvalResult = z3Model.eval(entry.getKey(), true);
// TODO: This check should be placed on the input side.
// FIXME: Specifying the SMTObjective as an ExplorationObjective of the type Boolean
// is a misuse of the concept. The type of ExplorationTargets specifies the expected
// return value.
if(!ExplorationUtils.getReturnTypeOf(entry.getValue()).equals(Integer.class)) {
LoggingUtils.error(AF3ExplorationSMTActivator.getDefault(),
"Could not transform " + z3EvalResult + " into integer value. Not" +
" supported.");
continue;
}
ExplorationResult<Integer> result = createExplorationResult();
if(z3EvalResult instanceof IntNum) {
result.setResult(((IntNum)z3EvalResult).getInt());
} else if(z3EvalResult instanceof RatNum) {
RatNum ratnum = (RatNum)z3EvalResult;
IntNum denominator = ratnum.getDenominator();
IntNum numerator = ratnum.getNumerator();
if(denominator.getInt() == 1) {
result.setResult(numerator.getInt());
} else {
// not supported yet
LoggingUtils.error(AF3ExplorationSMTActivator.getDefault(),
"Could not transform " + z3EvalResult + " into integer value. The" +
" returned value from the solver is not an integer value.");
}
}
singleSolution.put(entry.getValue(), result);
}
} catch(Z3Exception e) {
// TODO(AD): Use LoggingUtils from the kernel/base.
e.printStackTrace();
} catch(InvalidTargetObjectTypeException e) {
LoggingUtils.error(AF3ExplorationSMTActivator.getDefault(),
"Could not determine the result type of an objective.", e);
}
}
}
......@@ -29,7 +29,6 @@ import java.util.function.Predicate;
import org.eclipse.emf.common.util.EList;
import org.fortiss.af3.deployment.model.VirtualLink;
import org.fortiss.af3.exploration.backend.SuperSetMap;
import org.fortiss.af3.exploration.dsl_v2.model.arithmetic.ModelElementPropertyLiteral;
import org.fortiss.af3.exploration.dsl_v2.model.expression.IExpression;
import org.fortiss.af3.exploration.dsl_v2.model.expression.Set;
......@@ -38,6 +37,7 @@ import org.fortiss.af3.exploration.dsl_v2.model.function.End;
import org.fortiss.af3.exploration.dsl_v2.model.function.Start;
import org.fortiss.af3.exploration.dsl_v2.model.function.Uses;
import org.fortiss.af3.exploration.dsl_v2.model.function.Weight;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.TransmissionUnit;
import org.fortiss.af3.task.model.Signal;
......
DeploymentSMTResult.java 2a1265e2e2eef2bb96a9ed556977dc24ad33bd59 RED
DeploymentToSchedule.java a856b52f66d1fcb0707c3b9e4498a82bca9575e9 RED
AllocationToSchedule.java 44e616eb56c8382fc4769b329aa5672e05a952c3 RED
RouteUtils.java e54d56bcb2c698a2a33fb763a67dd4c5e2e8b765 RED
SolvedSMTResult.java c09b1e4af3c07b8fcfccb9bc95ce58ab745b7dde RED
Z3ModelElementFactory.java a140ccf5e218dbc72ed4b643e2ab6a309f4000b2 RED
/*-------------------------------------------------------------------------+
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.smt.util;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.deployment.model.ComponentAllocation;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.deployment.utils.DeploymentModelElementFactory;
/**
* Deployment SMT result, stored in lists of allocation lists.
*
* @author eder
*/
// TODO(AD): Not a util class.
public class DeploymentSMTResult extends SolvedSMTResult {
/** A list of deployments, represented as lists of allocations. */
private List<Deployment> deployments = new ArrayList<>();
/** Sets deployments. */
public void setDeployments(List<List<ComponentAllocation>> deployments) {
for(List<ComponentAllocation> allocList : deployments) {
Deployment solutionDepl =
DeploymentModelElementFactory.createDeployment("", null, null);
solutionDepl.getComponentAllocations().addAll(allocList);
this.deployments.add(solutionDepl);
}
}
/** Returns deployments. */
public List<Deployment> getDeployments() {
return deployments;
}
}
......@@ -15,6 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui;
import static org.fortiss.af3.exploration.util.DesignSpaceExplorationModelElementFactory.createExplorationSpecification;
import java.util.ArrayList;
import java.util.List;
......@@ -24,15 +26,16 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.EList;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.deployment.model.ComponentAllocation;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.exploration.model.ExplorationSpecification;
import org.fortiss.af3.exploration.model.solutions.ExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SolutionState;
import org.fortiss.af3.exploration.projectmodel.RuleSet;
import org.fortiss.af3.exploration.projectmodel.dseArtifacts.DSEPlatformArtifact;
import org.fortiss.af3.exploration.smt.AF3ExplorationSMTActivator;
import org.fortiss.af3.exploration.smt.model.SMTConstraint;
import org.fortiss.af3.exploration.smt.modeltransformation.rework.BasicDeploymentConstraint;
import org.fortiss.af3.exploration.smt.modeltransformation.rework.DeploymentRun2;
import org.fortiss.af3.exploration.smt.util.DeploymentSMTResult;
import org.fortiss.af3.exploration.util.DSEProjectModelElementFactory;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.PlatformArchitecture;
......@@ -40,8 +43,10 @@ import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.project.utils.ProjectUtils;
import org.fortiss.af3.task.model.Task;
import org.fortiss.af3.task.model.TaskArchitecture;
import org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationEntry;
import org.fortiss.af3.task.util.ComponentToTaskArchitectureTransformation;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.common.util.LambdaUtils;
import org.fortiss.tooling.kernel.model.IIdLabeled;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
import org.junit.Test;
......@@ -140,11 +145,11 @@ public class RoutingTest {
// }
DeploymentRun2 run2 = new DeploymentRun2();
List<RuleSet> subsets = new ArrayList<>();
subsets.add(subset);
DeploymentSMTResult solveDeployment = run2.solveDeployment(subsets, 5000, null, null);
ExplorationSpecification explorationSpec = createExplorationSpecification();
explorationSpec.getTargets().addAll(subset.getExplorationTargets());
ExplorationSolution solvedDeployment = run2.solveDeployment(explorationSpec, 5000, null);
if(solveDeployment.isUNSAT()) {
if(solvedDeployment.getSolutionState() == SolutionState.UNSAT) {
for(SMTConstraint f : run2.getFailedConstraints()) {
System.out.println(f.getName());
System.out.println(f.getExpression());
......@@ -152,10 +157,14 @@ public class RoutingTest {
}
}
for(Deployment d : solveDeployment.getDeployments()) {
for(ComponentAllocation cal : d.getComponentAllocations()) {
System.out.println(cal.getComponent().getName() + "_" + cal.getComponent().getId() +
" -> " + cal.getExecutionUnit().getName());
for(SingleExplorationSolution sol : solvedDeployment.getSolutions()) {
for(ComponentToTaskAllocationEntry alloc : sol
.getSolutionModel(ComponentToTaskAllocationEntry.class).getEntries()) {
// Currently, we only have one to one allocations.
Component comp = (Component)LambdaUtils.getFirst(alloc.getSourceElements()).get();
ExecutionUnit execUnit = (ExecutionUnit)alloc.getTargetElement();
System.out
.println(comp.getName() + "_" + comp.getId() + " -> " + execUnit.getName());
}
}
// Log.close();
......
......@@ -17,6 +17,8 @@
+--------------------------------------------------------------------------*/