Group parentGroup = grouper.nodeGroup(parent); if(parentGroup!=null && !parentGroup.equals(g)) { equivs.addEdge(parentGroup, g);
/** * Craete a toy graph based on String objects. * * @return a graph based on String objects. */ private static UndirectedGraph<String, DefaultEdge> createStringGraph() { UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); String v1 = "v1"; String v2 = "v2"; String v3 = "v3"; String v4 = "v4"; // add the vertices g.addVertex(v1); g.addVertex(v2); g.addVertex(v3); g.addVertex(v4); // add edges to create a circuit g.addEdge(v1, v2); g.addEdge(v2, v3); g.addEdge(v3, v4); g.addEdge(v4, v1); return g; } }
private void addEdgeBetweenSameGeographicalSpotNodes(UcteNetwork network, UndirectedGraph<UcteNodeCode, Object> graph) { // ...nodes with same geographical spot Multimap<String, UcteNode> nodesByGeographicalSpot = Multimaps.index(network.getNodes(), node -> node.getCode().getUcteCountryCode() + node.getCode().getGeographicalSpot()); for (Map.Entry<String, Collection<UcteNode>> entry : nodesByGeographicalSpot.asMap().entrySet()) { for (UcteNode n1 : entry.getValue()) { for (UcteNode n2 : entry.getValue()) { if (n1 != n2) { graph.addEdge(n1.getCode(), n2.getCode()); } } } } }
public void addProcessModelElement(ProcessModelElement processModelElement, ControlFlowOutputPort<?> statePort) { processModelElementGraph.addVertex(processModelElement); Set<ControlFlowOutputPort<?>> statesInvolved = getStatesInvolved(processModelElement); Set<ControlFlowInputPort<?>> inputs = processModelElement.getInputs(); for (ProcessModelElement otherProcessModelElement : processModelElementGraph.vertexSet()) { if (processModelElement != otherProcessModelElement) { Set<ControlFlowOutputPort<?>> otherStatesInvolved = getStatesInvolved(otherProcessModelElement); Set<ControlFlowOutputPort<?>> stateIntersection = new LinkedHashSet<ControlFlowOutputPort<?>>(statesInvolved); stateIntersection.retainAll(otherStatesInvolved); boolean stateCouplingExists = stateIntersection.size() > 0; Set<ControlFlowInputPort<?>> otherInputs = otherProcessModelElement.getInputs(); Set<ControlFlowInputPort<?>> inputIntersection = new LinkedHashSet<ControlFlowInputPort<?>>(inputs); inputIntersection.retainAll(otherInputs); boolean inputCouplingExists = inputIntersection.size() > 0; if (stateCouplingExists || inputCouplingExists) { ProcessModelGraphEdge edge = new ProcessModelGraphEdge(stateIntersection, inputIntersection); processModelElementGraph.addEdge(processModelElement, otherProcessModelElement, edge); } } } }
private UndirectedGraph<String, Object> graphSubstationsTransformers() { UndirectedGraph<String, Object> graph = new Pseudograph<>(Object.class); for (PropertyBag s : context.cgmes().substations()) { String id = s.getId(CgmesNames.SUBSTATION); graph.addVertex(context.namingStrategy().getId(CgmesNames.SUBSTATION, id)); } for (PropertyBags tends : context.cgmes().groupedTransformerEnds().values()) { List<String> substationsIds = substationsIds(tends); if (substationsIds.size() > 1) { for (int i = 1; i < substationsIds.size(); i++) { graph.addEdge(substationsIds.get(0), substationsIds.get(i)); } } } return graph; }
private List<Set<String>> getClusters(List<String> dir1, List<String> dir2, Matrix scores) { UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); for (String f : dir1) graph.addVertex(f); if (dir1 != dir2) for (String f : dir2) graph.addVertex(f); final double[][] matrixData = scores.getArray(); for (int r=0; r<matrixData.length; r++) { for (int c=r; c<matrixData[0].length; c++) { String f1 = dir1.get(r); String f2 = dir2.get(c); if ( matrixData[r][c] != 0 && f1!=f2 ) { graph.addEdge(f1, f2); } } } ConnectivityInspector<String, DefaultEdge> conn = new ConnectivityInspector<String, DefaultEdge>(graph); return conn.connectedSets(); }
private List<Set<String>> getClusters(List<String> dir1, List<String> dir2, Matrix scores) { UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); for (String f : dir1) graph.addVertex(f); if (dir1 != dir2) for (String f : dir2) graph.addVertex(f); final double[][] matrixData = scores.getArray(); for (int r=0; r<matrixData.length; r++) { for (int c=r; c<matrixData[0].length; c++) { String f1 = dir1.get(r); String f2 = dir2.get(c); if ( matrixData[r][c] != 0 && f1!=f2 ) { graph.addEdge(f1, f2); } } } ConnectivityInspector<String, DefaultEdge> conn = new ConnectivityInspector<String, DefaultEdge>(graph); return conn.connectedSets(); }
g.addEdge("s"+i, "f"+j);
public static UndirectedGraph<Node, DefaultLink> asDefaultGraph(UndirectedGraph<Node, LabeledLink> graph) { if (graph == null) { logger.debug("graph is null."); return null; } UndirectedGraph<Node, DefaultLink> g = new WeightedMultigraph<>(DefaultLink.class); for (Node v : graph.vertexSet()) g.addVertex(v); for (DefaultLink e: graph.edgeSet()) g.addEdge(e.getSource(), e.getTarget(), e); return g; }
g.addEdge("s"+i, "f"+j);
private void addEdgeForCouplerOrLowImpedanceLine(UcteNetwork network, UndirectedGraph<UcteNodeCode, Object> graph) { // ...nodes connected by a coupler or by a low impedance line for (UcteLine l : network.getLines()) { UcteNodeCode nodeCode1 = l.getId().getNodeCode1(); UcteNodeCode nodeCode2 = l.getId().getNodeCode2(); if (l.getStatus() == UcteElementStatus.BUSBAR_COUPLER_IN_OPERATION || l.getStatus() == UcteElementStatus.BUSBAR_COUPLER_OUT_OF_OPERATION) { graph.addEdge(nodeCode1, nodeCode2); } else { double z = Math.hypot(l.getResistance(), l.getReactance()); if (z < lineMinZ) { graph.addEdge(nodeCode1, nodeCode2); } } } }
private void addEdgeBetweenTransformers(UcteNetwork network, UndirectedGraph<UcteNodeCode, Object> graph) { // ...nodes connected by a transformer for (UcteTransformer tfo : network.getTransformers()) { UcteNodeCode nodeCode1 = tfo.getId().getNodeCode1(); UcteNodeCode nodeCode2 = tfo.getId().getNodeCode2(); graph.addEdge(nodeCode1, nodeCode2); } }
Group parentGroup = grouper.nodeGroup(parent); if(parentGroup!=null && !parentGroup.equals(g)) { equivs.addEdge(parentGroup, g);
while (it.hasNext()) { PossibleTopology.Equipment next = it.next(); graph.addEdge(new Vertex(first.getId(), substation.getId(), possibleTopology.getTopoHash()), new Vertex(next.getId(), substation.getId(), possibleTopology.getTopoHash())); Vertex v2 = new Vertex(branchId, substationId2, topoId); if (graph.containsVertex(v1) && graph.containsVertex(v2)) { graph.addEdge(v1, v2); Vertex v2 = new Vertex(branchId, substationId2, topoId2); if (graph.containsVertex(v1) && graph.containsVertex(v2)) { graph.addEdge(v1, v2);
/** * Convert the similarity matrix to an unweighted, undirected * graph representation. A threshold is used to determine * if edges should be created. If the value at [r][c] is bigger * than the threshold, then an edge will be created between the * vertices represented by index[r] and index[c]. * * @param threshold the threshold * @return the graph */ public UndirectedGraph<String, DefaultEdge> toUndirectedUnweightedGraph(double threshold) { UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); final int rows = this.getRowDimension(); final int cols = this.getColumnDimension(); final double[][] data = this.getArray(); for (String s : index) { graph.addVertex(s); } for (int r=0; r<rows; r++) { for (int c=0; c<cols; c++) { if (r != c && data[r][c] > threshold) graph.addEdge(index[r], index[c]); } } return graph; }
for (PossibleTopology.Bus bus2 : uniqueTopo.getBuses()) { if (bus1 != bus2 && !graph.containsEdge(bus1, bus2)) { graph.addEdge(bus1, bus2);
graph.addEdge(substationsIds.get(0), substationsIds.get(i));
for(int j=0; j<functionNonZeros.size(); ++j) { if(candidateList.get(signatureNonZeros.get(i), functionNonZeros.get(j)) != 0) { g.addEdge("s"+signatureNonZeros.get(i), "f"+functionNonZeros.get(j));
public DistanceGraph(ConnectionData data, Hierarchy hierarchy) { // this.data = data; this.hierarchy = hierarchy; allMethods = data.getAllMethods(); g = new SimpleGraph<MethodDescription, DefaultEdge>(DefaultEdge.class); Set<Tuple> connections = data.getConnections(); for (Tuple tuple : connections) { MethodDescription start = tuple.getStart(); MethodDescription end = tuple.getEnd(); if (!start.equals(end)) { if (!g.containsVertex(start)) { g.addVertex(start); } if (!g.containsVertex(end)) { g.addVertex(end); } g.addEdge(start, end); } } }