use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.
the class MinHosts method toPermutationHelpers.
/**
* Wrap possible replacements for permutation algorithm.
*/
private List<List<PermutationHelper>> toPermutationHelpers(Map<TNodeTemplate, List<TTopologyTemplate>> possibleReplacements) {
List<List<PermutationHelper>> possibilities = new ArrayList<>();
for (Map.Entry<TNodeTemplate, List<TTopologyTemplate>> entry : possibleReplacements.entrySet()) {
List<PermutationHelper> possibilitiesForNT = new ArrayList<>();
for (TTopologyTemplate possibility : entry.getValue()) {
possibilitiesForNT.add(new PermutationHelper(entry.getKey(), possibility));
}
possibilities.add(possibilitiesForNT);
}
return possibilities;
}
use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.
the class MinExternalConnections method getPossibleMatches.
@Override
protected List<List<PermutationHelper>> getPossibleMatches(TopologyWrapper topology) {
List<List<PermutationHelper>> possibilities = new ArrayList<>();
try {
for (TNodeTemplate topLevelNT : topology.getTopLevelNTs()) {
Map<TNodeTemplate, List<TTopologyTemplate>> fragments = fragmentsCache.getAllMatchingFragments(topology, topLevelNT);
List<PermutationHelper> possibility = new ArrayList<>();
for (Map.Entry<TNodeTemplate, List<TTopologyTemplate>> entry : fragments.entrySet()) {
possibility.add(new PermutationHelper(entry.getKey(), entry.getValue()));
}
possibilities.add(possibility);
}
} catch (AllocationException e) {
logger.debug("Exception calculating matching fragments: " + e.getMessage());
return new ArrayList<>();
}
return possibilities;
}
use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.
the class TargetLabelAssignment method computeTargetLabelPermutations.
protected List<TopologyWrapper> computeTargetLabelPermutations() {
addMissingTargetLabels();
List<List<PermutationHelper>> possibilities = new ArrayList<>();
// permute node templates which were assigned target labels at the same time as group
for (List<TNodeTemplate> group : assignedAsGroup) {
Set<String> targetLabels = possibleTargetLabels.get(group.get(0));
List<PermutationHelper> possibility = new ArrayList<>();
for (String targetLabel : targetLabels) {
possibility.add(new PermutationHelper(group, targetLabel));
}
possibilities.add(possibility);
}
List<TNodeTemplate> done = assignedAsGroup.stream().flatMap(List::stream).collect(Collectors.toList());
// permute rest of node templates
for (Map.Entry<TNodeTemplate, Set<String>> entry : possibleTargetLabels.entrySet()) {
if (done.contains(entry.getKey()) || !original.isTopLevelNT(entry.getKey()) || !original.getNodeTemplates().contains(entry.getKey())) {
continue;
}
List<PermutationHelper> possibility = new ArrayList<>();
for (String targetLabel : entry.getValue()) {
possibility.add(new PermutationHelper(entry.getKey(), targetLabel));
}
possibilities.add(possibility);
}
List<List<PermutationHelper>> permutations = AllocationUtils.getPermutations(possibilities, outputCap);
return AllocationUtils.generateTargetLabelTopologies(original, permutations);
}
Aggregations