本文整理匯總了Java中org.jgrapht.Graph.edgeSet方法的典型用法代碼示例。如果您正苦於以下問題:Java Graph.edgeSet方法的具體用法?Java Graph.edgeSet怎麽用?Java Graph.edgeSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jgrapht.Graph
的用法示例。
在下文中一共展示了Graph.edgeSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkPresenceOfExpectedReferences
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void checkPresenceOfExpectedReferences(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
final AssertionErrorCollector errorCollector) {
for (final Edge expectedEdge : expectedGraph.edgeSet()) {
final List<String> attributesToExclude = expectedEdge.getLabels().stream().map(toExclude::getColumns).flatMap(List::stream)
.distinct().collect(toList());
final List<Edge> availableEdgesOfExpectedType = givenGraph.edgeSet().stream()
.filter(e -> e.getType().equals(expectedEdge.getType())).collect(toList());
final List<Edge> foundEdges = availableEdgesOfExpectedType.stream().filter(e -> e.isSame(expectedEdge, attributesToExclude))
.collect(toList());
if (foundEdges.isEmpty()) {
errorCollector.collect(expectedEdge.asString() + " was expected, but is not present");
} else if (foundEdges.size() > 1) {
errorCollector.collect("Ambiguouty detected for edge " + expectedEdge.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: Marcs
import org.jgrapht.Graph; //導入方法依賴的package包/類
public Marcs(Graph<V,E> g1, Graph<V,E> g2, boolean connectedOnly, int labelSize){
this.g1 = g1;
this.g2 = g2;
edgeList1 = new ArrayList<E>(g1.edgeSet());
edgeList2 = new ArrayList<E>(g2.edgeSet());
mappedVerticesFromG1 = new ArrayList<V>();
mappedVerticesFromG2 = new ArrayList<V>();
dimx = edgeList1.size();
dimy = edgeList2.size();
directed = g1 instanceof DirectedGraph && g2 instanceof DirectedGraph;
this.connectedOnly = connectedOnly;
matrix = new boolean[dimx][dimy];
rowOrs = new boolean[dimx];
for(int x=0;x<dimx;x++){
rowOrs[x] = true;
for(int y=0;y<dimy;y++){
matrix[x][y] = edgesCompatible(x,y);
}
}
labelCount = new int[labelSize];
for(int i=0;i<labelSize;i++){
labelCount[i] =0;
}
}
示例7: 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());
}
示例8: 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);
}
}
示例9: checkAbsenseOfNotExpectedReferences
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void checkAbsenseOfNotExpectedReferences(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
final AssertionErrorCollector errorCollector) {
final List<List<String>> expectedEdgeLables = expectedGraph.edgeSet().stream().map(Edge::getLabels).distinct().collect(toList());
for (final List<String> labels : expectedEdgeLables) {
final List<Edge> expectedEdges = expectedGraph.edgeSet().stream().filter(node -> node.getLabels().containsAll(labels))
.collect(toList());
final List<String> edgeAttributesToExclude = labels.stream().map(toExclude::getColumns).flatMap(List::stream).distinct()
.collect(toList());
for (final Edge givenEdge : givenGraph.edgeSet()) {
if (!givenEdge.getLabels().containsAll(labels)) {
continue;
}
final boolean edgePresent = expectedEdges.stream().anyMatch(edge -> {
final Set<Attribute> attributesToRetain = edge.getAttributes().stream()
.filter(a -> !edgeAttributesToExclude.contains(a.getName())).collect(toSet());
final List<String> sourceNodeAttributesToExclude = edge.getSourceNode().getLabels().stream().map(toExclude::getColumns)
.flatMap(List::stream).distinct().collect(toList());
final List<String> targetNodeAttributesToExclude = edge.getTargetNode().getLabels().stream().map(toExclude::getColumns)
.flatMap(List::stream).distinct().collect(toList());
return givenEdge.getAttributes().containsAll(attributesToRetain)
&& givenEdge.getSourceNode().isSame(edge.getSourceNode(), sourceNodeAttributesToExclude)
&& givenEdge.getTargetNode().isSame(edge.getTargetNode(), targetNodeAttributesToExclude);
});
if (!edgePresent) {
errorCollector.collect(givenEdge.asString() + " was not expected, but is present");
}
}
}
}
示例10: buildGraph
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static ListenableGraph<String, MyEdge> buildGraph(double threshold, boolean showEdgeLabels) {
ListenableDirectedWeightedGraph<String, MyEdge> g =
new ListenableDirectedWeightedGraph<String, MyEdge>(MyEdge.class);
Graph<Integer, DefaultWeightedEdge> inGraph = getGraph();
Set<DefaultWeightedEdge> edgeSet = inGraph.edgeSet();
for (DefaultWeightedEdge e : edgeSet) {
int sourceV = inGraph.getEdgeSource(e);
String v1 = names[sourceV];
int targetV = inGraph.getEdgeTarget(e);
String v2 = names[targetV];
g.addVertex(v1);
g.addVertex(v2);
double w = inGraph.getEdgeWeight(e);
if(w>threshold) {
MyEdge edge = g.addEdge(v1, v2);
if(showEdgeLabels){
g.setEdgeWeight(edge, w);
}
}
}
return g;
}
示例11: write
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void write(Path path, Graph<Sense<String>, DefaultWeightedEdge> graph) throws IOException {
try (final BufferedWriter writer = Files.newBufferedWriter(path)) {
for (final DefaultWeightedEdge edge : graph.edgeSet()) {
final IndexedSense<String> source = (IndexedSense<String>) graph.getEdgeSource(edge);
final IndexedSense<String> target = (IndexedSense<String>) graph.getEdgeTarget(edge);
writer.write(String.format(Locale.ROOT, "%s#%d\t%s#%d\t%f\n",
source.get(), source.getSense(),
target.get(), target.getSense(),
graph.getEdgeWeight(edge)));
}
}
}
示例12: insertJGraphT
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void insertJGraphT(Graph<V, E> graphT) {
getModel().beginUpdate();
try {
for (V vertex : graphT.vertexSet())
addJGraphTVertex(vertex);
for (E edge : graphT.edgeSet())
addJGraphTEdge(edge);
} finally {
getModel().endUpdate();
}
}
示例13: copyGraph
import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
* Creates a shallow copy of Graph g, a new graph is created, the edge and vertex sets are copied,
* but the same edge and vertex object are used
* @param g the Graph that should be copied
* @return a copy of g
*/
protected Graph<StringLabeledObject,StringLabeledObject> copyGraph(Graph<StringLabeledObject,StringLabeledObject> g){
Graph<StringLabeledObject,StringLabeledObject> result = SharedStaticMethods.createEmptyMultiGraph(directed);
for(StringLabeledObject v: g.vertexSet()){
result.addVertex(v);
}
for(StringLabeledObject e : g.edgeSet()){
result.addEdge(g.getEdgeSource(e), g.getEdgeTarget(e), e);
}
return result;
}
示例14: checkNondegeneracy
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static <V,E> boolean checkNondegeneracy(Graph<V,E> g) {
Set<V> inits = new HashSet<V>();
Set<V> tails = new HashSet<V>();
inits.addAll(g.vertexSet());
tails.addAll(g.vertexSet());
for(E e : g.edgeSet()) {
inits.remove(g.getEdgeSource(e));
tails.remove(g.getEdgeTarget(e));
}
return (inits.isEmpty() && tails.isEmpty());
}
示例15: insertJGraphT
import org.jgrapht.Graph; //導入方法依賴的package包/類
private void insertJGraphT(Graph<V, E> graphT) {
getModel().beginUpdate();
try {
for (V vertex : graphT.vertexSet())
addJGraphTVertex(vertex);
for (E edge : graphT.edgeSet())
addJGraphTEdge(edge);
} finally {
getModel().endUpdate();
}
}