/** * As the base implementation here, all templates will be considered for each edge. */ @Override protected void populateEdgeTemplateMap() { if (templateCatalog.isPresent()) { for (FlowEdge flowEdge : this.weightedGraph.edgeSet()) { edgeTemplateMap.put(flowEdge.getEdgeIdentity(), templateCatalog.get(). getAllTemplates(). stream().map(jobTemplate -> jobTemplate.getUri()).collect(Collectors.toList())); } } }
@Override public void populateBlackListedEdges(DirectedWeightedMultigraph<ServiceNode, FlowEdge> graph) { for (ServiceNode node: serviceNodes) { if (graph.containsVertex(node)) { blacklistedEdges.addAll(graph.incomingEdgesOf(node)); blacklistedEdges.addAll(graph.outgoingEdgesOf(node)); } else { log.info("The graph " + graph + " doesn't contains node " + node.toString()); } } for( FlowEdge flowEdge: flowEdges) { if (graph.containsEdge(flowEdge)) { blacklistedEdges.add(flowEdge); } else { log.info("The graph " + graph + "doesn't contains edge " + flowEdge.toString()); } } } }
private void weightGraphGenerateHelper(TopologySpec topologySpec) { try { Map<ServiceNode, ServiceNode> capabilities = topologySpec.getSpecExecutor().getCapabilities().get(); for (Map.Entry<ServiceNode, ServiceNode> capability : capabilities.entrySet()) { BaseServiceNodeImpl sourceNode = new BaseServiceNodeImpl(capability.getKey().getNodeName()); BaseServiceNodeImpl targetNode = new BaseServiceNodeImpl(capability.getValue().getNodeName()); if (!weightedGraph.containsVertex(sourceNode)) { weightedGraph.addVertex(sourceNode); } if (!weightedGraph.containsVertex(targetNode)) { weightedGraph.addVertex(targetNode); } FlowEdge flowEdge = new LoadBasedFlowEdgeImpl(sourceNode, targetNode, defaultFlowEdgeProps, topologySpec.getSpecExecutor()); // In Multi-Graph if flowEdge existed, just skip it. if (!weightedGraph.containsEdge(flowEdge)) { weightedGraph.addEdge(sourceNode, targetNode, flowEdge); } } } catch (InterruptedException | ExecutionException e) { Instrumented.markMeter(this.flowCompilationFailedMeter); throw new RuntimeException("Cannot determine topology capabilities", e); } }
private boolean userSpecifiedPathVerificator(Map<Spec, SpecExecutor> specExecutorInstanceMap, FlowSpec flowSpec) { Map<Spec, SpecExecutor> tmpSpecExecutorInstanceMap = new HashMap<>(); List<String> userSpecfiedPath = Arrays.asList(optionalUserSpecifiedPath.get().split(",")); for (int i = 0; i < userSpecfiedPath.size() - 1; i++) { ServiceNode sourceNode = new BaseServiceNodeImpl(userSpecfiedPath.get(i)); ServiceNode targetNode = new BaseServiceNodeImpl(userSpecfiedPath.get(i + 1)); if (weightedGraph.containsVertex(sourceNode) && weightedGraph.containsVertex(targetNode) && weightedGraph.containsEdge(sourceNode, targetNode)) { tmpSpecExecutorInstanceMap.put(convertHopToJobSpec(sourceNode, targetNode, flowSpec), (((LoadBasedFlowEdgeImpl) weightedGraph.getEdge(sourceNode, targetNode)).getSpecExecutorInstance())); } else { log.error("User Specified Path is invalid"); return false; } } specExecutorInstanceMap.putAll(tmpSpecExecutorInstanceMap); return true; }
public static DirectedWeightedMultigraph<Node, DefaultLink> asDefaultGraph(DirectedWeightedMultigraph<Node, LabeledLink> graph) { if (graph == null) { logger.debug("graph is null."); return null; } DirectedWeightedMultigraph<Node, DefaultLink> g = new DirectedWeightedMultigraph<>(DefaultLink.class); for (Node v : graph.vertexSet()) g.addVertex(v); for (DefaultLink e: graph.edgeSet()) g.addEdge(e.getSource(), e.getTarget(), e); return g; }
private void mergeModels(DirectedWeightedMultigraph<Node, LabeledLink> model1, DirectedWeightedMultigraph<Node, LabeledLink> model2) { for(Node n : model1.vertexSet()) { model2.addVertex(n); for(LabeledLink link : model1.incomingEdgesOf(n)) { model2.addVertex(link.getSource()); model2.addVertex(link.getTarget()); model2.addEdge(link.getSource(), link.getTarget(), link); } } this.models.remove(model1); } }
/** * Create a builder for this kind of graph. * * @param edgeClass class on which to base factory for edges * @param <V> the graph vertex type * @param <E> the graph edge type * @return a builder for this kind of graph */ public static <V, E> GraphBuilder<V, E, ? extends DirectedWeightedMultigraph<V, E>> createBuilder( Class<? extends E> edgeClass) { return new GraphBuilder<>(new DirectedWeightedMultigraph<>(edgeClass)); }
public void printModel(DirectedWeightedMultigraph<Node, LabeledLink> model) { logger.debug("Vertices: "); for(Node n : model.vertexSet()) { logger.debug("\t" + n.getId()); } logger.debug("Edges: "); for(LabeledLink l : model.edgeSet()) { logger.debug("\t" + l.getSource().getId() + " --> " + l.getTarget().getId()); } }
Set<DefaultLink> incomingLinks = this.graph.incomingEdgesOf(node); if (incomingLinks != null) { DefaultLink[] incomingLinksArray = incomingLinks.toArray(new DefaultLink[0]); Set<DefaultLink> outgoingLinks = this.graph.outgoingEdgesOf(node); if (outgoingLinks != null) { DefaultLink[] outgoingLinksArray = outgoingLinks.toArray(new DefaultLink[0]); this.forcedNodes.remove(node); if (!this.graph.removeVertex(node)) return false; nodesWithSameType.remove(node); logger.debug("total number of nodes in graph: " + this.graph.vertexSet().size()); logger.debug("total number of links in graph: " + this.graph.edgeSet().size());
&& !alignmentGraph.vertexSet().isEmpty()) { Set<Node> nodes = alignmentGraph.vertexSet(); for (Node node : nodes) { if (node instanceof ColumnNode) { && !alignmentGraph.vertexSet().isEmpty()) { Set<Node> nodes = alignmentGraph.vertexSet(); for (Node node : nodes) { Set<LabeledLink> links = alignmentGraph.edgeSet(); for (LabeledLink link : links) { Integer targetIndex = verticesIndex.get(target); Set<LabeledLink> outEdges = alignmentGraph .outgoingEdgesOf(target);
Set<DefaultLink> incomingLinks = tree.incomingEdgesOf(node); if (incomingLinks != null) { LabeledLink[] incomingLinksArr = incomingLinks.toArray(new LabeledLink[0]); tree.removeEdge(inLink); tree.addEdge(target, source, reverseLink); tree.setEdgeWeight(reverseLink, inLink.getWeight()); Set<DefaultLink> outgoingLinks = tree.outgoingEdgesOf(node); target = outLink.getTarget(); if (visitedNodes.contains(target)) { tree.removeEdge(outLink); removedLinks.add(outLink.getId()); } else {
public static DirectedWeightedMultigraph<Node, DefaultLink> readGraph(JsonReader reader) throws IOException { new DirectedWeightedMultigraph<Node, DefaultLink>(LabeledLink.class); if (n != null) { idToNodes.put(n.getId(), n); graph.addVertex(n); target = idToNodes.get(LinkIdFactory.getLinkTargetId(l.getId())); if (source != null && target != null) { graph.addEdge(source, target, l); if (weight[0] != null) graph.setEdgeWeight(l, weight[0].doubleValue());
private void buildOutputTree(boolean allowedChangingGraph) { DefaultLink[] links = tree.edgeSet().toArray(new DefaultLink[0]); tree.addEdge(link.getSource(), link.getTarget(), newLink); tree.setEdgeWeight(newLink, link.getWeight()); if (allowedChangingGraph) this.graphBuilder.addLink(link.getSource(), link.getTarget(), newLink); tree.removeEdge(link); if (allowedChangingGraph) this.graphBuilder.removeLink(link);
public Set<LabeledLink> getOutgoingLinksInTree(String nodeId) { Set<LabeledLink> results = new HashSet<>(); if (steinerTree == null) return results; if (steinerTree.vertexSet().isEmpty()) return results; Node node = null; for (Node n : steinerTree.vertexSet()) { if (n.getId().equals(nodeId)) { node = n; break; } } if (node == null) return results; results = this.steinerTree.outgoingEdgesOf(node); return results; }
for (SemanticTypeMapping stm : steinerNodes.getColumnNodeInfo().values()) { LabeledLink dataPropertyLink = stm.getLink(); tree.addVertex(stm.getTarget()); if (tree.vertexSet().contains(stm.getSource())) { tree.addEdge(stm.getSource(), stm.getTarget(), dataPropertyLink); tree.setEdgeWeight(dataPropertyLink, stm.getLink().getWeight()); } else { logger.error("this should not conceptually happen, there should be a bug in the code!");
private void addLinks(Set<LabeledLink> links) { if (links == null) return; for (LabeledLink link : links) { if (!this.tree.containsEdge(link) && this.tree.containsVertex(link.getSource()) && this.tree.containsVertex(link.getTarget())) { this.tree.addEdge(link.getSource(), link.getTarget(), link); } } }
for (Node n : model.vertexSet()) { Set<ColumnNode> columnNodes = new HashSet<>(); nodesSpan.put(n, columnNodes); Set<LabeledLink> outgoingLinks = model.outgoingEdgesOf(n); if (outgoingLinks != null && !outgoingLinks.isEmpty()) for (LabeledLink l : outgoingLinks) neighborsInLowerLevel.add(l.getTarget()); Set<LabeledLink> incomingLinks = model.incomingEdgesOf(n); if (incomingLinks != null && !incomingLinks.isEmpty()) for (LabeledLink l : incomingLinks)
if (model.outgoingEdgesOf(in) == null || model.outgoingEdgesOf(in).isEmpty()) { this.itemsCount += model.edgeSet().size(); return;
public Set<LabeledLink> getOutgoingEdgesOf(Node node) { Set<LabeledLink> edges = new HashSet<>(); for(DirectedWeightedMultigraph<Node, LabeledLink> model : models) { GraphUtil.printGraph(GraphUtil.asDefaultGraph(model)); if(model.containsVertex(node)) edges.addAll(model.outgoingEdgesOf(node)); } return edges; }