Commit 160d7c68 authored by Marco Volpe's avatar Marco Volpe

Decoupling constraint rewritten.

* Makes reduced use of quantifiers and seems to behave better wrt
aramis2 use case

Issue-Ref: 000
Signed-off-by: Marco Volpe's avatarMarco Volpe <volpe@fortiss.org>
parent 1c876f04
......@@ -21,7 +21,7 @@ import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_SELECTED_EVENT;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.calcPatternName;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.createFunctionCouplingPattern;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.createTileLevelFunctionDecouplingConstraint;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.createTileLevelFunctionDecouplingConstraint2;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.prepareUniqueID;
......@@ -153,7 +153,7 @@ public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeG
SMTConstraint constraint = createSMTConstraint();
constraint.setName(header.getConstraintName());
constraint.setExpression(
createTileLevelFunctionDecouplingConstraint(dse, selectedTasks));
createTileLevelFunctionDecouplingConstraint2(dse, selectedTasks));
constraint.setDimension(header.getCategoryName());
prepareUniqueID(constraint, dse.eContainer());
......
......@@ -31,6 +31,7 @@ import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createMax
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createMinimize;
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.createNot;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createSet;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createSum;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createUses;
......@@ -52,6 +53,7 @@ import org.fortiss.af3.exploration.dseml.model.booleanp.Exists;
import org.fortiss.af3.exploration.dseml.model.booleanp.ForAll;
import org.fortiss.af3.exploration.dseml.model.booleanp.IBooleanExpression;
import org.fortiss.af3.exploration.dseml.model.booleanp.Implies;
import org.fortiss.af3.exploration.dseml.model.booleanp.Not;
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;
......@@ -642,8 +644,6 @@ public class PatternFactoryUtils {
// =>
// (t1 = t2)
List<IExpression> list = new ArrayList<IExpression>();
SuperSetMap superSetMap = dse.getCurrentStep().getSuperSetMap();
SuperSet<ExecutionUnit> ecuSet = superSetMap.get(ExecutionUnit.class);
List<ExecutionUnit> alreadySeen = new ArrayList<ExecutionUnit>();
......@@ -716,6 +716,106 @@ public class PatternFactoryUtils {
return formula;
}
// Variant of the decoupling constraint to be used with tiles
// This variant seems to behave better with the aramis2 example
/** Creates the Decoupling Constraint. */
public static IExpression createTileLevelFunctionDecouplingConstraint2(DSE dse,
Collection<Task> selectedTasks) {
SuperSetMap superSetMap = dse.getCurrentStep().getSuperSetMap();
SuperSet<ExecutionUnit> ecuSet = superSetMap.get(ExecutionUnit.class);
List<ExecutionUnit> alreadySeen = new ArrayList<ExecutionUnit>();
IBooleanExpression formula = null;
IBooleanExpression conjunction1 = null;
IBooleanExpression conjunction2 = null;
List<List<ExecutionUnit>> tiles = new ArrayList<>();
for(ExecutionUnit myEcu : ecuSet.getEntries()) {
Tile tile = (Tile)myEcu.getContainer();
if(alreadySeen.contains(tile)) {
continue;
}
alreadySeen.add(tile);
List<ExecutionUnit> ecusInTheTile = new ArrayList<ExecutionUnit>();
for(ExecutionUnit ecu1 : ecuSet.getEntries()) {
if(ecu1.getContainer() == tile) {
ecusInTheTile.add(ecu1);
}
}
tiles.add(ecusInTheTile);
}
Object[] taskArray = selectedTasks.toArray();
boolean firstConjunct1, firstConjunct2, firstConjunctGlobal;
firstConjunctGlobal = true;
for(List<ExecutionUnit> tile : tiles) {
// exists ecu \in TILE. t[i] -> ecu
// =>
// forall ecu' \in TILE. t[i+1] -/> ecu' AND ... AND t[size] -/> ecu'
firstConjunct1 = true;
for(int i = 0; i < selectedTasks.size() - 1; i++) {
Set<ExecutionUnit> hwcs1 = createSet(superSetMap.get(ExecutionUnit.class), tile,
"aHardwareComponents", ExecutionUnit.class);
Set<ExecutionUnit> hwcs2 = createSet(superSetMap.get(ExecutionUnit.class), tile,
"bHardwareComponents", ExecutionUnit.class);
Set<Task> task1 = createSet(superSetMap.get(Task.class), (Task)taskArray[i],
"cTask", Task.class);
// create premise
Allocation loc = createAllocation(createModelElementLiteral(task1),
createModelElementLiteral(hwcs1));
ForAll forall = createForAll(task1.getCastedSet(IModelElement.class), loc, true);
Exists premise =
createExists(hwcs1.getCastedSet(IModelElement.class), forall, true);
// create conclusion
firstConjunct2 = true;
for(int j = 1; i + j < selectedTasks.size(); j++) {
Set<Task> task2 = createSet(superSetMap.get(Task.class), (Task)taskArray[i + j],
"dTask", Task.class);
Allocation locationConstraint = createAllocation(
createModelElementLiteral(task2), createModelElementLiteral(hwcs2));
Not dislocationConstraint = createNot(locationConstraint);
ForAll task2forall = createForAll(task2.getCastedSet(IModelElement.class),
dislocationConstraint, true);
if(firstConjunct2) {
firstConjunct2 = false;
conjunction2 = task2forall;
} else {
conjunction2 = createAnd(conjunction2, task2forall);
}
}
ForAll conclusion =
createForAll(hwcs2.getCastedSet(IModelElement.class), conjunction2, true);
// create implication
Implies implication = createImplies(premise, conclusion);
// conjuncts more implications
if(firstConjunct1) {
firstConjunct1 = false;
conjunction1 = implication;
} else {
conjunction1 = createAnd(conjunction1, implication);
}
}
// conjuncts more tiles
// conjuncts more implications
if(firstConjunctGlobal) {
firstConjunctGlobal = false;
formula = conjunction1;
} else {
formula = createAnd(formula, conjunction1);
}
}
return formula;
}
/**
* Calculates the "name" of constraints. It supports sets and shortening the name if it becomes
* "too long". The contained elements of sets can still be easily seen by setting
......
Markdown is supported
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