diff --git a/org.fortiss.af3.exploration.alg/META-INF/MANIFEST.MF b/org.fortiss.af3.exploration.alg/META-INF/MANIFEST.MF index e826057a6a95078009cd3643eeb654ec982a5ede..b0eb425520f99345e88d2d590e7b93a40b8eabaf 100644 --- a/org.fortiss.af3.exploration.alg/META-INF/MANIFEST.MF +++ b/org.fortiss.af3.exploration.alg/META-INF/MANIFEST.MF @@ -1,170 +1,170 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Exploration Algorithms -Bundle-SymbolicName: org.fortiss.af3.exploration.alg;singleton:=true -Bundle-Version: 2.13.0.qualifier -Bundle-ClassPath: ., - lib/jgrapht-core-0.9.0.jar, - lib/aopalliance-1.0.jar, - lib/apfloat.jar, - lib/jgrapht-ext-0.9.0.jar, - lib/jgraphx-2.0.0.1.jar, - lib/guice-assistedinject-4.2.0.jar, - lib/guice-4.2.0.jar, - lib/guice-multibindings-4.2.0.jar, - lib/commons-collections4-4.1.jar, - lib/opt4j-optimizers-SNAPSHOT-20161110.jar, - lib/guava-25.1-jre.jar, - lib/jfreechart-1.0.19.jar, - lib/jcommon-1.0.23.jar, - lib/opt4j-core-SNAPSHOT-20180714.jar, - lib/opt4j-operators-SNAPSHOT-20180714.jar -Bundle-Vendor: fortiss GmbH -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Bundle-ActivationPolicy: lazy -Bundle-Activator: org.fortiss.af3.exploration.alg.ExplorationAlgActivator -Require-Bundle: org.fortiss.tooling.base.ui;visibility:=reexport, - org.fortiss.af3.safety;bundle-version="2.9.0";visibility:=reexport, - org.fortiss.tooling.kernel;visibility:=reexport, - org.fortiss.af3.schedule;visibility:=reexport, - org.eclipse.core.runtime, - org.eclipse.emf.ecore;visibility:=reexport, - org.fortiss.tooling.base;visibility:=reexport, - org.fortiss.af3.component;visibility:=reexport, - org.fortiss.af3.exploration;bundle-version="2.11.0";visibility:=reexport, - org.fortiss.af3.expression;visibility:=reexport, - org.fortiss.af3.platform;visibility:=reexport, - org.fortiss.af3.project;visibility:=reexport, - org.eclipse.ui.ide;visibility:=reexport, - org.fortiss.af3.exploration.smt;bundle-version="2.11.0", - org.fortiss.af3.platform.hierarchic, - org.fortiss.af3.task, - org.fortiss.af3.partition;visibility:=reexport -Export-Package: org.fortiss.af3.exploration.alg, - org.fortiss.af3.exploration.alg.backend, - org.fortiss.af3.exploration.alg.dse, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.comm, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.repair, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, - org.fortiss.af3.exploration.alg.dse.evaluator; - uses:="org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, - org.fortiss.af3.exploration.model, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.evaluate, - org.opt4j.core", - org.fortiss.af3.exploration.alg.dse.evaluator.constraint; - uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, - org.fortiss.af3.exploration.alg.dse.modeltransformation, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, - eu.dreamsproject.ikerlan.safetystandards.SafetyCompliance, - org.fortiss.af3.exploration.model, - org.fortiss.af3.exploration.alg.dse.evaluator", - org.fortiss.af3.exploration.alg.dse.evaluator.objective; - uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, - org.apfloat, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, - org.fortiss.af3.exploration.model, - org.fortiss.af3.exploration.alg.dse.evaluator", - org.fortiss.af3.exploration.alg.dse.modeltransformation, - org.fortiss.af3.exploration.alg.dse.modeltransformation.base, - org.fortiss.af3.exploration.alg.dse.modeltransformation.comparch, - org.fortiss.af3.exploration.alg.dse.modeltransformation.deployment, - org.fortiss.af3.exploration.alg.dse.modeltransformation.element, - org.fortiss.af3.exploration.alg.dse.sysmodel, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch; - uses:="org.eclipse.emf.ecore, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, - org.eclipse.emf.common.util, - org.jgrapht", - org.fortiss.af3.exploration.alg.dse.sysmodel.arch.af3; - uses:="org.fortiss.tooling.base.model.element, - eu.dreamsproject.application.model.annotation, - org.fortiss.af3.component.model, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, - org.eclipse.emf.common.util, - org.fortiss.af3.timing.model.annotation, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.platform.model, - eu.dreamsproject.platform.model.annotation", - org.fortiss.af3.exploration.alg.dse.sysmodel.arch.af3.helper, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, - org.fortiss.af3.exploration.alg.dse.sysmodel.comm; - uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.exploration.alg.dse.sysmodel.mapping, - org.jgrapht", - org.fortiss.af3.exploration.alg.dse.sysmodel.faultmodel, - org.fortiss.af3.exploration.alg.dse.sysmodel.mapping;uses:="org.fortiss.af3.exploration.alg.dse.sysmodel.arch", - org.fortiss.af3.exploration.alg.dse.sysmodel.mapping.comm, - org.fortiss.af3.exploration.alg.dse.sysmodel.random, - org.fortiss.af3.exploration.alg.dse.sysmodel.sched;uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution,org.fortiss.af3.exploration.alg.dse.sysmodel.arch,org.fortiss.af3.exploration.model", - org.fortiss.af3.exploration.alg.dse.sysmodel.sched.comm; - uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, - org.fortiss.af3.exploration.alg.dse.sysmodel.sched, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.exploration.model, - org.fortiss.af3.exploration.alg.dse.sysmodel.mapping.comm", - org.fortiss.af3.exploration.alg.dse.sysmodel.sched.proc; - uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping, - org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping, - org.apfloat, - org.fortiss.af3.exploration.alg.dse.sysmodel.sched, - org.fortiss.af3.exploration.alg.dse.sysmodel.arch, - org.fortiss.af3.exploration.model", - org.fortiss.af3.exploration.alg.exception, - org.fortiss.af3.exploration.alg.guava, - org.fortiss.af3.exploration.alg.plot, - org.fortiss.af3.exploration.alg.service, - org.fortiss.af3.exploration.alg.util, - org.fortiss.af3.exploration.dsl.model, - org.fortiss.af3.exploration.dsl.model.expressions, - org.fortiss.af3.exploration.dsl.model.expressions.impl, - org.fortiss.af3.exploration.dsl.model.expressions.util, - org.fortiss.af3.exploration.dsl.model.impl, - org.fortiss.af3.exploration.dsl.model.operators, - org.fortiss.af3.exploration.dsl.model.operators.impl, - org.fortiss.af3.exploration.dsl.model.operators.util, - org.fortiss.af3.exploration.dsl.model.patterns, - org.fortiss.af3.exploration.dsl.model.patterns.impl, - org.fortiss.af3.exploration.dsl.model.patterns.util, - org.fortiss.af3.exploration.dsl.model.types, - org.fortiss.af3.exploration.dsl.model.types.impl, - org.fortiss.af3.exploration.dsl.model.types.util, - org.fortiss.af3.exploration.dsl.model.util, - org.fortiss.af3.exploration.model, - org.fortiss.af3.exploration.model.impl, - org.fortiss.af3.exploration.model.location, - org.fortiss.af3.exploration.model.location.impl, - org.fortiss.af3.exploration.model.location.util, - org.fortiss.af3.exploration.model.time, - org.fortiss.af3.exploration.model.time.impl, - org.fortiss.af3.exploration.model.time.util, - org.fortiss.af3.exploration.model.util, - org.fortiss.af3.exploration.moea.model, - org.fortiss.af3.exploration.moea.model.annotation, - org.fortiss.af3.exploration.moea.model.annotation.impl, - org.fortiss.af3.exploration.moea.model.annotation.util, - org.fortiss.af3.exploration.moea.model.feature, - org.fortiss.af3.exploration.moea.model.feature.impl, - org.fortiss.af3.exploration.moea.model.feature.util, - org.fortiss.af3.exploration.moea.model.impl, - org.fortiss.af3.exploration.moea.model.parameters, - org.fortiss.af3.exploration.moea.model.parameters.impl, - org.fortiss.af3.exploration.moea.model.parameters.util, - org.fortiss.af3.exploration.moea.model.predefined, - org.fortiss.af3.exploration.moea.model.predefined.impl, - org.fortiss.af3.exploration.moea.model.predefined.util, - org.fortiss.af3.exploration.moea.model.util, - org.fortiss.af3.exploration.util +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Exploration Algorithms +Bundle-SymbolicName: org.fortiss.af3.exploration.alg;singleton:=true +Bundle-Version: 2.13.0.qualifier +Bundle-ClassPath: ., + lib/jgrapht-core-0.9.0.jar, + lib/aopalliance-1.0.jar, + lib/apfloat.jar, + lib/jgrapht-ext-0.9.0.jar, + lib/jgraphx-2.0.0.1.jar, + lib/guice-assistedinject-4.2.0.jar, + lib/guice-4.2.0.jar, + lib/guice-multibindings-4.2.0.jar, + lib/commons-collections4-4.1.jar, + lib/opt4j-optimizers-SNAPSHOT-20161110.jar, + lib/guava-25.1-jre.jar, + lib/jfreechart-1.0.19.jar, + lib/jcommon-1.0.23.jar, + lib/opt4j-core-SNAPSHOT-20180714.jar, + lib/opt4j-operators-SNAPSHOT-20180714.jar +Bundle-Vendor: fortiss GmbH +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.fortiss.af3.exploration.alg.ExplorationAlgActivator +Require-Bundle: org.fortiss.tooling.base.ui;visibility:=reexport, + org.fortiss.af3.safety;bundle-version="2.9.0";visibility:=reexport, + org.fortiss.tooling.kernel;visibility:=reexport, + org.fortiss.af3.schedule;visibility:=reexport, + org.eclipse.core.runtime, + org.eclipse.emf.ecore;visibility:=reexport, + org.fortiss.tooling.base;visibility:=reexport, + org.fortiss.af3.component;visibility:=reexport, + org.fortiss.af3.exploration;bundle-version="2.11.0";visibility:=reexport, + org.fortiss.af3.expression;visibility:=reexport, + org.fortiss.af3.platform;visibility:=reexport, + org.fortiss.af3.project;visibility:=reexport, + org.eclipse.ui.ide;visibility:=reexport, + org.fortiss.af3.exploration.smt;bundle-version="2.11.0", + org.fortiss.af3.platform.hierarchic, + org.fortiss.af3.task, + org.fortiss.af3.partition;visibility:=reexport +Export-Package: org.fortiss.af3.exploration.alg, + org.fortiss.af3.exploration.alg.backend, + org.fortiss.af3.exploration.alg.dse, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.comm, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.repair, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, + org.fortiss.af3.exploration.alg.dse.evaluator; + uses:="org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, + org.fortiss.af3.exploration.model, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.evaluate, + org.opt4j.core", + org.fortiss.af3.exploration.alg.dse.evaluator.constraint; + uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, + org.fortiss.af3.exploration.alg.dse.modeltransformation, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, + eu.dreamsproject.ikerlan.safetystandards.SafetyCompliance, + org.fortiss.af3.exploration.model, + org.fortiss.af3.exploration.alg.dse.evaluator", + org.fortiss.af3.exploration.alg.dse.evaluator.objective; + uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, + org.apfloat, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype, + org.fortiss.af3.exploration.model, + org.fortiss.af3.exploration.alg.dse.evaluator", + org.fortiss.af3.exploration.alg.dse.modeltransformation, + org.fortiss.af3.exploration.alg.dse.modeltransformation.base, + org.fortiss.af3.exploration.alg.dse.modeltransformation.comparch, + org.fortiss.af3.exploration.alg.dse.modeltransformation.deployment, + org.fortiss.af3.exploration.alg.dse.modeltransformation.element, + org.fortiss.af3.exploration.alg.dse.sysmodel, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch; + uses:="org.eclipse.emf.ecore, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, + org.eclipse.emf.common.util, + org.jgrapht", + org.fortiss.af3.exploration.alg.dse.sysmodel.arch.af3; + uses:="org.fortiss.tooling.base.model.element, + eu.dreamsproject.application.model.annotation, + org.fortiss.af3.component.model, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, + org.eclipse.emf.common.util, + org.fortiss.af3.timing.model.annotation, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.platform.model, + eu.dreamsproject.platform.model.annotation", + org.fortiss.af3.exploration.alg.dse.sysmodel.arch.af3.helper, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph, + org.fortiss.af3.exploration.alg.dse.sysmodel.comm; + uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.exploration.alg.dse.sysmodel.mapping, + org.jgrapht", + org.fortiss.af3.exploration.alg.dse.sysmodel.faultmodel, + org.fortiss.af3.exploration.alg.dse.sysmodel.mapping;uses:="org.fortiss.af3.exploration.alg.dse.sysmodel.arch", + org.fortiss.af3.exploration.alg.dse.sysmodel.mapping.comm, + org.fortiss.af3.exploration.alg.dse.sysmodel.random, + org.fortiss.af3.exploration.alg.dse.sysmodel.sched;uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution,org.fortiss.af3.exploration.alg.dse.sysmodel.arch,org.fortiss.af3.exploration.model", + org.fortiss.af3.exploration.alg.dse.sysmodel.sched.comm; + uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, + org.fortiss.af3.exploration.alg.dse.sysmodel.sched, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.exploration.model, + org.fortiss.af3.exploration.alg.dse.sysmodel.mapping.comm", + org.fortiss.af3.exploration.alg.dse.sysmodel.sched.proc; + uses:="org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping, + org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping, + org.apfloat, + org.fortiss.af3.exploration.alg.dse.sysmodel.sched, + org.fortiss.af3.exploration.alg.dse.sysmodel.arch, + org.fortiss.af3.exploration.model", + org.fortiss.af3.exploration.alg.exception, + org.fortiss.af3.exploration.alg.guava, + org.fortiss.af3.exploration.alg.plot, + org.fortiss.af3.exploration.alg.service, + org.fortiss.af3.exploration.alg.util, + org.fortiss.af3.exploration.dsl.model, + org.fortiss.af3.exploration.dsl.model.expressions, + org.fortiss.af3.exploration.dsl.model.expressions.impl, + org.fortiss.af3.exploration.dsl.model.expressions.util, + org.fortiss.af3.exploration.dsl.model.impl, + org.fortiss.af3.exploration.dsl.model.operators, + org.fortiss.af3.exploration.dsl.model.operators.impl, + org.fortiss.af3.exploration.dsl.model.operators.util, + org.fortiss.af3.exploration.dsl.model.patterns, + org.fortiss.af3.exploration.dsl.model.patterns.impl, + org.fortiss.af3.exploration.dsl.model.patterns.util, + org.fortiss.af3.exploration.dsl.model.types, + org.fortiss.af3.exploration.dsl.model.types.impl, + org.fortiss.af3.exploration.dsl.model.types.util, + org.fortiss.af3.exploration.dsl.model.util, + org.fortiss.af3.exploration.model, + org.fortiss.af3.exploration.model.impl, + org.fortiss.af3.exploration.model.location, + org.fortiss.af3.exploration.model.location.impl, + org.fortiss.af3.exploration.model.location.util, + org.fortiss.af3.exploration.model.time, + org.fortiss.af3.exploration.model.time.impl, + org.fortiss.af3.exploration.model.time.util, + org.fortiss.af3.exploration.model.util, + org.fortiss.af3.exploration.moea.model, + org.fortiss.af3.exploration.moea.model.annotation, + org.fortiss.af3.exploration.moea.model.annotation.impl, + org.fortiss.af3.exploration.moea.model.annotation.util, + org.fortiss.af3.exploration.moea.model.feature, + org.fortiss.af3.exploration.moea.model.feature.impl, + org.fortiss.af3.exploration.moea.model.feature.util, + org.fortiss.af3.exploration.moea.model.impl, + org.fortiss.af3.exploration.moea.model.parameters, + org.fortiss.af3.exploration.moea.model.parameters.impl, + org.fortiss.af3.exploration.moea.model.parameters.util, + org.fortiss.af3.exploration.moea.model.predefined, + org.fortiss.af3.exploration.moea.model.predefined.impl, + org.fortiss.af3.exploration.moea.model.predefined.util, + org.fortiss.af3.exploration.moea.model.util, + org.fortiss.af3.exploration.util diff --git a/org.fortiss.af3.exploration.alg/model/.ratings b/org.fortiss.af3.exploration.alg/model/.ratings index f54baab02cbe655c4e0f12bc0840a268c572b896..7e6407a4bd699bb3f7c4218ad2ba0df4b341620c 100644 --- a/org.fortiss.af3.exploration.alg/model/.ratings +++ b/org.fortiss.af3.exploration.alg/model/.ratings @@ -1,3 +1,3 @@ common.ecore 3e3e3a1484cebe698e99621a60be4fa285238c92 RED explorationDsl.ecore 6950a6116721764800ad6bf3b301e0dec934c365 RED -moea.ecore 099cf6fd45522f4b427d21f6bca28ec493e36c35 RED +moea.ecore 3af9fb8410fd06f1bafd7f841de03db3fdd4327e RED diff --git a/org.fortiss.af3.exploration.alg/model/moea.ecore b/org.fortiss.af3.exploration.alg/model/moea.ecore index 099cf6fd45522f4b427d21f6bca28ec493e36c35..3af9fb8410fd06f1bafd7f841de03db3fdd4327e 100644 --- a/org.fortiss.af3.exploration.alg/model/moea.ecore +++ b/org.fortiss.af3.exploration.alg/model/moea.ecore @@ -5,9 +5,14 @@ <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> <details key="documentation" value="Contains the selected {@link IOptimizer}, the {@link SystemParameter}s, and the {@link ExplorationSpecification} that define a particular DSE problemn."/> </eAnnotations> - <eStructuralFeatures xsi:type="ecore:EReference" name="features" lowerBound="1" - upperBound="-1" eType="ecore:EClass platform:/resource/org.fortiss.af3.exploration/model/exploration.ecore#//IExplorationFeature" - containment="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="features" lowerBound="1" + upperBound="-1"> + <eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaClass"> + <eTypeArguments> + <eUpperBound eClassifier="#//feature/IExplorationFeature"/> + </eTypeArguments> + </eGenericType> + </eStructuralFeatures> <eStructuralFeatures xsi:type="ecore:EReference" name="optimizer" lowerBound="1" eType="#//parameters/IOptimizer" containment="true"> <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> @@ -70,6 +75,7 @@ <eClassifiers xsi:type="ecore:EClass" name="TaskMapping" eSuperTypes="platform:/resource/org.fortiss.af3.exploration/model/exploration.ecore#//IExplorationFeature"/> <eClassifiers xsi:type="ecore:EDataType" name="ISafetyFunctionAdapter" instanceClassName="org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ISafetyFunctionAdapter" serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="IExplorationFeature" instanceClassName="org.fortiss.af3.exploration.alg.feature.IExplorationFeature"/> </eSubpackages> <eSubpackages name="parameters" nsURI="http://www.fortiss.org/af3/exploration/moea/parameters" nsPrefix="org-fortiss-af3-exploration-moea-parameters"> diff --git a/org.fortiss.af3.exploration.alg/model/moea.genmodel b/org.fortiss.af3.exploration.alg/model/moea.genmodel index ba106c86ef8c122fe4dcf9eda2f701f78212aba2..223aad898d0d56f663a674bfb0b64bfa971ab863 100644 --- a/org.fortiss.af3.exploration.alg/model/moea.genmodel +++ b/org.fortiss.af3.exploration.alg/model/moea.genmodel @@ -15,7 +15,7 @@ <genEnumLiterals ecoreEnumLiteral="moea.ecore#//VoterType_t/MajorityVoter"/> </genEnums> <genClasses ecoreClass="moea.ecore#//DseSpecification"> - <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference moea.ecore#//DseSpecification/features"/> + <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EAttribute moea.ecore#//DseSpecification/features"/> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference moea.ecore#//DseSpecification/optimizer"/> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference moea.ecore#//DseSpecification/parameters"/> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference moea.ecore#//DseSpecification/targetSpecification"/> @@ -40,6 +40,7 @@ <nestedGenPackages prefix="Feature" basePackage="org.fortiss.af3.exploration.moea.model" disposableProviderFactory="true" ecorePackage="moea.ecore#//feature"> <genDataTypes ecoreDataType="moea.ecore#//feature/ISafetyFunctionAdapter"/> + <genDataTypes ecoreDataType="moea.ecore#//feature/IExplorationFeature"/> <genClasses ecoreClass="moea.ecore#//feature/SafetyExploration"> <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EAttribute moea.ecore#//feature/SafetyExploration/adapters"/> diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/.ratings index 6bc689648101684268416919ead53d67db884dbd..2e07f40a068c778c9693924275ec25ea721f5b71 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/.ratings @@ -1,2 +1,2 @@ -ExplorationAlg.java 213524a903ff48c0b8edcac6819c206440519274 RED -ExplorationAlgActivator.java 1970505dc53286fd3752c909abc568e0bf598fe0 RED +ExplorationAlg.java 8d8775418e82ebd92b4ceedcee410b3cd5f8e038 YELLOW +ExplorationAlgActivator.java 1970505dc53286fd3752c909abc568e0bf598fe0 YELLOW diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/ExplorationAlg.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/ExplorationAlg.java index 213524a903ff48c0b8edcac6819c206440519274..8d8775418e82ebd92b4ceedcee410b3cd5f8e038 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/ExplorationAlg.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/ExplorationAlg.java @@ -20,44 +20,20 @@ import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager. import org.eclipse.ui.IStartup; import org.fortiss.af3.exploration.alg.backend.Opt4JDseBackend; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.partitionmapping.PartitionMappingCreator; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.safetyfunctionarch.SafetyFunctionArchCreator; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.taskmapping.AbstractTaskMappingCreator; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.taskmapping.FailSilentTaskMappingCreator; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.comm.MessageEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmapping.PartitionMappingEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.platform.PlatformCommunicationGraphEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch.SafetyFunctionArchEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.InstantiatedAcyclicTaskGraphEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.InstantiatedTaskGraphEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.SafeTaskGraphEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.FailSilentTaskMappingEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.InstantiatedTaskMappingEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.partitionmapping.PartitionMappingModule; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.safetyarch.MutateSafetyFunctionArchitectureModule; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskinstantiation.MutateTaskInstanceModule; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmapping.MutateTaskMappingModule; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.StrictTTDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.comm.MessageDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.instantiatetaskgraph.InstantiatedTaskMappingDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.instantiatetaskgraph.InstantiatedTaskMappingDecoderAcyclic; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.partitionmapping.PartitionMappingDecoderGraph; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.safetyfunction.SFGraphDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.safetyfunction.SFMappingDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.AbstractTaskMappingIdentityDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.instantiate.FailSilentAbstractTaskMappingDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.instantiate.TaskInstanceResourceAlignmentDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.StrictTTSchedule; +import org.fortiss.af3.exploration.alg.feature.DesignDiversityExploration; +import org.fortiss.af3.exploration.alg.feature.PartitionArchitectureExploration; +import org.fortiss.af3.exploration.alg.feature.SafetyArchitectureExploration; +import org.fortiss.af3.exploration.alg.feature.TTScheduleExploration; +import org.fortiss.af3.exploration.alg.feature.TaskMappingExploration; import org.fortiss.af3.exploration.alg.service.IExplorationConstraintTransformationService; import org.fortiss.af3.exploration.alg.service.IExplorationEvaluatationService; -import org.fortiss.af3.exploration.alg.service.IExplorationModuleService; +import org.fortiss.af3.exploration.alg.service.IExplorationFeatureService; import org.fortiss.af3.exploration.alg.service.IExplorationRepairService; import org.fortiss.af3.exploration.alg.service.IExplorationService; import org.fortiss.af3.exploration.alg.service.IExplorationTransformationService; import org.fortiss.af3.exploration.alg.service.internal.ExplorationConstraintTransformationService; import org.fortiss.af3.exploration.alg.service.internal.ExplorationEvaluationService; -import org.fortiss.af3.exploration.alg.service.internal.ExplorationModuleService; +import org.fortiss.af3.exploration.alg.service.internal.ExplorationFeatureService; import org.fortiss.af3.exploration.alg.service.internal.ExplorationRepairService; import org.fortiss.af3.exploration.alg.service.internal.ExplorationTransformationService; import org.fortiss.af3.exploration.backend.DseBackendHandler; @@ -90,7 +66,7 @@ public final class ExplorationAlg implements IStartup { public static void initialize() { registerServices(); - getService(IExplorationModuleService.class).initializeService(); + getService(IExplorationFeatureService.class).initializeService(); getService(IExplorationConstraintTransformationService.class).initializeService(); getService(IExplorationEvaluatationService.class).initializeService(); getService(IExplorationRepairService.class).initializeService(); @@ -104,8 +80,8 @@ public final class ExplorationAlg implements IStartup { private static void registerServices() { BundleContext context = getDefault().getBundle().getBundleContext(); - context.registerService(IExplorationModuleService.class.getName(), - ExplorationModuleService.getInstance(), null); + context.registerService(IExplorationFeatureService.class.getName(), + ExplorationFeatureService.getInstance(), null); context.registerService(IExplorationConstraintTransformationService.class.getName(), ExplorationConstraintTransformationService.getInstance(), null); context.registerService(IExplorationEvaluatationService.class.getName(), @@ -117,84 +93,18 @@ public final class ExplorationAlg implements IStartup { } /** Registers the exploration modules bundled with this plugin. */ - @SuppressWarnings("unchecked") private static void registerExplorationModules() { // Functional groups of Decoders. - registerSafetyFunctionModules(); - registerPartitionMappingModules(); - registerTaskMappingModules(); - registerInstTaskGraphModules(); - - // Single exploration modules: Decoding. - getService(IExplorationModuleService.class).registerProblem(StrictTTSchedule.class, - new StrictTTDecoder()); - getService(IExplorationModuleService.class).registerProblem(MessageEncoding.class, - new MessageDecoder()); - } - - /** Registers problem modules related to safety functions. */ - @SuppressWarnings("unchecked") - private static void registerSafetyFunctionModules() { - // Variables - getService(IExplorationModuleService.class).registerVariable( - SafetyFunctionArchEncoding.class, new SafetyFunctionArchCreator(), - new MutateSafetyFunctionArchitectureModule()); - - // Decoding - getService(IExplorationModuleService.class).registerProblem( - AbstractTaskMappingEncoding.class, new SFMappingDecoder()); - // TODO: ConstraintDecoder - // getService(IExplorationModuleService.class).registerProblem( - // AbstractTaskMappingEncoding.class, new SFMappingConstraintDecoder()); - getService(IExplorationModuleService.class).registerProblem(SafeTaskGraphEncoding.class, - new SFGraphDecoder()); - } - - /** Registers problem modules related to safety functions. */ - private static void registerPartitionMappingModules() { - // Variables - getService(IExplorationModuleService.class).registerVariable( - PartitionMappingEncoding.class, new PartitionMappingCreator(), - new PartitionMappingModule()); - - // Decoding - getService(IExplorationModuleService.class).registerProblem( - PlatformCommunicationGraphEncoding.class, new PartitionMappingDecoderGraph()); - } - - /** Registers all problem modules related to task mapping. */ - private static void registerTaskMappingModules() { - // Variables - getService(IExplorationModuleService.class).registerVariable( - AbstractTaskMappingEncoding.class, new AbstractTaskMappingCreator(), - new MutateTaskMappingModule()); - getService(IExplorationModuleService.class).registerVariable( - FailSilentTaskMappingEncoding.class, new FailSilentTaskMappingCreator(), - new MutateTaskInstanceModule()); - - // Decoding - getService(IExplorationModuleService.class).registerProblem( - AbstractTaskMappingEncoding.class, new AbstractTaskMappingIdentityDecoder()); - getService(IExplorationModuleService.class).registerProblem( - FailSilentTaskMappingEncoding.class, new FailSilentAbstractTaskMappingDecoder()); - // getService(IExplorationModuleService.class).registerProblem( - // FaultDetectionVotingTaskMappingEncoding.class, - // new FaultDetectionVotingAbstractTaskMappingDecoder()); - getService(IExplorationModuleService.class).registerProblem( - InstantiatedTaskMappingEncoding.class, new TaskInstanceResourceAlignmentDecoder()); - } - - /** - * Registers all modules related to the derivation of task graphs from instantiated task - * mappings. - */ - @SuppressWarnings("unchecked") - private static void registerInstTaskGraphModules() { - getService(IExplorationModuleService.class).registerProblem( - InstantiatedTaskGraphEncoding.class, new InstantiatedTaskMappingDecoder()); - getService(IExplorationModuleService.class).registerProblem( - InstantiatedAcyclicTaskGraphEncoding.class, - new InstantiatedTaskMappingDecoderAcyclic()); + getService(IExplorationFeatureService.class).registerExplorationFeature( + new SafetyArchitectureExploration()); + getService(IExplorationFeatureService.class).registerExplorationFeature( + new PartitionArchitectureExploration()); + getService(IExplorationFeatureService.class).registerExplorationFeature( + new TaskMappingExploration()); + getService(IExplorationFeatureService.class).registerExplorationFeature( + new DesignDiversityExploration()); + getService(IExplorationFeatureService.class).registerExplorationFeature( + new TTScheduleExploration()); } /** Register the DSE backend with the exploration plugin. */ @@ -208,7 +118,7 @@ public final class ExplorationAlg implements IStartup { */ public static void start() { // TODO: Check start order w.r.t. the transformation service. - getService(IExplorationModuleService.class).startService(); + getService(IExplorationFeatureService.class).startService(); getService(IExplorationConstraintTransformationService.class).startService(); // The Transformation Service must be started before the Evaluation Service such that it can // check for the availability of required transformation modules. diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/.ratings index 826fc063fe7259a8608e18c5df7df5d1e9590d18..3b9a9d0dfdd39f3c918be75c588f325aaeb19981 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/.ratings @@ -1 +1 @@ -Opt4JDseBackend.java 91928dee43716df571dc3a6a5f4031401ed3ae61 RED +Opt4JDseBackend.java aa55d9d0655712fb90ff871e5033541587aa305a RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/Opt4JDseBackend.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/Opt4JDseBackend.java index 91928dee43716df571dc3a6a5f4031401ed3ae61..aa55d9d0655712fb90ff871e5033541587aa305a 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/Opt4JDseBackend.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/backend/Opt4JDseBackend.java @@ -19,7 +19,6 @@ import static org.fortiss.af3.exploration.alg.util.DesignSpaceExplorationModelEl import static org.fortiss.tooling.common.util.LambdaUtils.getFirst; import static org.fortiss.tooling.kernel.utils.EcoreUtils.getParentsWithType; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -32,19 +31,23 @@ import org.eclipse.swt.widgets.Display; import org.fortiss.af3.component.model.ComponentArchitecture; import org.fortiss.af3.exploration.alg.dse.CompositeExplorationSolution; import org.fortiss.af3.exploration.alg.dse.Explorer; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.StrictTTSchedule; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.af3.AF3SystemModelAdapter; +import org.fortiss.af3.exploration.alg.feature.DesignDiversityExploration; +import org.fortiss.af3.exploration.alg.feature.IExplorationFeature; +import org.fortiss.af3.exploration.alg.feature.PartitionArchitectureExploration; +import org.fortiss.af3.exploration.alg.feature.SafetyArchitectureExploration; +import org.fortiss.af3.exploration.alg.feature.TTScheduleExploration; +import org.fortiss.af3.exploration.alg.feature.TaskMappingExploration; import org.fortiss.af3.exploration.alg.plot.XYPlotter; -import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; import org.fortiss.af3.exploration.backend.IDseBackend; import org.fortiss.af3.exploration.dsl_v2.model.expression.SuperSet; import org.fortiss.af3.exploration.model.ExplorationSpecification; -import org.fortiss.af3.exploration.model.IExplorationFeature; import org.fortiss.af3.exploration.model.SuperSetMap; import org.fortiss.af3.exploration.model.solutions.ExplorationSolution; import org.fortiss.af3.exploration.moea.model.DseSpecification; -import org.fortiss.af3.exploration.moea.model.feature.FeatureFactory; import org.fortiss.af3.platform.model.ExecutionUnit; import org.fortiss.af3.platform.model.PlatformArchitecture; import org.fortiss.af3.task.model.Signal; @@ -82,8 +85,8 @@ public class Opt4JDseBackend implements IDseBackend { @Override public Optional<ExplorationSolution> executeDSE(ExplorationSpecification expSpec, Set<Class<? extends IModelElement>> solutionModelTypes, - Collection<IExplorationFeature> explorationModules, IProgressMonitor monitor, - int timeoutMS) throws Exception { + Collection<org.fortiss.af3.exploration.model.IExplorationFeature> explorationModules, + IProgressMonitor monitor, int timeoutMS) throws Exception { ExplorationSolution explorationSolution; SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter; SuperSetMap superSets = expSpec.getSearchSpace(); @@ -101,26 +104,21 @@ public class Opt4JDseBackend implements IDseBackend { superSets.get(ExecutionUnit.class), superSets.get(Signal.class)); DseSpecification dseSpec = createDefaultDesignSpaceExploration(EcoreUtil.copy(expSpec), context); + addDefaultExplorationFeatures(dseSpec); // Set the requested solutions. Set<Class<?>> solutionTypes = new HashSet<>(); solutionTypes.add(StrictTTSchedule.class); - // Features enabled by default. - Collection<IExplorationFeature> dseFeatures = new ArrayList<>(); - dseFeatures.add(FeatureFactory.eINSTANCE.createTaskMapping()); - dseFeatures.add(FeatureFactory.eINSTANCE.createTaskInstantiation()); - dseSpec.getFeatures().addAll(dseFeatures); - try { Explorer explorer = new Explorer(); - Set<Class<? extends IExplorationEncoding>> solPhenotypeTypes = new HashSet<>(); + Set<Class<? extends Phenotype>> solPhenotypeTypes = new HashSet<>(); for(Class<?> solType : solutionTypes) { - if(!IExplorationEncoding.class.isAssignableFrom(solType)) { + if(!Phenotype.class.isAssignableFrom(solType)) { throw new Exception( "The demanded solution is not available in the sleceted DSE backend."); } - solPhenotypeTypes.add((Class<? extends IExplorationEncoding>)solType); + solPhenotypeTypes.add((Class<? extends Phenotype>)solType); } CompositeExplorationSolution<?> expResult = explorer.explore(dseSpec, systemModelAdapter, solPhenotypeTypes, monitor, true); @@ -158,6 +156,15 @@ public class Opt4JDseBackend implements IDseBackend { return getFirst(getParentsWithType(anyElem.get(), archModelType)).orElse(null); } + /** Adds the default set of {@link IExplorationFeature}s to the given {@link DseSpecification}. */ + private void addDefaultExplorationFeatures(DseSpecification dseSpec) { + dseSpec.getFeatures().add(SafetyArchitectureExploration.class); + dseSpec.getFeatures().add(PartitionArchitectureExploration.class); + dseSpec.getFeatures().add(TaskMappingExploration.class); + dseSpec.getFeatures().add(DesignDiversityExploration.class); + dseSpec.getFeatures().add(TTScheduleExploration.class); + } + /** * Creates and launches the Dialog that displays the results from the exploration. * Pareto-optimal points are displayed in a 2D-graph, while schedules can be inspected for diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/.ratings index 95c9ceba8ccb045777c1b428ccad7ec660d3cd63..a18c43f873d9ac53ee84a65785938d2efa252f51 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/.ratings @@ -1,6 +1,6 @@ -CompositeExplorationSolution.java db9dadb94e6696cddaf12f0c5238fecfc4348afc RED -DSEFactory.java a4afb8c8c2ab23258ca13083c58b9d8ea766eed2 RED -Explorer.java 48ce78929632a9b78b4c809c7719eb5aa46d21df RED -ImplicitExplorationTargetFactory.java 25c3c668ed268843f8af7e37eb03370ed513b482 RED -SolutionQuantification.java 19cd7caa721bbca3112af7825c7fb20a96a4a799 RED -TaskMappingFactory.java 13f4e8104769a1592050ebb6e23d6fbcf864d1d2 RED +CompositeExplorationSolution.java db9dadb94e6696cddaf12f0c5238fecfc4348afc RED +DSEFactory.java b2eda5cf4b3fb41f0247751116276c3f7a3fd33c RED +Explorer.java be3ff1506a4aa34861de98e0a7e56743630f5afe RED +ImplicitExplorationTargetFactory.java 25c3c668ed268843f8af7e37eb03370ed513b482 RED +SolutionQuantification.java 19cd7caa721bbca3112af7825c7fb20a96a4a799 RED +TaskMappingFactory.java 13f4e8104769a1592050ebb6e23d6fbcf864d1d2 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/DSEFactory.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/DSEFactory.java index a4afb8c8c2ab23258ca13083c58b9d8ea766eed2..b2eda5cf4b3fb41f0247751116276c3f7a3fd33c 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/DSEFactory.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/DSEFactory.java @@ -15,8 +15,6 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf; - import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -42,7 +40,7 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegen import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.graph.DecoderDependencyGraph; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.problem.CompositeProblemModuleBase; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.ArchitectureDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.ArchitectureExplorationProblemModule; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.DseProcessProblemModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.partitionmapping.PartitionMappingDecoderGraph; import org.fortiss.af3.exploration.alg.dse.evaluator.ArchitectureEvaluator; import org.fortiss.af3.exploration.alg.dse.sysmodel.FailSilentExecModelFactory; @@ -108,13 +106,13 @@ public class DSEFactory { @SuppressWarnings("unchecked") public <C, S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>> - void createSubProblems(ArchitectureExplorationProblemModule archExpProblemModule, + void createSubProblems(DseProcessProblemModule archExpProblemModule, DseSpecification dse, DecoderDependencyGraph execDepGraph) throws Exception { // Java-limitation: it is not possible to pass the generic to the static methods. TaskMappingFactory<S, T> tmFactory = (TaskMappingFactory<S, T>)TaskMappingFactory.getInstance(); - SafetyExploration sfExplorationModule = - pickFirstInstanceOf(SafetyExploration.class, dse.getFeatures()); + SafetyExploration sfExplorationModule = null; + // pickFirstInstanceOf(SafetyExploration.class, dse.getFeatures()); if(sfExplorationModule != null) { // Initialize & register safety function adapters with the SystemModelAdapter. sfExplorationModule.getAdapters().parallelStream() @@ -142,7 +140,7 @@ public class DSEFactory { */ @SuppressWarnings("unchecked") private <C, T extends SafetyFunctionArchEncoding> void createSafetyFunctionArchProblem( - ArchitectureExplorationProblemModule archExpProblemModule, + DseProcessProblemModule archExpProblemModule, DecoderDependencyGraph execDepGraph) throws Exception { // These suppress warnings are required since type erasure in Java does not allow to pass // XY<Z>.class. @@ -169,7 +167,7 @@ public class DSEFactory { * if a cyclic dependency is discovered when registering the problem. */ private void createPartitionMappingProblem( - ArchitectureExplorationProblemModule archExpProblemModule, DseSpecification dse, + DseProcessProblemModule archExpProblemModule, DseSpecification dse, DecoderDependencyGraph execDepGraph) throws CycleFoundException { Class<PartitionMappingEncoding> pmEnodingClass = PartitionMappingEncoding.class; PartitionMappingCreator pmCreator = new PartitionMappingCreator(); @@ -186,7 +184,7 @@ public class DSEFactory { */ @SuppressWarnings("unchecked") private void createPlatformCommunicationGraphProblem( - ArchitectureExplorationProblemModule archExpProblemModule, + DseProcessProblemModule archExpProblemModule, DecoderDependencyGraph execDepGraph) throws CycleFoundException { Class<PlatformCommunicationGraphEncoding> pmEnodingClass = PlatformCommunicationGraphEncoding.class; @@ -228,7 +226,7 @@ public class DSEFactory { @SuppressWarnings("unchecked") private <S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>> void createAbstractTaskMappingProblem(TaskMappingFactory<S, T> tmFactory, - ArchitectureExplorationProblemModule archExpProblemModule, + DseProcessProblemModule archExpProblemModule, DseSpecification dse, DecoderDependencyGraph execDepGraph) throws Exception { Class<AbstractTaskMappingEncoding> tmEnodingClass = AbstractTaskMappingEncoding.class; AbstractTaskMappingCreator tmCreator = @@ -262,7 +260,7 @@ public class DSEFactory { @SuppressWarnings("unchecked") private <S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>> void createTaskMappingInstantiationProblem(TaskMappingFactory<S, T> tmFactory, - ArchitectureExplorationProblemModule archExpProblemModule, + DseProcessProblemModule archExpProblemModule, DseSpecification dse, DecoderDependencyGraph execDepGraph) throws Exception { // These suppress warnings are required since type erasure in Java does not allow to pass // XY<Z>.class. diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/Explorer.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/Explorer.java index 9af6eeae2c9d41c25145175c5938b1b1ba7fb6ec..be3ff1506a4aa34861de98e0a7e56743630f5afe 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/Explorer.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/Explorer.java @@ -1,246 +1,247 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 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.alg.dse; - -import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; -import static org.fortiss.tooling.common.util.LambdaUtils.filter; -import static org.fortiss.tooling.common.util.LambdaUtils.filterType; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.ecore.EObject; -import org.fortiss.af3.exploration.alg.dse.backend.IExplorerBackend; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.Opt4JExplorerBackend; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; -import org.fortiss.af3.exploration.alg.service.IExplorationConstraintTransformationService; -import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; -import org.fortiss.af3.exploration.model.ExplorationConstraint; -import org.fortiss.af3.exploration.model.ExplorationSpecification; -import org.fortiss.af3.exploration.model.ExplorationTarget; -import org.fortiss.af3.exploration.model.ExternalModelTarget; -import org.fortiss.af3.exploration.moea.model.DseSpecification; -import org.fortiss.af3.exploration.moea.model.parameters.EAOptimizer; -import org.fortiss.af3.exploration.moea.model.parameters.IOptimizer; -import org.fortiss.tooling.kernel.utils.EcoreUtils; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Explorer - entry point to architectural exploration - * - * @author huang - */ -public class Explorer { - - /** - * Performs the DSE defined a given {@link DseSpecification} specification on a given - * system model (represented by a {@link SystemModelAdapter}). - * - * @throws Exception - */ - public CompositeExplorationSolution<?> explore(DseSpecification dse, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, - Set<Class<? extends IExplorationEncoding>> requestedSolutions, - boolean generateImplicitConstraints) throws Exception { - return explore(dse, systemModelAdapter, requestedSolutions, null, - generateImplicitConstraints); - } - - /** - * Performs the DSE defined a given {@link DseSpecification} specification on a given - * system model (represented by a {@link SystemModelAdapter}). - */ - public CompositeExplorationSolution<?> explore(DseSpecification dse, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, - Set<Class<? extends IExplorationEncoding>> requestedSolutions, - IProgressMonitor progressMonitor, boolean generateImplicitConstraints) throws Exception { - validateDesignSpaceExploration(dse); - validateSystemModelAdapter(systemModelAdapter); - - // Clear & add implicit constraints to the Goal specification that are defined by the system - // model. - Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap = new HashMap<>(); - DseSpecification dseSpec = copyDSESpecification(dse, targetAssocMap); - ExplorationSpecification expSpec = dseSpec.getTargetSpecification(); - // FIXME: temporally disable the the implicit constraint generation. - // generateImplicitConstraints = false; - if(generateImplicitConstraints) { - expSpec.getTargets().addAll( - ImplicitExplorationTargetFactory.getInstance() - .createImplicitExplorationTargets(dseSpec, systemModelAdapter)); - } - - // Extract external models to add them to the available input models. - // TODO: readd support for "external" EMF models - for(ExplorationTarget<?> expTarget : expSpec.getTargets()) { - if(expTarget instanceof ExternalModelTarget) { - Collection<EObject> extModels = - ((ExternalModelTarget)expTarget).getExternalModels(); - for(EObject extModel : extModels) { - @SuppressWarnings("unchecked") Class<? extends EObject> modelType = - (Class<? extends EObject>)extModel.eClass().getInstanceClass(); - } - } - } - - // Execute the Constraint Transformation. - IExplorationConstraintTransformationService constrService = - getService(IExplorationConstraintTransformationService.class); - Collection<ExplorationConstraint<?>> genConstrs = - filter(filterType(expSpec.getTargets(), ExplorationConstraint.class), - t -> (t.getExpression() == null)); - // TODO: Reenable the constraint transformation service. - genConstrs = Collections.emptySet(); - Collection<ExplorationConstraint<?>> transformedConstrs = - constrService.getTransformedConstraints(systemModelAdapter, genConstrs); - expSpec.getTargets().addAll(transformedConstrs); - - // Invoke the backend in order to perform the DSE - IExplorerBackend<? extends IOptimizer> explorerBackend = - createExplorerBackend(dseSpec, expSpec, targetAssocMap, systemModelAdapter, - requestedSolutions, progressMonitor); - CompositeExplorationSolution<?> explorationResult = explorerBackend.explore(); - - // Print results - System.out.println(explorationResult); - - return explorationResult; - } - - /** - * Copies a DSE model, and returns a map that associates the {@link ExplorationTarget}s given in - * the original {@link ExplorationSpecification} with the copied ones. - */ - private DseSpecification copyDSESpecification(DseSpecification dse, - Map<ExplorationTarget<?>, ExplorationTarget<?>> assocMap) { - // TODO: rework this method, can be done more efficient. - DseSpecification dseCopy = EcoreUtils.copy(dse); - - ExplorationSpecification origExpSpec = dse.getTargetSpecification(); - dseCopy.getTargetSpecification().getTargets().clear(); - - // Instead of this extra hook, use the M2MCopier. - ExplorationSpecification expSpecCopy = dseCopy.getTargetSpecification(); - for(ExplorationTarget<?> target : origExpSpec.getTargets()) { - ExplorationTarget<?> targetCopy = EcoreUtils.copy(target); - expSpecCopy.getTargets().add(targetCopy); - assocMap.put(target, targetCopy); - } - return dseCopy; - } - - /** Helper method to issue an exception for invalid DSE configurations */ - private void createDesignSpaceExplorationConfigurationException(final String msg) - throws Exception { - throw new Exception("DSE configuration: " + msg); - } - - // TODO: Port validation of DSE configuration to model validation framework that creates markers - // in the problem view - /** Validation of DSE configuration */ - private void validateDesignSpaceExploration(DseSpecification dse) throws Exception { - if(dse == null) { - createDesignSpaceExplorationConfigurationException("No DSE configuration has been specified."); - // Never here - return; - } - - if(dse.getParameters() == null) { - createDesignSpaceExplorationConfigurationException("No optimizer independent parameters have been provided."); - } - - if(dse.getParameters().getExecutionModel() == null) { - createDesignSpaceExplorationConfigurationException("No execution model has been specified."); - } - - if(dse.getOptimizer() == null) { - createDesignSpaceExplorationConfigurationException("No optimizer backend has been specified."); - } - - // TODO: create a validation whether the constraints or objectives are not given - if(dse.getTargetSpecification() == null || - dse.getTargetSpecification().getTargets() == null || - dse.getTargetSpecification().getTargets().isEmpty()) { - createDesignSpaceExplorationConfigurationException("No Optimization goals have been provided."); - } - } - - // TODO: Use a subclassed Exception here. - /** Helper method to issue an exception for invalid input system models */ - private void createSystemModelAdapterConfigurationException(final String msg) throws Exception { - throw new Exception("System model: " + msg); - } - - // TODO: Port validation of system model to model validation framework that creates markers - // in the problem view - /** Validation of system model */ - private void validateSystemModelAdapter( - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter) throws Exception { - - if(systemModelAdapter == null) { - createSystemModelAdapterConfigurationException("No DSE configuration has been specified."); - return; - } - - if(systemModelAdapter.getDeployableComponents().isEmpty()) { - createSystemModelAdapterConfigurationException("Component architecture does not contain any deployable components.\n\nMake sure the \"Trigger\" annotation have been defined for all components that should be deployed."); - } - - if(systemModelAdapter.getDeploymentTargets().isEmpty()) { - createSystemModelAdapterConfigurationException("Platform architecture does not contain any deployment targets.\n\nMake sure the \"Deployment Target\" annotation has been set for all execution units that should be deployed.\n\nMaybe you selected the wrong platform architecture?"); - } - - if(systemModelAdapter.getTaskGraphs().isEmpty()) { - createSystemModelAdapterConfigurationException("System model does not contain any valid task graphs. All tasks in a task graph must share the same period."); - } - - if(systemModelAdapter.getAcyclicTaskGraphs().isEmpty()) { - createSystemModelAdapterConfigurationException("System model does not contain any valid task graphs. All tasks in a task graph must share the same period."); - } - - // FIXME: readd? ==>> VL Generation. - // if(systemModelAdapter.getHyperPeriod() <= 0) { - // createSystemModelAdapterConfigurationException("System model does not have a valid hyper - // period."); - // } - } - - /** Explorer backend */ - private IExplorerBackend<? extends IOptimizer> createExplorerBackend(DseSpecification dse, - ExplorationSpecification expSpec, - Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, - Set<Class<? extends IExplorationEncoding>> requestedSolutions, - IProgressMonitor progressMonitor) throws Exception { - Injector dseInjector = Guice.createInjector(systemModelAdapter); - - if(dse.getOptimizer() instanceof EAOptimizer) { - return new Opt4JExplorerBackend(dse, expSpec, targetAssocMap, dseInjector, - requestedSolutions, progressMonitor); - } - - createDesignSpaceExplorationConfigurationException("Unsupported exploration backend."); - - // Never here - return null; - } -} +/*-------------------------------------------------------------------------+ +| Copyright 2014 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.alg.dse; + +import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; +import static org.fortiss.tooling.common.util.LambdaUtils.filter; +import static org.fortiss.tooling.common.util.LambdaUtils.filterType; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.fortiss.af3.exploration.alg.dse.backend.IExplorerBackend; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.Opt4JExplorerBackend; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; +import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; +import org.fortiss.af3.exploration.alg.service.IExplorationConstraintTransformationService; +import org.fortiss.af3.exploration.model.ExplorationConstraint; +import org.fortiss.af3.exploration.model.ExplorationSpecification; +import org.fortiss.af3.exploration.model.ExplorationTarget; +import org.fortiss.af3.exploration.model.ExternalModelTarget; +import org.fortiss.af3.exploration.moea.model.DseSpecification; +import org.fortiss.af3.exploration.moea.model.parameters.EAOptimizer; +import org.fortiss.af3.exploration.moea.model.parameters.IOptimizer; +import org.fortiss.tooling.kernel.utils.EcoreUtils; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Explorer - entry point to architectural exploration + * + * @author huang + */ +public class Explorer { + + /** + * Performs the DSE defined a given {@link DseSpecification} specification on a given + * system model (represented by a {@link SystemModelAdapter}). + * + * @throws Exception + */ + public CompositeExplorationSolution<?> + explore(DseSpecification dse, + SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, + Set<Class<? extends Phenotype>> requestedSolutions, + boolean generateImplicitConstraints) throws Exception { + return explore(dse, systemModelAdapter, requestedSolutions, null, + generateImplicitConstraints); + } + + /** + * Performs the DSE defined a given {@link DseSpecification} specification on a given + * system model (represented by a {@link SystemModelAdapter}). + */ + public CompositeExplorationSolution<?> explore(DseSpecification dse, + SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, + Set<Class<? extends Phenotype>> requestedSolutions, IProgressMonitor progressMonitor, + boolean generateImplicitConstraints) throws Exception { + validateDesignSpaceExploration(dse); + validateSystemModelAdapter(systemModelAdapter); + + // Clear & add implicit constraints to the Goal specification that are defined by the system + // model. + Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap = new HashMap<>(); + DseSpecification dseSpec = copyDSESpecification(dse, targetAssocMap); + ExplorationSpecification expSpec = dseSpec.getTargetSpecification(); + // FIXME: temporally disable the the implicit constraint generation. + // generateImplicitConstraints = false; + if(generateImplicitConstraints) { + expSpec.getTargets().addAll( + ImplicitExplorationTargetFactory.getInstance() + .createImplicitExplorationTargets(dseSpec, systemModelAdapter)); + } + + // Extract external models to add them to the available input models. + // TODO: readd support for "external" EMF models + for(ExplorationTarget<?> expTarget : expSpec.getTargets()) { + if(expTarget instanceof ExternalModelTarget) { + Collection<EObject> extModels = + ((ExternalModelTarget)expTarget).getExternalModels(); + for(EObject extModel : extModels) { + @SuppressWarnings("unchecked") Class<? extends EObject> modelType = + (Class<? extends EObject>)extModel.eClass().getInstanceClass(); + } + } + } + + // Execute the Constraint Transformation. + IExplorationConstraintTransformationService constrService = + getService(IExplorationConstraintTransformationService.class); + Collection<ExplorationConstraint<?>> genConstrs = + filter(filterType(expSpec.getTargets(), ExplorationConstraint.class), + t -> (t.getExpression() == null)); + // TODO: Reenable the constraint transformation service. + genConstrs = Collections.emptySet(); + Collection<ExplorationConstraint<?>> transformedConstrs = + constrService.getTransformedConstraints(systemModelAdapter, genConstrs); + expSpec.getTargets().addAll(transformedConstrs); + + // Invoke the backend in order to perform the DSE + IExplorerBackend<? extends IOptimizer> explorerBackend = + createExplorerBackend(dseSpec, expSpec, targetAssocMap, systemModelAdapter, + requestedSolutions, progressMonitor); + CompositeExplorationSolution<?> explorationResult = explorerBackend.explore(); + + // Print results + System.out.println(explorationResult); + + return explorationResult; + } + + /** + * Copies a DSE model, and returns a map that associates the {@link ExplorationTarget}s given in + * the original {@link ExplorationSpecification} with the copied ones. + */ + private DseSpecification copyDSESpecification(DseSpecification dse, + Map<ExplorationTarget<?>, ExplorationTarget<?>> assocMap) { + // TODO: rework this method, can be done more efficient. + DseSpecification dseCopy = EcoreUtils.copy(dse); + + ExplorationSpecification origExpSpec = dse.getTargetSpecification(); + dseCopy.getTargetSpecification().getTargets().clear(); + + // Instead of this extra hook, use the M2MCopier. + ExplorationSpecification expSpecCopy = dseCopy.getTargetSpecification(); + for(ExplorationTarget<?> target : origExpSpec.getTargets()) { + ExplorationTarget<?> targetCopy = EcoreUtils.copy(target); + expSpecCopy.getTargets().add(targetCopy); + assocMap.put(target, targetCopy); + } + return dseCopy; + } + + /** Helper method to issue an exception for invalid DSE configurations */ + private void createDesignSpaceExplorationConfigurationException(final String msg) + throws Exception { + throw new Exception("DSE configuration: " + msg); + } + + // TODO: Port validation of DSE configuration to model validation framework that creates markers + // in the problem view + /** Validation of DSE configuration */ + private void validateDesignSpaceExploration(DseSpecification dse) throws Exception { + if(dse == null) { + createDesignSpaceExplorationConfigurationException("No DSE configuration has been specified."); + // Never here + return; + } + + if(dse.getParameters() == null) { + createDesignSpaceExplorationConfigurationException("No optimizer independent parameters have been provided."); + } + + if(dse.getParameters().getExecutionModel() == null) { + createDesignSpaceExplorationConfigurationException("No execution model has been specified."); + } + + if(dse.getOptimizer() == null) { + createDesignSpaceExplorationConfigurationException("No optimizer backend has been specified."); + } + + // TODO: create a validation whether the constraints or objectives are not given + if(dse.getTargetSpecification() == null || + dse.getTargetSpecification().getTargets() == null || + dse.getTargetSpecification().getTargets().isEmpty()) { + createDesignSpaceExplorationConfigurationException("No Optimization goals have been provided."); + } + } + + // TODO: Use a subclassed Exception here. + /** Helper method to issue an exception for invalid input system models */ + private void createSystemModelAdapterConfigurationException(final String msg) throws Exception { + throw new Exception("System model: " + msg); + } + + // TODO: Port validation of system model to model validation framework that creates markers + // in the problem view + /** Validation of system model */ + private void validateSystemModelAdapter( + SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter) throws Exception { + + if(systemModelAdapter == null) { + createSystemModelAdapterConfigurationException("No DSE configuration has been specified."); + return; + } + + if(systemModelAdapter.getDeployableComponents().isEmpty()) { + createSystemModelAdapterConfigurationException("Component architecture does not contain any deployable components.\n\nMake sure the \"Trigger\" annotation have been defined for all components that should be deployed."); + } + + if(systemModelAdapter.getDeploymentTargets().isEmpty()) { + createSystemModelAdapterConfigurationException("Platform architecture does not contain any deployment targets.\n\nMake sure the \"Deployment Target\" annotation has been set for all execution units that should be deployed.\n\nMaybe you selected the wrong platform architecture?"); + } + + if(systemModelAdapter.getTaskGraphs().isEmpty()) { + createSystemModelAdapterConfigurationException("System model does not contain any valid task graphs. All tasks in a task graph must share the same period."); + } + + if(systemModelAdapter.getAcyclicTaskGraphs().isEmpty()) { + createSystemModelAdapterConfigurationException("System model does not contain any valid task graphs. All tasks in a task graph must share the same period."); + } + + // FIXME: readd? ==>> VL Generation. + // if(systemModelAdapter.getHyperPeriod() <= 0) { + // createSystemModelAdapterConfigurationException("System model does not have a valid hyper + // period."); + // } + } + + /** Explorer backend */ + private IExplorerBackend<? extends IOptimizer> createExplorerBackend(DseSpecification dse, + ExplorationSpecification expSpec, + Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, + SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, + Set<Class<? extends Phenotype>> requestedSolutions, IProgressMonitor progressMonitor) + throws Exception { + Injector dseInjector = Guice.createInjector(systemModelAdapter); + + if(dse.getOptimizer() instanceof EAOptimizer) { + return new Opt4JExplorerBackend(dse, expSpec, targetAssocMap, dseInjector, + requestedSolutions, progressMonitor); + } + + createDesignSpaceExplorationConfigurationException("Unsupported exploration backend."); + + // Never here + return null; + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/.ratings index 3e8c90bab5cbe34338c0915245129833bc58c8ad..f71514662eaf1f7a4c62d4ab5252bbaddb60ebc2 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/.ratings @@ -1,3 +1,3 @@ -ExplorerBackendBase.java c8cb7fda00311b9f3002833eb5cd3d2eb3615ea4 RED +ExplorerBackendBase.java 19c9b3977fce8f8c4ab6153994c3f2608ca1b492 RED IExplorerBackend.java 608f40896becf86dd68cc7b6994383e58c0885a8 RED SolutionCandidateBase.java ba1b16d55680ea45bffd665ac7b0fd71b589b769 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/ExplorerBackendBase.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/ExplorerBackendBase.java index c8cb7fda00311b9f3002833eb5cd3d2eb3615ea4..19c9b3977fce8f8c4ab6153994c3f2608ca1b492 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/ExplorerBackendBase.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/ExplorerBackendBase.java @@ -1,195 +1,193 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2014 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.alg.dse.backend; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import javax.activation.UnsupportedDataTypeException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.fortiss.af3.exploration.alg.dse.DSEFactory; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.EvaluatorWrapper; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.IExplorationSolution; -import org.fortiss.af3.exploration.alg.dse.evaluator.constraint.IConstraintEvaluator; -import org.fortiss.af3.exploration.alg.dse.sysmodel.random.RandomExploration; -import org.fortiss.af3.exploration.alg.dse.sysmodel.random.RandomExploration.RandomnessType; -import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; -import org.fortiss.af3.exploration.model.ExplorationConstraint; -import org.fortiss.af3.exploration.model.ExplorationSpecification; -import org.fortiss.af3.exploration.model.ExplorationTarget; -import org.fortiss.af3.exploration.moea.model.DseSpecification; -import org.fortiss.af3.exploration.moea.model.parameters.IOptimizer; -import org.opt4j.core.Value; -import org.opt4j.core.problem.Evaluator; - -import com.google.inject.AbstractModule; -import com.google.inject.Injector; - -/** - * Base class for general optimization backends. - * - * @author barner - */ -public abstract class ExplorerBackendBase<O extends IOptimizer> extends AbstractModule implements - IExplorerBackend<O> { - - /** DSE specification (optimizer parameters, goal specification, input model, ...) */ - protected DseSpecification dse; - - /** Contains all ExplorationTargets of the exploration. */ - protected ExplorationSpecification expSpec; - - /** - * Map that relates the {@link ExplorationTarget}s from input specification with the - * {@link ExplorationTarget}s that are actually used in the DSE. - */ - protected Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap; - - /** Representation of system model (=input) that is evaluated during this DSE run */ - protected Injector dseInjector; - - /** Set of requested {@link Phenotype}s that form the solution set. */ - protected Set<Class<? extends IExplorationEncoding>> requestedSolutions; - - /** - * {@link IProgressMonitor} used to visualize the progress of the exploration process (may be - * {@code null}). - */ - protected IProgressMonitor progressMonitor; - - /** - * Contains the EvaluatorWrapper factory. It is used to instantiate the objectives and - * constraints that are used during the exploration for specific execution models. - */ - protected DSEFactory explorationFactory; - - /** - * Constructor that initializes the DSE backend with the given optimizer independent parameters - * and the goal specification - */ - protected ExplorerBackendBase(DseSpecification dse, ExplorationSpecification expSpec, - Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, Injector dseInjector, - Set<Class<? extends IExplorationEncoding>> requestedSolutions, - IProgressMonitor progressMonitor) { - this.dse = dse; - this.expSpec = expSpec; - this.targetAssocMap = targetAssocMap; - this.dseInjector = dseInjector; - this.requestedSolutions = requestedSolutions; - this.progressMonitor = progressMonitor; - - // TODO: Initialization of the TaskMappingFactory is currently done here to allow an - // instantiation of the Evaluators by the goals. Those are generified, and hence, the - // instance must exist already. - try { - DSEFactory.getInstance().createTaskMappingFactory( - dse.getParameters().getExecutionModel()); - } catch(UnsupportedDataTypeException e) { - // See todo above - e.printStackTrace(); - } - - // (Re-)Initialize the Random number generator - initCentralRandomGenerator(); - } - - /** - * (Re-)Initializes the central random number generator of the DSE. It must be re-initialized on - * successive runs to obtain deterministic behavior. - */ - private void initCentralRandomGenerator() { - if(!RandomExploration.getInstance().isInitialized()) { - try { - RandomExploration.getInstance().init(RandomnessType.realRandom, 30); - } catch(Exception e) { - // This is the correct place to initialize the central random generator. - assert (false) : "The centralized random number generator of the DSE has been initialized in another location, where it should not be initialized."; - } - } else { - try { - RandomExploration.getInstance().reInit(); - } catch(Exception e) { - // This is the correct place to re-initialize the central random generator, it has - // been initialized in this place before. - assert (false) : "The centralized random number generator of the DSE has not been initialized."; - } - } - } - - /** - * Performs the initialization of the optimizer backend. Must be called from constructor in - * concrete derived classes. - */ - protected abstract void init(O optimizer); - - /** - * Feasibility check for the results from the exploration. It validates that each constraint is - * fulfilled by applying the validate function of the {@link IConstraintEvaluator}s onto each - * possible solution. - */ - // protected CompositeExplorationSolution<?> validate( - // CompositeExplorationSolution<?> explorationResult, - // Collection<EvaluatorWrapper<?, ?, ?>> evalWrappers) { - // CompositeExplorationSolution<?> feasibleExplorationResult = explorationResult.copy(); - // - // // Iterate over all (feasible + infeasible) solutions - // for(Entry<IExplorationSolution<?>, SolutionQuantification> solution : explorationResult - // .getSolutionQuantification().entrySet()) { - // boolean isFeasible = - // validateSolution(solution.getKey(), solution.getValue(), evalWrappers); - // - // // Remove the current solution if the feasibility check failed. - // if(!isFeasible) { - // feasibleExplorationResult.deleteSolutionQuantification(solution.getKey()); - // } - // } - // - // return feasibleExplorationResult; - // } - - /** */ - protected <M extends Phenotype> boolean validateSolution(IExplorationSolution<?> solution, - ExplorationConstraint<?> target, Value<?> value, - Collection<EvaluatorWrapper<?, ?, ?>> evalWrappers) { - EvaluatorWrapper<?, ?, ?> evalWrapper = getEvaluatorOf(target, evalWrappers); - - assert (evalWrapper.getEvaluator() instanceof IConstraintEvaluator) : "The evaluator for the exploration constraint " + - target.getName() + " has an evaluator which is not an IConstraintEvaluator."; - - @SuppressWarnings("unchecked") Class<M> phenoClass = - (Class<M>)evalWrapper.getTargetPhenotypeType(); - M targetSubSolution = solution.getSubSolution(phenoClass); - return ((IConstraintEvaluator<?, ?, ?>)evalWrapper.getEvaluator()).validate(target, - targetSubSolution, phenoClass, value); - } - - /** - * From a given set of {@link Evaluator}s that are {@link EvaluatorWrapper}s, return the first - * found evaluator that is associated with the given {@link ExplorationTarget}. - */ - private <E extends EvaluatorWrapper<?, ?, ?>> E getEvaluatorOf(ExplorationTarget<?> expTarget, - Collection<E> evaluators) { - for(E evaluator : evaluators) { - if(expTarget.getClass().isAssignableFrom(evaluator.getTargetType())) { - return evaluator; - } - } - return null; - } -} +/*-------------------------------------------------------------------------+ +| Copyright 2014 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.alg.dse.backend; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import javax.activation.UnsupportedDataTypeException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.fortiss.af3.exploration.alg.dse.DSEFactory; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.EvaluatorWrapper; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.IExplorationSolution; +import org.fortiss.af3.exploration.alg.dse.evaluator.constraint.IConstraintEvaluator; +import org.fortiss.af3.exploration.alg.dse.sysmodel.random.RandomExploration; +import org.fortiss.af3.exploration.alg.dse.sysmodel.random.RandomExploration.RandomnessType; +import org.fortiss.af3.exploration.model.ExplorationConstraint; +import org.fortiss.af3.exploration.model.ExplorationSpecification; +import org.fortiss.af3.exploration.model.ExplorationTarget; +import org.fortiss.af3.exploration.moea.model.DseSpecification; +import org.fortiss.af3.exploration.moea.model.parameters.IOptimizer; +import org.opt4j.core.Value; +import org.opt4j.core.problem.Evaluator; + +import com.google.inject.AbstractModule; +import com.google.inject.Injector; + +/** + * Base class for general optimization backends. + * + * @author barner + */ +public abstract class ExplorerBackendBase<O extends IOptimizer> extends AbstractModule implements + IExplorerBackend<O> { + + /** DSE specification (optimizer parameters, goal specification, input model, ...) */ + protected DseSpecification dse; + + /** Contains all ExplorationTargets of the exploration. */ + protected ExplorationSpecification expSpec; + + /** + * Map that relates the {@link ExplorationTarget}s from input specification with the + * {@link ExplorationTarget}s that are actually used in the DSE. + */ + protected Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap; + + /** Representation of system model (=input) that is evaluated during this DSE run */ + protected Injector dseInjector; + + /** Set of requested {@link Phenotype}s that form the solution set. */ + protected Set<Class<? extends Phenotype>> requestedSolutions; + + /** + * {@link IProgressMonitor} used to visualize the progress of the exploration process (may be + * {@code null}). + */ + protected IProgressMonitor progressMonitor; + + /** + * Contains the EvaluatorWrapper factory. It is used to instantiate the objectives and + * constraints that are used during the exploration for specific execution models. + */ + protected DSEFactory explorationFactory; + + /** + * Constructor that initializes the DSE backend with the given optimizer independent parameters + * and the goal specification + */ + protected ExplorerBackendBase(DseSpecification dse, ExplorationSpecification expSpec, + Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, Injector dseInjector, + Set<Class<? extends Phenotype>> requestedSolutions, IProgressMonitor progressMonitor) { + this.dse = dse; + this.expSpec = expSpec; + this.targetAssocMap = targetAssocMap; + this.dseInjector = dseInjector; + this.requestedSolutions = requestedSolutions; + this.progressMonitor = progressMonitor; + + // TODO: Initialization of the TaskMappingFactory is currently done here to allow an + // instantiation of the Evaluators by the goals. Those are generified, and hence, the + // instance must exist already. + try { + DSEFactory.getInstance().createTaskMappingFactory( + dse.getParameters().getExecutionModel()); + } catch(UnsupportedDataTypeException e) { + // See todo above + e.printStackTrace(); + } + + // (Re-)Initialize the Random number generator + initCentralRandomGenerator(); + } + + /** + * (Re-)Initializes the central random number generator of the DSE. It must be re-initialized on + * successive runs to obtain deterministic behavior. + */ + private void initCentralRandomGenerator() { + if(!RandomExploration.getInstance().isInitialized()) { + try { + RandomExploration.getInstance().init(RandomnessType.realRandom, 30); + } catch(Exception e) { + // This is the correct place to initialize the central random generator. + assert (false) : "The centralized random number generator of the DSE has been initialized in another location, where it should not be initialized."; + } + } else { + try { + RandomExploration.getInstance().reInit(); + } catch(Exception e) { + // This is the correct place to re-initialize the central random generator, it has + // been initialized in this place before. + assert (false) : "The centralized random number generator of the DSE has not been initialized."; + } + } + } + + /** + * Performs the initialization of the optimizer backend. Must be called from constructor in + * concrete derived classes. + */ + protected abstract void init(O optimizer); + + /** + * Feasibility check for the results from the exploration. It validates that each constraint is + * fulfilled by applying the validate function of the {@link IConstraintEvaluator}s onto each + * possible solution. + */ + // protected CompositeExplorationSolution<?> validate( + // CompositeExplorationSolution<?> explorationResult, + // Collection<EvaluatorWrapper<?, ?, ?>> evalWrappers) { + // CompositeExplorationSolution<?> feasibleExplorationResult = explorationResult.copy(); + // + // // Iterate over all (feasible + infeasible) solutions + // for(Entry<IExplorationSolution<?>, SolutionQuantification> solution : explorationResult + // .getSolutionQuantification().entrySet()) { + // boolean isFeasible = + // validateSolution(solution.getKey(), solution.getValue(), evalWrappers); + // + // // Remove the current solution if the feasibility check failed. + // if(!isFeasible) { + // feasibleExplorationResult.deleteSolutionQuantification(solution.getKey()); + // } + // } + // + // return feasibleExplorationResult; + // } + + /** */ + protected <M extends Phenotype> boolean validateSolution(IExplorationSolution<?> solution, + ExplorationConstraint<?> target, Value<?> value, + Collection<EvaluatorWrapper<?, ?, ?>> evalWrappers) { + EvaluatorWrapper<?, ?, ?> evalWrapper = getEvaluatorOf(target, evalWrappers); + + assert (evalWrapper.getEvaluator() instanceof IConstraintEvaluator) : "The evaluator for the exploration constraint " + + target.getName() + " has an evaluator which is not an IConstraintEvaluator."; + + @SuppressWarnings("unchecked") Class<M> phenoClass = + (Class<M>)evalWrapper.getTargetPhenotypeType(); + M targetSubSolution = solution.getSubSolution(phenoClass); + return ((IConstraintEvaluator<?, ?, ?>)evalWrapper.getEvaluator()).validate(target, + targetSubSolution, phenoClass, value); + } + + /** + * From a given set of {@link Evaluator}s that are {@link EvaluatorWrapper}s, return the first + * found evaluator that is associated with the given {@link ExplorationTarget}. + */ + private <E extends EvaluatorWrapper<?, ?, ?>> E getEvaluatorOf(ExplorationTarget<?> expTarget, + Collection<E> evaluators) { + for(E evaluator : evaluators) { + if(expTarget.getClass().isAssignableFrom(evaluator.getTargetType())) { + return evaluator; + } + } + return null; + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/.ratings index 8861e9538628790c8d0eb66d422f51f3ec079a2d..f98c91472303287a8f446561c8e27c4bfd4c714d 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/.ratings @@ -1,5 +1,5 @@ -Opt4JDseTask.java b5cb9e664e7a8fc2b5157bcdcaca740c2fa85336 YELLOW -Opt4JDseTaskProvider.java ff2bbc6da2b21bd0bc64c3fa77dc8fa9939d10af RED -Opt4JExplorationSolutionSet.java 8578ee9c438bc3327a64172e996306a89606c782 RED -Opt4JExplorerBackend.java 143812e08f4ef9a803e0e24dc32612007c98cbd2 RED -Opt4JSingleExplorationSolution.java 41ce92d11b2e7a6a8c39bffa990c691160c36c8d RED +Opt4JDseTask.java b5cb9e664e7a8fc2b5157bcdcaca740c2fa85336 YELLOW +Opt4JDseTaskProvider.java ff2bbc6da2b21bd0bc64c3fa77dc8fa9939d10af RED +Opt4JExplorationSolutionSet.java 8578ee9c438bc3327a64172e996306a89606c782 RED +Opt4JExplorerBackend.java cddd1dc5ff5833b7e23cca7328682d88ee782677 RED +Opt4JSingleExplorationSolution.java 41ce92d11b2e7a6a8c39bffa990c691160c36c8d RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JExplorerBackend.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JExplorerBackend.java index 143812e08f4ef9a803e0e24dc32612007c98cbd2..cddd1dc5ff5833b7e23cca7328682d88ee782677 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JExplorerBackend.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JExplorerBackend.java @@ -15,7 +15,8 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j; -import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf; +import static com.google.common.collect.Sets.newHashSet; +import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf; import java.util.ArrayList; @@ -29,6 +30,8 @@ import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; import org.fortiss.af3.exploration.alg.dse.CompositeExplorationSolution; import org.fortiss.af3.exploration.alg.dse.backend.ExplorerBackendBase; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.decode.GuiceDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.mating.MatingCrossoverMutateRepairModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.copy.partitionmapping.CopyPartitionMappingModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.copy.platform.CopyPlatformCommunicationGraphModule; @@ -41,18 +44,19 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.crossover.NopC import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.crossover.NopCrossoverSFArchModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.partitionmapping.PartitionMappingModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.platform.NopPlatformCommGraphMutateModule; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.safetyarch.MutateSafetyFunctionArchitectureModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskinstantiation.MutateTaskInstanceModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmapping.MutateTaskMappingModule; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.ArchitectureExplorationProblemModule; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.DseProcessProblemModule; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.ArchitectureSolution; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.IExplorationSolution; -import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; +import org.fortiss.af3.exploration.alg.dse.module.DecoderModule; +import org.fortiss.af3.exploration.alg.exception.ExplorationRuntimeException; +import org.fortiss.af3.exploration.alg.feature.IExplorationFeature; +import org.fortiss.af3.exploration.alg.service.IExplorationFeatureService; import org.fortiss.af3.exploration.model.ExplorationConstraint; import org.fortiss.af3.exploration.model.ExplorationSpecification; import org.fortiss.af3.exploration.model.ExplorationTarget; import org.fortiss.af3.exploration.moea.model.DseSpecification; -import org.fortiss.af3.exploration.moea.model.feature.SafetyExploration; import org.fortiss.af3.exploration.moea.model.parameters.EAOptimizer; import org.opt4j.core.Individual; import org.opt4j.core.Objective; @@ -64,9 +68,11 @@ import org.opt4j.core.config.Task; import org.opt4j.core.config.TaskStateListener; import org.opt4j.core.optimizer.Archive; import org.opt4j.core.optimizer.Control; +import org.opt4j.core.problem.Decoder; import org.opt4j.optimizers.ea.EvolutionaryAlgorithmModule; import org.opt4j.optimizers.ea.Spea2Module; +import com.google.inject.CreationException; import com.google.inject.Injector; import com.google.inject.Module; @@ -89,7 +95,7 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { * Contains the problem module that includes the evaluators associated with the goals of the * DSE. */ - private ArchitectureExplorationProblemModule archExplorationProblemModule; + private DseProcessProblemModule archExplorationProblemModule; /** * Constructor that initializes the Opt4J backend, and sets optimizer independent parameters @@ -99,8 +105,8 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { */ public Opt4JExplorerBackend(DseSpecification dse, ExplorationSpecification expSpec, Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, Injector dseInjector, - Set<Class<? extends IExplorationEncoding>> requestedSolutions, - IProgressMonitor progressMonitor) throws Exception { + Set<Class<? extends Phenotype>> requestedSolutions, IProgressMonitor progressMonitor) + throws Exception { // Optimizer independent configuration super(dse, expSpec, targetAssocMap, dseInjector, requestedSolutions, progressMonitor); @@ -114,11 +120,12 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { } /** {@inheritDoc} */ - @SuppressWarnings("unchecked") @Override protected void init(EAOptimizer opt4JParameters) { this.opt4JParameters = opt4JParameters; + checkDseProcessExploration(requestedSolutions); + System.out.println("Initializing EA optimizer (generations: " + "" + opt4JParameters.getIterations() + ", alpha: " + opt4JParameters.getAlpha() + ")."); @@ -158,7 +165,7 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { // modules.add(multiEvaluatorModule); archExplorationProblemModule = - new ArchitectureExplorationProblemModule(dse, dseInjector, requestedSolutions); + new DseProcessProblemModule(dse, dseInjector, requestedSolutions); modules.add(archExplorationProblemModule); // Configure operators @@ -174,11 +181,11 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { // ===================================== // Safety functions (if the safety exploration module is enabled) - if(pickFirstInstanceOf(SafetyExploration.class, dse.getFeatures()) != null) { - MutateSafetyFunctionArchitectureModule sfArchModule = - new MutateSafetyFunctionArchitectureModule(); - modules.add(sfArchModule); - } + // if(pickFirstInstanceOf(SafetyExploration.class, dse.getFeatures()) != null) { + // MutateSafetyFunctionArchitectureModule sfArchModule = + // new MutateSafetyFunctionArchitectureModule(); + // modules.add(sfArchModule); + // } // NOP for PlatformCommunicationGraph modules.add(new NopPlatformCommGraphMutateModule()); @@ -241,10 +248,50 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { } /** - * {@inheritDoc} + * Consistency check for the DSE process configuration. + * An {@link Injector} for the decoding phase is setup to check whether the bindings of the + * {@link DecoderModule}s are correct given the current configuration of + * {@link IExplorationFeature}s and the desired result types. + * <p> + * Typical errors that are detected include: + * <ul> + * <li>Circular dependencies</li> + * <li>Two or more {@link DecoderModule}s that provide the same {@link Phenotype}</li> + * </ul> + */ + private void checkDseProcessExploration(Set<Class<? extends Phenotype>> resultTypes) { + Collection<IExplorationFeature> enabledFeatures = + getService(IExplorationFeatureService.class).getExplorationFeatures( + dse.getFeatures()); + Collection<DecoderModule<?>> enabledDecoders = newHashSet(); + enabledFeatures.forEach(f -> enabledDecoders.addAll(f.getDecoders())); + GuiceDecoder guiceDecoder = new GuiceDecoder(resultTypes, enabledDecoders); + buildCheckedDecodingInjector(guiceDecoder); + } + + /** + * Creates an decoding {@link Injector} for the DSE process decoding that throws an + * {@link ExplorationRuntimeException} if the {@link DecoderModule} setup is invalid. * - * @throws Exception + * @param guiceDecoder + * {@link Decoder} installing its sub-decoders. + * @return the {@link Injector} of the DSE process top-most {@link Decoder}. */ + private Injector buildCheckedDecodingInjector(GuiceDecoder guiceDecoder) { + Injector decodingInjector = null; + try { + decodingInjector = dseInjector.createChildInjector(guiceDecoder); + } catch(CreationException e) { + throw new ExplorationRuntimeException( + "Error while configuring the DSE process decoder chain.\n" + + "See the subsequent error message for details. Typical configuration faults include:\n" + + "1) 2 or more decoders attemp to provide the same type.\n" + "2) ...", + e); + } + return decodingInjector; + } + + /** {@inheritDoc} */ @Override public CompositeExplorationSolution<?> explore() throws Exception { @@ -335,6 +382,8 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { return rval; } + /** {@inheritDoc} */ + @Override protected void configure() { bind(Opt4JDseTask.class).toProvider(new Opt4JDseTaskProvider(opt4JTask)); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/.ratings index dfd938348718663eaf587a4b02ccbb856c32e0a4..0662f84aac1368fdd24d97b8ece557150ffdde7b 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/.ratings @@ -1,5 +1,5 @@ -ComposableCreator.java 6d2d61205890a2b0b99f41d2caa4debc511c8b4a RED -ComposableCreatorBase.java e1a898541dd2b480e6c345ad2429bf93393957e6 RED -CompositeCreator.java bb054d281931f461ca67def20360cc767940e204 RED -CompositeCreatorBase.java d897947ff0db02ea1cac4034a4912f9afce283ec RED -GuiceCreator.java d97b10032981b574922d292afd9306a55df351bb RED +ComposableCreator.java 6d2d61205890a2b0b99f41d2caa4debc511c8b4a RED +ComposableCreatorBase.java e1a898541dd2b480e6c345ad2429bf93393957e6 RED +CompositeCreator.java bb054d281931f461ca67def20360cc767940e204 RED +CompositeCreatorBase.java d897947ff0db02ea1cac4034a4912f9afce283ec RED +GuiceCreator.java 3cea3607c0aae0a5ec1365294073d5970e0ab0cf RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/GuiceCreator.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/GuiceCreator.java index d97b10032981b574922d292afd9306a55df351bb..3cea3607c0aae0a5ec1365294073d5970e0ab0cf 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/GuiceCreator.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/create/GuiceCreator.java @@ -15,13 +15,11 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.create; -import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; - import java.util.Collection; +import java.util.Set; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.Opt4JDseTaskProvider; import org.fortiss.af3.exploration.alg.dse.module.CreatorModule; -import org.fortiss.af3.exploration.alg.service.IExplorationModuleService; import org.opt4j.core.Genotype; import org.opt4j.core.genotype.CompositeGenotype; import org.opt4j.core.problem.Creator; @@ -40,7 +38,10 @@ public class GuiceCreator extends AbstractModule implements Creator<CompositeGenotype<Class<? extends Genotype>, ? extends Genotype>> { /** Set of {@link Genotype}-Types for which instances shall be created. */ - private Collection<Class<? extends Genotype>> requiredGenotypes; + private Set<Class<? extends Genotype>> requiredGenotypes; + + /** Set of {@link CreatorModule}s provided by the enabled exploration features. */ + private Collection<CreatorModule<?>> enabledCreators; /** {@link Opt4JTask} provider used to obtain the opt4j injector. */ @Inject @@ -50,8 +51,10 @@ public class GuiceCreator extends AbstractModule implements protected Injector createInjector; /** Constructor. */ - public GuiceCreator(Collection<Class<? extends Genotype>> requiredGenotypes) { + public GuiceCreator(Set<Class<? extends Genotype>> requiredGenotypes, + Collection<CreatorModule<?>> enabledCreators) { this.requiredGenotypes = requiredGenotypes; + this.enabledCreators = enabledCreators; } /** {@inheritDoc} */ @@ -73,7 +76,7 @@ public class GuiceCreator extends AbstractModule implements protected void configure() { // bindScope(ThreadScoped.class, new ThreadScope()); - for(CreatorModule<?> module : getService(IExplorationModuleService.class).getCreators()) { + for(CreatorModule<?> module : enabledCreators) { install(module); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/.ratings index 63f97eac6e193e5ffc234af556bf8e4d8837ea6f..db66ca2fedaecb7d43f0e3f7c2f522d1e35529ad 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/.ratings @@ -1,8 +1,9 @@ -ComposableDecoder.java 0ef247e0e8424968cd8dab8317df0e504c5018d4 RED -ComposableDecoderBase.java 7c47b41e609b6911128efa469c2dd65122276bcc RED -CompositeDecoder.java 68864146cbd7b0d1444d4157cf88023deb4a21ea RED -CompositeDecoderBase.java cc878483ec3dcf3afd60509579c7c17a3433893c RED -GuiceDecoder.java e118048ae4abd7dedc858845cda9bc67e7565835 RED -PhenotypeDecoder.java 042d35c9bcba9a2cddc5e82ca5abe6f52438d1c3 RED -ThreadScope.java f3a2b90fdbf0b2aabde4112c94623da5c262952b RED -ThreadScoped.java a8335b0831586ea6ced17a5e7adf2952b72957d9 RED +ComposableDecoder.java 0ef247e0e8424968cd8dab8317df0e504c5018d4 RED +ComposableDecoderBase.java 7c47b41e609b6911128efa469c2dd65122276bcc RED +CompositeDecoder.java 68864146cbd7b0d1444d4157cf88023deb4a21ea RED +CompositeDecoderBase.java cc878483ec3dcf3afd60509579c7c17a3433893c RED +Genotyped.java c74c870c570597bdb373308fa339ccf2c8e88942 YELLOW +GuiceDecoder.java ed4e3e79d95a7f0ab7f0dfdbf602a06af930c432 RED +PhenotypeDecoder.java 042d35c9bcba9a2cddc5e82ca5abe6f52438d1c3 RED +ThreadScope.java f3a2b90fdbf0b2aabde4112c94623da5c262952b RED +ThreadScoped.java a8335b0831586ea6ced17a5e7adf2952b72957d9 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/Genotyped.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/Genotyped.java new file mode 100644 index 0000000000000000000000000000000000000000..c74c870c570597bdb373308fa339ccf2c8e88942 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/Genotyped.java @@ -0,0 +1,43 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.dse.backend.opt4j.extensions.compositegene.decode; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.opt4j.core.Genotype; +import org.opt4j.core.genotype.CompositeGenotype; + +import com.google.inject.BindingAnnotation; + +/** + * Marker for {@link Genotype}s that are retrieved in decoders. It is intended to be used by + * decoders that require an encoding from a previous iteration, not another decoder. Here, the + * encoding is provided from the {@link CompositeGenotype}. + * + * @author diewald + */ +@BindingAnnotation +@Target({FIELD, PARAMETER, METHOD}) +@Retention(RUNTIME) +public @interface Genotyped { + // Java annotation --> Empty. +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/GuiceDecoder.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/GuiceDecoder.java index e118048ae4abd7dedc858845cda9bc67e7565835..ed4e3e79d95a7f0ab7f0dfdbf602a06af930c432 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/GuiceDecoder.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/GuiceDecoder.java @@ -15,27 +15,29 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.decode; -import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; +import static org.fortiss.tooling.common.util.LambdaUtils.getFirst; +import java.util.Collection; import java.util.Set; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.Opt4JDseTaskProvider; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch.SafetyFunctionArchEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.FailSilentTaskMappingEncoding; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.exception.DecodingRuntimeException; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.graph.GenotypeFinder; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; +import org.fortiss.af3.exploration.alg.dse.module.CreatorModule; import org.fortiss.af3.exploration.alg.dse.module.DecoderModule; -import org.fortiss.af3.exploration.alg.service.IExplorationModuleService; import org.opt4j.core.Genotype; import org.opt4j.core.genotype.CompositeGenotype; import org.opt4j.core.problem.Decoder; import org.opt4j.core.start.Opt4JTask; -import com.google.common.collect.Sets; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provides; +import com.google.inject.name.Named; /** * {@link Decoder} that handles dependencies between {@link Decoder}s, {@link Genotype}s, and @@ -50,7 +52,10 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph /** Defines the desired exploration result type. */ // TODO: Remove this hard coded line and get the desired result from the backend interface. - protected Class<? extends Phenotype> resultType; + protected Set<Class<? extends Phenotype>> resultTypes; + + /** Set of {@link CreatorModule}s provided by the enabled exploration features. */ + private Collection<DecoderModule<?>> enabledDecoders; /** {@link Opt4JTask} provider used to obtain the opt4j injector. */ @Inject @@ -65,8 +70,10 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph new ThreadLocal<>(); /** Constructor. Remembers the demanded {@link Phenotype}ss to be produced. */ - public GuiceDecoder(Class<? extends Phenotype> resultType) { - this.resultType = resultType; + public GuiceDecoder(Set<Class<? extends Phenotype>> resultTypes, + Collection<DecoderModule<?>> enabledDecoders) { + this.resultTypes = resultTypes; + this.enabledDecoders = enabledDecoders; } // To be used later: Constructor injection is favorable. @@ -91,9 +98,8 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph // TODO(AD): See configure(): We need a service machenism and user configuration to select // the desired set of activated decoders. decodingInjector = opt4JProvider.get().get().createChildInjector(this); - GenotypeFinder genotypeFinder = new GenotypeFinder(); - @SuppressWarnings("unused") Set<Class<? extends Genotype>> reqGenotypes = - genotypeFinder.getGenotypesFor(Sets.newHashSet(resultType), decodingInjector); + // FIXME: Hack to get the correct instance: Is multiprovisioning supported by Guice? + Class<? extends Phenotype> resultType = getFirst(resultTypes).get(); decodingInjector.getInstance(resultType); return composedPhenotype; } @@ -116,7 +122,7 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph protected void configure() { // bindScope(ThreadScoped.class, new ThreadScope()); - for(DecoderModule<?> module : getService(IExplorationModuleService.class).getDecoders()) { + for(DecoderModule<?> module : enabledDecoders) { install(module); } } @@ -137,13 +143,24 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph return getGenotype(SafetyFunctionArchEncoding.class); } - // @Provides - // public SafetyFunctionArchEncoding getSFAEnc() { - // return getGenotype(SafetyFunctionArchEncoding.class); - // } - // - // @Provides - // public SafetyFunctionArchEncoding getSFAEnc() { - // return getGenotype(SafetyFunctionArchEncoding.class); - // } + /** + * Returns the {@link AbstractTaskMappingEncoding} sub-{@link Genotype} passed to this decoder. + * (Testing!!!) + */ + @Provides + @Named("Genotyped") + public AbstractTaskMappingEncoding getATMEnc() { + return getGenotype(AbstractTaskMappingEncoding.class); + } + + /** + * Returns the {@link FailSilentTaskMappingEncoding} sub-{@link Genotype} passed to this + * decoder. (Testing!!!) + */ + /** */ + @Provides + @Named("Genotyped") + public FailSilentTaskMappingEncoding getITMEnc() { + return getGenotype(FailSilentTaskMappingEncoding.class); + } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/.ratings index 3c95bb397e2450a6440d5f29f1a527d0efa4af90..564d087f24567c958ca1d63be1b3b76305c2543f 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/.ratings @@ -1,4 +1,5 @@ -DecoderDependencyGraph.java c2d1a8d6c86002c4faea11b6ab822b0d1bef408b RED -DecoderEdge.java b72d75a14a0cf4b7fd7c632951b6d88474a1ba56 RED -GenotypeFinder.java 675edad7a91117ef3df77cde2b48f769c02f707f YELLOW -TransitiveDependencyVisitor.java ecb9b5c57877654e45e0392d6532e8d7a0a8b6e6 YELLOW +BindingWalker.java 77b92051f6a3351cc88a36de9890111ce4df8170 YELLOW +DecoderDependencyGraph.java c2d1a8d6c86002c4faea11b6ab822b0d1bef408b RED +DecoderEdge.java b72d75a14a0cf4b7fd7c632951b6d88474a1ba56 RED +GenotypeFinder.java bc9b7ac2e403a3645bcdd592299438c3c009d027 YELLOW +TypeMemorizingDependencyVisitor.java ed2c9f746e6b4d0079ce3e6c7119117ff68639a9 YELLOW diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/BindingWalker.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/BindingWalker.java new file mode 100644 index 0000000000000000000000000000000000000000..77b92051f6a3351cc88a36de9890111ce4df8170 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/BindingWalker.java @@ -0,0 +1,67 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.dse.backend.opt4j.extensions.compositegene.graph; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.opt4j.core.Genotype; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.google.inject.Binding; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.spi.BindingTargetVisitor; + +/** + * Base class to trigger a walk over the bindings of an {@link Injector} using a specialized + * {@link BindingTargetVisitor} that extracts the relevant information. + * + * @author diewald + */ +public abstract class BindingWalker<T extends BindingTargetVisitor<Object, Collection<Key<?>>>> { + + /** Dependency tree visitor that remembers the visited {@link Genotype} bindings. */ + protected T keyVisitor; + + /** Constructor. */ + public BindingWalker(T keyVisitor) { + this.keyVisitor = keyVisitor; + } + + /** Iterates over the bindings for the root keys and their transitive dependencies. */ + protected void iterateBindings(Injector injector, Set<Key<?>> searchKeys) { + Set<Key<?>> keys = Sets.newHashSet(searchKeys); + Set<Key<?>> visitedKeys = Sets.newHashSet(); + List<Binding<?>> bindings = Lists.newArrayList(); + + while(!keys.isEmpty()) { + Iterator<Key<?>> iterator = keys.iterator(); + Key<?> key = iterator.next(); + iterator.remove(); + + if(!visitedKeys.contains(key)) { + Binding<?> binding = injector.getBinding(key); + bindings.add(binding); + visitedKeys.add(key); + keys.addAll(binding.acceptTargetVisitor(keyVisitor)); + } + } + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/GenotypeFinder.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/GenotypeFinder.java index 675edad7a91117ef3df77cde2b48f769c02f707f..bc9b7ac2e403a3645bcdd592299438c3c009d027 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/GenotypeFinder.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/GenotypeFinder.java @@ -15,17 +15,15 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.graph; +import static com.google.common.collect.Sets.newHashSet; + import java.util.Base64.Decoder; -import java.util.Iterator; -import java.util.List; import java.util.Set; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; import org.opt4j.core.Genotype; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.inject.Binding; import com.google.inject.Injector; import com.google.inject.Key; @@ -38,12 +36,13 @@ import com.google.inject.Key; * * @author diewald */ -public class GenotypeFinder { +public class GenotypeFinder extends BindingWalker<TypeMemorizingDependencyVisitor<Genotype>> { - /** Dependency tree visitor that remembers the visited {@link Genotype} bindings. */ + /** Constructor. */ @SuppressWarnings("unchecked") - private TransitiveDependencyVisitor<Genotype> keyVisitor = new TransitiveDependencyVisitor<>( - Sets.newHashSet(Genotype.class)); + public GenotypeFinder() { + super(new TypeMemorizingDependencyVisitor<>(newHashSet(Genotype.class))); + } /** * Collects the set of {@link Genotype}s that is required to construct the set of given @@ -62,24 +61,4 @@ public class GenotypeFinder { iterateBindings(injector, phenotypeKeys); return keyVisitor.getFoundSubTypes(); } - - /** Iterates over the bindings for the root keys and their transitive dependencies. */ - private void iterateBindings(Injector injector, Set<Key<?>> phenotypeKeys) { - Set<Key<?>> keys = Sets.newHashSet(phenotypeKeys); - Set<Key<?>> visitedKeys = Sets.newHashSet(); - List<Binding<?>> bindings = Lists.newArrayList(); - - while(!keys.isEmpty()) { - Iterator<Key<?>> iterator = keys.iterator(); - Key<?> key = iterator.next(); - iterator.remove(); - - if(!visitedKeys.contains(key)) { - Binding<?> binding = injector.getBinding(key); - bindings.add(binding); - visitedKeys.add(key); - keys.addAll(binding.acceptTargetVisitor(keyVisitor)); - } - } - } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/TransitiveDependencyVisitor.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/TypeMemorizingDependencyVisitor.java similarity index 97% rename from org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/TransitiveDependencyVisitor.java rename to org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/TypeMemorizingDependencyVisitor.java index ecb9b5c57877654e45e0392d6532e8d7a0a8b6e6..ed2c9f746e6b4d0079ce3e6c7119117ff68639a9 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/TransitiveDependencyVisitor.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/graph/TypeMemorizingDependencyVisitor.java @@ -47,7 +47,7 @@ import com.google.inject.spi.ProviderKeyBinding; * @author phopkins@gmail.com (Pete Hopkins) * @author diewald@fortiss.org (Alexander Diewald) */ -public class TransitiveDependencyVisitor<G> extends +public class TypeMemorizingDependencyVisitor<G> extends DefaultBindingTargetVisitor<Object, Collection<Key<?>>> { /** @@ -60,7 +60,7 @@ public class TransitiveDependencyVisitor<G> extends private Collection<Class<?>> seekTypes = Sets.newHashSet(); /** Constructor. */ - public TransitiveDependencyVisitor(Collection<Class<?>> seekTypes) { + public TypeMemorizingDependencyVisitor(Collection<Class<?>> seekTypes) { this.seekTypes = seekTypes; } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/.ratings index 135c19b0600cc66ceff84cf4cfc5655a88a6e4b2..2219771a712bf1c6483769e4016ad115ad5d7fd3 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/.ratings @@ -1,7 +1,7 @@ -ArchitectureDecoder.java d067dc995e0895860d98d717647c0f7b061f5908 RED -ArchitectureExplorationProblemModule.java a856314dfb6f0b4e3a0f7af28fcede66563dac74 RED -DseProblemModuleBase.java 0eba41852529e92e7255c7a7d8fce18354facbca RED -EvaluatorWrapper.java 3747e5b78b1dcef8e1595c1ae9354e8ef2738e79 RED -ExplorationGoalPriorityMultiEvaluator.java 1f6d2aa6ece8acdf4f57face0439f3429ab87329 RED -ProblemModuleBase.java 460f7a8a07435eb13634caa9072e425bdf20e399 RED -StrictTTDecoder.java d55ece0076bec24d74fd18dae3e33aaa9d2ac854 RED +ArchitectureDecoder.java d067dc995e0895860d98d717647c0f7b061f5908 RED +DseProblemModuleBase.java bfe6dadc48386308ccbf40dbb0da18f74e43a986 RED +DseProcessProblemModule.java c7f76c9926e6d49c058fe550ac8d0b31bd6b4d30 RED +EvaluatorWrapper.java 3747e5b78b1dcef8e1595c1ae9354e8ef2738e79 RED +ExplorationGoalPriorityMultiEvaluator.java 1f6d2aa6ece8acdf4f57face0439f3429ab87329 RED +ProblemModuleBase.java 460f7a8a07435eb13634caa9072e425bdf20e399 RED +StrictTTDecoder.java d55ece0076bec24d74fd18dae3e33aaa9d2ac854 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProblemModuleBase.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProblemModuleBase.java index 75c5c2a3d3369be817573af006ec6f35cf7089d0..bfe6dadc48386308ccbf40dbb0da18f74e43a986 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProblemModuleBase.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProblemModuleBase.java @@ -1,201 +1,200 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2015 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.alg.dse.backend.opt4j.problem; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import org.fortiss.af3.exploration.alg.dse.TaskMappingFactory; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.decode.CompositeDecoder; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.evaluate.ComposableEvaluator; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.evaluate.CompositeEvaluator; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.genotype.ComposableGenotype; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.problem.CompositeProblemModuleBase; -import org.fortiss.af3.exploration.alg.dse.evaluator.ArchitectureEvaluator; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; -import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; -import org.fortiss.af3.exploration.model.ExplorationConstraint; -import org.fortiss.af3.exploration.model.ExplorationObjective; -import org.fortiss.af3.exploration.model.ExplorationTarget; -import org.fortiss.af3.exploration.model.MOExplorationObjective; -import org.fortiss.af3.exploration.moea.model.DseSpecification; -import org.fortiss.af3.exploration.smt.model.SMTObjective; -import org.opt4j.core.Objective; -import org.opt4j.core.genotype.CompositeGenotype; -import org.opt4j.core.problem.Evaluator; - -/** - * Base class for problems that are solved within this DSE. It allows to create - * {@link EvaluatorWrapper}s which associate {@link ExplorationTarget}s with {@link Evaluator}s of - * possible solutions to the problem that shall be solved by the DSE. - * - * @author diewald - */ -public abstract class DseProblemModuleBase<C extends CompositeGenotype<Class<? extends ComposableGenotype>, ComposableGenotype>, P extends Phenotype, CD extends CompositeDecoder<C, P>> - extends CompositeProblemModuleBase<C, P, CD> { - - /** DSE configuration */ - protected DseSpecification dse; - - /** Representation of input system */ - // TODO(#3270) - protected SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter; - - /** Set of requested {@link Phenotype}s that form the solution set. */ - Set<Class<? extends IExplorationEncoding>> requestedSolutions; - - /** - * Constructor the DSE specification and an adapter to the input system model has to be - * specified. - */ - public DseProblemModuleBase(DseSpecification dse, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, - Set<Class<? extends IExplorationEncoding>> requestedSolutions) { - this.dse = dse; - this.systemModelAdapter = systemModelAdapter; - this.requestedSolutions = requestedSolutions; - } - - /** - * Adds the evaluators of the sub problems of the architectural exploration. - * - * @throws Exception - */ - protected <RT, T extends ExplorationTarget<RT>, S extends Phenotype, E extends Evaluator<?>> - void addGoalEvaluators(CompositeEvaluator<P> dseEvaluator) throws Exception { - Collection<ExplorationTarget<?>> targets = dse.getTargetSpecification().getTargets(); - Collection<ExplorationConstraint<?>> constraints = - targets.stream().filter(t -> t instanceof ExplorationConstraint<?>) - .map(ExplorationConstraint.class::cast).collect(Collectors.toList()); - - int currentConstrPrio = 0; - Map<Class<? extends ExplorationTarget<?>>, Integer> priorityMap = new LinkedHashMap<>(); - for(ExplorationConstraint<?> currConstraint : constraints) { - if(!priorityMap.containsKey(currConstraint.getClass())) { - @SuppressWarnings("unchecked") Class<? extends ExplorationTarget<?>> contraintType = - (Class<? extends ExplorationTarget<?>>)currConstraint.getClass(); - priorityMap.put(contraintType, currentConstrPrio); - currentConstrPrio++; - } - } - - Collection<ExplorationObjective<?>> smtObjectives = - targets.stream().filter(t -> t instanceof SMTObjective) - .map(ExplorationObjective.class::cast).collect(Collectors.toList()); - for(ExplorationObjective<?> currObjective : smtObjectives) { - if(!priorityMap.containsKey(currObjective.getClass())) { - @SuppressWarnings("unchecked") Class<? extends ExplorationTarget<?>> objectiveType = - (Class<? extends ExplorationTarget<?>>)currObjective.getClass(); - priorityMap.put(objectiveType, currentConstrPrio); - currentConstrPrio++; - } - } - - int objectivePrioOffset = currentConstrPrio; - Collection<ExplorationObjective<?>> objectives = - targets.stream().filter(t -> t instanceof ExplorationObjective<?>) - .map(ExplorationObjective.class::cast).collect(Collectors.toList()); - for(ExplorationObjective<?> currObjective : objectives) { - if(MOExplorationObjective.class.isAssignableFrom(currObjective.getClass())) { - if(!priorityMap.containsKey(currObjective.getClass())) { - int objPrio = ((MOExplorationObjective<?>)currObjective).getPriority(); - @SuppressWarnings("unchecked") Class<? extends ExplorationTarget<?>> objectiveType = - (Class<? extends ExplorationTarget<?>>)currObjective.getClass(); - priorityMap.put(objectiveType, objectivePrioOffset + objPrio); - } - } /* - * else { - * throw new IllegalClassException( - * "Objectives that are not MOExplorationObjectives are currently not supported by this backend." - * ); - * } - */ - } - - for(ExplorationTarget<?> target : targets) { - @SuppressWarnings({"cast", "unchecked"}) EvaluatorWrapper<?, RT, T> evalWrapper = - (EvaluatorWrapper<?, RT, T>)addGoalEvaluator(dseEvaluator, (T)target, - priorityMap.get(target.getClass())); - Objective evalObjective = evalWrapper.getObjective(); - targetObjectiveAssoc.put(target, evalObjective); - } - } - - /** - * Adds an goal-specific {@link EvaluatorWrapper} to the {@link ArchitectureEvaluator}. - * - * @throws Exception - */ - protected - <RT, T extends ExplorationTarget<RT>, S extends Phenotype, E extends ComposableEvaluator<S>> - EvaluatorWrapper<?, RT, T> addGoalEvaluator(CompositeEvaluator<P> dseEvaluator, T goal, - int priority) throws Exception { - @SuppressWarnings("unchecked") EvaluatorWrapper<?, RT, T> wrappedEvaluator = - (EvaluatorWrapper<?, RT, T>)TaskMappingFactory.getInstance() - .createEvaluatorWrapper(goal, priority); - if(wrappedEvaluator != null) { - // Here, we check whether the goal evaluator is defined for composable phenotypes (only - // composable evaluators are allowed then). - if(Phenotype.class.isAssignableFrom(wrappedEvaluator.getTargetPhenotypeType())) { - - Class<?> phenotypeClass = wrappedEvaluator.getTargetPhenotypeType(); - - if(Phenotype.class.isAssignableFrom(phenotypeClass)) { - // if(phenoClass.isAssignableFrom(phenotypeClass) && - // evalClass.isAssignableFrom(wrappedEvaluator.getClass())) { - @SuppressWarnings("unchecked") Class<S> subPhenotypeClass = - (Class<S>)phenotypeClass; - @SuppressWarnings("unchecked") E wrappedSubEvaluator = (E)wrappedEvaluator; - - try { - dseEvaluator.registerSubEvaluator(subPhenotypeClass, wrappedSubEvaluator); - } catch(Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // Register the wrapped Evaluator, - registerEvaluator(wrappedEvaluator); - // } - // else { - // throw new IllegalArgumentException("The sub-phenotye class " + - // phenotypeClass + " and the evaluator class " + - // wrappedEvaluator.getClass() + " does not match the classes " + - // phenoClass + " and " + evalClass + " used to describe the problem."); - // } - } else { - throw new Exception(); - } - } else if(!(Phenotype.class.isAssignableFrom(wrappedEvaluator.getTargetPhenotypeType()))) { - // Otherwise, a "simple" goal evaluator is created - addEvaluator(wrappedEvaluator); - } else { - throw new Exception(); - } - } else { - // TODO: Evaluate, if the optimization should stop here, i.e. throw an exception or - // similar (if possible). - System.out.println("Could not instantiate an evaluator for goal of dimension \"" + - goal.getName() + "\". Skipping."); - return null; - } - - return wrappedEvaluator; - } -} +/*-------------------------------------------------------------------------+ +| Copyright 2015 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.alg.dse.backend.opt4j.problem; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.fortiss.af3.exploration.alg.dse.TaskMappingFactory; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.decode.CompositeDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.evaluate.ComposableEvaluator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.evaluate.CompositeEvaluator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.genotype.ComposableGenotype; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.problem.CompositeProblemModuleBase; +import org.fortiss.af3.exploration.alg.dse.evaluator.ArchitectureEvaluator; +import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; +import org.fortiss.af3.exploration.model.ExplorationConstraint; +import org.fortiss.af3.exploration.model.ExplorationObjective; +import org.fortiss.af3.exploration.model.ExplorationTarget; +import org.fortiss.af3.exploration.model.MOExplorationObjective; +import org.fortiss.af3.exploration.moea.model.DseSpecification; +import org.fortiss.af3.exploration.smt.model.SMTObjective; +import org.opt4j.core.Objective; +import org.opt4j.core.genotype.CompositeGenotype; +import org.opt4j.core.problem.Evaluator; + +/** + * Base class for problems that are solved within this DSE. It allows to create + * {@link EvaluatorWrapper}s which associate {@link ExplorationTarget}s with {@link Evaluator}s of + * possible solutions to the problem that shall be solved by the DSE. + * + * @author diewald + */ +public abstract class DseProblemModuleBase<C extends CompositeGenotype<Class<? extends ComposableGenotype>, ComposableGenotype>, P extends Phenotype, CD extends CompositeDecoder<C, P>> + extends CompositeProblemModuleBase<C, P, CD> { + + /** DSE configuration */ + protected DseSpecification dse; + + /** Representation of input system */ + // TODO(#3270) + protected SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter; + + /** Set of requested {@link Phenotype}s that form the solution set. */ + protected Set<Class<? extends Phenotype>> requestedSolutions; + + /** + * Constructor the DSE specification and an adapter to the input system model has to be + * specified. + */ + public DseProblemModuleBase(DseSpecification dse, + SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, + Set<Class<? extends Phenotype>> requestedSolutions) { + this.dse = dse; + this.systemModelAdapter = systemModelAdapter; + this.requestedSolutions = requestedSolutions; + } + + /** + * Adds the evaluators of the sub problems of the architectural exploration. + * + * @throws Exception + */ + protected <RT, T extends ExplorationTarget<RT>, S extends Phenotype, E extends Evaluator<?>> + void addGoalEvaluators(CompositeEvaluator<P> dseEvaluator) throws Exception { + Collection<ExplorationTarget<?>> targets = dse.getTargetSpecification().getTargets(); + Collection<ExplorationConstraint<?>> constraints = + targets.stream().filter(t -> t instanceof ExplorationConstraint<?>) + .map(ExplorationConstraint.class::cast).collect(Collectors.toList()); + + int currentConstrPrio = 0; + Map<Class<? extends ExplorationTarget<?>>, Integer> priorityMap = new LinkedHashMap<>(); + for(ExplorationConstraint<?> currConstraint : constraints) { + if(!priorityMap.containsKey(currConstraint.getClass())) { + @SuppressWarnings("unchecked") Class<? extends ExplorationTarget<?>> contraintType = + (Class<? extends ExplorationTarget<?>>)currConstraint.getClass(); + priorityMap.put(contraintType, currentConstrPrio); + currentConstrPrio++; + } + } + + Collection<ExplorationObjective<?>> smtObjectives = + targets.stream().filter(t -> t instanceof SMTObjective) + .map(ExplorationObjective.class::cast).collect(Collectors.toList()); + for(ExplorationObjective<?> currObjective : smtObjectives) { + if(!priorityMap.containsKey(currObjective.getClass())) { + @SuppressWarnings("unchecked") Class<? extends ExplorationTarget<?>> objectiveType = + (Class<? extends ExplorationTarget<?>>)currObjective.getClass(); + priorityMap.put(objectiveType, currentConstrPrio); + currentConstrPrio++; + } + } + + int objectivePrioOffset = currentConstrPrio; + Collection<ExplorationObjective<?>> objectives = + targets.stream().filter(t -> t instanceof ExplorationObjective<?>) + .map(ExplorationObjective.class::cast).collect(Collectors.toList()); + for(ExplorationObjective<?> currObjective : objectives) { + if(MOExplorationObjective.class.isAssignableFrom(currObjective.getClass())) { + if(!priorityMap.containsKey(currObjective.getClass())) { + int objPrio = ((MOExplorationObjective<?>)currObjective).getPriority(); + @SuppressWarnings("unchecked") Class<? extends ExplorationTarget<?>> objectiveType = + (Class<? extends ExplorationTarget<?>>)currObjective.getClass(); + priorityMap.put(objectiveType, objectivePrioOffset + objPrio); + } + } /* + * else { + * throw new IllegalClassException( + * "Objectives that are not MOExplorationObjectives are currently not supported by this backend." + * ); + * } + */ + } + + for(ExplorationTarget<?> target : targets) { + @SuppressWarnings({"cast", "unchecked"}) EvaluatorWrapper<?, RT, T> evalWrapper = + (EvaluatorWrapper<?, RT, T>)addGoalEvaluator(dseEvaluator, (T)target, + priorityMap.get(target.getClass())); + Objective evalObjective = evalWrapper.getObjective(); + targetObjectiveAssoc.put(target, evalObjective); + } + } + + /** + * Adds an goal-specific {@link EvaluatorWrapper} to the {@link ArchitectureEvaluator}. + * + * @throws Exception + */ + protected + <RT, T extends ExplorationTarget<RT>, S extends Phenotype, E extends ComposableEvaluator<S>> + EvaluatorWrapper<?, RT, T> addGoalEvaluator(CompositeEvaluator<P> dseEvaluator, T goal, + int priority) throws Exception { + @SuppressWarnings("unchecked") EvaluatorWrapper<?, RT, T> wrappedEvaluator = + (EvaluatorWrapper<?, RT, T>)TaskMappingFactory.getInstance() + .createEvaluatorWrapper(goal, priority); + if(wrappedEvaluator != null) { + // Here, we check whether the goal evaluator is defined for composable phenotypes (only + // composable evaluators are allowed then). + if(Phenotype.class.isAssignableFrom(wrappedEvaluator.getTargetPhenotypeType())) { + + Class<?> phenotypeClass = wrappedEvaluator.getTargetPhenotypeType(); + + if(Phenotype.class.isAssignableFrom(phenotypeClass)) { + // if(phenoClass.isAssignableFrom(phenotypeClass) && + // evalClass.isAssignableFrom(wrappedEvaluator.getClass())) { + @SuppressWarnings("unchecked") Class<S> subPhenotypeClass = + (Class<S>)phenotypeClass; + @SuppressWarnings("unchecked") E wrappedSubEvaluator = (E)wrappedEvaluator; + + try { + dseEvaluator.registerSubEvaluator(subPhenotypeClass, wrappedSubEvaluator); + } catch(Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // Register the wrapped Evaluator, + registerEvaluator(wrappedEvaluator); + // } + // else { + // throw new IllegalArgumentException("The sub-phenotye class " + + // phenotypeClass + " and the evaluator class " + + // wrappedEvaluator.getClass() + " does not match the classes " + + // phenoClass + " and " + evalClass + " used to describe the problem."); + // } + } else { + throw new Exception(); + } + } else if(!(Phenotype.class.isAssignableFrom(wrappedEvaluator.getTargetPhenotypeType()))) { + // Otherwise, a "simple" goal evaluator is created + addEvaluator(wrappedEvaluator); + } else { + throw new Exception(); + } + } else { + // TODO: Evaluate, if the optimization should stop here, i.e. throw an exception or + // similar (if possible). + System.out.println("Could not instantiate an evaluator for goal of dimension \"" + + goal.getName() + "\". Skipping."); + return null; + } + + return wrappedEvaluator; + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/ArchitectureExplorationProblemModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProcessProblemModule.java similarity index 65% rename from org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/ArchitectureExplorationProblemModule.java rename to org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProcessProblemModule.java index a856314dfb6f0b4e3a0f7af28fcede66563dac74..c7f76c9926e6d49c058fe550ac8d0b31bd6b4d30 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/ArchitectureExplorationProblemModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/DseProcessProblemModule.java @@ -16,6 +16,7 @@ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem; import static com.google.common.collect.Sets.newHashSet; +import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; import static org.fortiss.af3.exploration.alg.util.ExplorationAlgUtils.rethrow; import java.util.Collection; @@ -23,45 +24,53 @@ import java.util.Set; import org.fortiss.af3.exploration.alg.dse.DSEFactory; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.ArchitectureExplorationEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.FailSilentTaskMappingEncoding; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.create.GuiceCreator; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.decode.GuiceDecoder; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.graph.GenotypeFinder; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.ArchitectureSolution; import org.fortiss.af3.exploration.alg.dse.evaluator.ArchitectureEvaluator; -import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; +import org.fortiss.af3.exploration.alg.dse.module.CreatorModule; +import org.fortiss.af3.exploration.alg.dse.module.DecoderModule; +import org.fortiss.af3.exploration.alg.feature.IExplorationFeature; +import org.fortiss.af3.exploration.alg.service.IExplorationFeatureService; import org.fortiss.af3.exploration.moea.model.DseSpecification; import org.opt4j.core.Genotype; +import org.opt4j.core.problem.Creator; +import org.opt4j.core.problem.Decoder; +import org.opt4j.core.problem.Evaluator; import com.google.inject.Injector; /** - * Problem module for fail-silent execution model, that encapsulates a creator, a decoder and - * the set of goal-specific evaluators. + * Problem module that setups the main control entities constituting the DSE process exploration. It + * defines the top-most {@link Creator}s, {@link Decoder}s, and {@link Evaluator}s, which consists + * of sub-modules. Moreover, this class calculates the set of required decoders to be launched on + * the basis of the activated {@link IExplorationFeature}s and the demanded solutions. * - * @author huang + * @author diewald */ -public class ArchitectureExplorationProblemModule +public class DseProcessProblemModule extends DseProblemModuleBase<ArchitectureExplorationEncoding, ArchitectureSolution, ArchitectureDecoder> { /** To be removed. */ - DSEFactory dseFactory = DSEFactory.getInstance(); + private DSEFactory dseFactory = DSEFactory.getInstance(); /** Reference to the DSE-wide {@link Injector} to allow access to the system model parameters. */ private Injector dseInjector; /** Constructor. */ - public ArchitectureExplorationProblemModule(DseSpecification dse, Injector dseInjector, - Set<Class<? extends IExplorationEncoding>> requestedSolutions) { + public DseProcessProblemModule(DseSpecification dse, Injector dseInjector, + Set<Class<? extends Phenotype>> requestedSolutions) { super(dse, null, requestedSolutions); this.dseInjector = dseInjector; dseFactory.init(null); } /** - * Configure genotype creator (execution model dependent), problem decoder and goal evaluators. + * Configure {@link Genotype} creator (execution model dependent), problem decoder and goal + * evaluators. */ @Override protected void config() { @@ -74,16 +83,23 @@ public class ArchitectureExplorationProblemModule ArchitectureEvaluator archEvaluator = dseFactory.createArchitectureEvaluator(); + Collection<IExplorationFeature> enabledFeatures = + getService(IExplorationFeatureService.class).getExplorationFeatures( + dse.getFeatures()); + Collection<CreatorModule<?>> enabledCreators = newHashSet(); + enabledFeatures.forEach(f -> enabledCreators.addAll(f.getCreators())); + Collection<DecoderModule<?>> enabledDecoders = newHashSet(); + enabledFeatures.forEach(f -> enabledDecoders.addAll(f.getDecoders())); + // TODO: construct the execution dependency graph elsewhere? // bindProblem(dseFactory.createArchitectureExplorationCreator(), // dseFactory.createArchitectureDecoder(execDepGraph), archEvaluator); - Class<? extends Phenotype> resultType = FailSilentTaskMappingEncoding.class; - GuiceDecoder guiceDecoder = new GuiceDecoder(resultType); - Collection<Class<? extends Genotype>> requiredGenotypes = - findRequiredGenotypes(resultType, guiceDecoder); - bindProblem(new GuiceCreator(requiredGenotypes), new GuiceDecoder(resultType), - archEvaluator); + GuiceDecoder guiceDecoder = new GuiceDecoder(requestedSolutions, enabledDecoders); + + Set<Class<? extends Genotype>> requiredGenotypes = findRequiredGenotypes(guiceDecoder); + bindProblem(new GuiceCreator(requiredGenotypes, enabledCreators), new GuiceDecoder( + requestedSolutions, enabledDecoders), archEvaluator); // Create/Bind the subproblems of the architectural exploration problem. try { @@ -106,11 +122,9 @@ public class ArchitectureExplorationProblemModule * Returns the collection of {@link Genotype}s that are required as inputs to decoders to obtain * the requested {@link Phenotype}. */ - @SuppressWarnings("unchecked") - private Collection<Class<? extends Genotype>> findRequiredGenotypes( - Class<? extends Phenotype> resultType, GuiceDecoder guiceDecoder) { + private Set<Class<? extends Genotype>> findRequiredGenotypes(GuiceDecoder guiceDecoder) { Injector decodingInjector = dseInjector.createChildInjector(guiceDecoder); GenotypeFinder genotypeFinder = new GenotypeFinder(); - return genotypeFinder.getGenotypesFor(newHashSet(resultType), decodingInjector); + return genotypeFinder.getGenotypesFor(requestedSolutions, decodingInjector); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/.ratings index 9d13ec3c482d870dc214771346492d62bcff9039..8ad342ed64a92c2185c612d9f7800dd71012757b 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/.ratings @@ -1,3 +1,3 @@ SFGraphDecoder.java 0b42b83465213eb13ae59765f6bf53c1c8bd3b66 RED SFMappingConstraintDecoder.java 01e8f450a78ffff9572a7f203b3699cff507e99f RED -SFMappingDecoder.java 8d890da23b7dab19ff11163a79f9ba6a2c0a9a3c RED +SFMappingDecoder.java 689365b0718847258decd9f20f3cca5b0ff3c6e3 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/SFMappingDecoder.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/SFMappingDecoder.java index 8d890da23b7dab19ff11163a79f9ba6a2c0a9a3c..689365b0718847258decd9f20f3cca5b0ff3c6e3 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/SFMappingDecoder.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/safetyfunction/SFMappingDecoder.java @@ -38,6 +38,7 @@ import org.fortiss.af3.exploration.alg.exception.ExplorationException; import org.opt4j.core.Genotype; import com.google.inject.Provides; +import com.google.inject.name.Named; /** * Decodes a {@link SafetyFunctionArchEncoding} into an {@link AbstractTaskMappingEncoding}. @@ -47,15 +48,36 @@ import com.google.inject.Provides; public class SFMappingDecoder<C> extends DecoderModule<AbstractTaskMappingEncoding> implements ConstraintGenerationDecoder { + /** {@inheritDoc} */ + @Override + protected void configure() { + // TODO: Check whether overriding is a reasonable approach to interchange decoders. + // Modules.override(AbstractTaskMappingIdentityDecoder()). + } + /** {@inheritDoc} */ @Override public AbstractTaskMappingEncoding decode(Genotype genotype) { return null; } + /** + * Decodes a {@link SafetyFunctionArchEncoding} into an {@link AbstractTaskMappingEncoding} + * where allocations are added or removed such that all Tasks of the (replicated) safety + * channels and their voters are mapped to the target platform. To calculate these updates, the + * {@link AbstractTaskMappingEncoding} from a previous iteration is required. + * + * @param sfaEnc + * Encoding of the architectures of safety functions present in the system. + * @param atmEnc + * Mapping of tasks to the target execution platform. + * @return Updated / Aligned task mapping. + * @throws DecodingException + * if the creation of some mapping entry fails. + */ @Provides public AbstractTaskMappingEncoding decode(SafetyFunctionArchEncoding sfaEnc, - AbstractTaskMappingEncoding atmEnc) throws DecodingException { + @Named("Genotyped") AbstractTaskMappingEncoding atmEnc) throws DecodingException { // TODO: replace with a dynamic mechanism for the retrieval of deployable components. for(SafetyFunctionArchEntry sFAEntry : sfaEnc.getAllEntries()) { diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/.ratings index b31ab89928f4e8b7789d3847eec8a4601a436b2d..8ba618a6fbf94673f7728db83453674bb8844b21 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/.ratings @@ -1,2 +1,2 @@ -AbstractTaskMappingIdentityDecoder.java 78febd451216d4635c565b352c4c9e895334ff2f RED +AbstractTaskMappingIdentityDecoder.java 88806dc773c1f8c5fdc899b119bd99d06087e835 RED TaskMappingDecoderBase.java 38993e58fbb58bb577827079cacf04d487670713 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/AbstractTaskMappingIdentityDecoder.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/AbstractTaskMappingIdentityDecoder.java index 78febd451216d4635c565b352c4c9e895334ff2f..88806dc773c1f8c5fdc899b119bd99d06087e835 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/AbstractTaskMappingIdentityDecoder.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/AbstractTaskMappingIdentityDecoder.java @@ -22,6 +22,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegen import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; import org.opt4j.core.Genotype; +import com.google.inject.Provides; + /** * Provides a {@link AbstractTaskMappingEncoding} to the set of {@link Phenotype} types. * This {@link ComposableDecoder} is an identity operation. @@ -35,6 +37,7 @@ public class AbstractTaskMappingIdentityDecoder extends TaskMappingDecoderBase<AbstractTaskMappingEntry, AbstractTaskMappingEncoding> { // FIXME: Update the mapping. --> Provides + @Provides public AbstractTaskMappingEncoding decode(AbstractTaskMappingEncoding atmEnc, PartitionMappingEncoding partEnc) { return alignWithResourceModifications(atmEnc, partEnc); diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/.ratings index 04941aa3c53d2f7ab0ed33f06c8c5f61f857a269..68dd117fb9ff9d15bf0b66dc12da9ab766263cb0 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/.ratings @@ -1,3 +1,3 @@ -FailSilentAbstractTaskMappingDecoder.java 40acf470cbc4f47ca0593e75a2aa060d67b04db4 RED +FailSilentAbstractTaskMappingDecoder.java 4ef8ebd557e31ad61fa0e90df06434c98e121452 RED FaultDetectionVotingAbstractTaskMappingDecoder.java fe6777288a89b1ca3e5eaf842653fbc768016a08 RED TaskInstanceResourceAlignmentDecoder.java 8567290ebc74927263f5265f44d7acdcbf99797f RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/FailSilentAbstractTaskMappingDecoder.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/FailSilentAbstractTaskMappingDecoder.java index 40acf470cbc4f47ca0593e75a2aa060d67b04db4..4ef8ebd557e31ad61fa0e90df06434c98e121452 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/FailSilentAbstractTaskMappingDecoder.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/problem/taskmapping/instantiate/FailSilentAbstractTaskMappingDecoder.java @@ -29,6 +29,7 @@ import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; import org.opt4j.core.Genotype; import com.google.inject.Provides; +import com.google.inject.name.Named; /** * Decoder for instantiating an {@link AbstractTaskMappingEncoding} to a @@ -42,9 +43,20 @@ public class FailSilentAbstractTaskMappingDecoder extends // TODO: Abstract to the AbstractTaskMappingDecoder. // FIXME: Handle the case where no previous FailSilentTaskMappingEncoding exists. + /** + * Decodes an {@link AbstractTaskMappingEncoding} into a {@link FailSilentTaskMappingEncoding} + * by instantiating abstract tasks. If a {@link FailSilentTaskMappingEncoding} exists from a + * previous iteration, this encoding is updated. + * + * @param atmEnc + * task mapping that contains potentially abstract tasks (no implementation). + * @param fstmEnc + * task mapping that shall contain only tasks backed by an implementation. + * @return task mapping that contains only tasks backed by an implementation. + */ @Provides public FailSilentTaskMappingEncoding decode(AbstractTaskMappingEncoding atmEnc, - FailSilentTaskMappingEncoding fstmEnc) { + @Named("Genotyped") FailSilentTaskMappingEncoding fstmEnc) { fstmEnc.replaceConstraints(atmEnc.getConstraints()); for(ITaskAdapter<?> comp : atmEnc.getRequesters()) { diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..a32aa1c150ba06dd1fdba0d8b1b4ef4af90cba05 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/.ratings @@ -0,0 +1,7 @@ +DesignDiversityExploration.java 7769f449def9cc3cb147da5e1991074bc2669c8a RED +ExplorationFeature.java 9e077fed7f0485f1ccaa2b5b4d0407161ec787ca YELLOW +IExplorationFeature.java f0057888990fb5c35e7e97c5d74b7f22d09eabe9 YELLOW +PartitionArchitectureExploration.java 61ea586e3acade91d3c9cc0d37a349e0bb26b3af YELLOW +SafetyArchitectureExploration.java 89a5c8c5e42c8c55857699ba7d2503e6342cd401 RED +TTScheduleExploration.java 9d7e6b4eea4030881006fa85f0be4cb584383b09 RED +TaskMappingExploration.java a548b4757ad6560c3ae640f956910f83fd77b1e1 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/DesignDiversityExploration.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/DesignDiversityExploration.java new file mode 100644 index 0000000000000000000000000000000000000000..7769f449def9cc3cb147da5e1991074bc2669c8a --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/DesignDiversityExploration.java @@ -0,0 +1,37 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.feature; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.InstantiatedAcyclicTaskGraphEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.InstantiatedTaskGraphEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.instantiatetaskgraph.InstantiatedTaskMappingDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.instantiatetaskgraph.InstantiatedTaskMappingDecoderAcyclic; + +/** + * + * @author diewald + */ +public class DesignDiversityExploration extends ExplorationFeature { + + /** Constructor. */ + public DesignDiversityExploration() { + super("Exploration of diversely designed tasks"); + + addProblem(InstantiatedTaskGraphEncoding.class, new InstantiatedTaskMappingDecoder()); + addProblem(InstantiatedAcyclicTaskGraphEncoding.class, + new InstantiatedTaskMappingDecoderAcyclic()); + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/ExplorationModuleService.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/ExplorationFeature.java similarity index 53% rename from org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/ExplorationModuleService.java rename to org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/ExplorationFeature.java index c3ae40f2c20e38c7aa7a3f24a9ace41b59e421d3..9e077fed7f0485f1ccaa2b5b4d0407161ec787ca 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/ExplorationModuleService.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/ExplorationFeature.java @@ -13,9 +13,8 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.af3.exploration.alg.service.internal; +package org.fortiss.af3.exploration.alg.feature; -import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -24,11 +23,9 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegen import org.fortiss.af3.exploration.alg.dse.module.CreatorModule; import org.fortiss.af3.exploration.alg.dse.module.DecoderModule; import org.fortiss.af3.exploration.alg.dse.module.EvaluatorModule; -import org.fortiss.af3.exploration.alg.exception.ExplorationServiceRuntimeException; -import org.fortiss.af3.exploration.alg.service.IExplorationModuleService; -import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; -import org.fortiss.tooling.kernel.introspection.IIntrospectionItem; +import org.fortiss.af3.exploration.alg.service.IExplorationFeatureService; import org.opt4j.core.Genotype; +import org.opt4j.core.problem.Creator; import org.opt4j.core.problem.Decoder; import org.opt4j.operators.OperatorModule; @@ -37,78 +34,68 @@ import com.google.common.collect.MutableClassToInstanceMap; import com.google.inject.AbstractModule; /** - * Implementation of the {@link IExplorationModuleService}. + * Implementation of the {@link IExplorationFeatureService}. * * @author diewald */ -public class ExplorationModuleService implements IExplorationModuleService { +public abstract class ExplorationFeature implements IExplorationFeature { + + /** Name of the {@link IExplorationFeature}. */ + private String name; /** Set referencing all registered optimization variables. */ + // TODO: Do we really need sets here (leftover) or is a single genotype sufficient for + // exploration features. private Set<Class<? extends Genotype>> genotypes = new HashSet<>(); /** Set referencing all register candidate solution types. */ private Set<Class<? extends Phenotype>> phenotypes = new HashSet<>(); /** - * References all registered exploration modules. Differing between {@link Genotype}s, + * References all registered exploration modules. Differing between {@link Creator}s, * {@link Decoder}s etc. is currently not needed. */ private ClassToInstanceMap<AbstractModule> registeredExpModules = MutableClassToInstanceMap .create(); - /** Holds the instance of the evaluation service. */ - private volatile static ExplorationModuleService INSTANCE; - /** Constructor. */ - private ExplorationModuleService() { - // Prevent direct instantiation. - } - - /** The instance (singleton) of the ExplorationTransformationService. */ - public static synchronized ExplorationModuleService getInstance() { - if(INSTANCE == null) { - INSTANCE = new ExplorationModuleService(); - } - return INSTANCE; + public ExplorationFeature(String name) { + this.name = name; } - /** {@inheritDoc} */ - @Override - public void initializeService() { - // Typically used to read extension point configs. Not needed since we won't use eclipse - // extension points in the DSE any more. - } - - /** {@inheritDoc} */ - @Override - public void startService() { - // Not needed. - } - - /** {@inheritDoc} */ - @Override - public <G extends Genotype> void registerVariable(Class<G> genotype, CreatorModule<G> creator, + /** + * Registers an optimization variable ({@code genotype}) with the DSE, along with its + * initializer ({@code creator}) and modificator ({@code operator}). + * + * @param genotype + * optimization variable type. + * @param creator + * initializes the opt. variable. + * @param operator + * modifications applied during the process iterations. + */ + public <G extends Genotype> void addVariable(Class<G> genotype, CreatorModule<G> creator, OperatorModule<?> operator) { // Input check: Allow only fully specified variable registrations. if(genotype == null) { - throw new ExplorationServiceRuntimeException(getClass(), "The passed genotype is null!"); + throw new RuntimeException(getClass() + ": The passed genotype is null!"); } else if(creator == null) { - throw new ExplorationServiceRuntimeException(getClass(), "The passed creator is null!"); + throw new RuntimeException(getClass() + ": The passed creator is null!"); } else if(operator == null) { - throw new ExplorationServiceRuntimeException(getClass(), "The passed operator is null!"); + throw new RuntimeException(getClass() + ": The passed operator is null!"); } // Input check: Register modules only once. @SuppressWarnings("unchecked") Class<CreatorModule<G>> creatorClass = (Class<CreatorModule<G>>)creator.getClass(); if(registeredExpModules.getInstance(creatorClass) != null) { - throw new ExplorationServiceRuntimeException(getClass(), "The module " + - creatorClass.getSimpleName() + " has already been registered!"); + throw new RuntimeException(getClass() + ": The module " + creatorClass.getSimpleName() + + " has already been registered!"); } @SuppressWarnings("unchecked") Class<OperatorModule<?>> operatorClass = (Class<OperatorModule<?>>)operator.getClass(); if(registeredExpModules.getInstance(operatorClass) != null) { - throw new ExplorationServiceRuntimeException(getClass(), "The module " + + throw new RuntimeException(getClass() + ": The module " + operatorClass.getSimpleName() + " has already been registered!"); } @@ -117,43 +104,52 @@ public class ExplorationModuleService implements IExplorationModuleService { registeredExpModules.putInstance(operatorClass, operator); } - /** {@inheritDoc} */ - @Override - public <P extends Phenotype> void registerProblem(Class<P> phenotype, DecoderModule<P> decoder) { + /** + * Registers a problem definition with the DSE process. The {@code phenotype} is equivalent to + * a candidate solution that is produced by the given {@code decoder}. + * + * @param phenotype + * candidate solution type. + * @param decoder + * transforms variables (and/or other inputs) to candidate solutions. + */ + public <P extends Phenotype> void addProblem(Class<P> phenotype, DecoderModule<P> decoder) { // Input check: Allow only fully specified variable registrations. if(phenotype == null) { - throw new ExplorationServiceRuntimeException(getClass(), - "The passed phenotype is null!"); + throw new RuntimeException(getClass() + ": The passed phenotype is null!"); } else if(decoder == null) { - throw new ExplorationServiceRuntimeException(getClass(), "The passed decoder is null!"); + throw new RuntimeException(getClass() + ": The passed decoder is null!"); } // Input check: Register modules only once. @SuppressWarnings("unchecked") Class<DecoderModule<P>> decoderClass = (Class<DecoderModule<P>>)decoder.getClass(); if(registeredExpModules.getInstance(decoderClass) != null) { - throw new ExplorationServiceRuntimeException(getClass(), "The module " + - decoderClass.getSimpleName() + " has already been registered!"); + throw new RuntimeException(getClass() + ": The module " + decoderClass.getSimpleName() + + " has already been registered!"); } phenotypes.add(phenotype); registeredExpModules.putInstance(decoderClass, decoder); } - /** {@inheritDoc} */ - @Override - public void registerEvaluator(EvaluatorModule<Phenotype> evaluator) { + /** + * Registers the given {@code evaluator} to quantifies the quality of a solution by some metric. + * + * @param evaluator + * applies some metric to a candidate solution. + */ + public void addEvaluator(EvaluatorModule<Phenotype> evaluator) { // Input check: Allow only fully specified variable registrations. if(evaluator == null) { - throw new ExplorationServiceRuntimeException(getClass(), - "The passed evaluator is null!"); + throw new RuntimeException(getClass() + ": The passed evaluator is null!"); } // Input check: Register modules only once. @SuppressWarnings("unchecked") Class<EvaluatorModule<Phenotype>> evaluatorClass = (Class<EvaluatorModule<Phenotype>>)evaluator.getClass(); if(registeredExpModules.getInstance(evaluatorClass) != null) { - throw new ExplorationServiceRuntimeException(getClass(), "The module " + + throw new RuntimeException(getClass() + ": The module " + evaluatorClass.getSimpleName() + " has already been registered!"); } @@ -190,45 +186,7 @@ public class ExplorationModuleService implements IExplorationModuleService { /** {@inheritDoc} */ @Override - public String getIntrospectionDescription() { - // KEEP DESCRIPTION IN SYNC WITH THE SERVICE INTERFACE CLASS COMMENT!!!! - return "Service for adding Exploration Modules to the DSE. The define the concrete problems" - + " that shall be solved by the DSE process. Modules registered with this service" - + " are known to the DSE and can be selected by users to define a DSE process.\n" - + "The Modules registered here are not defining a a concrete DSE process, just the" - + " concrete problems. Exploration modules can be categorized into three classes:" - + " Variable definitions, Problem statements and transformations, and Evaluators" - + " (solution metrics). The variable definitions consist of a Genotypes" - + " (variables), Operators (modify variables), and Creators" - + " (variable initialization). Problem statements transform Genotypes into" - + " evaluable solutions implemented by Decoders that produce" - + " Phenotypes. Evaluators rate Phenotypes such that the quality of a solution can" - + " be quantified.\n" - + "The complete DSE process is based on DI: each of the elements composing" - + " exploration modules have to be implemented as Guice AbstractModules."; - } - - /** {@inheritDoc} */ - @Override - public String getIntrospectionLabel() { - return "Exploration Module Service"; - } - - /** {@inheritDoc} */ - @Override - public boolean showInIntrospectionNavigation() { - return true; - } - - /** {@inheritDoc} */ - @Override - public Collection<IIntrospectionItem> getIntrospectionItems() { - return null; - } - - /** {@inheritDoc} */ - @Override - public IIntrospectionDetailsItem getDetailsItem() { - return null; + public String getName() { + return name; } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/IExplorationFeature.java similarity index 63% rename from org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java rename to org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/IExplorationFeature.java index 55f602c4ba4cb80de3d249e1722819482828a471..f0057888990fb5c35e7e97c5d74b7f22d09eabe9 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/IExplorationFeature.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.af3.exploration.alg.service; +package org.fortiss.af3.exploration.alg.feature; import java.util.Set; @@ -31,10 +31,6 @@ import org.opt4j.operators.OperatorModule; import com.google.inject.AbstractModule; /** - * Service for adding Exploration Modules to the DSE. The define the concrete problems that shall - * be solved by the DSE process. Modules registered with this service are known to the DSE and - * can be selected by users to define a DSE process. The Modules registered here are not defining a - * concrete DSE process, just the concrete problems. * * Exploration modules can be categorized into three classes: Variable definitions, Problem * statements and transformations, and Evaluators (solution metrics). The variable definitions @@ -51,40 +47,10 @@ import com.google.inject.AbstractModule; * * @author diewald */ -public interface IExplorationModuleService extends IExplorationService { +public interface IExplorationFeature { - /** - * Registers an optimization variable ({@code genotype}) with the DSE, along with its - * initializer ({@code creator}) and modificator ({@code operator}). - * - * @param genotype - * optimization variable type. - * @param creator - * initializes the opt. variable. - * @param operator - * modifications applied during the process iterations. - */ - <G extends Genotype> void registerVariable(Class<G> genotype, CreatorModule<G> creator, - OperatorModule<?> operator); - - /** - * Registers a problem definition with the DSE process. The {@code phenotype} is equivalent to - * a candidate solution that is produced by the given {@code decoder}. - * - * @param phenotype - * candidate solution type. - * @param decoder - * transforms variables (and/or other inputs) to candidate solutions. - */ - <P extends Phenotype> void registerProblem(Class<P> phenotype, DecoderModule<P> decoder); - - /** - * Registers the given {@code evaluator} to quantifies the quality of a solution by some metric. - * - * @param evaluator - * applies some metric to a candidate solution. - */ - void registerEvaluator(EvaluatorModule<Phenotype> evaluator); + /** Returns the name of the {@link IExplorationFeature}. */ + String getName(); /** Returns the set of registered {@link Creator}s. */ Set<CreatorModule<?>> getCreators(); diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/PartitionArchitectureExploration.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/PartitionArchitectureExploration.java new file mode 100644 index 0000000000000000000000000000000000000000..61ea586e3acade91d3c9cc0d37a349e0bb26b3af --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/PartitionArchitectureExploration.java @@ -0,0 +1,38 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.feature; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.partitionmapping.PartitionMappingCreator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmapping.PartitionMappingEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.platform.PlatformCommunicationGraphEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.partitionmapping.PartitionMappingModule; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.partitionmapping.PartitionMappingDecoderGraph; + +/** + * + * @author diewald + */ +public class PartitionArchitectureExploration extends ExplorationFeature { + + /** Constructor. */ + public PartitionArchitectureExploration() { + super("Partition Architecture Exploration"); + + addVariable(PartitionMappingEncoding.class, new PartitionMappingCreator(), + new PartitionMappingModule()); + addProblem(PlatformCommunicationGraphEncoding.class, new PartitionMappingDecoderGraph()); + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/SafetyArchitectureExploration.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/SafetyArchitectureExploration.java new file mode 100644 index 0000000000000000000000000000000000000000..89a5c8c5e42c8c55857699ba7d2503e6342cd401 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/SafetyArchitectureExploration.java @@ -0,0 +1,46 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.feature; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.safetyfunctionarch.SafetyFunctionArchCreator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch.SafetyFunctionArchEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.SafeTaskGraphEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.safetyarch.MutateSafetyFunctionArchitectureModule; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.safetyfunction.SFGraphDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.safetyfunction.SFMappingDecoder; + +/** + * + * @author diewald + */ +public class SafetyArchitectureExploration extends ExplorationFeature { + + /** Constructor. */ + public SafetyArchitectureExploration() { + super("Safety Architecture Exploration"); + + // Variables + addVariable(SafetyFunctionArchEncoding.class, new SafetyFunctionArchCreator(), + new MutateSafetyFunctionArchitectureModule()); + // Decoding + addProblem(AbstractTaskMappingEncoding.class, new SFMappingDecoder()); + // TODO: ConstraintDecoder + // getService(IExplorationModuleService.class).registerProblem( + // AbstractTaskMappingEncoding.class, new SFMappingConstraintDecoder()); + addProblem(SafeTaskGraphEncoding.class, new SFGraphDecoder()); + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/TTScheduleExploration.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/TTScheduleExploration.java new file mode 100644 index 0000000000000000000000000000000000000000..9d7e6b4eea4030881006fa85f0be4cb584383b09 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/TTScheduleExploration.java @@ -0,0 +1,33 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.feature; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.StrictTTDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.StrictTTSchedule; + +/** + * + * @author diewald + */ +public class TTScheduleExploration extends ExplorationFeature { + + /** Constructor. */ + public TTScheduleExploration() { + super("Decoding mappings -> schedules"); + + addProblem(StrictTTSchedule.class, new StrictTTDecoder()); + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/TaskMappingExploration.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/TaskMappingExploration.java new file mode 100644 index 0000000000000000000000000000000000000000..a548b4757ad6560c3ae640f956910f83fd77b1e1 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/feature/TaskMappingExploration.java @@ -0,0 +1,58 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.feature; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.taskmapping.AbstractTaskMappingCreator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.create.taskmapping.FailSilentTaskMappingCreator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.comm.MessageEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.FailSilentTaskMappingEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.InstantiatedTaskMappingEncoding; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskinstantiation.MutateTaskInstanceModule; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmapping.MutateTaskMappingModule; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.comm.MessageDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.AbstractTaskMappingIdentityDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.instantiate.FailSilentAbstractTaskMappingDecoder; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.instantiate.TaskInstanceResourceAlignmentDecoder; + +/** + * + * @author diewald + */ +public class TaskMappingExploration extends ExplorationFeature { + + /** Constructor. */ + // FIXME: Split up in std task mapping and the instantiated one (Fail-Silent). + public TaskMappingExploration() { + super("Task Mapping Exploration"); + + // Variables + addVariable(AbstractTaskMappingEncoding.class, new AbstractTaskMappingCreator(), + new MutateTaskMappingModule()); + addVariable(FailSilentTaskMappingEncoding.class, new FailSilentTaskMappingCreator(), + new MutateTaskInstanceModule()); + + // Decoding + addProblem(AbstractTaskMappingEncoding.class, new AbstractTaskMappingIdentityDecoder()); + addProblem(FailSilentTaskMappingEncoding.class, new FailSilentAbstractTaskMappingDecoder()); + // getService(IExplorationModuleService.class).registerProblem( + // FaultDetectionVotingTaskMappingEncoding.class, + // new FaultDetectionVotingAbstractTaskMappingDecoder()); + addProblem(InstantiatedTaskMappingEncoding.class, + new TaskInstanceResourceAlignmentDecoder()); + addProblem(MessageEncoding.class, new MessageDecoder()); + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings index 4072df2b2df0300873eedefd7405258022ebd6e1..efd393a9cf5c197e2afb3b6e021dad04f5f645ca 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings @@ -1,14 +1,14 @@ -ExplorationEncodingMap.java aaea06f5731018d159a04266c92f1a701e461323 RED -ExplorationServiceManager.java 6b15f230dd0cac5f3a9b954da805526da7358ad1 RED -ExplorationTransformationInputs.java 3374ce609b50e69c3c29f1eb79bee25cd06b181d RED -IExplorationConstraintTransformationService.java 48b673e1fb69c05e35c4e60ecf73b8f708cfcf0e RED -IExplorationContraintTransformationModule.java 1d3560401275f719e2b9901d1639a6be6bd7c169 RED -IExplorationEncoding.java f58adbcf840af521333c2777f50041a60548bff3 RED -IExplorationEvaluatationService.java c79cd47a3eac58d56071e51bb5465efefa226fc5 RED -IExplorationExtension.java c2a148e18c580d2432357e93da45e7bf7df8eb0c RED -IExplorationModuleService.java 55f602c4ba4cb80de3d249e1722819482828a471 RED -IExplorationRepairService.java 879d73fce129cd3c4c6fd2819a5c4ed0a625c55b RED -IExplorationService.java 5aaf2b75e88e4ee1b1a206c00e77dd173a5cdeb5 RED -IExplorationTargetEvaluator.java 99c27a053a123462b8a4faadc9c3530fe6bc0c67 RED -IExplorationTransformationService.java eed8f4a86eda433c2fc0af00fbef31dbd942c9f0 RED -IRepairModule.java 0cca5fea3835e4fccc151eec42232ad0e6c88e66 RED +ExplorationEncodingMap.java aaea06f5731018d159a04266c92f1a701e461323 RED +ExplorationServiceManager.java 6b15f230dd0cac5f3a9b954da805526da7358ad1 RED +ExplorationTransformationInputs.java 3374ce609b50e69c3c29f1eb79bee25cd06b181d RED +IExplorationConstraintTransformationService.java 48b673e1fb69c05e35c4e60ecf73b8f708cfcf0e RED +IExplorationContraintTransformationModule.java 1d3560401275f719e2b9901d1639a6be6bd7c169 RED +IExplorationEncoding.java f58adbcf840af521333c2777f50041a60548bff3 RED +IExplorationEvaluatationService.java c79cd47a3eac58d56071e51bb5465efefa226fc5 RED +IExplorationExtension.java c2a148e18c580d2432357e93da45e7bf7df8eb0c YELLOW +IExplorationFeatureService.java e97bee18dc6f67689386849ace02ff79c262787e YELLOW +IExplorationRepairService.java 879d73fce129cd3c4c6fd2819a5c4ed0a625c55b RED +IExplorationService.java 5aaf2b75e88e4ee1b1a206c00e77dd173a5cdeb5 RED +IExplorationTargetEvaluator.java 99c27a053a123462b8a4faadc9c3530fe6bc0c67 RED +IExplorationTransformationService.java eed8f4a86eda433c2fc0af00fbef31dbd942c9f0 RED +IRepairModule.java 0cca5fea3835e4fccc151eec42232ad0e6c88e66 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationFeatureService.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationFeatureService.java new file mode 100644 index 0000000000000000000000000000000000000000..e97bee18dc6f67689386849ace02ff79c262787e --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationFeatureService.java @@ -0,0 +1,54 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.service; + +import java.util.Collection; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype; +import org.fortiss.af3.exploration.alg.feature.IExplorationFeature; + +/** + * Service for adding {@link IExplorationFeature}s to the DSE. They define the concrete problems + * that shall be solved by the DSE process. {@link IExplorationFeature}s registered with this + * service are known to the DSE and can be selected by users to define a DSE process. + * + * Each feature consists of so-called Exploration Modules that can be Variables, Decodings of these + * Variables (aka. Problem descriptions), or evaluators that rate {@link Phenotype}s to derive + * metrics for the quality of a solution. + * + * @author diewald + */ +public interface IExplorationFeatureService extends IExplorationService { + + /** + * Registers the given {@link IExplorationFeature} with this service to make it selectable by + * users of the DSE. + * + * @param feature + * {@link IExplorationFeature} to register with the DSE. + */ + void registerExplorationFeature(IExplorationFeature feature); + + /** Returns the registered {@link IExplorationFeature}s. */ + Collection<IExplorationFeature> getExplorationFeatures(); + + /** + * Returns the {@link IExplorationFeature}s that have the given types from the set of registered + * {@link IExplorationFeature}s. + */ + Collection<IExplorationFeature> getExplorationFeatures( + Collection<Class<? extends IExplorationFeature>> features); +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/.ratings index 78a3116640fb7cb26c095a3b7ed563e15122c694..5249fc73f49053bc8c568f7a9c9a5ba0c65a1a72 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/.ratings @@ -1,5 +1,6 @@ -ExplorationConstraintTransformationService.java 5e7117398827ae129b3c9a8a16457d816ba665a7 RED -ExplorationEvaluationService.java ed22af146e8230a39a47ba60224b824b6d0ac599 RED -ExplorationModuleService.java c3ae40f2c20e38c7aa7a3f24a9ace41b59e421d3 YELLOW -ExplorationRepairService.java 940ceda7c8c48f282132355249af1fe0a005c0f5 RED -ExplorationTransformationService.java 36e2368dd6098e1f3aa210a6defd4f269628e28a RED +ExplorationConstraintTransformationService.java 5e7117398827ae129b3c9a8a16457d816ba665a7 RED +ExplorationEvaluationService.java ed22af146e8230a39a47ba60224b824b6d0ac599 RED +ExplorationFeatureService.java 3521ed653a98e9ad09591faf5fdebb7ca57c45b7 YELLOW +ExplorationModuleService.java c3ae40f2c20e38c7aa7a3f24a9ace41b59e421d3 YELLOW +ExplorationRepairService.java 940ceda7c8c48f282132355249af1fe0a005c0f5 RED +ExplorationTransformationService.java 36e2368dd6098e1f3aa210a6defd4f269628e28a RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/ExplorationFeatureService.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/ExplorationFeatureService.java new file mode 100644 index 0000000000000000000000000000000000000000..3521ed653a98e9ad09591faf5fdebb7ca57c45b7 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/internal/ExplorationFeatureService.java @@ -0,0 +1,186 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.alg.service.internal; + +import java.util.Collection; +import java.util.HashSet; + +import org.fortiss.af3.exploration.alg.dse.module.CreatorModule; +import org.fortiss.af3.exploration.alg.dse.module.DecoderModule; +import org.fortiss.af3.exploration.alg.dse.module.EvaluatorModule; +import org.fortiss.af3.exploration.alg.exception.ExplorationServiceRuntimeException; +import org.fortiss.af3.exploration.alg.feature.IExplorationFeature; +import org.fortiss.af3.exploration.alg.service.IExplorationFeatureService; +import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; +import org.fortiss.tooling.kernel.introspection.IIntrospectionItem; +import org.opt4j.core.problem.Creator; +import org.opt4j.core.problem.Decoder; +import org.opt4j.operators.OperatorModule; + +import com.google.common.collect.ClassToInstanceMap; +import com.google.common.collect.MutableClassToInstanceMap; +import com.google.inject.AbstractModule; + +/** + * Implementation of the {@link IExplorationFeatureService}. + * + * @author diewald + */ +public class ExplorationFeatureService implements IExplorationFeatureService { + + /** Holds the registered {@link IExplorationFeature}s. */ + private ClassToInstanceMap<IExplorationFeature> explorationFeatures = MutableClassToInstanceMap + .create(); + + /** + * References all registered exploration modules of {@link IExplorationFeature}s for consistency + * checks. Differing between {@link Creator}s, {@link Decoder}s etc. is currently not needed. + */ + private ClassToInstanceMap<AbstractModule> registeredExpModules = MutableClassToInstanceMap + .create(); + + /** Holds the instance of the evaluation service. */ + private volatile static ExplorationFeatureService INSTANCE; + + /** Constructor. */ + private ExplorationFeatureService() { + // Prevent direct instantiation. + } + + /** The instance (singleton) of the ExplorationTransformationService. */ + public static synchronized ExplorationFeatureService getInstance() { + if(INSTANCE == null) { + INSTANCE = new ExplorationFeatureService(); + } + return INSTANCE; + } + + /** {@inheritDoc} */ + @Override + public void initializeService() { + // Typically used to read extension point configs. Not needed since we won't use eclipse + // extension points in the DSE any more. + } + + /** {@inheritDoc} */ + @Override + public void startService() { + // Not needed. + } + + /** {@inheritDoc} */ + @Override + public void registerExplorationFeature(IExplorationFeature feature) { + // Consistency checks. + for(CreatorModule<?> creatorModule : feature.getCreators()) { + Class<?> creatorClass = creatorModule.getClass(); + if(registeredExpModules.containsKey(creatorClass)) { + throw new ExplorationServiceRuntimeException(getClass(), "The module " + + creatorClass.getSimpleName() + " has already been registered!"); + } + } + for(DecoderModule<?> decoderModule : feature.getDecoders()) { + Class<?> decoderClass = decoderModule.getClass(); + if(registeredExpModules.containsKey(decoderClass)) { + throw new ExplorationServiceRuntimeException(getClass(), "The module " + + decoderClass.getSimpleName() + " has already been registered!"); + } + } + for(OperatorModule<?> operatorModule : feature.getOperators()) { + Class<?> operatorClass = operatorModule.getClass(); + if(registeredExpModules.containsKey(operatorClass)) { + throw new ExplorationServiceRuntimeException(getClass(), "The module " + + operatorClass.getSimpleName() + " has already been registered!"); + } + } + for(EvaluatorModule<?> evaluatorModule : feature.getEvaluators()) { + Class<?> evaluatorClass = evaluatorModule.getClass(); + if(registeredExpModules.containsKey(evaluatorClass)) { + throw new ExplorationServiceRuntimeException(getClass(), "The module " + + evaluatorClass.getSimpleName() + " has already been registered!"); + } + } + + explorationFeatures.put(feature.getClass(), feature); + } + + /** {@inheritDoc} */ + @Override + public Collection<IExplorationFeature> getExplorationFeatures() { + return explorationFeatures.values(); + } + + /** {@inheritDoc} */ + @Override + public Collection<IExplorationFeature> getExplorationFeatures( + Collection<Class<? extends IExplorationFeature>> features) { + Collection<IExplorationFeature> featureInstances = new HashSet<>(); + for(Class<? extends IExplorationFeature> featureType : features) { + IExplorationFeature featureInstance = explorationFeatures.getInstance(featureType); + if(featureInstance == null) { + throw new ExplorationServiceRuntimeException(getClass(), + "No exploration feature of the type " + featureType.getClass() + + " has been registered."); + } + featureInstances.add(explorationFeatures.getInstance(featureType)); + } + return featureInstances; + } + + /** {@inheritDoc} */ + @Override + public String getIntrospectionDescription() { + // KEEP DESCRIPTION IN SYNC WITH THE SERVICE INTERFACE CLASS COMMENT!!!! + return "Service for adding Exploration Modules to the DSE. The define the concrete problems" + + " that shall be solved by the DSE process. Modules registered with this service" + + " are known to the DSE and can be selected by users to define a DSE process.\n" + + "The Modules registered here are not defining a a concrete DSE process, just the" + + " concrete problems. Exploration modules can be categorized into three classes:" + + " Variable definitions, Problem statements and transformations, and Evaluators" + + " (solution metrics). The variable definitions consist of a Genotypes" + + " (variables), Operators (modify variables), and Creators" + + " (variable initialization). Problem statements transform Genotypes into" + + " evaluable solutions implemented by Decoders that produce" + + " Phenotypes. Evaluators rate Phenotypes such that the quality of a solution can" + + " be quantified.\n" + + "The complete DSE process is based on DI: each of the elements composing" + + " exploration modules have to be implemented as Guice AbstractModules."; + } + + /** {@inheritDoc} */ + @Override + public String getIntrospectionLabel() { + return "Exploration Module Service"; + } + + /** {@inheritDoc} */ + @Override + public boolean showInIntrospectionNavigation() { + return true; + } + + /** {@inheritDoc} */ + @Override + public Collection<IIntrospectionItem> getIntrospectionItems() { + return null; + } + + /** {@inheritDoc} */ + @Override + public IIntrospectionDetailsItem getDetailsItem() { + return null; + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/.ratings index 707cffe050c98001d35b966799fe1f3c2ac7eee9..0d5278bf6ae4c2c70f275268b7f164b2937f7f04 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/.ratings @@ -1,5 +1,5 @@ AF3Utils.java a7269b4db6db75c4d3332c46fa62b7597711507b RED -DesignSpaceExplorationModelElementFactory.java bc6a6462bb655f3709afbc6b0c50ccd4f9764b5d RED +DesignSpaceExplorationModelElementFactory.java 088730563c404be12c4138fb96af59db387a1f32 RED ExplorationAlgDebugUtils.java acdb59e8a413c89e26f91b8829149afcb8328600 RED ExplorationAlgUtils.java 3ae0811b433c0be37af094086aff720cb42ea862 RED ExplorationEcoreUtils.java d816b750378d2bcbd307ff86e121c8d38ef5c28b RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/DesignSpaceExplorationModelElementFactory.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/DesignSpaceExplorationModelElementFactory.java index bc6a6462bb655f3709afbc6b0c50ccd4f9764b5d..088730563c404be12c4138fb96af59db387a1f32 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/DesignSpaceExplorationModelElementFactory.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/util/DesignSpaceExplorationModelElementFactory.java @@ -65,8 +65,8 @@ public class DesignSpaceExplorationModelElementFactory { } /** Creates a DseSpecification referencing the given {@link ExplorationSpecification}. */ - public static DseSpecification - createDefaultDesignSpaceExploration(ExplorationSpecification expSpec) { + public static DseSpecification createDefaultDesignSpaceExploration( + ExplorationSpecification expSpec) { ITopLevelElement modelContext = IPersistencyService.getInstance().getTopLevelElementFor(expSpec); return createDefaultDesignSpaceExploration(expSpec, modelContext); @@ -78,8 +78,9 @@ public class DesignSpaceExplorationModelElementFactory { */ public static DseSpecification createDefaultDesignSpaceExploration( ExplorationSpecification expSpec, ITopLevelElement modelContext) { - DseSpecification dseSpec = createDseSpecification("Default DSE model", - ExecutionModel.TT_FAIL_SILENCE, createDefaultEAOptimizer()); + DseSpecification dseSpec = + createDseSpecification("Default DSE model", ExecutionModel.TT_FAIL_SILENCE, + createDefaultEAOptimizer()); modelContext.runAsCommand(() -> dseSpec.setTargetSpecification(expSpec)); return dseSpec; } @@ -205,8 +206,8 @@ public class DesignSpaceExplorationModelElementFactory { /** * Creates a fixed deployment constraint within the goal specification of the current DSE model. */ - public static ComponentMultiAllocationConstraint - addMultiComponentAllocationConstraint(ExplorationSpecification targetSpec) { + public static ComponentMultiAllocationConstraint addMultiComponentAllocationConstraint( + ExplorationSpecification targetSpec) { ComponentMultiAllocationConstraint fixedDeploymentConstraint = createComponentMultiAllocationConstraint(); prepareUniqueID(fixedDeploymentConstraint, targetSpec); @@ -237,15 +238,15 @@ public class DesignSpaceExplorationModelElementFactory { * Creates a {@link ComponentMultiDislocationConstraint} to the given * {@link ExplorationSpecification}. */ - public static ComponentMultiDislocationConstraint - addComponentMultiDislocationConstraint(ExplorationSpecification targetSpec) { + public static ComponentMultiDislocationConstraint addComponentMultiDislocationConstraint( + ExplorationSpecification targetSpec) { ComponentMultiDislocationConstraint multiComponentDislocationConstraint = createComponentMultiDislocationConstraint(); prepareUniqueID(multiComponentDislocationConstraint, targetSpec); ITopLevelElement modelContext = IPersistencyService.getInstance().getTopLevelElementFor(targetSpec); - modelContext.runAsCommand( - () -> targetSpec.getTargets().add(multiComponentDislocationConstraint)); + modelContext.runAsCommand(() -> targetSpec.getTargets().add( + multiComponentDislocationConstraint)); return multiComponentDislocationConstraint; } @@ -261,8 +262,8 @@ public class DesignSpaceExplorationModelElementFactory { * Creates a safety integrity level constraint within the goal specification of the current DSE * model. */ - public static SafetyIntegrityLevelConstraint - addSafetyIntegrityLevelConstraint(ExplorationSpecification targetSpec) { + public static SafetyIntegrityLevelConstraint addSafetyIntegrityLevelConstraint( + ExplorationSpecification targetSpec) { SafetyIntegrityLevelConstraint safetyIntegrityLevelConstraint = PredefinedFactory.eINSTANCE.createSafetyIntegrityLevelConstraint(); safetyIntegrityLevelConstraint.setName("Safety Integrity Level Constraint");