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

Constraints: Make phenotypes constrainable

* Decoders produce constraints on phenotype to inform other decoders
  about restrictions generated by decoders executed earlier in the
  process.
* Let the PhenotypeBase class implement the IConstrainedEncoding Iface
  such that all standard phenotypes are constrainable. Note that the
  Phenotype interface is not altered to allow the construction of
  unconstrainable Phenotypes.

Issue-Ref: 3279
Issue-Url: https://af3-developer.fortiss.org/issues/3279


Signed-off-by: default avatarAlexander Diewald <diewald@fortiss.org>
parent 56da78d2
No related branches found
No related tags found
1 merge request!63279
This commit is part of merge request !6. Comments created here will be created in the context of that merge request.
Showing
with 77 additions and 119 deletions
TaskMappingEncoding.java 04fcfd2674d8acf32a6f75465bf0ac0c00530c09 RED
TaskMappingEncoding.java 7751fe844ecb86a3cb62e919639cfaf5da913211 RED
TaskMappingEntry.java 407c9065007f8cd4adc8b64eea13a837bba581ae RED
......@@ -30,7 +30,7 @@ import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmappi
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskgraph.TaskGraphEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.constraint.InternalReplicationConstraint;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.constraint.InternalSeparationConstraint;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.encoding.ConstrainedEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.encoding.IConstrainedEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.operator.copy.Copyable;
import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.IExecutionUnitAdapter;
import org.fortiss.af3.exploration.alg.dse.sysmodel.arch.ITaskAdapter;
......@@ -58,7 +58,7 @@ import com.google.common.collect.Multimap;
public abstract class TaskMappingEncoding<S extends ITaskAdapter<?>, T extends TaskMappingEntry<S, IExecutionUnitAdapter<?>>>
extends MappingEncoding<TaskMappingEncoding<S, T>, S, IExecutionUnitAdapter<?>, T>
implements IMappingEncoding<S, IExecutionUnitAdapter<?>, T>, Genotype, IExplorationEncoding,
ConstrainedEncoding, Copyable<TaskMappingEncoding<S, T>> {
IConstrainedEncoding, Copyable<TaskMappingEncoding<S, T>> {
/** Random generator */
private RandomExploration rand = RandomExploration.getInstance();
......@@ -297,40 +297,6 @@ public abstract class TaskMappingEncoding<S extends ITaskAdapter<?>, T extends T
return (Collection<U>)constraintMap.get(type);
}
/** {@inheritDoc} */
@Override
public Multimap<Class<? extends ExplorationConstraint<?>>, ExplorationConstraint<?>>
getConstraints() {
return constraintMap;
}
/** {@inheritDoc} */
@Override
public <U extends ExplorationConstraint<?>> void
replaceConstraints(Multimap<Class<? extends U>, U> constraintMap) {
constraintMap.keySet().forEach(c -> this.constraintMap.removeAll(c));
this.constraintMap.putAll(constraintMap);
}
/** {@inheritDoc} */
@Override
public <U extends ExplorationConstraint<?>> void replaceConstraints(Class<U> type,
Collection<U> constraints) {
constraintMap.replaceValues(type, constraints);
}
/** {@inheritDoc} */
@Override
public <U extends ExplorationConstraint<?>> void putConstraint(Class<U> type, U constraint) {
constraintMap.put(type, constraint);
}
/** {@inheritDoc} */
@Override
public <U extends ExplorationConstraint<?>> void removeConstraint(Class<U> type, U constraint) {
constraintMap.remove(type, constraint);
}
/**
* Initializes the allocation table for the {@link ITaskAdapter}s that are not
* yet present in the given {@code incompleteEncoding}.
......
Phenotype.java f05a45ea3b3577079b4f894aa97af1ab3620c5e7 YELLOW
PhenotypeBase.java 73397a01276ccf72c1569bfa577e9fd3f5874324 YELLOW
PhenotypeBase.java 24eea2e9443aa0974245ab30953f992d742d6b48 YELLOW
ProvidingPhenotype.java b18a8385e97c98f83219daa508d156ac57ba365b RED
......@@ -15,16 +15,31 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype;
import java.util.Collection;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.encoding.IConstrainedEncoding;
import org.fortiss.af3.exploration.model.ExplorationConstraint;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
/**
* Base class for {@link Phenotype}s which consists of {@link Phenotype}s.
*
* @author diewald
*/
public class PhenotypeBase implements Phenotype {
public abstract class PhenotypeBase implements Phenotype, IConstrainedEncoding {
/** Flag to mark a phenotype as being processed by sub-Decoders. */
private boolean isSubDecoding;
/**
* Map holding the constraints on the encoding. Initial capacity is zero to reduce the memory
* footprint of non-constrained encodings.
*/
private Multimap<Class<? extends ExplorationConstraint<?>>, ExplorationConstraint<?>> constraintMap =
HashMultimap.create(0, 0);
/** {@inheritDoc} */
@Override
public void setSubDecoding(boolean isSubDecoding) {
......@@ -36,4 +51,23 @@ public class PhenotypeBase implements Phenotype {
public boolean isSubDecoding() {
return isSubDecoding;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T extends ExplorationConstraint<?>> Collection<T> getConstraintsOf(Class<T> type) {
return (Collection<T>)constraintMap.get(type);
}
/** {@inheritDoc} */
@Override
public <T extends ExplorationConstraint<?>> void putConstraint(Class<T> type, T constraint) {
constraintMap.put(type, constraint);
}
/** {@inheritDoc} */
@Override
public <T extends ExplorationConstraint<?>> void removeConstraints() {
constraintMap.clear();
}
}
ConstrainedEncoding.java fa3d09a853883e8991f11a0ad810c9e58eb21aa7 RED
IConstrainedEncoding.java 722f7f5551cf36443d3e17b37804b63cdbab007e YELLOW
......@@ -20,15 +20,13 @@ import java.util.Collection;
import org.fortiss.af3.exploration.alg.service.IExplorationEncoding;
import org.fortiss.af3.exploration.model.ExplorationConstraint;
import com.google.common.collect.Multimap;
/**
* {@link ConstrainedEncoding}s are {@link IExplorationEncoding}s that may carry constraints which
* {@link IConstrainedEncoding}s are {@link IExplorationEncoding}s that may carry constraints which
* limit the allowed operation performed on them.
*
* @author diewald
*/
public interface ConstrainedEncoding extends IExplorationEncoding {
public interface IConstrainedEncoding {
/**
* Returns the collection of {@link ExplorationConstraint}s that are of the given type.
......@@ -40,35 +38,6 @@ public interface ConstrainedEncoding extends IExplorationEncoding {
*/
<T extends ExplorationConstraint<?>> Collection<T> getConstraintsOf(Class<T> type);
/**
* Returns the {@link Multimap} containing the complete set of constraints defined on a
* particular encoding which can be queried by their type.
*/
Multimap<Class<? extends ExplorationConstraint<?>>, ExplorationConstraint<?>> getConstraints();
/**
* Adds a given collection of {@link ExplorationConstraint}s to the encoding which is identified
* by the given type. Existing {@link ExplorationConstraint}s identified by the same type are
* replaced.
*
* @param type
* to identify the {@link ExplorationConstraint}s.
* @param constraints
* Collection of {@link ExplorationConstraint}s to be added to the encoding.
*/
<T extends ExplorationConstraint<?>> void replaceConstraints(Class<T> type,
Collection<T> constraints);
/**
* Replaces all existing constraint sets with identical keys with those present in the given
* map.
*
* @param constraintMap
* Replacement constraints.
*/
<T extends ExplorationConstraint<?>> void
replaceConstraints(Multimap<Class<? extends T>, T> constraintMap);
/**
* Adds the given {@code constraint} to the set of constraints that is identified by the given
* {@code type}.
......@@ -81,13 +50,9 @@ public interface ConstrainedEncoding extends IExplorationEncoding {
<T extends ExplorationConstraint<?>> void putConstraint(Class<T> type, T constraint);
/**
* Removes the given {@code constraint} from the set of constraints that is identified by the
* given {@code type}.
*
* @param type
* Constraint set identifier.
* @param constraint
* Constraint to remove from the constraint set.
* Removes the {@link ExplorationConstraint}s from {@code this} encoding. This operation is to
* be executed when constraints were invalidated, e.g., due to modifications of depending
* encodings.
*/
<T extends ExplorationConstraint<?>> void removeConstraint(Class<T> type, T constraint);
<T extends ExplorationConstraint<?>> void removeConstraints();
}
SFGraphDecoder.java bec642d6d1ae69eb39fdb2b18f331ae0720ab5c8 RED
SFMappingConstraintDecoder.java 6ebda962400d82ea4738eedbedda03ebf3db2a5e RED
SFMappingConstraintDecoder.java 15eb6df982f55e5b36ede1cf2af53befdb55132c RED
SFMappingDecoder.java 90fd2b466e4d62434068088af0f24d599227c7ca RED
......@@ -16,8 +16,6 @@
package org.fortiss.af3.exploration.alg.dse.backend.opt4j.problem.safetyfunction;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch.SafetyFunctionArchEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.safetyfunctionarch.SafetyFunctionArchEntry;
......@@ -52,46 +50,44 @@ public class SFMappingConstraintDecoder<C> extends DecoderModule<AbstractTaskMap
@UpdatesEncoding
public AbstractTaskMappingEncoding updateComposable(SafetyFunctionArchEncoding sfaEnc,
AbstractTaskMappingEncoding atmEnc) {
for(SafetyFunctionArchEntry sFAEntry : sfaEnc.getAllEntries()) {
int channelNumber = sFAEntry.getNumChannels();
Collection<InternalReplicationConstraint> replicationConstraints = new HashSet<>();
for(ITaskAdapter<?> comp : sFAEntry.getSafetyFunctionAdapter().getAllComponents()) {
replicationConstraints
.add(new InternalReplicationConstraint(comp, channelNumber, channelNumber));
}
atmEnc.replaceConstraints(InternalReplicationConstraint.class, replicationConstraints);
for(SafetyFunctionArchEntry sfaEntry : sfaEnc.getAllEntries()) {
addReplicationConstraints(sfaEntry, sfaEnc);
addSeparationConstraints(sfaEntry, sfaEnc);
}
atmEnc.replaceConstraints(InternalSeparationConstraint.class,
createSeparationConstraints(sfaEnc));
return atmEnc;
}
/**
* Creates {@link InternalSeparationConstraint}s for the sets of realizing, diagnostic, and
* output units of each safety function.
* Add constraints on the number of task replia such that the number of {@link ITaskAdapter}s
* corresponds to the number of safety channels.
*/
private Collection<InternalSeparationConstraint>
createSeparationConstraints(SafetyFunctionArchEncoding sfEnc) {
Collection<InternalSeparationConstraint> sepConstraints = new HashSet<>();
for(SafetyFunctionArchEntry sfEntry : sfEnc.getAllEntries()) {
ISafetyFunctionAdapter<?> sfAdp = sfEntry.getSafetyFunctionAdapter();
private void addReplicationConstraints(SafetyFunctionArchEntry sFAEntry,
SafetyFunctionArchEncoding sfaEnc) {
int channelNumber = sFAEntry.getNumChannels();
// TODO: We should not be aware of the Tile type here.
// FIXME: We need a "better" machanism than the fault containment region. Also,
sepConstraints.add(
new InternalSeparationConstraint(sfAdp.getRealizingComponents(), Tile.class));
sepConstraints.add(
new InternalSeparationConstraint(sfAdp.getDiagnosticComponents(), Tile.class));
sepConstraints.add(new InternalSeparationConstraint(
Arrays.asList(sfAdp.getOutputComponent()), Tile.class));
for(ITaskAdapter<?> comp : sFAEntry.getSafetyFunctionAdapter().getAllComponents()) {
sfaEnc.putConstraint(InternalReplicationConstraint.class,
new InternalReplicationConstraint(comp, channelNumber, channelNumber));
}
}
/**
* Creates {@link InternalSeparationConstraint}s for the sets of realizing, diagnostic, and
* output units of each safety function.
*/
private void addSeparationConstraints(SafetyFunctionArchEntry sfaEntry,
SafetyFunctionArchEncoding sfaEnc) {
ISafetyFunctionAdapter<?> sfAdp = sfaEntry.getSafetyFunctionAdapter();
return sepConstraints;
// TODO: We should not be aware of the Tile type here.
// FIXME: We need a "better" machanism than the fault containment region. Also,
sfaEnc.putConstraint(InternalSeparationConstraint.class,
new InternalSeparationConstraint(sfAdp.getRealizingComponents(), Tile.class));
sfaEnc.putConstraint(InternalSeparationConstraint.class,
new InternalSeparationConstraint(sfAdp.getDiagnosticComponents(), Tile.class));
sfaEnc.putConstraint(InternalSeparationConstraint.class, new InternalSeparationConstraint(
Arrays.asList(sfAdp.getOutputComponent()), Tile.class));
}
/** {@inheritDoc} */
......
FailSilentAbstractTaskMappingDecoder.java ebb6d70d69e94f748c89749f0fd07d1c235bb4c9 RED
FaultDetectionVotingAbstractTaskMappingDecoder.java 0468b58b3aea3c2a0c6f318f80819194e083aa4c RED
FailSilentAbstractTaskMappingDecoder.java d61e120ceda6ee60b819de94a541ef8862f990f3 RED
FaultDetectionVotingAbstractTaskMappingDecoder.java 28aec484fa4f8420b4e6fe53ce591624c9cefea6 RED
TaskInstanceResourceAlignmentDecoder.java 8567290ebc74927263f5265f44d7acdcbf99797f RED
......@@ -59,8 +59,6 @@ public class FailSilentAbstractTaskMappingDecoder
@Decodes
public FailSilentTaskMappingEncoding decode(AbstractTaskMappingEncoding atmEnc,
@Genotyped FailSilentTaskMappingEncoding fstmEnc) {
fstmEnc.replaceConstraints(atmEnc.getConstraints());
for(ITaskAdapter<?> comp : atmEnc.getRequesters()) {
Collection<AbstractTaskMappingEntry> abstrEntries = atmEnc.getMappingEntriesOf(comp);
Collection<FailSilentTaskMappingEntry> instEntries;
......
......@@ -54,8 +54,6 @@ public class FaultDetectionVotingAbstractTaskMappingDecoder
public FaultDetectionVotingTaskMappingEncoding updateComposable(
AbstractTaskMappingEncoding inGenotype,
FaultDetectionVotingTaskMappingEncoding outGenotype) throws DecodingException {
outGenotype.replaceConstraints(inGenotype.getConstraints());
for(ITaskAdapter<?> comp : inGenotype.getRequesters()) {
Collection<AbstractTaskMappingEntry> abstrEntries =
inGenotype.getMappingEntriesOf(comp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment