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

Couplings: Consider allocation constraints of its members


* Create an intersects method for N sets.
* Respect allocation constraints in the allocation of the first member
  of a coupled set.

Signed-off-by: default avatarAlexander Diewald <diewald@fortiss.org>
parent 1cee0ab8
No related branches found
No related tags found
No related merge requests found
IInstanceEncoding.java b0a3f51217dde1d5a534a880f82de07cf8afd453 YELLOW
IMappingEncoding.java a0b9332ece9244e57066575d9081e3f069095207 YELLOW
IMappingEntry.java 5b78626cd7247543d9581992e3322aabb1ca4449 YELLOW
InstanceEncodingBase.java 49deec0258e46c6d426366386ccb25a55e61d464 RED
MappingEncodingBase.java 16b1e44709472990faa297e531fcba9dc3da4552 YELLOW
MappingEntryBase.java 156259b4fdf3068994ea619e16c53558369b9205 YELLOW
IInstanceEncoding.java b0a3f51217dde1d5a534a880f82de07cf8afd453 YELLOW
IMappingEncoding.java a0b9332ece9244e57066575d9081e3f069095207 YELLOW
IMappingEntry.java 5b78626cd7247543d9581992e3322aabb1ca4449 YELLOW
InstanceEncodingBase.java 49deec0258e46c6d426366386ccb25a55e61d464 RED
MappingEncodingBase.java 1452dea91d6e25ed6a2845d93ed6dc3e1c3e1aa4 RED
MappingEntryBase.java 156259b4fdf3068994ea619e16c53558369b9205 YELLOW
......@@ -16,10 +16,13 @@
package org.fortiss.af3.exploration.alg.module.common.encoding;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableSet;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.eclipse.core.runtime.Assert.isTrue;
import static org.fortiss.af3.exploration.alg.util.ExplorationAlgUtils.DSE_VALIDATE_ENCODING;
import static org.fortiss.af3.exploration.alg.util.ExplorationAlgUtils.intersects;
import static org.fortiss.tooling.common.util.LambdaUtils.filterByType;
import static org.fortiss.tooling.common.util.LambdaUtils.getFirst;
......@@ -164,12 +167,24 @@ public abstract class MappingEncodingBase<S extends IRequestAdapter, T extends I
Optional<S> existingSrc =
getFirst(cConstr.getSetOf(source), s -> allocationTable.containsRow(s));
if(existingSrc.isPresent()) {
// Only allocate to the target where other members of the coupled set are already
// allocated to.
Set<T> tgtSet = getMappingEntriesOf(existingSrc.get()).stream()
.map(e -> e.getTarget()).collect(toSet());
return ImmutableList.copyOf(tgtSet);
}
// If no element of a coupled set has been allocated yet, it may be only allocated to
// targets that are part of all allocation constraints of the coupled elements.
Collection<Set<T>> validTargets = cConstr.getSetOf(source).stream()
.map(s -> getValidTargetResourcesAsSet(s)).collect(toSet());
return unmodifiableList(new ArrayList<>(intersects(validTargets)));
}
return validAllocations.get(source);
return unmodifiableList(validAllocations.get(source));
}
/** Returns a set view of the valid target resources of the given requester. */
protected Set<T> getValidTargetResourcesAsSet(S source) {
return unmodifiableSet(new HashSet<>(validAllocations.get(source)));
}
/**
......
AF3Utils.java 015cd73497d0fe695ba46b1b4fea55bd51ccb9e2 RED
DesignSpaceExplorationModelElementFactory.java c4d4ab53dcc75e5a45bc0f512c51aa1928fcaaa1 YELLOW
DseMLUtils.java 9976afd27d8079096b93edb556a31fd18be8baee YELLOW
ExplorationAlgUtils.java 9970bd555341c0db43e287b5a9e9c91849d4f99e RED
ExplorationFeatureUtils.java 7a92ff889e45f3b89655fbd9e265343b19b49d25 YELLOW
GraphUtils.java 550784a7fa53eaf370f9cca248cc776843cf1134 RED
TransformationUtils.java a578525713ca9b715f8e64826b614f332fb5e34d YELLOW
AF3Utils.java 015cd73497d0fe695ba46b1b4fea55bd51ccb9e2 RED
DesignSpaceExplorationModelElementFactory.java c4d4ab53dcc75e5a45bc0f512c51aa1928fcaaa1 YELLOW
DseMLUtils.java 9976afd27d8079096b93edb556a31fd18be8baee YELLOW
ExplorationAlgUtils.java 9e6113ab5a983a362ff8a51050d0eb9e5a324fd2 RED
ExplorationFeatureUtils.java 7a92ff889e45f3b89655fbd9e265343b19b49d25 YELLOW
GraphUtils.java 550784a7fa53eaf370f9cca248cc776843cf1134 RED
TransformationUtils.java a578525713ca9b715f8e64826b614f332fb5e34d YELLOW
......@@ -18,6 +18,9 @@ package org.fortiss.af3.exploration.alg.util;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.System.getenv;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
import static org.apache.commons.collections4.SetUtils.intersection;
import static org.fortiss.af3.exploration.alg.service.ExplorationServiceManager.getService;
import static org.fortiss.tooling.common.util.LambdaUtils.getFirst;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copyToRefMap;
......@@ -321,6 +324,23 @@ public class ExplorationAlgUtils {
return getFirst(method).get();
}
/** Returns the intersection of all given sets. */
public static <T> Set<T> intersects(Collection<Set<T>> intersectingSets) {
if(intersectingSets.isEmpty()) {
return unmodifiableSet(emptySet());
} else if(intersectingSets.size() == 1) {
return unmodifiableSet(getFirst(intersectingSets).get());
}
Set<T> intersection = getFirst(intersectingSets).get();
intersectingSets.remove(intersection);
for(Set<T> cmpSet : intersectingSets) {
intersection = intersection(intersection, cmpSet);
}
return unmodifiableSet(intersection);
}
/**
* Returns a self-contained copy of the given <code>eObject</code>.
* Here, the copier that performs the copy operation must be given. The copier (which is a
......
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