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

Guice: Proof of concept impl for decoder dependencies.


* Testwise implementation of a decoding mechanism that is intended to
  replace the current dependency declaration and resolution mechanism
  with the Guice framework. This step should allow to reduce a lot of
  boilerplate code and ease maintenance.
* The mechanism is is based on the "Providers" and "@Provide"
  annotation in combination with "@Inject" fields that declare the
  input dependencies.
* TODOs:
** Switch all decoders to the new mechanism.
** Reduce the mountain of abstraction code that is not really required
   to configure the DSE.
** Implement a service mechanism that binds the guice modules belonging
   to an exploration feature.

Signed-off-by: default avatarAlexander Diewald <diewald@fortiss.org>
parent 540c157b
No related branches found
No related tags found
1 merge request!2Dependency injection
Showing
with 261 additions and 92 deletions
CompositeExplorationSolution.java 1910fcd1d1e4a1b003b7a4e1bb52460eec5362dd RED
DSEFactory.java ae8a0f876a1db3372d116066db10aa1e736980ab RED
DSEFactory.java 1ae5fecb636a1a3eb8520d7906ad664828f22fe7 RED
Explorer.java 91cdb26b6f42e4e5e82a26f7dbd9141ec2ff7b18 RED
ImplicitExplorationTargetFactory.java 25c3c668ed268843f8af7e37eb03370ed513b482 RED
SolutionQuantification.java 19cd7caa721bbca3112af7825c7fb20a96a4a799 RED
......
......@@ -118,7 +118,8 @@ public class DSEFactory {
* if (one of) the sub problem(s) cannot be registered.
*/
@SuppressWarnings("unchecked")
public <C, S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>>
public
<C, S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>>
void createSubProblems(ArchitectureExplorationProblemModule archExpProblemModule,
DseSpecification dse, DecoderDependencyGraph execDepGraph) throws Exception {
// Java-limitation: it is not possible to pass the generic to the static methods.
......@@ -202,10 +203,11 @@ public class DSEFactory {
ArchitectureExplorationProblemModule archExpProblemModule, DseSpecification dse,
DecoderDependencyGraph execDepGraph) throws CycleFoundException {
Class<PartitionMappingEncoding> pmEnodingClass = PartitionMappingEncoding.class;
PartitionMappingCreator pmCreator = new PartitionMappingCreator(execDepGraph,
(Collection<IExecutionUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getDeploymentTargets(),
systemModelAdapter.getDeployableComponents().size());
PartitionMappingCreator pmCreator =
new PartitionMappingCreator(execDepGraph,
(Collection<IExecutionUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getDeploymentTargets(), systemModelAdapter
.getDeployableComponents().size());
@SuppressWarnings("rawtypes") List<ComposableDecoder> pmDecoders = new ArrayList<>();
PartitionMappingIdentityDecoder pmDecoder = new PartitionMappingIdentityDecoder();
......@@ -229,17 +231,16 @@ public class DSEFactory {
DecoderDependencyGraph execDepGraph) throws CycleFoundException {
Class<PlatformCommunicationGraphEncoding> pmEnodingClass =
PlatformCommunicationGraphEncoding.class;
PlatformCommunicationGraphCreator pmCreator = new PlatformCommunicationGraphCreator(
execDepGraph,
(Collection<IExecutionUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getDeploymentTargets(),
(Collection<IMemoryUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getMemoryUnits(),
(Collection<IGatewayUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getGatewayUnits(),
(Collection<ITransmissionUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getTransmissionUnits(),
systemModelAdapter.getResouceConnections());
PlatformCommunicationGraphCreator pmCreator =
new PlatformCommunicationGraphCreator(execDepGraph,
(Collection<IExecutionUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getDeploymentTargets(),
(Collection<IMemoryUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getMemoryUnits(),
(Collection<IGatewayUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getGatewayUnits(),
(Collection<ITransmissionUnitAdapter<?>>)(Collection<?>)systemModelAdapter
.getTransmissionUnits(), systemModelAdapter.getResouceConnections());
@SuppressWarnings("rawtypes") List<ComposableDecoder> pmDecoders = new ArrayList<>();
PartitionMappingDecoderGraph pmgDecoder = new PartitionMappingDecoderGraph();
......@@ -269,8 +270,8 @@ public class DSEFactory {
@SuppressWarnings("unchecked")
private <S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>>
void createAbstractTaskMappingProblem(TaskMappingFactory<S, T> tmFactory,
ArchitectureExplorationProblemModule archExpProblemModule, DseSpecification dse,
DecoderDependencyGraph execDepGraph) throws Exception {
ArchitectureExplorationProblemModule archExpProblemModule,
DseSpecification dse, DecoderDependencyGraph execDepGraph) throws Exception {
Class<AbstractTaskMappingEncoding> tmEnodingClass = AbstractTaskMappingEncoding.class;
AbstractTaskMappingCreator tmCreator =
tmFactory.createAbstractTaskMappingCreator(dse, execDepGraph);
......@@ -310,8 +311,8 @@ public class DSEFactory {
@SuppressWarnings("unchecked")
private <S extends InstantiatedTaskMappingEntry, T extends InstantiatedTaskMappingEncoding<S>>
void createTaskMappingInstantiationProblem(TaskMappingFactory<S, T> tmFactory,
ArchitectureExplorationProblemModule archExpProblemModule, DseSpecification dse,
DecoderDependencyGraph execDepGraph) throws Exception {
ArchitectureExplorationProblemModule 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.
StrictTTDecoder<S, T> tmDecoder = tmFactory.createStrictTTDecoder(dse);
......@@ -352,8 +353,8 @@ public class DSEFactory {
*/
@SuppressWarnings("unchecked")
public <S extends TaskMappingEntry<?, Partition>>
TaskMappingFactory<?, ? extends TaskMappingEncoding<?, S>>
createTaskMappingFactory(ExecutionModel execModel) throws UnsupportedDataTypeException {
TaskMappingFactory<?, ? extends TaskMappingEncoding<?, S>> createTaskMappingFactory(
ExecutionModel execModel) throws UnsupportedDataTypeException {
// TODO: Remove the error-prone casting. Remove the differentiation between the failure
// modes here as well?
switch(execModel) {
......
Opt4JDseTask.java b5cb9e664e7a8fc2b5157bcdcaca740c2fa85336 YELLOW
Opt4JExplorationSolutionSet.java 8578ee9c438bc3327a64172e996306a89606c782 RED
Opt4JExplorerBackend.java 000231dcd7f3a76d06567c7bb987410fa80602ba RED
Opt4JExplorerBackend.java f5683ab89923cad54a07a15523216f096d225702 RED
Opt4JSingleExplorationSolution.java 41ce92d11b2e7a6a8c39bffa990c691160c36c8d RED
/*-------------------------------------------------------------------------+
| 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;
import org.opt4j.core.start.Opt4JTask;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
/**
* Specialized {@link Opt4JTask} that allows access to the {@link Injector} used in Opt4J to
* implement the dependency-driven decoding.
* This {@link Opt4JTask} implements a provider of the opt4J {@link Injector} in order to make it
* accessible for decoders and evaluators. An improvement to this generic {@link Injector} retrieval
* limited to Guice (Abstract)Modules that cannot be used here (no polymorphism in Java).
*
* @author diewald
*/
public class Opt4JDseTask extends Opt4JTask implements Provider<Injector> {
/** No-arg constructor. */
@Inject
public Opt4JDseTask() {
super(true);
}
/**
* Constructs a {@link Opt4JTask}.
*
* @param closeOnStop
* close automatically after optimization
*/
public Opt4JDseTask(boolean closeOnStop) {
super(closeOnStop);
}
/** {@inheritDoc} */
@Override
public Injector get() {
return injector;
}
}
......@@ -88,6 +88,8 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> {
/** EA parameters. */
private EAOptimizer opt4JParameters;
// public static Injector DseInjector = Guice.createInjector();
/**
* Contains the problem module that includes the evaluators associated with the goals of the
* DSE.
......@@ -227,7 +229,7 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> {
modules.add(comp);
// Create and initialize optimization task
opt4JTask = new Opt4JTask(false);
opt4JTask = new Opt4JDseTask(false);
opt4JTask.init(modules);
if(progressMonitor != null) {
......
......@@ -2,3 +2,4 @@ ComposableCreator.java 6d2d61205890a2b0b99f41d2caa4debc511c8b4a RED
ComposableCreatorBase.java e1a898541dd2b480e6c345ad2429bf93393957e6 RED
CompositeCreator.java bb054d281931f461ca67def20360cc767940e204 RED
CompositeCreatorBase.java d897947ff0db02ea1cac4034a4912f9afce283ec RED
GuiceCreator.java 34e89e1ed5c8aa411b61682e84be0e9910533b3e RED
......@@ -13,14 +13,21 @@
| 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;
package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.create;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.PhenotypeBase;
import org.opt4j.core.genotype.IntegerGenotype;
import org.opt4j.core.problem.Creator;
/**
* Dummy creator to allow registering the Guice Decoder.
*
* @author diewald
*/
public class GuicePhenotype extends PhenotypeBase {
public class GuiceCreator implements Creator<IntegerGenotype> {
/** {@inheritDoc} */
@Override
public IntegerGenotype create() {
return new IntegerGenotype(1, 10);
}
}
ComposableDecoder.java 0ef247e0e8424968cd8dab8317df0e504c5018d4 RED
ComposableDecoderBase.java 7a4c510bcdff54df5b27045d06db4ee923f995e2 RED
ComposableDecoderBase.java 7c47b41e609b6911128efa469c2dd65122276bcc RED
CompositeDecoder.java 68864146cbd7b0d1444d4157cf88023deb4a21ea RED
CompositeDecoderBase.java cc878483ec3dcf3afd60509579c7c17a3433893c RED
GuiceDecoder.java eb0fec9132b95dd8ecd07c134339ec93e9fbb3b7 RED
GuicePhenotype.java 36deb82848fd14c0bf2649f9cb0553f24de68e9a RED
GuiceDecoder.java 3fda47c70fa49cbe4398dc43e0819f2c6179202f RED
PhenotypeDecoder.java 82766d64d8d6d0aa02078921517848c3585240a6 RED
......@@ -22,6 +22,7 @@ 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 com.google.common.reflect.TypeToken;
import com.google.inject.AbstractModule;
/**
* Base class for {@link ComposableDecoder}s.
......@@ -29,7 +30,7 @@ import com.google.common.reflect.TypeToken;
* @author diewald
*/
public abstract class ComposableDecoderBase<G extends ComposableGenotype, P extends Phenotype>
implements ComposableDecoder<G, P> {
extends AbstractModule implements ComposableDecoder<G, P> {
/** Type information: Concrete input genotype of the decoder. */
private TypeToken<G> genotype = new TypeToken<G>(getClass()) { // Empty class
};
......@@ -37,6 +38,12 @@ public abstract class ComposableDecoderBase<G extends ComposableGenotype, P exte
private TypeToken<P> phenotype = new TypeToken<P>(getClass()) { // Empty class
};
/** {@inheritDoc} */
@Override
public void configure() {
// Nothing to be done here by default.
}
/** {@inheritDoc} */
@Override
public Class<?> getPrimaryInputType() {
......
......@@ -15,33 +15,75 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.decode;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.TaskMappingEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.taskmapping.instantiate.FailSilentAbstractTaskMappingDecoder;
import org.opt4j.core.Genotype;
import org.opt4j.core.problem.Decoder;
import org.opt4j.core.start.Opt4JTask;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provides;
/**
* {@link Decoder} that handles dependencies between {@link Decoder}s, {@link Genotype}s, and
* {@link Phenotype}s using the Guice framework.
*
* @author diewald
*/
public class GuiceDecoder implements Decoder<Genotype, GuicePhenotype> {
protected GuicePhenotype composedPhenotype;
public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Phenotype> {
/** Resulting phenotype from the decoding phase that is composed of sub-{@link Phenotype}s. */
@Inject
Class<Phenotype> resultType;
protected Phenotype composedPhenotype;
/** 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 = TaskMappingEncoding.class;
/** Injector created by the {@link Opt4JTask}. */
@Inject
protected Injector decoderInjector;
protected Injector opt4JInjector;
/** Child injector for the dependency management of the decode phase. */
protected Injector decodingInjector;
/** Reference to the input {@link Genotype}. */
protected Genotype genotype;
// TODO: Switch from field injections to Constructor injection as far as possible.
// /** Constructor. */
// @Inject
// public GuiceDecoder(Injector opt4JInjector) {
// decoderInjector = opt4JInjector;
// }
/** {@inheritDoc} */
@Override
public GuicePhenotype decode(Genotype genotype) {
public Phenotype decode(Genotype genotype) {
// The decode operations are responsible to add the results of the decode operation to the
// parent phenotype.
Phenotype resultPhenotype = decoderInjector.getInstance(resultType);
this.genotype = genotype;
// TODO(AD): See configure(): We need a service machenism and user configuration to select
// the desired set of activated decoders.
decodingInjector = opt4JInjector.createChildInjector(this);
decodingInjector.getInstance(resultType);
return composedPhenotype;
}
/** Provides the composite {@link Genotype} as required by the Guice framework. */
@Provides
public Genotype getGenotype() {
return genotype;
}
/** {@inheritDoc} */
@Override
protected void configure() {
// TODO(AD): we need to implement a service mechanism in this configure method. (Plugin
// Style)
bind(TaskMappingEncoding.class).toProvider(FailSilentAbstractTaskMappingDecoder.class);
}
}
ArchExpSubDecoder.java 8878133e8b65858b4cd7cedd243d49d391066323 RED
ArchitectureDecoder.java d067dc995e0895860d98d717647c0f7b061f5908 RED
ArchitectureExplorationProblemModule.java 6a8f34a29885d14c6f96e7516d23b30a646cd032 RED
ArchitectureExplorationProblemModule.java a1c6b8ced3b1bf54ce9d9b957b0f4c80a821bdab RED
DseProblemModuleBase.java 0eba41852529e92e7255c7a7d8fce18354facbca RED
EvaluatorWrapper.java 3747e5b78b1dcef8e1595c1ae9354e8ef2738e79 RED
ExplorationGoalPriorityMultiEvaluator.java 1f6d2aa6ece8acdf4f57face0439f3429ab87329 RED
ProblemModuleBase.java 4d5c2a80cada7ba6e4722c27f4625777ee0bbd87 RED
ProblemModuleBase.java e776938a9d2cc2a40e559c266b5c7bf405cb3eec RED
StrictTTDecoder.java d44d02b5f866717ebaa40a8a1a32225852e56af8 RED
......@@ -21,6 +21,8 @@ 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.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.DecoderDependencyGraph;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.solution.ArchitectureSolution;
import org.fortiss.af3.exploration.alg.dse.evaluator.ArchitectureEvaluator;
......@@ -34,7 +36,8 @@ import org.fortiss.af3.exploration.moea.model.DseSpecification;
*
* @author huang
*/
public class ArchitectureExplorationProblemModule extends
public class ArchitectureExplorationProblemModule
extends
DseProblemModuleBase<ArchitectureExplorationEncoding, ArchitectureSolution, ArchitectureDecoder> {
DSEFactory dseFactory = DSEFactory.getInstance();
......@@ -65,12 +68,14 @@ public class ArchitectureExplorationProblemModule extends
DecoderDependencyGraph execDepGraph = new DecoderDependencyGraph(requestedSolutions);
// TODO: construct the execution dependency graph elsewhere?
bindProblem(dseFactory.createArchitectureExplorationCreator(),
dseFactory.createArchitectureDecoder(execDepGraph), archEvaluator);
// bindProblem(dseFactory.createArchitectureExplorationCreator(),
// dseFactory.createArchitectureDecoder(execDepGraph), archEvaluator);
bindProblem(new GuiceCreator(), new GuiceDecoder(), archEvaluator);
// Create/Bind the subproblems of the architectural exploration problem.
try {
dseFactory.createSubProblems(this, dse, execDepGraph);
// dseFactory.createSubProblems(this, dse, execDepGraph);
} catch(Exception e) {
throw new RuntimeException("Failed setting up the DSE Problem instance.", e);
}
......@@ -78,6 +83,8 @@ public class ArchitectureExplorationProblemModule extends
// Create evaluators wrappers (based on provided goal specification)
try {
addGoalEvaluators(archEvaluator);
// addGoalEvaluator(new EnergyObjectiveEvaluator(),
// PredefinedFactory.eINSTANCE.createEnergyMinObjective(), 0);
} catch(Exception e) {
throw rethrow(e);
}
......
......@@ -124,31 +124,30 @@ public abstract class ProblemModuleBase<G extends Genotype, R extends Creator<G>
multibinder.addBinding().toInstance((Evaluator<Object>)evaluator);
}
/** Registers a pre-constructor creator and decoder with the Opt4J engine. */
@SuppressWarnings("unchecked")
protected void bindProblem(R creator, D decoder) {
registerCreatorDecoder(creator, decoder);
// This is inspired from ProblemModule.bindProblem(), which does not allow to pass
// parameters to the constructor of the creators/decoders. Hence, a pre-constructed
// creator/decoder is bound here.
// Note that in contrast to ProblemModule.bindProblem(), the creator and the decoder
// are not bound in the singleton scope, since these classes need to be parameterized
// with the current input model.
binder().bind(new TypeLiteral<Creator<Genotype>>() { // empty
}).toInstance((Creator<Genotype>)creator);
// /** Registers a pre-constructor creator and decoder with the Opt4J engine. */
// @SuppressWarnings("unchecked")
// protected void bindProblem(R creator, D decoder) {
// registerCreatorDecoder(creator, decoder);
//
// // This is inspired from ProblemModule.bindProblem(), which does not allow to pass
// // parameters to the constructor of the creators/decoders. Hence, a pre-constructed
// // creator/decoder is bound here.
//
// // Note that in contrast to ProblemModule.bindProblem(), the creator and the decoder
// // are not bound in the singleton scope, since these classes need to be parameterized
// // with the current input model.
// binder().bind(new TypeLiteral<Creator<Genotype>>() { // empty
// }).toInstance((Creator<Genotype>)creator);
//
// binder().bind(new TypeLiteral<Decoder<Genotype, Object>>() { // empty
// }).toInstance((Decoder<Genotype, Object>)decoder);
// }
binder().bind(new TypeLiteral<Decoder<Genotype, Object>>() { // empty
}).toInstance((Decoder<Genotype, Object>)decoder);
}
/** Registers a pre-constructor creator, decoder, and evaluator with the Opt4J engine. */
/** Registers a pre-constructor creator and decoder with the Opt4J engine. */
@SuppressWarnings("unchecked")
// TODO: remove casts and rethrow the exception.
protected
void bindProblem(R creator, D decoder, Evaluator<? extends Phenotype> evaluator) {
registerCreatorDecoder(creator, decoder);
protected void bindProblem(Creator creator, Decoder decoder,
Evaluator<? extends Phenotype> evaluator) {
registerCreatorDecoder((R)creator, (D)decoder);
// This is inspired from ProblemModule.bindProblem(), which does not allow to pass
// parameters to the constructor of the creators/decoders. Hence, a pre-constructed
......@@ -166,6 +165,29 @@ public abstract class ProblemModuleBase<G extends Genotype, R extends Creator<G>
addEvaluator(evaluator);
}
// /** Registers a pre-constructor creator, decoder, and evaluator with the Opt4J engine. */
// @SuppressWarnings("unchecked")
// // TODO: remove casts and rethrow the exception.
// protected
// void bindProblem(R creator, D decoder, Evaluator<? extends Phenotype> evaluator) {
// registerCreatorDecoder(creator, decoder);
//
// // This is inspired from ProblemModule.bindProblem(), which does not allow to pass
// // parameters to the constructor of the creators/decoders. Hence, a pre-constructed
// // creator/decoder is bound here.
//
// // Note that in contrast to ProblemModule.bindProblem(), the creator and the decoder
// // are not bound in the singleton scope, since these classes need to be parameterized
// // with the current input model.
// binder().bind(new TypeLiteral<Creator<Genotype>>() { // empty
// }).toInstance((Creator<Genotype>)creator);
//
// binder().bind(new TypeLiteral<Decoder<Genotype, Object>>() { // empty
// }).toInstance((Decoder<Genotype, Object>)decoder);
//
// addEvaluator(evaluator);
// }
/**
* Stores the associated creator and decoder at this class, if they are not already set. (They
* might be set for this {@link ProblemModule} already, if multiple {@link Evaluator}s are
......
SFEncodingDecoder.java 38d5a6c261315d2fd24f06f764c97e9d9f6808db RED
SFEncodingDecoder.java 35536dec62c42b3acfc3a53973e804e238cfdad2 RED
SFGraphDecoder.java 82c9b536a526e0e2b23d35a64124e622e5eedd5a RED
SFMappingConstraintDecoder.java 69b46dc6184f316102df770ebad3814361db6d11 RED
SFMappingDecoder.java 0fe8c6aad79085a5be5ead4c38b21e06095944a9 RED
......@@ -33,8 +33,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.ArchExpSubDecod
* @author diewald
*/
public class SFEncodingDecoder<C> extends
ComposableDecoderBase<SafetyFunctionArchEncoding<C>, SafetyFunctionArchEncoding> implements
ArchExpSubDecoder {
ComposableDecoderBase<SafetyFunctionArchEncoding<C>, SafetyFunctionArchEncoding<C>>
implements ArchExpSubDecoder {
/**
* {@inheritDoc}
......
AbstractTaskMappingDecoder.java 52a08984ae1270bba11cf3a215009c9d8c1f9a17 RED
FailSilentAbstractTaskMappingDecoder.java 0d68a832a1e9bca8ef93aaffb9d309c1fe7d7f7a RED
AbstractTaskMappingDecoder.java 8f42a638ceeba220da3a22f281ce08fe0764934b RED
FailSilentAbstractTaskMappingDecoder.java f5a3160d8b34da3f5c1e77d370af98670d694923 RED
FaultDetectionVotingAbstractTaskMappingDecoder.java 91ad48817fdd592a70da6a08d4a0f666c01acc33 RED
TaskInstanceResourceAlignmentDecoder.java fe8b789f3a0185585a90cf1882fd3983453b4a0d RED
......@@ -28,8 +28,6 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.ArchExpSubDecod
import org.fortiss.af3.exploration.moea.model.DseSpecification;
import org.opt4j.core.problem.Decoder;
import com.google.inject.Inject;
/**
* Base class for {@link Decoder}s that instantiate {@link AbstractTaskMappingEncoding}s to
* {@link InstantiatedTaskMappingEncoding}.
......@@ -42,7 +40,6 @@ public abstract class AbstractTaskMappingDecoder<S extends InstantiatedTaskMappi
DseSpecification explorationDefinition;
/** Constructs a new decoder that instantiates {@link AbstractTaskMappingEncoding}. */
@Inject
public AbstractTaskMappingDecoder(DseSpecification explorationDefinition) {
this.explorationDefinition = explorationDefinition;
}
......
......@@ -22,6 +22,7 @@ import java.util.Collection;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmapping.PartitionMappingEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.AbstractTaskGraphEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.TaskMappingEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEntry;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.FailSilentTaskMappingEncoding;
......@@ -33,6 +34,10 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegen
import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter;
import org.fortiss.af3.exploration.moea.model.DseSpecification;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Provides;
/**
* Decoder for instantiating an {@link AbstractTaskMappingEncoding} to a
* {@link FailSilentTaskMappingEncoding}.
......@@ -41,25 +46,37 @@ import org.fortiss.af3.exploration.moea.model.DseSpecification;
*/
// FIXME: The type hierarchy and naming of the classes is extremely confusing. FIX ASAP!
public class FailSilentAbstractTaskMappingDecoder extends
AbstractTaskMappingDecoder<FailSilentTaskMappingEntry, FailSilentTaskMappingEncoding> {
AbstractTaskMappingDecoder<FailSilentTaskMappingEntry, FailSilentTaskMappingEncoding>
implements Provider<TaskMappingEncoding> {
/** Input task mapping that may contain components which need to be instantiated. */
@Inject
AbstractTaskMappingEncoding atmEnc;
/** Input task graph to perform the mapping. */
@Inject
AbstractTaskGraphEncoding<?, ?> atgEnc;
/**
* Input mapping of partitions to executions units. This step maps to partitions encoded here.
* Additionally, information about the phys. executor may be required for smart mapping
* decisions.
*/
@Inject
PartitionMappingEncoding partEnc;
/** Constructor. */
@Inject
public FailSilentAbstractTaskMappingDecoder(DseSpecification explorationDefinition) {
super(explorationDefinition);
}
/** {@inheritDoc} */
@Override
@Provides
public FailSilentTaskMappingEncoding decodeComposable(AbstractTaskMappingEncoding genotype,
FlatPhenotypeMap<Phenotype> phenotypeTypeMap) {
assert (false);
AbstractTaskGraphEncoding<?, ?> atgEnc =
phenotypeTypeMap.getEncoding(AbstractTaskGraphEncoding.class);
assert (atgEnc != null) : "The required abstract task graph encoding could not be found in the map of already decoded phenotypes.";
PartitionMappingEncoding partEnc =
phenotypeTypeMap.getEncoding(PartitionMappingEncoding.class);
assert (partEnc != null) : "The required partition mapping encoding could not be found in the map of already decoded phenotypes.";
return new FailSilentTaskMappingEncoding(explorationDefinition, partEnc, atgEnc, genotype);
return new FailSilentTaskMappingEncoding(explorationDefinition, partEnc, atgEnc, atmEnc);
}
// TODO: Abstract to the AbstractTaskMappingDecoder.
......@@ -70,9 +87,10 @@ public class FailSilentAbstractTaskMappingDecoder extends
* see {@link ComposableDecoder}.
*/
@Override
public FailSilentTaskMappingEncoding updateComposable(AbstractTaskMappingEncoding inGenotype,
FailSilentTaskMappingEncoding outGenotype,
FlatPhenotypeMap<Phenotype> decodedPhenotypes) throws DecodingException {
public FailSilentTaskMappingEncoding
updateComposable(AbstractTaskMappingEncoding inGenotype,
FailSilentTaskMappingEncoding outGenotype,
FlatPhenotypeMap<Phenotype> decodedPhenotypes) throws DecodingException {
outGenotype.replaceConstraints(inGenotype.getConstraints());
for(ITaskAdapter<?> comp : inGenotype.getRequesters()) {
......@@ -80,8 +98,9 @@ public class FailSilentAbstractTaskMappingDecoder extends
inGenotype.getMappingEntriesOf(comp);
Collection<FailSilentTaskMappingEntry> instEntries;
if(comp.isInstantiationRequired()) {
instEntries = filterSet(outGenotype.getMappingEntries(),
e -> e.getSource().getReplacedComponent() == comp);
instEntries =
filterSet(outGenotype.getMappingEntries(), e -> e.getSource()
.getReplacedComponent() == comp);
} else {
instEntries = outGenotype.getMappingEntriesOf(comp);
}
......@@ -117,8 +136,8 @@ public class FailSilentAbstractTaskMappingDecoder extends
rmTasks.forEach(e -> outGenotype.removeTask(e));
for(FailSilentTaskMappingEntry entry : outGenotype.getMappingEntries()) {
entry.resetTarget(
entry.getAssociatedElement(AbstractTaskMappingEntry.class).getTarget());
entry.resetTarget(entry.getAssociatedElement(AbstractTaskMappingEntry.class)
.getTarget());
}
return outGenotype;
......@@ -129,4 +148,12 @@ public class FailSilentAbstractTaskMappingDecoder extends
public Class<?> getPrimaryInputType() {
return AbstractTaskMappingEncoding.class;
}
// TODO: The list of parameters injected into the decodeComposable call should be 0, use fields
// for now.
/** {@inheritDoc} */
@Override
public TaskMappingEncoding get() {
return decodeComposable(null, null);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment