Commit 170f89cd authored by Tarik Terzimehic's avatar Tarik Terzimehic
Browse files

work on modularizaton quality objective (wip)


Signed-off-by: Tarik Terzimehic's avatarTarik Terzimehic <terzimehic@fortiss.org>
parent 386f5775
......@@ -20,28 +20,29 @@ import static org.fortiss.af3.exploration.smt.util.ConstraintDefinitionUtils.cre
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createAllocation;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createAnd;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createArithmeticLiteral;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createDiv;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createEquals;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createExists;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createMaximize;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createMinimize;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createMinus;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createModelElementLiteral;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createMul;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createNotEqual;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createPlus;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createSet;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createSum;
import java.math.BigDecimal;
import org.fortiss.af3.exploration.dseml.model.arithmetic.Minus;
import org.fortiss.af3.exploration.dseml.model.arithmetic.Mul;
import org.fortiss.af3.exploration.dseml.model.arithmetic.Plus;
import org.fortiss.af3.exploration.dseml.model.arithmetic.Sum;
import org.fortiss.af3.exploration.dseml.model.booleanp.And;
import org.fortiss.af3.exploration.dseml.model.booleanp.Exists;
import org.fortiss.af3.exploration.dseml.model.booleanp.IBooleanExpression;
import org.fortiss.af3.exploration.dseml.model.booleanp.allocation.Allocation;
import org.fortiss.af3.exploration.dseml.model.booleanp.allocation.ILocationExpression;
import org.fortiss.af3.exploration.dseml.model.booleanp.comparison.Equal;
import org.fortiss.af3.exploration.dseml.model.booleanp.comparison.NotEqual;
import org.fortiss.af3.exploration.dseml.model.expression.ModelElementLiteral;
import org.fortiss.af3.exploration.dseml.model.expression.Set;
import org.fortiss.af3.exploration.dseml.model.expression.SuperSet;
import org.fortiss.af3.exploration.dseml.model.function.End;
......@@ -133,77 +134,175 @@ public class TaskCouplingObjective {
public static Maximize createMaximizeModularizationObjective(SuperSet<Task> taskSS,
SuperSet<ExecutionUnit> ecuSS, SuperSet<Signal> signalSS) {
// Coupling
Set<Task> taskSet = createSet(taskSS, taskSS.getEntries(), "aTasks", Task.class);
Set<Signal> signalSet =
createSet(signalSS, signalSS.getEntries(), "bSignals", Signal.class);
Start srcTask = createStart(signalSet, taskSet);
End tgtTask = createEnd(signalSet, taskSet);
Set<ExecutionUnit> ecuSet1 =
createSet(ecuSS, ecuSS.getEntries(), "aEcus", ExecutionUnit.class);
Set<ExecutionUnit> ecuSet2 =
createSet(ecuSS, ecuSS.getEntries(), "bEcus", ExecutionUnit.class);
Allocation allocSrcTask = createAllocation(srcTask, createModelElementLiteral(ecuSet1));
Allocation allocTgtTask = createAllocation(tgtTask, createModelElementLiteral(ecuSet2));
And isAlloc = createAnd(allocSrcTask, allocTgtTask);
NotEqual isDistinctECUs = createNotEqual(createModelElementLiteral(ecuSet1),
createModelElementLiteral(ecuSet2));
IBooleanExpression isCoupled = createAnd(isAlloc, isDistinctECUs);
Exists hwSet2Exists =
createExists(ecuSet2.getCastedSet(IModelElement.class), isCoupled, true);
Exists hwSetExists =
createExists(ecuSet1.getCastedSet(IModelElement.class), hwSet2Exists, true);
Sum coupling = createSum(signalSet.getCastedSet(IModelElement.class), hwSetExists,
createArithmeticLiteral(BigDecimal.ONE));
int numECUs = ecuSS.getEntries().size();
double couplingScaling = 1. / (numECUs * (numECUs - 1));
Mul couplingScaled =
createMul(coupling, createArithmeticLiteral(BigDecimal.valueOf(couplingScaling)));
// Cohesion
Set<Task> taskSetCohesion = createSet(taskSS, taskSS.getEntries(), "aTasks", Task.class);
Set<Signal> signalSetCohesion =
createSet(signalSS, signalSS.getEntries(), "bSignals", Signal.class);
Start srcTaskCohesion = createStart(signalSetCohesion, taskSetCohesion);
End tgtTaskCohesion = createEnd(signalSetCohesion, taskSetCohesion);
Set<ExecutionUnit> ecuSet1Cohesion =
createSet(ecuSS, ecuSS.getEntries(), "aEcus", ExecutionUnit.class);
Set<ExecutionUnit> ecuSet2Cohesion =
createSet(ecuSS, ecuSS.getEntries(), "bEcus", ExecutionUnit.class);
Allocation allocSrcTaskCohesion =
createAllocation(srcTaskCohesion, createModelElementLiteral(ecuSet1Cohesion));
Allocation allocTgtTaskCohesion =
createAllocation(tgtTaskCohesion, createModelElementLiteral(ecuSet2Cohesion));
And isAllocCohesion = createAnd(allocSrcTaskCohesion, allocTgtTaskCohesion);
Equal isSameECUs = createEquals(createModelElementLiteral(ecuSet1Cohesion),
createModelElementLiteral(ecuSet2Cohesion));
IBooleanExpression isLocal = createAnd(isAllocCohesion, isSameECUs);
Exists hwSet2ExistsCohesion =
createExists(ecuSet2Cohesion.getCastedSet(IModelElement.class), isLocal, true);
Exists hwSetExistsCohesion = createExists(ecuSet1Cohesion.getCastedSet(IModelElement.class),
hwSet2ExistsCohesion, true);
Sum cohesion = createSum(signalSetCohesion.getCastedSet(IModelElement.class),
hwSetExistsCohesion, createArithmeticLiteral(BigDecimal.ONE));
double cohesionScaling = 1. / numECUs;
Mul cohesionScaled =
createMul(cohesion, createArithmeticLiteral(BigDecimal.valueOf(cohesionScaling)));
Minus modularizationQuality = createMinus(cohesionScaled, couplingScaled);
return createMaximize(modularizationQuality);
// COUPLING
// Set<Task> taskSet = createSet(taskSS, taskSS.getEntries(), "aTasks", Task.class);
// Set<Signal> signalSet =
// createSet(signalSS, signalSS.getEntries(), "bSignals", Signal.class);
//
// Start srcTask = createStart(signalSet, taskSet);
// End tgtTask = createEnd(signalSet, taskSet);
//
// Set<ExecutionUnit> ecuSet1 =
// createSet(ecuSS, ecuSS.getEntries(), "aEcus", ExecutionUnit.class);
// Set<ExecutionUnit> ecuSet2 =
// createSet(ecuSS, ecuSS.getEntries(), "bEcus", ExecutionUnit.class);
//
// Allocation allocSrcTask = createAllocation(srcTask, createModelElementLiteral(ecuSet1));
// Allocation allocTgtTask = createAllocation(tgtTask, createModelElementLiteral(ecuSet2));
//
// And isAlloc = createAnd(allocSrcTask, allocTgtTask);
// NotEqual isDistinctECUs = createNotEqual(createModelElementLiteral(ecuSet1),
// createModelElementLiteral(ecuSet2));
// IBooleanExpression isCoupled = createAnd(isAlloc, isDistinctECUs);
//
// // TODO Calculate denominator
//
// Exists hwSet2Exists =
// createExists(ecuSet2.getCastedSet(IModelElement.class), isCoupled, true);
// Exists hwSetExists =
// createExists(ecuSet1.getCastedSet(IModelElement.class), hwSet2Exists, true);
// Sum coupling = createSum(signalSet.getCastedSet(IModelElement.class), hwSetExists,
// createArithmeticLiteral(BigDecimal.ONE));
//
// // double couplingScaling = 1. / (numECUs * (numECUs - 1));
// // Mul couplingScaled =
// // createMul(coupling, createArithmeticLiteral(BigDecimal.valueOf(couplingScaling)));
// int couplingScaling = 2; // Overall objective is multiplied by common denominator to have
// // int weights (otherwise not suppored by DSE)
// ArithmeticLiteral couplingScalingLiteral =
// createArithmeticLiteral(new BigDecimal(String.valueOf(couplingScaling)));
// Mul couplingScaled = createMul(coupling, couplingScalingLiteral);
// COHESION
// Set<Task> taskSetCohesion =
// createSet(taskSS, taskSS.getEntries(), "aTasksCohesion", Task.class);
// Set<Signal> signalSetCohesion =
// createSet(signalSS, signalSS.getEntries(), "bSignalscohesion", Signal.class);
//
// Start srcTaskCohesion = createStart(signalSetCohesion, taskSetCohesion);
// End tgtTaskCohesion = createEnd(signalSetCohesion, taskSetCohesion);
//
// Set<ExecutionUnit> ecuSet1Cohesion =
// createSet(ecuSS, ecuSS.getEntries(), "aEcusCohesion", ExecutionUnit.class);
// Set<ExecutionUnit> ecuSet2Cohesion =
// createSet(ecuSS, ecuSS.getEntries(), "bEcusCohesion", ExecutionUnit.class);
//
// Allocation allocSrcTaskCohesion =
// createAllocation(srcTaskCohesion, createModelElementLiteral(ecuSet1Cohesion));
// Allocation allocTgtTaskCohesion =
// createAllocation(tgtTaskCohesion, createModelElementLiteral(ecuSet2Cohesion));
//
// And isAllocCohesion = createAnd(allocSrcTaskCohesion, allocTgtTaskCohesion);
// Equal isSameECUs = createEquals(createModelElementLiteral(ecuSet1Cohesion),
// createModelElementLiteral(ecuSet2Cohesion));
//
// IBooleanExpression isLocal = createAnd(isAllocCohesion, isSameECUs);
//
// Exists hwSet2ExistsCohesion =
// createExists(ecuSet2Cohesion.getCastedSet(IModelElement.class), isLocal, true);
// Exists hwSetExistsCohesion =
// createExists(ecuSet1Cohesion.getCastedSet(IModelElement.class),
// hwSet2ExistsCohesion, true);
// Calc. denominator
// Exist ECU
// Set<Task> taskSetCohesionScale =
// createSet(taskSS, taskSS.getEntries(), "bTasksCohesion", Task.class);
// Set<ExecutionUnit> ecuSet1CohesionScale =
// createSet(ecuSS, ecuSS.getEntries(), "cEcusCohesion", ExecutionUnit.class);
// ModelElementLiteral swc =
// createModelElementLiteral(taskSetCohesionScale.getCastedSet(IModelElement.class));
// ModelElementLiteral hwc =
// createModelElementLiteral(ecuSet1CohesionScale.getCastedSet(IModelElement.class));
// ILocationExpression predicate = createAllocation(swc, hwc);
//
// Exists swSet3ExistsCohesion = createExists(
// taskSetCohesionScale.getCastedSet(IModelElement.class), predicate, true);
// Sum taskSum = createSum(taskSetCohesionScale.getCastedSet(IModelElement.class),
// swSet3ExistsCohesion, createArithmeticLiteral(BigDecimal.ONE));
// Mul ecuCohesionScaling = createMul(createArithmeticLiteral(BigDecimal.ONE), taskSum);
//
// Sum cohesion = createSum(signalSetCohesion.getCastedSet(IModelElement.class),
// hwSetExistsCohesion, ecuCohesionScaling);
// // Sum cohesion = createSum(signalSetCohesion.getCastedSet(IModelElement.class),
// // hwSetExistsCohesion, createArithmeticLiteral(BigDecimal.ONE));
// // double cohesionScaling = 1. / numECUs;
// int cohesionScaling = numECUs - 1;
// Mul cohesionScaled =
// createMul(cohesion, createArithmeticLiteral(BigDecimal.valueOf(cohesionScaling)));
// Minus modularizationQuality = createMinus(cohesionScaled, couplingScaled);
// Create ECU-vise cohesion
// IBooleanExpression expression = createBooleanLiteral(true);
Plus cohesionTotal = createPlus(createArithmeticLiteral(BigDecimal.ZERO),
createArithmeticLiteral(BigDecimal.ZERO));
// ExecutionUnit executionUnit = ecuSetCohesion.getEntries().get(0);
for(ExecutionUnit executionUnit : ecuSS.getEntries()) {
Set<Task> taskSetCohesion =
createSet(taskSS, taskSS.getEntries(), "aTasksCohesion", Task.class);
Set<Signal> signalSetCohesion =
createSet(signalSS, signalSS.getEntries(), "bSignalscohesion", Signal.class);
Start srcTaskCohesion = createStart(signalSetCohesion, taskSetCohesion);
End tgtTaskCohesion = createEnd(signalSetCohesion, taskSetCohesion);
Set<ExecutionUnit> ecuSelectedSet1Cohesion =
createSet(ecuSS, executionUnit, "aEcusCohesion", ExecutionUnit.class);
Set<ExecutionUnit> ecuSelectedSet2Cohesion =
createSet(ecuSS, executionUnit, "bEcusCohesion", ExecutionUnit.class);
Allocation allocSrcTaskCohesion = createAllocation(srcTaskCohesion,
createModelElementLiteral(ecuSelectedSet1Cohesion));
Allocation allocTgtTaskCohesion = createAllocation(tgtTaskCohesion,
createModelElementLiteral(ecuSelectedSet2Cohesion));
And isAllocCohesion = createAnd(allocSrcTaskCohesion, allocTgtTaskCohesion);
Equal isSameECUs = createEquals(createModelElementLiteral(ecuSelectedSet1Cohesion),
createModelElementLiteral(ecuSelectedSet2Cohesion));
IBooleanExpression isLocal = createAnd(isAllocCohesion, isSameECUs);
Exists hwSet2ExistsCohesion = createExists(
ecuSelectedSet2Cohesion.getCastedSet(IModelElement.class), isLocal, true);
Exists hwSetExistsCohesion =
createExists(ecuSelectedSet1Cohesion.getCastedSet(IModelElement.class),
hwSet2ExistsCohesion, true);
Set<Task> taskSetCohesionScale =
createSet(taskSS, taskSS.getEntries(), "bTasksCohesion", Task.class);
ModelElementLiteral swc = createModelElementLiteral(
taskSetCohesionScale.getCastedSet(IModelElement.class));
Set<Task> taskSetCohesionScale1 =
createSet(taskSS, taskSS.getEntries(), "bTasksCohesion", Task.class);
Set<ExecutionUnit> ecuSet1CohesionScale =
createSet(ecuSS, executionUnit, "cEcusCohesion", ExecutionUnit.class);
ModelElementLiteral hwc = createModelElementLiteral(
ecuSet1CohesionScale.getCastedSet(IModelElement.class));
ILocationExpression predicate = createAllocation(swc, hwc);
// BooleanLiteral predicate = DSMLModelElementFactory.createBooleanLiteral(true);
Exists swSet3ExistsCohesion = createExists(
taskSetCohesionScale.getCastedSet(IModelElement.class), predicate, true);
Sum taskSum = createSum(taskSetCohesionScale1.getCastedSet(IModelElement.class),
swSet3ExistsCohesion, createArithmeticLiteral(BigDecimal.ONE));
// Sum cohesionEcu = createSum(signalSetCohesion.getCastedSet(IModelElement.class),
// hwSetExistsCohesion, createArithmeticLiteral(BigDecimal.ONE));
Sum cohesionEcu = createSum(signalSetCohesion.getCastedSet(IModelElement.class),
hwSetExistsCohesion,
createDiv(createArithmeticLiteral(BigDecimal.ONE), taskSum));
cohesionTotal = createPlus(cohesionTotal, cohesionEcu);
}
return createMaximize(cohesionTotal);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment