本文整理匯總了Java中org.jgrapht.Graph.vertexSet方法的典型用法代碼示例。如果您正苦於以下問題:Java Graph.vertexSet方法的具體用法?Java Graph.vertexSet怎麽用?Java Graph.vertexSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jgrapht.Graph
的用法示例。
在下文中一共展示了Graph.vertexSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkPresenceOfExpectedNodes
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void checkPresenceOfExpectedNodes(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
final AssertionErrorCollector errorCollector) {
for (final Node expectedNode : expectedGraph.vertexSet()) {
final List<String> attributesToExclude = expectedNode.getLabels().stream().map(toExclude::getColumns).flatMap(List::stream)
.distinct().collect(toList());
final List<Node> availableNodesOfExpectedType = givenGraph.vertexSet().stream()
.filter(n -> n.getType().equals(expectedNode.getType())).collect(toList());
final List<Node> foundNodes = availableNodesOfExpectedType.stream().filter(n -> n.isSame(expectedNode, attributesToExclude))
.collect(toList());
if (foundNodes.isEmpty()) {
errorCollector.collect(expectedNode.asString() + " was expected, but is not present");
} else if (foundNodes.size() > 1) {
errorCollector.collect("Ambiguouty detected for node " + expectedNode.asString() + " for given attribute filter");
}
}
}
示例2: printLabeledGraph
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static void printLabeledGraph(Graph<Node, LabeledLink> graph) {
if (graph == null) {
logger.debug("graph is null.");
return;
}
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (DefaultLink link : graph.edgeSet()) {
sb.append(link.getId());
sb.append(", ");
sb.append(link.getType().toString());
sb.append(", ");
sb.append(link.getWeight());
sb.append("\n");
}
// sb.append("------------------------------------------");
logger.debug(sb.toString());
}
示例3: printGraph
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static void printGraph(Graph<Node, DefaultLink> graph) {
if (graph == null) {
logger.debug("graph is null.");
return;
}
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (DefaultLink link : graph.edgeSet()) {
sb.append(link.getId());
sb.append(", ");
sb.append(link.getType().toString());
sb.append(", ");
sb.append(link.getWeight());
sb.append("\n");
}
// sb.append("------------------------------------------");
logger.debug(sb.toString());
}
示例4: defaultGraphToString
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static String defaultGraphToString(Graph<Node, DefaultLink> graph) {
if (graph == null) {
logger.debug("The input graph is null.");
return "";
}
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (DefaultLink edge : graph.edgeSet()) {
sb.append("(");
sb.append(edge.getId());
sb.append(" - w=" + edge.getWeight());
sb.append("\n");
}
//sb.append("------------------------------------------");
return sb.toString();
}
示例5: labeledGraphToString
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static String labeledGraphToString(Graph<Node, LabeledLink> graph) {
if (graph == null) {
logger.debug("The input graph is null.");
return "";
}
StringBuffer sb = new StringBuffer();
sb.append("*** Nodes ***\n");
for (Node n : graph.vertexSet()) {
sb.append(n.getLocalId());
sb.append("\n");
}
sb.append("*** Links ***\n");
for (LabeledLink edge : graph.edgeSet()) {
sb.append("(");
sb.append(edge.getId());
sb.append(" - status=" + edge.getStatus().name());
sb.append(" - w=" + edge.getWeight());
sb.append(" - type=" + edge.getType().name());
sb.append("\n");
}
//sb.append("------------------------------------------");
return sb.toString();
}
示例6: induce
import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
* Induce subgraph from super network.
*/
public static UndirectedGraph<HNode, DefaultEdge>
induce(Set<HNode> nodeSubset, SuperNetwork superNetwork) {
// Verify whether entire subset is present in super network.
for(HNode node: nodeSubset) {
if(!superNetwork.graph.containsVertex(node)) {
System.err.println("Sub network node " + node +
" not contained by super network.");
}
}
Graph<HNode, DefaultEdge> subGraph =
new Subgraph(superNetwork.graph, nodeSubset);
return new UndirectedSubgraph(superNetwork.graph,
subGraph.vertexSet(),
subGraph.edgeSet());
}
示例7: addToGraph
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void addToGraph(Graph<GraphNode, DefaultEdge> dst, Graph<GraphNode, DefaultEdge> source) {
for(GraphNode node : source.vertexSet()) {
GraphNode toAdd = node.clone();
toAdd.setGraph(dst);
dst.addVertex(toAdd);
}
for(DefaultEdge edge : source.edgeSet()) {
GraphNode src = graph.getEdgeSource(edge).clone();
GraphNode target = graph.getEdgeTarget(edge).clone();
for(GraphNode cur : dst.vertexSet()) {
if(cur.equals(src)) {
src = cur;
} else if(cur.equals(target)) {
target = cur;
}
}
dst.addEdge(src, target);
}
}
示例8: getPartitions
import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
* @param G
* @return An array of the nodes of the quotient graph <b>G</b>
*/
public static Partition[] getPartitions(Graph<Partition, PartitionBorder> G) {
Set<Partition> vertexSet = G.vertexSet();
Partition[] pars = new Partition[vertexSet.size()];
vertexSet.toArray(pars);
return pars;
}
示例9: getNodes
import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
* @param G
* @return An array of the nodes of the basic graph <b>G</b>
*/
public static Node[] getNodes(Graph<Node, Border> G) {
Set<Node> vertexSet = G.vertexSet();
Node[] pars = new Node[vertexSet.size()];
vertexSet.toArray(pars);
return pars;
}
示例10: jGraphTRun
import org.jgrapht.Graph; //導入方法依賴的package包/類
@Override
public Object jGraphTRun(Graph<Vertex, DefaultEdge> g,
AlgorithmParameters ap, Set<Object> selection,
ProgressHandler onprogress) throws Exception {
int i = 0;
for (Vertex v : g.vertexSet())
i++;
return "" + i + " nodes (computed through JGraphTBridge)";
}
示例11: shouldBeEmpty
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void shouldBeEmpty(final Graph<Node, Edge> givenGraph, final AssertionErrorCollector errorCollector) {
final Map<String, Integer> unexpectedNodesOccurence = new HashMap<>();
for (final Node node : givenGraph.vertexSet()) {
unexpectedNodesOccurence.compute(node.getType(), (k, v) -> v == null ? 1 : v + 1);
}
for (final Entry<String, Integer> nodeEntries : unexpectedNodesOccurence.entrySet()) {
if (nodeEntries.getValue() != 0) {
errorCollector.collect("No nodes with " + nodeEntries.getKey() + " labels were expected, but there are <"
+ nodeEntries.getValue() + "> nodes present.");
}
}
}
示例12: checkAbsenseOfNotExpectedNodes
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void checkAbsenseOfNotExpectedNodes(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
final AssertionErrorCollector errorCollector) {
final List<List<String>> expectedNodeLables = expectedGraph.vertexSet().stream().map(Node::getLabels).distinct().collect(toList());
for (final List<String> labels : expectedNodeLables) {
final List<Node> expectedNodes = expectedGraph.vertexSet().stream().filter(node -> node.getLabels().containsAll(labels))
.collect(toList());
final List<String> attributesToExclude = labels.stream().map(toExclude::getColumns).flatMap(List::stream).distinct()
.collect(toList());
for (final Node givenNode : givenGraph.vertexSet()) {
if (!givenNode.getLabels().containsAll(labels)) {
continue;
}
final boolean nodePresent = expectedNodes.stream().anyMatch(node -> {
final Set<Attribute> attributesToRetain = node.getAttributes().stream()
.filter(a -> !attributesToExclude.contains(a.getName())).collect(toSet());
return givenNode.getAttributes().containsAll(attributesToRetain);
});
if (!nodePresent) {
errorCollector.collect(givenNode.asString() + " was not expected, but is present");
}
}
}
}
示例13: execute
import org.jgrapht.Graph; //導入方法依賴的package包/類
@Override
public void execute(final Connection connection, final Graph<Node, Edge> graph) throws SQLException {
for (final Node node : graph.vertexSet()) {
final StartNext match = match(node.toPath().withId("n").build());
executeQuery(connection, match.toString() + " DETACH DELETE n");
}
}
示例14: buildNodeIndex
import org.jgrapht.Graph; //導入方法依賴的package包/類
protected Map<V, Integer> buildNodeIndex(Graph<V, E> graph) {
final Map<V, Integer> index = new HashMap<>();
int i = 0;
for (final V vertex : graph.vertexSet()) {
index.put(vertex, i++);
}
return index;
}
示例15: export
import org.jgrapht.Graph; //導入方法依賴的package包/類
public void export(JCas jcas, Graph<Figure, ?> graph) throws IOException {
StringWriter sw = new StringWriter();
sw.write(" \n");
for (Figure figure1 : graph.vertexSet()) {
for (Figure figure2 : graph.vertexSet()) {
if (graph.containsEdge(figure1, figure2)) {
sw.write(figure1.getBegin() + " " + figure2.getBegin());
Object edge = graph.getEdge(figure1, figure2);
try {
@SuppressWarnings("unchecked")
double w = ((WeightedGraph<Figure, Object>) graph).getEdgeWeight(edge);
sw.write(" " + w);
} catch (ClassCastException e) {
// we try to cast, but ignore it if impossible
}
sw.write("\n");
}
}
}
sw.flush();
sw.close();
jcas.setDocumentText(sw.toString());
jcas.setDocumentLanguage("");
GraphMetaData graphAnnotation = AnnotationFactory.createAnnotation(jcas, 0, 1, GraphMetaData.class);
graphAnnotation.setGraphClassName(graph.getClass().getCanonicalName());
if (!graph.edgeSet().isEmpty())
graphAnnotation.setEdgeClassName(graph.edgeSet().iterator().next().getClass().getCanonicalName());
}