From dea0bffac4b301a131abe0c0b055f333cf5d54b9 Mon Sep 17 00:00:00 2001 From: Alexander Diewald <diewald@fortiss.org> Date: Sat, 14 Jul 2018 21:58:27 +0200 Subject: [PATCH] DI: Base the DSE architecture on DI. * Create a top-most injector (DSE injector) when the explorer is created. It hosts the Opt4J injector and allows accessing data from the DSE from within Opt4J Modules. * Enable Multi-Operator bindings (multiple operators from which one is selected to be applied on the same Genotype-Type) by the Operator's type. This is required to allow injecting DSE-wide parameters, e.g., system model data. * Use a OperatorKey to allow registering Operators Objects or their Classes in the selection map. * Operators registered by their type are initialized lazily when they are delivered by the OperatorSelector on request. * Remove various dependencies on the SystemModelAdapter (Use DI where data is needed). This allows to break up very complex inheritance hierarchies. * Extend the SystemModelAdapter to use @Provides annotations that are used in opt4j modules (e.g. decoders) to obtain system model data. * Some of the old custom factories are now initialized with a null value for the SystemModelAdapter since they will be removed soon due to the use of DI. Signed-off-by: Alexander Diewald <diewald@fortiss.org> --- .../fortiss/af3/exploration/alg/dse/.ratings | 2 +- .../af3/exploration/alg/dse/Explorer.java | 9 ++- .../alg/dse/TaskMappingFactory.java | 26 +----- .../af3/exploration/alg/dse/backend/.ratings | 2 +- .../alg/dse/backend/ExplorerBackendBase.java | 25 +++--- .../alg/dse/backend/opt4j/.ratings | 3 +- .../backend/opt4j/Opt4JDseTaskProvider.java | 46 +++++++++++ .../backend/opt4j/Opt4JExplorerBackend.java | 38 ++++----- .../extensions/compositegene/decode/.ratings | 2 +- .../compositegene/decode/GuiceDecoder.java | 23 +++--- .../alg/dse/backend/opt4j/mating/.ratings | 2 +- .../MatingCrossoverMutateRepairModule.java | 2 +- .../alg/dse/backend/opt4j/operator/.ratings | 2 +- .../backend/opt4j/operator/OperatorUtil.java | 49 ++++++++++-- .../backend/opt4j/operator/crossover/.ratings | 2 +- .../CrossoverAbstractTaskMappingModule.java | 8 +- .../CrossoverOperatorModuleBase.java | 9 +++ .../backend/opt4j/operator/mutate/.ratings | 2 +- .../mutate/MutateOperatorModuleBase.java | 20 ++++- .../operator/mutate/partitionmapping/.ratings | 8 +- .../partitionmapping/MutatePartitionBase.java | 3 + .../MutatePartitionDecrement.java | 5 +- .../MutatePartitionIncrement.java | 3 + .../PartitionMappingModule.java | 16 +--- .../mutate/taskinstantiation/.ratings | 4 +- .../taskinstantiation/MutateTaskInstance.java | 12 +-- .../MutateTaskInstanceModule.java | 14 +--- .../operator/mutate/taskmapping/.ratings | 6 +- .../mutate/taskmapping/MutateAllocation.java | 17 ++-- .../MutateRedundancyDecrement.java | 3 + .../MutateRedundancyIncrement.java | 7 +- .../taskmapping/MutateTaskMappingModule.java | 24 +----- .../backend/opt4j/operator/selection/.ratings | 13 +-- .../IMultiSelectorOperatorModule.java | 11 ++- .../operator/selection/IOperatorSelector.java | 8 +- .../opt4j/operator/selection/OperatorKey.java | 79 +++++++++++++++++++ .../selection/OperatorSelectorBase.java | 41 +++++++--- .../selection/OperatorSelectorPredicate.java | 14 ++-- .../selection/RandomOperatorSelector.java | 4 +- .../selection/RoundRobinOperatorSelector.java | 2 +- .../alg/dse/backend/opt4j/problem/.ratings | 2 +- .../ArchitectureExplorationProblemModule.java | 15 ++-- .../opt4j/problem/DseProblemModuleBase.java | 2 +- .../alg/dse/sysmodel/arch/.ratings | 2 +- .../dse/sysmodel/arch/SystemModelAdapter.java | 18 ++++- 45 files changed, 392 insertions(+), 213 deletions(-) create mode 100644 org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JDseTaskProvider.java create mode 100644 org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorKey.java 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 7d71b687..80924703 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 @@ -3,4 +3,4 @@ DSEFactory.java c033d4fb34746a0f712be1d99e648d3c95623497 RED Explorer.java 48ce78929632a9b78b4c809c7719eb5aa46d21df RED ImplicitExplorationTargetFactory.java 25c3c668ed268843f8af7e37eb03370ed513b482 RED SolutionQuantification.java 19cd7caa721bbca3112af7825c7fb20a96a4a799 RED -TaskMappingFactory.java 7fc51aac3a3f0342c7fbee01db0dd7c17251e49b RED +TaskMappingFactory.java 88a64fe8b56faad869ccc5cb9111cee6e90d32d3 RED 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 48ce7892..9af6eeae 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 @@ -41,6 +41,9 @@ 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 * @@ -222,14 +225,16 @@ public class Explorer { } /** Explorer backend */ - private Opt4JExplorerBackend createExplorerBackend(DseSpecification dse, + 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, systemModelAdapter, + return new Opt4JExplorerBackend(dse, expSpec, targetAssocMap, dseInjector, requestedSolutions, progressMonitor); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/TaskMappingFactory.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/TaskMappingFactory.java index 7fc51aac..88a64fe8 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/TaskMappingFactory.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/TaskMappingFactory.java @@ -269,12 +269,10 @@ public abstract class TaskMappingFactory<S extends InstantiatedTaskMappingEntry, */ @SuppressWarnings("unchecked") public <RT, ET extends ExplorationTarget<RT>> EvaluatorWrapper<?, RT, ET> - createEvaluatorWrapper(ExplorationTarget<?> goal, int priority, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter) throws Exception { + createEvaluatorWrapper(ExplorationTarget<?> goal, int priority) throws Exception { ExplorationEvaluationService<?> evalService = ExplorationEvaluationService.getInstance(); EvaluatorWrapper<?, RT, ET> evaluatorWrapper = - (EvaluatorWrapper<?, RT, ET>)evalService.createEvalWrapperFor(systemModelAdapter, - goal); + (EvaluatorWrapper<?, RT, ET>)evalService.createEvalWrapperFor(null, goal); // TODO: remove the block below when all evaluators are migrated to the service interface. if(evaluatorWrapper == null) { @@ -282,30 +280,14 @@ public abstract class TaskMappingFactory<S extends InstantiatedTaskMappingEntry, if(goal instanceof FailureMinObjective) { evaluatorWrapper = (EvaluatorWrapper<?, RT, ET>)createFailureMinObjectiveWrapper(goal, - priority, systemModelAdapter); + priority, null); } /* Then, the constraints are handled */ else if(goal instanceof DeadlineConstraint) { evaluatorWrapper = (EvaluatorWrapper<?, RT, ET>)createDeadlineConstraintWrapper(goal, - priority, systemModelAdapter); - } else if(goal instanceof PeriodConstraint) { - evaluatorWrapper = - (EvaluatorWrapper<?, RT, ET>)createPeriodConstraintWrapper(goal, priority, - systemModelAdapter); - } else if(goal instanceof ComponentMultiAllocationConstraint) { - evaluatorWrapper = - (EvaluatorWrapper<?, RT, ET>)createComponentMultiAllocationConstraintWrapper( - goal, priority, systemModelAdapter); - } else if(goal instanceof ComponentMultiDislocationConstraint) { - evaluatorWrapper = - (EvaluatorWrapper<?, RT, ET>)createComponentMultiDislocationConstraintWrapper( - goal, priority, systemModelAdapter); - } else if(goal instanceof SafetyIntegrityLevelConstraint) { - evaluatorWrapper = - (EvaluatorWrapper<?, RT, ET>)createSafetyIntegrityLevelConstraintWrapper( - goal, priority, systemModelAdapter); + priority, 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 30eb5f3e..3e8c90ba 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 3171b381ae145417c339607ccc57eb8037cbb354 RED +ExplorerBackendBase.java c8cb7fda00311b9f3002833eb5cd3d2eb3615ea4 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 3171b381..c8cb7fda 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 @@ -24,11 +24,9 @@ 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.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.arch.SystemModelAdapter; 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; @@ -40,12 +38,16 @@ 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> implements IExplorerBackend<O> { +public abstract class ExplorerBackendBase<O extends IOptimizer> extends AbstractModule implements + IExplorerBackend<O> { /** DSE specification (optimizer parameters, goal specification, input model, ...) */ protected DseSpecification dse; @@ -60,7 +62,7 @@ public abstract class ExplorerBackendBase<O extends IOptimizer> implements IExpl protected Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap; /** Representation of system model (=input) that is evaluated during this DSE run */ - protected SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter; + protected Injector dseInjector; /** Set of requested {@link Phenotype}s that form the solution set. */ protected Set<Class<? extends IExplorationEncoding>> requestedSolutions; @@ -82,14 +84,13 @@ public abstract class ExplorerBackendBase<O extends IOptimizer> implements IExpl * and the goal specification */ protected ExplorerBackendBase(DseSpecification dse, ExplorationSpecification expSpec, - Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, + Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, Injector dseInjector, Set<Class<? extends IExplorationEncoding>> requestedSolutions, IProgressMonitor progressMonitor) { this.dse = dse; this.expSpec = expSpec; this.targetAssocMap = targetAssocMap; - this.systemModelAdapter = systemModelAdapter; + this.dseInjector = dseInjector; this.requestedSolutions = requestedSolutions; this.progressMonitor = progressMonitor; @@ -97,8 +98,8 @@ public abstract class ExplorerBackendBase<O extends IOptimizer> implements IExpl // instantiation of the Evaluators by the goals. Those are generified, and hence, the // instance must exist already. try { - DSEFactory.getInstance() - .createTaskMappingFactory(dse.getParameters().getExecutionModel()); + DSEFactory.getInstance().createTaskMappingFactory( + dse.getParameters().getExecutionModel()); } catch(UnsupportedDataTypeException e) { // See todo above e.printStackTrace(); @@ -168,10 +169,8 @@ public abstract class ExplorerBackendBase<O extends IOptimizer> implements IExpl 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."; + 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(); 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 9c1c8f25..9f36a7a7 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,4 +1,5 @@ Opt4JDseTask.java b5cb9e664e7a8fc2b5157bcdcaca740c2fa85336 YELLOW +Opt4JDseTaskProvider.java ff2bbc6da2b21bd0bc64c3fa77dc8fa9939d10af RED Opt4JExplorationSolutionSet.java 8578ee9c438bc3327a64172e996306a89606c782 RED -Opt4JExplorerBackend.java 8c673d28854328635af99c0df5ce2864b9bc2262 RED +Opt4JExplorerBackend.java efa271f055e57df194e24f4bb7e94a00d252f3bb RED Opt4JSingleExplorationSolution.java 41ce92d11b2e7a6a8c39bffa990c691160c36c8d RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JDseTaskProvider.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JDseTaskProvider.java new file mode 100644 index 00000000..ff2bbc6d --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/Opt4JDseTaskProvider.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.dse.backend.opt4j; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Provides; +import com.google.inject.name.Named; + +/** + * Provides the {@link Opt4JDseTask} wrapper that allows accessing the {@link Inject} used in the + * Opt4J framework. + * + * @author diewald + */ +public class Opt4JDseTaskProvider implements Provider<Opt4JDseTask> { + /** The current task instance. */ + private Opt4JDseTask opt4JTask; + + /** Constructor. */ + @Inject + public Opt4JDseTaskProvider(Opt4JDseTask opt4JDseTask) { + this.opt4JTask = opt4JDseTask; + } + + /** {@inheritDoc} */ + @Override + @Provides + @Named("Opt4JDseInjector") + public Opt4JDseTask get() { + return opt4JTask; + } +} 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 8c673d28..efa271f0 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 @@ -47,9 +47,6 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmap import org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.ArchitectureExplorationProblemModule; 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.dse.sysmodel.arch.IExecutionUnitAdapter; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; -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.ExplorationSpecification; @@ -67,10 +64,10 @@ 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.start.Opt4JTask; import org.opt4j.optimizers.ea.EvolutionaryAlgorithmModule; import org.opt4j.optimizers.ea.Spea2Module; +import com.google.inject.Injector; import com.google.inject.Module; /** @@ -83,7 +80,7 @@ import com.google.inject.Module; public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { /** Opt4J optimization process */ - private Opt4JTask opt4JTask; + private Opt4JDseTask opt4JTask; /** EA parameters. */ private EAOptimizer opt4JParameters; @@ -101,12 +98,11 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { * @throws Exception */ public Opt4JExplorerBackend(DseSpecification dse, ExplorationSpecification expSpec, - Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, + Map<ExplorationTarget<?>, ExplorationTarget<?>> targetAssocMap, Injector dseInjector, Set<Class<? extends IExplorationEncoding>> requestedSolutions, IProgressMonitor progressMonitor) throws Exception { // Optimizer independent configuration - super(dse, expSpec, targetAssocMap, systemModelAdapter, requestedSolutions, progressMonitor); + super(dse, expSpec, targetAssocMap, dseInjector, requestedSolutions, progressMonitor); if(dse.getOptimizer() instanceof EAOptimizer) { init((EAOptimizer)dse.getOptimizer()); @@ -128,6 +124,7 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { // Instantiate modules that describe the optimization problem Collection<Module> modules = new ArrayList<Module>(); + modules.add(this); // Evolutionary algorithm module EvolutionaryAlgorithmModule evolutionaryAlgorithmModule = new EvolutionaryAlgorithmModule(); @@ -161,8 +158,7 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { // modules.add(multiEvaluatorModule); archExplorationProblemModule = - new ArchitectureExplorationProblemModule(dse, systemModelAdapter, - requestedSolutions); + new ArchitectureExplorationProblemModule(dse, requestedSolutions); modules.add(archExplorationProblemModule); // Configure operators @@ -188,23 +184,18 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { modules.add(new NopPlatformCommGraphMutateModule()); // Partition Exploration - modules.add(new PartitionMappingModule( - (Collection<IExecutionUnitAdapter<?>>)(Collection<?>)systemModelAdapter - .getDeploymentTargets())); + // TODO: Remove the obfuscated injection below when the OperatorSelection is fixed for + // injected operators. + PartitionMappingModule partMapping = new PartitionMappingModule(); + modules.add(partMapping); // Task instantiation - MutateTaskInstanceModule mutateInstanceModule = - new MutateTaskInstanceModule( - (Collection<ITaskAdapter<?>>)(Collection<?>)systemModelAdapter - .getDeployableComponents()); + MutateTaskInstanceModule mutateInstanceModule = new MutateTaskInstanceModule(); // mutateInstanceModule.setMutationRateType(MutationRateType.ADAPTIVE); modules.add(mutateInstanceModule); // Task allocation - MutateTaskMappingModule mutateModule = - new MutateTaskMappingModule( - (Collection<ITaskAdapter<?>>)(Collection<?>)systemModelAdapter - .getDeployableComponents()); + MutateTaskMappingModule mutateModule = new MutateTaskMappingModule(); // mutateModule.setMutationRateType(MutationRateType.ADAPTIVE); // mutateModule.setMutationRate(0.125); modules.add(mutateModule); @@ -228,6 +219,7 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { // Create and initialize optimization task opt4JTask = new Opt4JDseTask(); + opt4JTask.init(dseInjector); opt4JTask.init(modules); if(progressMonitor != null) { @@ -342,4 +334,8 @@ public class Opt4JExplorerBackend extends ExplorerBackendBase<EAOptimizer> { return rval; } + + 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/decode/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/.ratings index e6e9b2d5..ae7800cd 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 @@ -2,7 +2,7 @@ ComposableDecoder.java 0ef247e0e8424968cd8dab8317df0e504c5018d4 RED ComposableDecoderBase.java 7c47b41e609b6911128efa469c2dd65122276bcc RED CompositeDecoder.java 68864146cbd7b0d1444d4157cf88023deb4a21ea RED CompositeDecoderBase.java cc878483ec3dcf3afd60509579c7c17a3433893c RED -GuiceDecoder.java d0284d290da2c0248f1a59b654045f5d1042303e RED +GuiceDecoder.java 40fe6757b224ffc399ef14e5b60a36775edffe3c 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/GuiceDecoder.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/extensions/compositegene/decode/GuiceDecoder.java index d0284d29..40fe6757 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 @@ -17,12 +17,12 @@ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositege import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService; +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.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.phenotype.Phenotype; import org.fortiss.af3.exploration.alg.dse.module.DecoderModule; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; import org.fortiss.af3.exploration.alg.service.IExplorationModuleService; import org.opt4j.core.Genotype; import org.opt4j.core.genotype.CompositeGenotype; @@ -42,10 +42,6 @@ import com.google.inject.Provides; */ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Phenotype> { - /** SystemModelAdapter containing input parameters. */ - // FIXME: Move to general injector in the ExplorationModule service. - protected SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> sysModel; - /** Resulting phenotype from the decoding phase that is composed of sub-{@link Phenotype}s. */ protected Phenotype composedPhenotype; @@ -53,9 +49,9 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph // TODO: Remove this hard coded line and get the desired result from the backend interface. protected Class<? extends Phenotype> resultType = FailSilentTaskMappingEncoding.class; - /** Injector created by the {@link Opt4JTask}. */ + /** {@link Opt4JTask} provider used to obtain the opt4j injector. */ @Inject - protected Injector opt4JInjector; + protected Opt4JDseTaskProvider opt4JProvider; /** Child injector for the dependency management of the decode phase. */ protected Injector decodingInjector; @@ -65,10 +61,12 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph protected ThreadLocal<CompositeGenotype<Class<? extends Genotype>, ? extends Genotype>> genotype = new ThreadLocal<>(); - /** Constructor. */ - public GuiceDecoder(SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> sysModel) { - this.sysModel = sysModel; - } + // To be used later: Constructor injection is favorable. + // /** Constructor. Gets the Opt4J injector by Guice. */ + // @Inject + // public GuiceDecoder(Opt4JDseTaskProvider provider) { + // decodingInjector = provider.get().get().createChildInjector(this); + // } /** {@inheritDoc} */ @SuppressWarnings("unchecked") @@ -84,7 +82,7 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph .set((CompositeGenotype<Class<? extends Genotype>, ? extends 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 = opt4JProvider.get().get().createChildInjector(this); decodingInjector.getInstance(resultType); return composedPhenotype; } @@ -106,7 +104,6 @@ public class GuiceDecoder extends AbstractModule implements Decoder<Genotype, Ph @Override protected void configure() { // bindScope(ThreadScoped.class, new ThreadScope()); - install(sysModel); for(DecoderModule<?> module : getService(IExplorationModuleService.class).getDecoders()) { install(module); diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/.ratings index 439edaad..3653b9d5 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/.ratings @@ -1,2 +1,2 @@ MatingCrossoverMutateRepair.java 062ba933109799bb27cc3d4b8ebe8d3925d5c8ec RED -MatingCrossoverMutateRepairModule.java ae5182b0db7401f2509dfe24ac3b85f42b00d5c1 RED +MatingCrossoverMutateRepairModule.java f1e17e5a5f94238fc81ff50d01a5537a98069a04 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/MatingCrossoverMutateRepairModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/MatingCrossoverMutateRepairModule.java index ae5182b0..f1e17e5a 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/MatingCrossoverMutateRepairModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/mating/MatingCrossoverMutateRepairModule.java @@ -27,6 +27,6 @@ public class MatingCrossoverMutateRepairModule extends MatingModule { /** {@inheritDoc} */ @Override protected void config() { - binder().bind(Mating.class).to(MatingCrossoverMutateRepair.class); + bind(Mating.class).to(MatingCrossoverMutateRepair.class); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/.ratings index a88bd1c6..4282cc19 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/.ratings @@ -1,2 +1,2 @@ ComposableOperatorClassPredicate.java 402b631f26ecff002f33f1dffa6989dc565a207e RED -OperatorUtil.java c95253d64ee68df857ef743df8cc151c5b1fc678 RED +OperatorUtil.java 1dbc835f3b04f8a6e001bed508857f20654496ae RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/OperatorUtil.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/OperatorUtil.java index c95253d6..1dbc835f 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/OperatorUtil.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/OperatorUtil.java @@ -15,7 +15,9 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.Opt4JDseTaskProvider; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.selection.IOperatorSelector; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.selection.OperatorKey; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.selection.OperatorSelectorPredicate; import org.opt4j.core.Genotype; import org.opt4j.core.optimizer.Operator; @@ -41,8 +43,8 @@ public class OperatorUtil { */ public static <O extends Operator<?>> void addOperatorInstance(O operator, IOperatorSelector operatorSelector, Binder binder, TypeLiteral<O> typeLiteral) { - addOperatorMapBinding(binder, operator, typeLiteral, new OperatorSelectorPredicate( - operator, operatorSelector)); + addOperatorMapBinding(binder, operator, typeLiteral, new OperatorSelectorPredicate<O>( + new OperatorKey<O>(operator), operatorSelector)); } /** @@ -53,13 +55,14 @@ public class OperatorUtil { public static <G extends Genotype, O extends Operator<?>> void addOperatorInstance( Class<G> genotypeType, O operator, IOperatorSelector operatorSelector, Binder binder, TypeLiteral<O> typeLiteral) { - addOperatorMapBinding(binder, operator, typeLiteral, new OperatorSelectorPredicate( - operator, new ComposableOperatorClassPredicate(genotypeType), operatorSelector)); + addOperatorMapBinding(binder, operator, typeLiteral, new OperatorSelectorPredicate<O>( + new OperatorKey<O>(operator), new ComposableOperatorClassPredicate(genotypeType), + operatorSelector)); } /** Registers a pre-constructed operator and predicate instance with the Opt4J framework. */ private static <O extends Operator<?>> void addOperatorMapBinding(Binder binder, O operator, - TypeLiteral<O> typeLiteral, OperatorSelectorPredicate predicate) { + TypeLiteral<O> typeLiteral, OperatorSelectorPredicate<O> predicate) { // This is inspired from org.opt4j.operators.OperatorModule.addOperator(), which does not // allow to pass parameters to the constructor of the operators. Hence, a pre-constructed // mutate operator is bound here (using toInstance() instead of to()). @@ -68,4 +71,40 @@ public class OperatorUtil { }, typeLiteral); map.addBinding(predicate).toInstance(operator); } + + /** + * Registers a pre-constructed operator instance with the Opt4J framework, i.e. an operator that + * can be built using a non-default constructor and that thus can be based on external state. + */ + public static <O extends Operator<?>> void addOperatorType(Class<O> operator, + IOperatorSelector operatorSelector, Binder binder, TypeLiteral<O> typeLiteral) { + addOperatorMapBinding(binder, operator, typeLiteral, new OperatorSelectorPredicate<O>( + new OperatorKey<O>(operator, binder.getProvider(Opt4JDseTaskProvider.class)), + operatorSelector)); + } + + /** + * Registers a pre-constructed operator instance with the Opt4J framework, i.e. an operator that + * can be built using a non-default constructor and that thus can be based on external state. + * The operator will be only applied to the given {@link Genotype}. + */ + public static <G extends Genotype, O extends Operator<?>> void addOperatorType( + Class<G> genotypeType, Class<O> operator, IOperatorSelector operatorSelector, + Binder binder, TypeLiteral<O> typeLiteral) { + addOperatorMapBinding(binder, operator, typeLiteral, new OperatorSelectorPredicate<O>( + new OperatorKey<O>(operator, binder.getProvider(Opt4JDseTaskProvider.class)), + new ComposableOperatorClassPredicate(genotypeType), operatorSelector)); + } + + /** Registers a pre-constructed operator and predicate instance with the Opt4J framework. */ + private static <O extends Operator<?>> void addOperatorMapBinding(Binder binder, + Class<O> operator, TypeLiteral<O> typeLiteral, OperatorSelectorPredicate<O> predicate) { + // This is inspired from org.opt4j.operators.OperatorModule.addOperator(), which does not + // allow to pass parameters to the constructor of the operators. Hence, a pre-constructed + // mutate operator is bound here (using toInstance() instead of to()). + MapBinder<OperatorPredicate, O> map = + MapBinder.newMapBinder(binder, new TypeLiteral<OperatorPredicate>() { // empty + }, typeLiteral); + map.addBinding(predicate).to(operator); + } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/.ratings index 972ab98a..8238c4c5 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/.ratings @@ -1,6 +1,6 @@ CrossoverAbstractTaskMappingModule.java 04c64460b461c69b09fe66b3af2a9423906ffaa8 RED CrossoverAllocationBase.java d11fd0c9627fd8224d49ee7541b7640b7f164bbb RED -CrossoverOperatorModuleBase.java 4343d7a3e8d5dc926b63fde625e8fee891b6ba9d RED +CrossoverOperatorModuleBase.java e4e6e14b529758f1664dc2df0cdb84f759ba2add RED CrossoverRandManyAllocation.java 961182441dfde02a76373791aec4db804fa2e675 RED CrossoverSingleAllocation.java 551f5c07151b80aac1e77e73d5c380474ef200c1 RED NopCrossover.java 6c6c7ab84b33865dae3740604372d3c7d544738f RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverAbstractTaskMappingModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverAbstractTaskMappingModule.java index 04c64460..4eb6b6da 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverAbstractTaskMappingModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverAbstractTaskMappingModule.java @@ -15,8 +15,8 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.crossover; -import org.fortiss.af3.exploration.alg.dse.TaskMappingFactory; 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; /** * Crossover module selecting the {@link CrossoverRandManyAllocation} operator to be applied on @@ -38,7 +38,9 @@ public class CrossoverAbstractTaskMappingModule extends CrossoverOperatorModuleB public void config() { super.config(); - addOperatorInstance(AbstractTaskMappingEncoding.class, - TaskMappingFactory.getInstance().createCrossoverRandManyAllocationOperator(rate)); + addOperatorInstance( + AbstractTaskMappingEncoding.class, + new CrossoverRandManyAllocation<AbstractTaskMappingEntry, AbstractTaskMappingEncoding>( + rate)); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverOperatorModuleBase.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverOperatorModuleBase.java index 4343d7a3..e4e6e14b 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverOperatorModuleBase.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/crossover/CrossoverOperatorModuleBase.java @@ -31,6 +31,7 @@ import org.opt4j.operators.crossover.Crossover; */ public abstract class CrossoverOperatorModuleBase extends BasicCrossoverModule implements IMultiSelectorOperatorModule<Crossover<?>> { + /** Default selection strategy for crossover operators: round robin */ private IOperatorSelector operatorSelector = new RoundRobinOperatorSelector(); @@ -42,6 +43,14 @@ public abstract class CrossoverOperatorModuleBase extends BasicCrossoverModule i binder(), getOperatorTypeLiteral()); } + /** {@inheritDoc} */ + @Override + public void addOperatorType(Class<? extends Genotype> genotypeType, + Class<Crossover<?>> crossoverOperator) { + OperatorUtil.addOperatorType(genotypeType, crossoverOperator, operatorSelector, binder(), + getOperatorTypeLiteral()); + } + /** {@inheritDoc} */ @Override public IOperatorSelector getOperatorSelector(Class<? extends Genotype> genotypeType) { diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/.ratings index d60f92a5..4b09baaf 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/.ratings @@ -1,3 +1,3 @@ MutateBase.java 74235bf78f594b887cba7a5005443eda80fc94f7 RED -MutateOperatorModuleBase.java 353924ab96686b5019c68c4bdd7741879cd998c4 RED +MutateOperatorModuleBase.java b8ff7e1656a2c206e7f7eca965fe00d0ad13b9cb RED NopMutateOperator.java 6cc7d102046e582360a62dcf12a24806f6525df5 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/MutateOperatorModuleBase.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/MutateOperatorModuleBase.java index 353924ab..b8ff7e16 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/MutateOperatorModuleBase.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/MutateOperatorModuleBase.java @@ -27,14 +27,17 @@ import org.opt4j.core.optimizer.Operator; import org.opt4j.operators.mutate.BasicMutateModule; import org.opt4j.operators.mutate.Mutate; +import com.google.inject.TypeLiteral; + /** * Base class for mutate operator module that enables the registration of pre-constructed operators, * which thus can be constructed using a non-default constructor. * * @author barner */ -public abstract class MutateOperatorModuleBase extends BasicMutateModule - implements IMultiSelectorOperatorModule<Mutate<?>> { +public abstract class MutateOperatorModuleBase<O extends Mutate<?>> extends BasicMutateModule + implements IMultiSelectorOperatorModule<O> { + /** * Contains the correspondences between the {@link Genotype}s and the {@link IOperatorSelector} * selecting the {@link Operator}s used to modify the {@link Genotype}s. @@ -44,8 +47,17 @@ public abstract class MutateOperatorModuleBase extends BasicMutateModule /** {@inheritDoc} */ @Override - public void addOperatorInstance(Class<? extends Genotype> genotypeType, - Mutate<?> mutateOperator) { + public void addOperatorType(Class<? extends Genotype> genotypeType, Class<O> mutateOperator) { + if(selectorForGenotype.get(genotypeType) == null) { + selectorForGenotype.put(genotypeType, new RoundRobinOperatorSelector()); + } + OperatorUtil.addOperatorType(genotypeType, mutateOperator, + selectorForGenotype.get(genotypeType), binder(), TypeLiteral.get(mutateOperator)); + } + + /** {@inheritDoc} */ + @Override + public void addOperatorInstance(Class<? extends Genotype> genotypeType, O mutateOperator) { if(selectorForGenotype.get(genotypeType) == null) { selectorForGenotype.put(genotypeType, new RoundRobinOperatorSelector()); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/.ratings index a5fe5c17..704a5750 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/.ratings @@ -1,4 +1,4 @@ -MutatePartitionBase.java 6cb254826ed2feb9a1609eb9208c8060868c5fe5 RED -MutatePartitionDecrement.java aa364f0d6e970ecc7e5d004c5d132878465951c0 RED -MutatePartitionIncrement.java 4b8e804d7b8e18bbd422cd74a204c7c5d458a31e RED -PartitionMappingModule.java 0eb2323ca27acf3ad32a973984a127a006e4f4aa RED +MutatePartitionBase.java da153ee2b1a61a16845597152ceec789ec9a3b46 RED +MutatePartitionDecrement.java 1fbbdb03e57934e32079aad6f369d81e38b8054e RED +MutatePartitionIncrement.java d2b4f4a6d14a99e478490af588c5b41980196e57 RED +PartitionMappingModule.java 129c951618c031b670a488f041d077bde52ff9e5 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionBase.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionBase.java index 6cb25482..da153ee2 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionBase.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionBase.java @@ -25,6 +25,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.MutateB import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IExecutionUnitAdapter; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IResourceAdapter; +import com.google.inject.Inject; + /** * Base class for the mutation functions operating on the Partition to ExecutionUnit mapping, e.g. * cores. @@ -39,6 +41,7 @@ public abstract class MutatePartitionBase extends MutateBase<PartitionMappingEnc private double rate; /** Constructor. */ + @Inject public MutatePartitionBase(Collection<IExecutionUnitAdapter<?>> executionUnits) { this.allocationTargets.addAll(executionUnits); this.rate = 1 / allocationTargets.size(); diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionDecrement.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionDecrement.java index aa364f0d..1fbbdb03 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionDecrement.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionDecrement.java @@ -23,6 +23,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmappi import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IExecutionUnitAdapter; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IResourceAdapter; +import com.google.inject.Inject; + /** * Mutation operator that randomly selects resources from which to remove a random partition. The * rate is designed such that one resource is selected in average. @@ -30,7 +32,9 @@ import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IResourceAdapter; * @author diewald */ public class MutatePartitionDecrement extends MutatePartitionBase { + /** Constructor. */ + @Inject public MutatePartitionDecrement(Collection<IExecutionUnitAdapter<?>> executionUnits) { super(executionUnits); } @@ -42,5 +46,4 @@ public class MutatePartitionDecrement extends MutatePartitionBase { Stream<IResourceAdapter<?>> resStream = genotype.getResources().stream(); resStream.filter((res) -> rand.nextDouble() < p).forEach(remove); } - } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionIncrement.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionIncrement.java index 4b8e804d..d2b4f4a6 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionIncrement.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/MutatePartitionIncrement.java @@ -23,6 +23,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmappi import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IExecutionUnitAdapter; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IResourceAdapter; +import com.google.inject.Inject; + /** * Mutation operator that randomly selects resources for which to create a partition. The * rate is designed such that one resource is selected in average. @@ -31,6 +33,7 @@ import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IResourceAdapter; */ public class MutatePartitionIncrement extends MutatePartitionBase { /** Constructor. */ + @Inject public MutatePartitionIncrement(Collection<IExecutionUnitAdapter<?>> executionUnits) { super(executionUnits); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/PartitionMappingModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/PartitionMappingModule.java index 0eb2323c..129c9516 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/PartitionMappingModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/partitionmapping/PartitionMappingModule.java @@ -15,33 +15,21 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.partitionmapping; -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.operator.mutate.MutateOperatorModuleBase; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IExecutionUnitAdapter; /** * * @author diewald */ public class PartitionMappingModule extends MutateOperatorModuleBase { - /** {@link IExecutionUnitAdapter}s available as allocation targets. */ - Collection<IExecutionUnitAdapter<?>> executionUnits; - - /** Constructor. */ - public PartitionMappingModule(Collection<IExecutionUnitAdapter<?>> executionUnits) { - this.executionUnits = executionUnits; - } /** {@inheritDoc} */ @Override public void config() { super.config(); - addOperatorInstance(PartitionMappingEncoding.class, - new MutatePartitionDecrement(executionUnits)); - addOperatorInstance(PartitionMappingEncoding.class, - new MutatePartitionIncrement(executionUnits)); + addOperatorType(PartitionMappingEncoding.class, MutatePartitionDecrement.class); + addOperatorType(PartitionMappingEncoding.class, MutatePartitionIncrement.class); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/.ratings index 82224c77..96c7926a 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/.ratings @@ -1,2 +1,2 @@ -MutateTaskInstance.java 0c101e73c2605c3ce7338a4894ed7fc4b388e880 RED -MutateTaskInstanceModule.java 4ec43fc3539409b360dd3c4939d22cc1b487e6b5 RED +MutateTaskInstance.java 4759e6578e8387bb96abfe6b8e4bc68f3edec013 RED +MutateTaskInstanceModule.java 6bbd6ac39fc4f70d912225d48e9bba8e636a0f11 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstance.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstance.java index 0c101e73..4759e657 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstance.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstance.java @@ -21,16 +21,18 @@ import java.util.HashSet; 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.InstantiatedTaskMappingEncoding; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.InstantiatedTaskMappingEntry; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmapping.MutateTasksBase; +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.MutateBase; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.taskgraph.TaskGraph; import org.opt4j.operators.mutate.Mutate; +import com.google.inject.Inject; + /** * {@link Mutate} operator which manipulates the instantiation of the referenced * {@link ITaskAdapter} of a {@link InstantiatedTaskMappingEntry}. The instantiated - * {@link ITaskAdapter} is randomly selected from the set of instantiatable - * {@link ITaskAdapter}s of the associated {@link AbstractTaskMappingEntry}. + * {@link ITaskAdapter} is randomly selected from the set of instantiatable {@link ITaskAdapter}s of + * the associated {@link AbstractTaskMappingEntry}. * <p> * <b>NOTE:</b> Currently, this is a Nop operator, as a correct handling of {@link TaskGraph}s and * an appropriate reliability analysis must be worked out. @@ -38,7 +40,7 @@ import org.opt4j.operators.mutate.Mutate; * @author diewald */ public class MutateTaskInstance extends - MutateTasksBase<InstantiatedTaskMappingEntry, InstantiatedTaskMappingEncoding<InstantiatedTaskMappingEntry>> { + MutateBase<InstantiatedTaskMappingEncoding<InstantiatedTaskMappingEntry>> { /** * Collection of {@link ITaskAdapter}s which must be instantiated to obtain a * "concrete" logical model". @@ -46,8 +48,8 @@ public class MutateTaskInstance extends private Collection<ITaskAdapter<?>> abstractComponents; /** Constructor. */ + @Inject public MutateTaskInstance(Collection<ITaskAdapter<?>> tasks) { - super(tasks); abstractComponents = new HashSet<ITaskAdapter<?>>(); for(ITaskAdapter<?> curTask : tasks) { if(curTask.isInstantiationRequired()) { diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstanceModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstanceModule.java index 4ec43fc3..6bbd6ac3 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstanceModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskinstantiation/MutateTaskInstanceModule.java @@ -15,12 +15,9 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskinstantiation; -import java.util.Collection; - import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.InstantiatedTaskMappingEncoding; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.MutateOperatorModuleBase; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmapping.MutateTaskMappingModule; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; import org.opt4j.operators.mutate.Mutate; import com.google.inject.Module; @@ -36,21 +33,14 @@ import com.google.inject.Module; * * @author diewald */ +// TODO: Generic handling. public class MutateTaskInstanceModule extends MutateOperatorModuleBase { - /** Representation of the {@link ITaskAdapter}s to deploy. */ - private Collection<ITaskAdapter<?>> tasks; - - /** Constructor where the input system model has to be specified. */ - public MutateTaskInstanceModule(Collection<ITaskAdapter<?>> tasks) { - this.tasks = tasks; - } - /** {@inheritDoc} */ @Override public void config() { super.config(); - addOperatorInstance(InstantiatedTaskMappingEncoding.class, new MutateTaskInstance(tasks)); + addOperatorType(InstantiatedTaskMappingEncoding.class, MutateTaskInstance.class); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/.ratings index f082b56e..c0f3ffa4 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/.ratings @@ -1,6 +1,6 @@ MutateAllocation.java cee21301311e7e1bc1164f152e11760297bbd793 RED MutateRedundancy.java 4b8f9ba0a9aa542bb4d3d168115f3fb01cd31829 RED -MutateRedundancyDecrement.java d2b176412ccf746641e7f7ebeade83f94de5d3dc RED -MutateRedundancyIncrement.java 6fb9e2312877fa57bb8970f167564f186008def8 RED -MutateTaskMappingModule.java 4f2d680a94c6aadb99eb576b66dbd3c06f193d33 RED +MutateRedundancyDecrement.java 4a668dc9a3fa008babff9c5c7dbd4ec8f7abb180 RED +MutateRedundancyIncrement.java 69b8f93ab41dc3a28832108e6ae27de00d77c333 RED +MutateTaskMappingModule.java 2bd7389ffc6de8348c5bc5fbbaa3da30a07dc40c RED MutateTasksBase.java 237e281449ec0601623873db8d07ffe0c94f80bf RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateAllocation.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateAllocation.java index cee21301..2d1ed582 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateAllocation.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateAllocation.java @@ -27,6 +27,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.Ta import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; import org.fortiss.af3.exploration.alg.exception.ExplorationException; +import com.google.inject.Inject; + /** * Mutate operator manipulates the allocation of tasks to resources by replacing an existing * allocation with a new random allocation. @@ -36,6 +38,7 @@ import org.fortiss.af3.exploration.alg.exception.ExplorationException; public class MutateAllocation<S extends TaskMappingEntry<ITaskAdapter<?>, Partition>, T extends TaskMappingEncoding<ITaskAdapter<?>, S>> extends MutateTasksBase<S, T> { /** Constructs a new allocation mutation operator for a given exploration run */ + @Inject public MutateAllocation(Collection<ITaskAdapter<?>> tasks) { super(tasks); } @@ -84,8 +87,7 @@ public class MutateAllocation<S extends TaskMappingEntry<ITaskAdapter<?>, Partit * Performs the actual re-allocation of the given {@link ITaskAdapter}. * * @throws ExplorationException - * if no valid allocation targets can be identified for one - * {@link ITaskAdapter}. + * if no valid allocation targets can be identified for one {@link ITaskAdapter}. */ private void reAllocateMappingEntry(T encoding, ITaskAdapter<?> deployableComponent) throws ExplorationException { @@ -107,13 +109,16 @@ public class MutateAllocation<S extends TaskMappingEntry<ITaskAdapter<?>, Partit // List<IExecutionUnitAdapter<?>> physExecUnits = // new ArrayList<>(encoding.getAllowedAllocations(deployableComponent)); // List<Partition> targets = encoding.getAllowedPartitionTargets(physExecUnits); - List<Partition> targets = new ArrayList<>((Collection<Partition>)(Collection<?>)encoding - .getAllowedAllocations(deployableComponent)); + List<Partition> targets = + new ArrayList<>( + (Collection<Partition>)(Collection<?>)encoding + .getAllowedAllocations(deployableComponent)); int selExecU = max(0, rand.nextInt(targets.size()) - 1); selectedEntry.resetTarget(targets.get(selExecU)); } else { - List<Partition> targets = (List<Partition>)(Collection<?>)encoding - .getAllowedAllocations(deployableComponent); + List<Partition> targets = + (List<Partition>)(Collection<?>)encoding + .getAllowedAllocations(deployableComponent); int selExecU = max(0, rand.nextInt(targets.size()) - 1); selectedEntry.resetTarget(targets.get(selExecU)); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyDecrement.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyDecrement.java index d2b17641..4a668dc9 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyDecrement.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyDecrement.java @@ -23,6 +23,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.Ta import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.TaskMappingEntry; import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; +import com.google.inject.Inject; + /** * Mutate operator that decreases the redundancy of allocations. * @@ -31,6 +33,7 @@ import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; public class MutateRedundancyDecrement<S extends TaskMappingEntry<ITaskAdapter<?>, Partition>, T extends TaskMappingEncoding<ITaskAdapter<?>, S>> extends MutateRedundancy<S, T> { /** Constructs a new decrement redundancy mutation operator for a given exploration run */ + @Inject public MutateRedundancyDecrement(Collection<ITaskAdapter<?>> tasks) { super(tasks); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyIncrement.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyIncrement.java index 6fb9e231..69b8f93a 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyIncrement.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateRedundancyIncrement.java @@ -24,6 +24,8 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.Ta import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; import org.fortiss.af3.exploration.alg.exception.ExplorationException; +import com.google.inject.Inject; + /** * Mutate operator that decreases the redundancy of allocations. * @@ -32,6 +34,7 @@ import org.fortiss.af3.exploration.alg.exception.ExplorationException; public class MutateRedundancyIncrement<S extends TaskMappingEntry<ITaskAdapter<?>, Partition>, T extends TaskMappingEncoding<ITaskAdapter<?>, S>> extends MutateRedundancy<S, T> { /** Constructs a new increment redundancy mutation operator for a given exploration run */ + @Inject public MutateRedundancyIncrement(Collection<ITaskAdapter<?>> tasks) { super(tasks); } @@ -53,8 +56,8 @@ public class MutateRedundancyIncrement<S extends TaskMappingEntry<ITaskAdapter<? // The following code ensures an equal distribution of temporal and spatial replication if(rand.nextBoolean()) { assignedResources.add(encoding.createRandomEntry(deployableComponent, - CollectionUtils.asRandomAccessList( - encoding.getAllocatedResourcesFor(deployableComponent)))); + CollectionUtils.asRandomAccessList(encoding + .getAllocatedResourcesFor(deployableComponent)))); } else { assignedResources.add(encoding.createRandomEntry(deployableComponent)); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateTaskMappingModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateTaskMappingModule.java index 4f2d680a..2bd7389f 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateTaskMappingModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/mutate/taskmapping/MutateTaskMappingModule.java @@ -15,14 +15,9 @@ +--------------------------------------------------------------------------*/ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.taskmapping; -import java.util.Collection; - -import org.fortiss.af3.exploration.alg.dse.TaskMappingFactory; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.TaskMappingEncoding; -import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.TaskMappingEntry; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.abstractmapping.AbstractTaskMappingEncoding; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.mutate.MutateOperatorModuleBase; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter; import org.opt4j.operators.mutate.Mutate; import com.google.inject.Module; @@ -33,27 +28,16 @@ import com.google.inject.Module; * * @author huang */ +// TODO: Generic handling. public class MutateTaskMappingModule extends MutateOperatorModuleBase { - /** Representation of input system */ - private Collection<ITaskAdapter<?>> tasks; - - /** Constructor where the input system model has to be specified. */ - public MutateTaskMappingModule(Collection<ITaskAdapter<?>> tasks) { - this.tasks = tasks; - } /** {@inheritDoc} */ @Override public void config() { super.config(); - TaskMappingFactory<? extends TaskMappingEntry<?, ?>, ? extends TaskMappingEncoding<?, ?>> tmFactory = - TaskMappingFactory.getInstance(); - addOperatorInstance(AbstractTaskMappingEncoding.class, - tmFactory.createMutateAllocationOperator(tasks)); - addOperatorInstance(AbstractTaskMappingEncoding.class, - tmFactory.createMutateRedundancyDecrementOperator(tasks)); - addOperatorInstance(AbstractTaskMappingEncoding.class, - tmFactory.createMutateRedundancyIncrementOperator(tasks)); + addOperatorType(AbstractTaskMappingEncoding.class, MutateAllocation.class); + addOperatorType(AbstractTaskMappingEncoding.class, MutateRedundancyDecrement.class); + addOperatorType(AbstractTaskMappingEncoding.class, MutateRedundancyIncrement.class); } } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/.ratings index 5f93fb40..afd743f6 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/.ratings @@ -1,7 +1,8 @@ -IMultiSelectorOperatorModule.java 157eea7b5b736034703db099931fdda439a632ba RED -IOperatorSelector.java 3da9c10eb864458097b7097bf2dd5129dd5ec271 RED +IMultiSelectorOperatorModule.java 6d8c719483e88e7167fd56399021ebdf88f6b913 RED +IOperatorSelector.java a50ba239e4de3a74880cfaa82aabb526c9729bbc RED ISelectorOperatorModule.java 8b7254d5a2c6eaf0ca802153cf637a65df7af182 RED -OperatorSelectorBase.java b7763544dd214d20bf0a4cfc48a752cc831bb595 RED -OperatorSelectorPredicate.java 8dbd944b60956c9414af0ba27f86a837a266372d RED -RandomOperatorSelector.java 48fd49694fb011b45bbc63291ec65c261d2cef3b RED -RoundRobinOperatorSelector.java 1cd0027f6d38e8829b03c88304eba424def673c0 RED +OperatorKey.java 588fd9a03f4bc356b3826715d781ee32b213402c RED +OperatorSelectorBase.java 926c0c706c19de47e60147dc548940f45cfc12a4 RED +OperatorSelectorPredicate.java 6c74461443fdf665393485930d569dc273fa8c57 RED +RandomOperatorSelector.java dc262de9aecde9e31b06afa940a0686a7b0a2ede RED +RoundRobinOperatorSelector.java 14293ae4ea1cbb5c4380749eab98385ced094852 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IMultiSelectorOperatorModule.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IMultiSelectorOperatorModule.java index 157eea7b..6d8c7194 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IMultiSelectorOperatorModule.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IMultiSelectorOperatorModule.java @@ -32,7 +32,14 @@ public interface IMultiSelectorOperatorModule<O extends Operator<?>> { * specific {@link Genotype} provided by the Opt4J framework. The operator will be applied only * to the given {@link Genotype}. */ - public void addOperatorInstance(Class<? extends Genotype> genotypeType, O crossoverOperator); + void addOperatorInstance(Class<? extends Genotype> genotypeType, O crossoverOperator); + + /** + * Registers a mutation operator type with an {@link OperatorModule} and a specific + * {@link Genotype} provided by the Opt4J framework. The operator will be applied only + * to the given {@link Genotype}. + */ + void addOperatorType(Class<? extends Genotype> genotypeType, Class<O> mutateOperator); /** * Returns the {@link IOperatorSelector} used to manage the selection of operators registered @@ -42,5 +49,5 @@ public interface IMultiSelectorOperatorModule<O extends Operator<?>> { * Implementations must ensure that the same {@link IOperatorSelector} instance is returned for * all calls of {@link #addOperatorInstance(Class, Operator)}. */ - public IOperatorSelector getOperatorSelector(Class<? extends Genotype> genotypeType); + IOperatorSelector getOperatorSelector(Class<? extends Genotype> genotypeType); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IOperatorSelector.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IOperatorSelector.java index 3da9c10e..a50ba239 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IOperatorSelector.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/IOperatorSelector.java @@ -36,12 +36,12 @@ public interface IOperatorSelector { * {@link AbstractGenericOperator#getOperator(org.opt4j.core.Genotype)}) delegates the * actual work to this method */ - public abstract boolean evaluate(Operator<?> operator); + public abstract boolean evaluate(OperatorKey<? extends Operator<?>> operator); /** - * Registers an operator with this {@link IOperatorSelector}. This method is + * Registers an operator type with this {@link IOperatorSelector}. This method is * invoked from the constructor - * {@link OperatorSelectorPredicate#OperatorSelectorPredicate(Operator, IOperatorSelector)}. + * {@link OperatorSelectorPredicate#OperatorSelectorPredicate(OperatorKey, IOperatorSelector)}. */ - public abstract void register(Operator<?> operator); + public abstract void register(OperatorKey<? extends Operator<?>> operator); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorKey.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorKey.java new file mode 100644 index 00000000..588fd9a0 --- /dev/null +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorKey.java @@ -0,0 +1,79 @@ +/*-------------------------------------------------------------------------+ +| 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.operator.selection; + +import org.fortiss.af3.exploration.alg.dse.backend.opt4j.Opt4JDseTaskProvider; +import org.opt4j.core.optimizer.Operator; + +import com.google.inject.Provider; + +/** + * "Key" class that enables registering both operator instances or their classes in the selection + * map of the {@link IOperatorSelector}. Whenever an operator is bound by it's type, this class will + * create an instance of it upon the first request. + * + * @author diewald + */ +public class OperatorKey<O extends Operator<?>> { + /** + * Provides the opt4j task that is used to construct an operator instance if it was registered + * by its type. + */ + private Provider<Opt4JDseTaskProvider> opt4JDseTaskProvider; + + /** The operator (cached in case of type registration). */ + private O operator; + + /** The operator type. Only used in case of type registration. */ + private Class<O> operatorType; + + /** Creates an {@link OperatorKey} for operator instances. */ + public OperatorKey(O operator) { + this.operator = operator; + } + + /** + * Creates an {@link OperatorKey} for operator type registrations. Requires the opt4j task + * provider for lazy {@link Operator} instantiation. + */ + public OperatorKey(Class<O> operatorType, Provider<Opt4JDseTaskProvider> provider) { + this.opt4JDseTaskProvider = provider; + this.operatorType = operatorType; + } + + /** Returns the operator wrapped by this {@link OperatorKey}. */ + public O getOperator() { + if(operator == null) { + operator = opt4JDseTaskProvider.get().get().getInstance(operatorType); + } + return operator; + } + + // TODO: unsafe hash + @Override + public int hashCode() { + return (operator != null) ? operator.hashCode() : operatorType.hashCode(); + } + + @Override + public boolean equals(Object other) { + if(!(other instanceof OperatorKey)) { + return false; + } + + return getOperator() == ((OperatorKey<?>)other).getOperator(); + } +} diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorBase.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorBase.java index b7763544..926c0c70 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorBase.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorBase.java @@ -21,6 +21,8 @@ import java.util.Map; import org.opt4j.core.optimizer.Operator; import org.opt4j.operators.AbstractGenericOperator; +import com.google.inject.AbstractModule; + /** * Base class for operator selection strategies. It is best suited for index-based strategies, such * as the ones provided by {@link RoundRobinOperatorSelector} and {@link RandomOperatorSelector}. @@ -36,13 +38,15 @@ import org.opt4j.operators.AbstractGenericOperator; * * @author barner */ -public abstract class OperatorSelectorBase implements IOperatorSelector { - /** Map: Operator -> 0-based index */ - protected Map<Operator<?>, Integer> operatorToIndexMap = new HashMap<Operator<?>, Integer>(); +public abstract class OperatorSelectorBase<O extends Operator<?>> extends AbstractModule implements + IOperatorSelector { + + /** Map: OperatorKey -> 0-based index */ + protected Map<OperatorKey<?>, Integer> operatorToIndexMap = new HashMap<>(); /** - * Number of invocations of {@link #evaluate(Operator)} in the current operator lookup loop in - * {@link AbstractGenericOperator#getOperator(org.opt4j.core.Genotype)}). Required to ensure + * Number of invocations of {@link #evaluate(OperatorKey)} in the current operator lookup loop + * in {@link AbstractGenericOperator#getOperator(org.opt4j.core.Genotype)}). Required to ensure * that an operator is returned in any round (= |number of operators managed by this * {@link IOperatorSelector}|, triggered by a single invocation of * {@link AbstractGenericOperator#getOperator(org.opt4j.core.Genotype)}). In case an operator @@ -53,30 +57,41 @@ public abstract class OperatorSelectorBase implements IOperatorSelector { /** {@inheritDoc} */ @Override - public void register(Operator<?> operator) { - operatorToIndexMap.put(operator, operatorToIndexMap.size()); - registerInternal(operator); + public void register(OperatorKey<? extends Operator<?>> operatorKey) { + operatorToIndexMap.put(operatorKey, operatorToIndexMap.size()); + // registerInternal(operatorType); + } + + /** + * Selection strategy specific registration of an operator. See + * {@link IOperatorSelector#register(OperatorKey)}. + * + * @param operator + * Operator to be registered. + */ + protected void registerInternal(Operator<? extends Operator<?>> operator) { + // By default, do nothing } /** * Selection strategy specific registration of an operator. See - * {@link IOperatorSelector#register(Operator)}. + * {@link IOperatorSelector#register(OperatorKey)}. * * @param operator * Operator to be registered. */ - protected void registerInternal(Operator<?> operator) { + protected void registerInternal(Class<Operator<?>> operator) { // By default, do nothing } /** {@inheritDoc} */ @Override - public final boolean evaluate(Operator<?> operator) { + public final boolean evaluate(OperatorKey<? extends Operator<?>> operator) { int numOperators = operatorToIndexMap.size(); // The actual evaluation if the current operator is to be selected - boolean rval = evaluateInternal(operator); + boolean rval = evaluateInternal(operator.getOperator()); evaluationCount++; if(rval || evaluationCount == numOperators) { @@ -94,7 +109,7 @@ public abstract class OperatorSelectorBase implements IOperatorSelector { return rval; } - /** The actual selection strategy (invoked from {@link #evaluate(Operator)}. */ + /** The actual selection strategy (invoked from {@link #evaluate(OperatorKey)}. */ protected abstract boolean evaluateInternal(Operator<?> operator); /** Selection strategy finalization of a selection round. */ diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorPredicate.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorPredicate.java index 8dbd944b..6c744614 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorPredicate.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/OperatorSelectorPredicate.java @@ -17,6 +17,7 @@ package org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.selection; import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.ComposableOperatorClassPredicate; import org.opt4j.core.Genotype; +import org.opt4j.core.genotype.CompositeGenotype; import org.opt4j.core.optimizer.Operator; import org.opt4j.operators.AbstractGenericOperator.OperatorPredicate; @@ -28,11 +29,11 @@ import org.opt4j.operators.AbstractGenericOperator.OperatorPredicate; * * @author barner */ -public class OperatorSelectorPredicate implements OperatorPredicate { +public class OperatorSelectorPredicate<O extends Operator<?>> implements OperatorPredicate { /** Operator whose selection is determined by this {@link OperatorSelectorPredicate}. */ - private Operator<?> operator; + private OperatorKey<O> operator; - /** */ + /** Predicate for {@link CompositeGenotype}s. */ private ComposableOperatorClassPredicate genotypePredicate; /** {@link IOperatorSelector} to which the actual work is delegated. */ @@ -43,7 +44,7 @@ public class OperatorSelectorPredicate implements OperatorPredicate { * particular class (mutate, crossover, ...) must share the some {@link IOperatorSelector} * object. */ - public OperatorSelectorPredicate(Operator<?> operator, IOperatorSelector operatorSelector) { + public OperatorSelectorPredicate(OperatorKey<O> operator, IOperatorSelector operatorSelector) { this.operator = operator; this.operatorSelector = operatorSelector; operatorSelector.register(operator); @@ -55,9 +56,8 @@ public class OperatorSelectorPredicate implements OperatorPredicate { * All operators of a particular class (mutate, crossover, ...) must share the same * {@link IOperatorSelector} object. */ - public OperatorSelectorPredicate(Operator<?> operator, - ComposableOperatorClassPredicate genotypePredicate, - IOperatorSelector operatorSelector) { + public OperatorSelectorPredicate(OperatorKey<O> operator, + ComposableOperatorClassPredicate genotypePredicate, IOperatorSelector operatorSelector) { this.operator = operator; this.genotypePredicate = genotypePredicate; this.operatorSelector = operatorSelector; diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RandomOperatorSelector.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RandomOperatorSelector.java index 48fd4969..dc262de9 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RandomOperatorSelector.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RandomOperatorSelector.java @@ -24,7 +24,7 @@ import org.opt4j.core.optimizer.Operator; * * @author barner */ -public class RandomOperatorSelector extends OperatorSelectorBase { +public class RandomOperatorSelector extends OperatorSelectorBase<Operator<?>> { /** Random generator */ private RandomExploration rand = RandomExploration.getInstance(); @@ -33,7 +33,7 @@ public class RandomOperatorSelector extends OperatorSelectorBase { /** {@inheritDoc} */ @Override - protected void registerInternal(Operator<?> operator) { + protected void registerInternal(Operator<? extends Operator<?>> operator) { currentOperator = rand.nextInt(operatorToIndexMap.size()); } diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RoundRobinOperatorSelector.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RoundRobinOperatorSelector.java index 1cd0027f..14293ae4 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RoundRobinOperatorSelector.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/backend/opt4j/operator/selection/RoundRobinOperatorSelector.java @@ -23,7 +23,7 @@ import org.opt4j.core.optimizer.Operator; * * @author barner */ -public class RoundRobinOperatorSelector extends OperatorSelectorBase { +public class RoundRobinOperatorSelector extends OperatorSelectorBase<Operator<?>> { /** Operator selected for the current round */ private int currentOperator; 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 85fbc6dc..a869f32a 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,5 +1,5 @@ ArchitectureDecoder.java d067dc995e0895860d98d717647c0f7b061f5908 RED -ArchitectureExplorationProblemModule.java 957299811d40d0a11126ff4f8eaa45d0cc54af7e RED +ArchitectureExplorationProblemModule.java 12878158971065df3395a6474ca86b785e667f52 RED DseProblemModuleBase.java 0eba41852529e92e7255c7a7d8fce18354facbca RED EvaluatorWrapper.java 3747e5b78b1dcef8e1595c1ae9354e8ef2738e79 RED ExplorationGoalPriorityMultiEvaluator.java 1f6d2aa6ece8acdf4f57face0439f3429ab87329 RED 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/ArchitectureExplorationProblemModule.java index 95729981..12878158 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/ArchitectureExplorationProblemModule.java @@ -23,10 +23,8 @@ 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; -import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.SystemModelAdapter; import org.fortiss.af3.exploration.alg.service.IExplorationEncoding; import org.fortiss.af3.exploration.moea.model.DseSpecification; @@ -40,14 +38,14 @@ public class ArchitectureExplorationProblemModule extends DseProblemModuleBase<ArchitectureExplorationEncoding, ArchitectureSolution, ArchitectureDecoder> { + /** To be removed. */ DSEFactory dseFactory = DSEFactory.getInstance(); /** Constructor. */ public ArchitectureExplorationProblemModule(DseSpecification dse, - SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter, Set<Class<? extends IExplorationEncoding>> requestedSolutions) { - super(dse, systemModelAdapter, requestedSolutions); - dseFactory.init(systemModelAdapter); + super(dse, null, requestedSolutions); + dseFactory.init(null); } /** @@ -60,18 +58,15 @@ public class ArchitectureExplorationProblemModule * added separately. */ DSEFactory dseFactory = DSEFactory.getInstance(); - dseFactory.init(systemModelAdapter); + dseFactory.init(null); ArchitectureEvaluator archEvaluator = dseFactory.createArchitectureEvaluator(); - // Dependency graph for the execution order. - DecoderDependencyGraph execDepGraph = new DecoderDependencyGraph(requestedSolutions); - // TODO: construct the execution dependency graph elsewhere? // bindProblem(dseFactory.createArchitectureExplorationCreator(), // dseFactory.createArchitectureDecoder(execDepGraph), archEvaluator); - bindProblem(new GuiceCreator(), new GuiceDecoder(systemModelAdapter), archEvaluator); + bindProblem(new GuiceCreator(), new GuiceDecoder(), archEvaluator); // Create/Bind the subproblems of the architectural exploration problem. try { 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 0eba4185..75c5c2a3 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 @@ -149,7 +149,7 @@ public abstract class DseProblemModuleBase<C extends CompositeGenotype<Class<? e int priority) throws Exception { @SuppressWarnings("unchecked") EvaluatorWrapper<?, RT, T> wrappedEvaluator = (EvaluatorWrapper<?, RT, T>)TaskMappingFactory.getInstance() - .createEvaluatorWrapper(goal, priority, systemModelAdapter); + .createEvaluatorWrapper(goal, priority); if(wrappedEvaluator != null) { // Here, we check whether the goal evaluator is defined for composable phenotypes (only // composable evaluators are allowed then). diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/.ratings index 4bf577b8..262a281c 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/.ratings +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/.ratings @@ -14,4 +14,4 @@ ISignalAdapter.java 2bdb578564cf1d3351c99811c9090e2e9bd70715 RED ITaskAdapter.java 0f8c8699bb48e609211713aef6a7e1e82a00c963 RED ITransmissionUnitAdapter.java 217aca158641261dc8035805f341fe4c4c527a36 RED InternalComponentParameters.java cd5eea4ddf104c4cb3c4521d3256566812876027 RED -SystemModelAdapter.java 28bf6b9de321f56d14bad7d8f362fe30e28d2fae RED +SystemModelAdapter.java 4c99efd7137bcef08924bf6c5d28d35bab722676 RED diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/SystemModelAdapter.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/SystemModelAdapter.java index 28bf6b9d..4c99efd7 100644 --- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/SystemModelAdapter.java +++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/dse/sysmodel/arch/SystemModelAdapter.java @@ -221,6 +221,7 @@ public class SystemModelAdapter<C, E, SO, SI, G, TR, M> extends AbstractModule { * * @throws Exception */ + @SuppressWarnings("unchecked") protected void setupTaskGraphs() throws Exception { // - Add data dependencies to {@link TaskGraph}s // - Print some debugging output @@ -410,8 +411,10 @@ public class SystemModelAdapter<C, E, SO, SI, G, TR, M> extends AbstractModule { * Returns the deployable (software) component from the original logical architecture. May * contain "abstract" {@link Component}s. */ - public Collection<ITaskAdapter<C>> getDeployableComponents() { - return tasks; + @SuppressWarnings("unchecked") + @Provides + public Collection<ITaskAdapter<?>> getDeployableComponents() { + return (Collection<ITaskAdapter<?>>)(Collection<?>)tasks; } /** @@ -490,26 +493,32 @@ public class SystemModelAdapter<C, E, SO, SI, G, TR, M> extends AbstractModule { * Returns the deployment targets, i.e. the execution units of the target platform, * where deployable software components will be mapped to. */ - public Collection<IExecutionUnitAdapter<E>> getDeploymentTargets() { - return deploymentTargets; + @SuppressWarnings("unchecked") + @Provides + public Collection<IExecutionUnitAdapter<?>> getDeploymentTargets() { + return (Collection<IExecutionUnitAdapter<?>>)(Collection<?>)deploymentTargets; } /** Returns the {@link IMemoryUnitAdapter} present in the target platform. */ + @Provides public Collection<IMemoryUnitAdapter<M>> getMemoryUnits() { return memoryUnits; } /** Returns the gateway units present in the platform. */ + @Provides public Collection<IGatewayUnitAdapter<G>> getGatewayUnits() { return gatewayUnits; } /** Returns the systems TDMA arbitrated transmission unit */ + @Provides public Collection<ITransmissionUnitAdapter<TR>> getTransmissionUnits() { return transmissionUnits; } /** Returns all the {@link IResourceAdapter}s present in the platform. */ + @Provides public Collection<IResourceAdapter<?>> getAvailableResources() { return availableResources; } @@ -526,6 +535,7 @@ public class SystemModelAdapter<C, E, SO, SI, G, TR, M> extends AbstractModule { * Returns the {@link ISafetyFunctionAdapter}s constructed from the safety functions that are * present in the input models. */ + @SuppressWarnings("unchecked") public Collection<ISafetyFunctionAdapter<?>> getSafetyFunctionAdapters() { if(safetyFunctionAdapters != null) { return (Collection<ISafetyFunctionAdapter<?>>)(Collection<?>)safetyFunctionAdapters; -- GitLab