public List<GraphMapping> extractViolatingMappings(ToscaGraph identifierGraph, List<GraphMapping> identifierMappings, List<GraphMapping> requiredStructureMappings) { List<GraphMapping> violatingMappings = new ArrayList<>(); // for all mappings in identifierMappings, we need to find the corresponding required Structure Mappings for (GraphMapping identifierMapping : identifierMappings) { boolean foundCorrespondence = false; for (GraphMapping requiredStructureMapping : requiredStructureMappings) { //get the corresponding ToscaNode from the searchInGraph ToscaNode identifierVertexCorrespondence = (ToscaNode) identifierMapping.getVertexCorrespondence(identifierGraph.getReferenceNode(), false); foundCorrespondence = (requiredStructureMapping.getVertexCorrespondence(identifierVertexCorrespondence, true) != null) ? true : false; } if (!foundCorrespondence) { violatingMappings.add(identifierMapping); } } return violatingMappings; }
public Map<ToscaNode, ToscaNode> getSubGraphMappingAsMap(GraphMapping mapping, ToscaGraph subGraph) { Map<ToscaNode, ToscaNode> result = new HashMap<>(); for (ToscaNode node : subGraph.vertexSet()) { Optional.of(mapping.getVertexCorrespondence(node, false)).map(vertex -> (ToscaNode) vertex).ifPresent(vertex -> result.put(node, vertex)); } return result; }
public ArrayList<String> getNodeIdsToBeReplaced() { ArrayList<String> ids = new ArrayList<>(); this.detectorGraph.vertexSet().forEach(toscaNode -> ids.add(graphMapping.getVertexCorrespondence(toscaNode, false).getTemplate().getId()) ); return ids; } }
/** * Checks for equality. Assuming both are mappings on the same graphs. * * @param rel the corresponding mapping * @return do both relations map to the same vertices */ public boolean isEqualMapping(GraphMapping<V, E> rel) { for (V v : graph2.vertexSet()) { if (!getVertexCorrespondence(v, false).equals(rel.getVertexCorrespondence(v, false))) { return false; } } return true; }
public boolean isApplicable(RefinementCandidate candidate, TTopologyTemplate topology) { return candidate.getDetectorGraph().vertexSet() .stream() .allMatch(vertex -> { TNodeTemplate matchingNode = candidate.getGraphMapping().getVertexCorrespondence(vertex, false).getTemplate(); return this.canRedirectExternalRelations(candidate, matchingNode, topology); }); }
private Map<String, Map<String, Integer>> calculateNewPositions(ToscaGraph detectorGraph, GraphMapping<ToscaNode, ToscaEdge> mapping, TTopologyTemplate refinementStructure) { HashMap<String, Map<String, Integer>> coordinates = new HashMap<>(); int[] topLeftOriginal = {-1, -1}; int[] topLeftReplacement = {-1, -1}; detectorGraph.vertexSet().forEach(toscaNode -> { ToscaNode node = mapping.getVertexCorrespondence(toscaNode, false); getTopLeft(node.getTemplate().getX(), node.getTemplate().getY(), topLeftOriginal); }); refinementStructure.getNodeTemplates().forEach( tNodeTemplate -> getTopLeft(tNodeTemplate.getX(), tNodeTemplate.getY(), topLeftReplacement) ); refinementStructure.getNodeTemplates().forEach(nodeTemplate -> { int x = Integer.parseInt(nodeTemplate.getX()); int y = Integer.parseInt(nodeTemplate.getY()); HashMap<String, Integer> newCoordinates = new HashMap<>(); newCoordinates.put("x", (x - topLeftReplacement[0]) + topLeftOriginal[0]); newCoordinates.put("y", (y - topLeftReplacement[1]) + topLeftOriginal[1]); coordinates.put(nodeTemplate.getId(), newCoordinates); }); return coordinates; }
.forEach(vertex -> { TNodeTemplate matchingNode = refinement.getGraphMapping().getVertexCorrespondence(vertex, false).getTemplate();
String topologyNodeId = refinement.getGraphMapping().getVertexCorrespondence(node, false).getId();