Search in sources :

Example 6 with PermutationHelper

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;
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 7 with PermutationHelper

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;
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Map(java.util.Map) AllocationException(org.eclipse.winery.repository.exceptions.AllocationException)

Example 8 with PermutationHelper

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);
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)8 PermutationHelper (org.eclipse.winery.repository.targetallocation.util.PermutationHelper)8 List (java.util.List)7 Map (java.util.Map)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 HashMap (java.util.HashMap)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)5 HashSet (java.util.HashSet)3 Set (java.util.Set)2 AllocationException (org.eclipse.winery.repository.exceptions.AllocationException)1 FragmentsCache (org.eclipse.winery.repository.targetallocation.util.FragmentsCache)1 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)1