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

Exploration.alg: SIL constraint for Partitions.

* Correctly implement a constraint that enforces partitions to host only Tasks of ONE safety level.
refs 3257
parent c28043a7
No related branches found
No related tags found
No related merge requests found
Showing
with 146 additions and 6 deletions
......@@ -373,5 +373,10 @@
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDoubleObject"/>
</eGenericSuperTypes>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="SameSilInPartitionConstraint">
<eGenericSuperTypes eClassifier="ecore:EClass platform:/resource/org.fortiss.af3.exploration/model/exploration.ecore#//ExplorationConstraint">
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDoubleObject"/>
</eGenericSuperTypes>
</eClassifiers>
</eSubpackages>
</ecore:EPackage>
......@@ -119,6 +119,7 @@
<genTypeParameters ecoreTypeParameter="moea.ecore#//predefined/SafetyComparison/T"/>
</genClasses>
<genClasses ecoreClass="moea.ecore#//predefined/NoEmptyPartitionConstraint"/>
<genClasses ecoreClass="moea.ecore#//predefined/SameSilInPartitionConstraint"/>
</nestedGenPackages>
</genPackages>
</genmodel:GenModel>
......@@ -267,7 +267,13 @@
<evaluator
module="org.fortiss.af3.exploration.alg.dse.evaluator.constraint.NoEmptyPartitionConstraintEvaluator">
<modelElementClass
modelElementClass="org.fortiss.af3.exploration.model.ExplorationConstraint">
modelElementClass="org.fortiss.af3.exploration.moea.model.predefined.NoEmptyPartitionConstraint">
</modelElementClass>
</evaluator>
<evaluator
module="org.fortiss.af3.exploration.alg.dse.evaluator.constraint.SameSilInPartitionConstraintEvaluator">
<modelElementClass
modelElementClass="org.fortiss.af3.exploration.moea.model.predefined.SameSilInPartitionConstraint">
</modelElementClass>
</evaluator>
<evaluator
......
CompositeExplorationSolution.java c35b0b0cf5658300b5e8c4f2cc9e217c29ae37a3 RED
DSEFactory.java 0a2f2cc6a197e760c1f8223339ffa5f16856b184 RED
Explorer.java 2194a74cbe51ca9e7dafb008dcefb51a54064dc8 RED
ImplicitExplorationTargetFactory.java e45c6c3344b46a275e2c74b5c714900229f5f8d3 RED
ImplicitExplorationTargetFactory.java 6c16c6712886b549dda0a73aef4a4c3fe18c1850 RED
SolutionQuantification.java efd31f192c3adbf1a4434452a19eb836a17390e2 RED
TaskMappingFactory.java 5e41df9d45e338dbcfa95bc3818ca17774951893 RED
......@@ -75,6 +75,7 @@ public class ImplicitExplorationTargetFactory {
Collection<ExplorationConstraint<?>> constraints = new ArrayList<>();
// constraints.addAll(createPeriodConstraints(systemModelAdapter));
constraints.add(createNoEmptyPartitionConstraint());
constraints.add(createSameSilInPartitionConstraint());
// Reassign the ids of generated constraints. By default, they are set to 0. Each constraint
// needs a "unique" id for its constraint type.
......@@ -95,6 +96,11 @@ public class ImplicitExplorationTargetFactory {
return PredefinedFactory.eINSTANCE.createNoEmptyPartitionConstraint();
}
/** Creates a single constraint that states a partition may only host tasks with the same SIL. */
private static ExplorationConstraint<?> createSameSilInPartitionConstraint() {
return PredefinedFactory.eINSTANCE.createSameSilInPartitionConstraint();
}
/**
* Creates a {@link PeriodConstraint} for each {@link TaskGraph} present in the
* {@link SystemModelAdapter}.
......
......@@ -7,3 +7,4 @@ MappingEvaluatorConstraint.java f1f44bffbef03f1650a7f026428423838b16b845 RED
NoEmptyPartitionConstraintEvaluator.java 33f7b4215b2ada1e60474e9385150a9ea234b060 YELLOW
PeriodConstraintEvaluator.java 05cf21be06c9ae12593f870efdf9c358efa2d97c RED
SafetyIntegrityLevelConstraintEvaluator.java 9ad7129faaa35d89af4fced7a7121a0a142cb6f1 RED
SameSilInPartitionConstraintEvaluator.java 9f30f5731fb64b73ab2c50868026e9d1af05beb5 RED
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.alg.dse.evaluator.constraint;
import static java.lang.Math.abs;
import static java.lang.Math.expm1;
import static org.fortiss.tooling.common.util.LambdaUtils.getFirst;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.partitionmapping.Partition;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.TaskMappingEncoding;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.encoding.taskmapping.instantiatedmapping.InstantiatedTaskMappingEntry;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.FlatPhenotypeMap;
import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype;
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.IExplorationTargetEvaluator;
import org.fortiss.af3.exploration.model.ExplorationConstraint;
import org.fortiss.af3.exploration.moea.model.predefined.SameSilInPartitionConstraint;
import org.opt4j.core.DoubleValue;
import org.opt4j.core.Value;
import com.google.common.collect.ClassToInstanceMap;
/**
* Evaluates whether all {@link ITaskAdapter}s mapped to {@link Partition}s have the same
* SIL/ASIL/DAL value and calculates a penality based on the difference in the Integrity Levels of
* the tasks.
*
* @author diewald
*/
public class SameSilInPartitionConstraintEvaluator
extends
ConstraintEvaluatorBase<TaskMappingEncoding<ITaskAdapter<?>, InstantiatedTaskMappingEntry>, Double, SameSilInPartitionConstraint> {
/** {@inheritDoc} */
@Override
public Value<?> evaluateGoal(
TaskMappingEncoding<ITaskAdapter<?>, InstantiatedTaskMappingEntry> phenotype,
FlatPhenotypeMap<Phenotype> phenotypeTypeMap,
ClassToInstanceMap<EObject> transformedModels) throws Exception {
double resVal = 0.0;
for(Partition partition : phenotype.getResources()) {
// FIXME: remove casts by specifying the TaskMapping.
Collection<ITaskAdapter<?>> allocatedTasks = phenotype.getRequesters(partition);
Optional<ITaskAdapter<?>> anyTask = getFirst(allocatedTasks);
if(!anyTask.isPresent()) {
continue;
}
int derivationSum = 0;
int firstSilVal = anyTask.get().getRequiredSafetyIntegrityLevel().getValue();
for(ITaskAdapter<?> task : allocatedTasks) {
int currentSilVal = task.getRequiredSafetyIntegrityLevel().getValue();
derivationSum += abs(firstSilVal - currentSilVal);
}
// TODO: Will the evaluator perform more efficiently if the penalty function is
// calculated over the sum of violation of partitions, or (as it is now) a sum over the
// penalties per partition mismatch.
resVal += expm1(derivationSum);
}
System.out.println("ResVal: " + resVal);
return new DoubleValue(resVal);
}
/** {@inheritDoc} */
@Override
public boolean validateInputs() throws Exception {
return true;
}
/** {@inheritDoc} */
@Override
public Collection<Class<?>> getRequiredInputTypes() {
Collection<Class<?>> inputs = new ArrayList<>();
inputs.add(TaskMappingEncoding.class);
return inputs;
}
/** {@inheritDoc} */
@Override
public Class<?> getPrimaryInputType() {
return TaskMappingEncoding.class;
}
/** {@inheritDoc} */
@Override
public
IExplorationTargetEvaluator<TaskMappingEncoding<ITaskAdapter<?>, InstantiatedTaskMappingEntry>, Double, SameSilInPartitionConstraint>
createEvaluator(SystemModelAdapter<?, ?, ?, ?, ?, ?, ?> systemModelAdapter,
SameSilInPartitionConstraint explorationTarget) throws Exception {
return new SameSilInPartitionConstraintEvaluator();
}
/** {@inheritDoc} */
@Override
public boolean validateInternal(ExplorationConstraint<?> expTarget,
TaskMappingEncoding<ITaskAdapter<?>, InstantiatedTaskMappingEntry> solution,
Value<?> value) {
return value.getDouble() <= 10e-6;
}
}
......@@ -9,5 +9,5 @@ AF3ResourceAdapter.java 00070d4e3ec7f19a672b6295c546fa1d30d7fc50 RED
AF3ResourceConnectionAdapter.java 0e791fd7d9602f4cf00f54c6254d31f1c9cc72b0 RED
AF3SignalAdapter.java bc102b65b929393808eb747572f9ae05b04a8856 RED
AF3SystemModelAdapter.java e6ea1aaae3c4867cfc38487d7534e847794fdb82 RED
AF3TaskAdapter.java ac021d7af31888d89d1cb58ec64bf7f551da160b RED
AF3TaskAdapter.java e59896eeb0a268435075474947a51fa0689df554 RED
AF3TransmissionUnitAdapter.java 0ce1a08c29d75a05fb49668d02abddd852487a4c RED
......@@ -66,8 +66,8 @@ public class AF3TaskAdapter extends AF3RequestAdapter<Task> implements ITaskAdap
private Collection<ITaskAdapter<Component>> replacementComponents;
/**
* "Trace" to the {@link ITaskAdapter} which {@code this}
* {@link ITaskAdapter} replaced (if applicable).
* "Trace" to the {@link ITaskAdapter} which {@code this} {@link ITaskAdapter} replaced (if
* applicable).
*/
private ITaskAdapter<Component> replacedComponent;
......@@ -89,7 +89,7 @@ public class AF3TaskAdapter extends AF3RequestAdapter<Task> implements ITaskAdap
"A non-specified period value and negative periods are not allowed.");
}
period = af3Period.doubleValue();
sil = getAnnotationChecked(af3Task, SafetyIntegrityLevel.class);
sil = getAnnotationChecked(af3Component, SafetyIntegrityLevel.class);
ReplicationBounds replicationSpec = getAnnotationChecked(af3Task, ReplicationBounds.class);
minReplication = replicationSpec.getMinReplication();
maxReplication = replicationSpec.getMaxReplication();
......
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