GraphDumper(DAGNode<Component, Dependency> g, Set<DAGNode<Component, Dependency>> unshared, GraphWriter gw) { writer = gw; graph = g; unsharedNodes = Sets.newHashSet(unshared); unsharedNodes.retainAll(g.getReachableNodes()); logger.debug("{} shared nodes", unsharedNodes.size()); nodeIds = new HashMap<>(); nodeTargets = new HashMap<>(); edgeQueue = new LinkedList<>(); }
/** * Get the placeholder nodes from a graph. * * @param graph The graph. * @return The set of nodes that have placeholder satisfactions. */ public static Set<DAGNode<Component, Dependency>> getPlaceholderNodes(DAGNode<Component,Dependency> graph) { return graph.getReachableNodes() .stream() .filter(n -> n.getLabel().getSatisfaction() instanceof PlaceholderSatisfaction) .collect(Collectors.toSet()); }
/** * Replace shareable nodes in a graph. * * @param replace A replacement function. For each shareable node, this function will * be called; if it returns a node different from its input node, the * new node will be used as a replacement for the old. */ private DAGNode<Component,Dependency> replaceShareableNodes(NodeProcessor replace) throws InjectionException { logger.debug("replacing nodes in graph with {} nodes", graph.getReachableNodes().size()); Set<DAGNode<Component,Dependency>> toReplace = GraphtUtils.getShareableNodes(graph); logger.debug("found {} shared nodes", toReplace.size()); DAGNode<Component, Dependency> result = NodeProcessors.processNodes(graph, toReplace, replace); logger.debug("final graph has {} nodes", result.getReachableNodes().size()); return result; } }
@Override protected DAGNode<Component, Dependency> instantiateGraph(DAGNode<Component, Dependency> graph) { if (cache == null) { logger.debug("Building directly without a cache"); return super.instantiateGraph(graph); } else { logger.debug("Instantiating graph with a cache"); try { Set<DAGNode<Component, Dependency>> nodes = GraphtUtils.getShareableNodes(graph); logger.debug("resolving {} nodes", nodes.size()); DAGNode<Component, Dependency> newGraph = NodeProcessors.processNodes(graph, nodes, cache); logger.debug("newGraph went from {} to {} nodes", newGraph.getReachableNodes().size(), newGraph.getReachableNodes().size()); return newGraph; } catch (InjectionException e) { logger.error("Error instantiating recommender nodes with cache", e); throw new RecommenderBuildException("Cached instantiation failed", e); } } } }
logger.debug("graph has {} nodes", graph.getReachableNodes().size()); logger.debug("simulating instantiation"); RecommenderInstantiator instantiator = RecommenderInstantiator.create(graph); DAGNode<Component, Dependency> unshared = instantiator.simulate(); logger.debug("unshared graph has {} nodes", unshared.getReachableNodes().size()); try (BufferedWriter bw = new BufferedWriter(graphvizFile); GraphWriter gw = new GraphWriter(bw)) { GraphDumper dumper = new GraphDumper(graph, unshared.getReachableNodes(), gw); logger.debug("writing root node"); String rid = dumper.setRoot(graph);
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("node ") .append(label) .append(" with ") .append(getReachableNodes().size()) .append(" nodes and ") .append(outgoingEdges.size()) .append(" edges"); return sb.toString(); }
GraphDumper(DAGNode<Component, Dependency> g, Set<DAGNode<Component, Dependency>> unshared, GraphWriter gw) { writer = gw; graph = g; unsharedNodes = Sets.newHashSet(unshared); unsharedNodes.retainAll(g.getReachableNodes()); logger.debug("{} shared nodes", unsharedNodes.size()); nodeIds = new HashMap<DAGNode<Component, Dependency>, String>(); nodeTargets = new HashMap<String, String>(); edgeQueue = new LinkedList<GVEdge>(); }
/** * Get the placeholder nodes from a graph. * * @param graph The graph. * @return The set of nodes that have placeholder satisfactions. */ public static Set<DAGNode<Component, Dependency>> getPlaceholderNodes(DAGNode<Component,Dependency> graph) { return graph.getReachableNodes() .stream() .filter(n -> n.getLabel().getSatisfaction() instanceof PlaceholderSatisfaction) .collect(Collectors.toSet()); }
/** * Replace shareable nodes in a graph. * * @param replace A replacement function. For each shareable node, this function will * be called; if it returns a node different from its input node, the * new node will be used as a replacement for the old. */ private DAGNode<Component,Dependency> replaceShareableNodes(NodeProcessor replace) throws InjectionException { logger.debug("replacing nodes in graph with {} nodes", graph.getReachableNodes().size()); Set<DAGNode<Component,Dependency>> toReplace = GraphtUtils.getShareableNodes(graph); logger.debug("found {} shared nodes", toReplace.size()); DAGNode<Component, Dependency> result = NodeProcessors.processNodes(graph, toReplace, replace); logger.debug("final graph has {} nodes", result.getReachableNodes().size()); return result; } }
graph = NodeProcessors.processNodes(cfgGraph, nodes, cache); logger.debug("graph went from {} to {} nodes", cfgGraph.getReachableNodes().size(), graph.getReachableNodes().size()); } catch (InjectionException e) { logger.error("Error encountered while pre-processing algorithm components for sharing", e);
} else if (getReachableNodes().contains(node)) { DAGNodeBuilder<V,E> bld = newBuilder(label); for (DAGEdge<V,E> edge: outgoingEdges) {
logger.debug("graph has {} nodes", graph.getReachableNodes().size()); logger.debug("simulating instantiation"); RecommenderInstantiator instantiator = RecommenderInstantiator.create(graph); DAGNode<Component, Dependency> unshared = instantiator.simulate(); logger.debug("unshared graph has {} nodes", unshared.getReachableNodes().size()); try (Writer writer = new FileWriter(graphvizFile); BufferedWriter bw = new BufferedWriter(writer); GraphWriter gw = new GraphWriter(bw)) { GraphDumper dumper = new GraphDumper(graph, unshared.getReachableNodes(), gw); logger.debug("writing root node"); String rid = dumper.setRoot(graph);
pool.addAll(newRoot.getReachableNodes());
logger.debug("rewriting graph with {} nodes", graph.getReachableNodes().size());
rootNode.getRight()) .build(); } else if (graph.getReachableNodes().contains(parent)) { if (merged.getReachableNodes().contains(parent)) {