本文整理汇总了Java中org.jgrapht.graph.SimpleWeightedGraph.edgeSet方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleWeightedGraph.edgeSet方法的具体用法?Java SimpleWeightedGraph.edgeSet怎么用?Java SimpleWeightedGraph.edgeSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.graph.SimpleWeightedGraph
的用法示例。
在下文中一共展示了SimpleWeightedGraph.edgeSet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeSimpleWeightedGraph2CSV
import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
public static void writeSimpleWeightedGraph2CSV(SimpleWeightedGraph<Long, DefaultWeightedEdge> colocationgraph,
File file) throws IOException {
CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
// write header
String[] line = new String[4];
line[0] = "source";
line[1] = "target";
line[2] = "weight";
line[3] = "type";
writer.writeNext(line);
for (DefaultWeightedEdge e : colocationgraph.edgeSet()) {
line = new String[4];
line[0] = String.valueOf(colocationgraph.getEdgeSource(e).longValue() + (long) 111);
line[1] = String.valueOf(colocationgraph.getEdgeTarget(e).longValue() + (long) 111);
line[2] = String.valueOf(colocationgraph.getEdgeWeight(e));
line[3] = "undirected";
writer.writeNext(line);
}
writer.close();
}
示例2: createSimpleAdjacencyMatrix
import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
/**
* creates the adjacency matrix of a simple weighted graph
**/
public static double[][] createSimpleAdjacencyMatrix(SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG,
double threshold) {
HashMap<Long, Integer> contributorIndex = contributorIndex(simpleG);
// Crée une matrice de taille nbContributeurs x nbContributeurs
// initialisés à zéro par défaut
double[][] adj = new double[simpleG.vertexSet().size()][simpleG.vertexSet().size()];
for (DefaultWeightedEdge e : simpleG.edgeSet()) {
Long nodeI = simpleG.getEdgeSource(e);
Long nodeF = simpleG.getEdgeTarget(e);
double w = simpleG.getEdgeWeight(e);
// Remplit la matrice symétrique
int j = contributorIndex.get(nodeI);
int k = contributorIndex.get(nodeF);
if (w >= threshold) {
adj[j][k] = 1;
adj[k][j] = 1;
}
}
return adj;
}
示例3: createInteractionMatrix
import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
public static double[][] createInteractionMatrix(SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG) {
HashMap<Long, Integer> contributorIndex = new HashMap<Long, Integer>();
int i = 0;
for (Long v : simpleG.vertexSet()) {
contributorIndex.put(v, i);
// System.out.println("Ajout de l'utilisateur " + v + " indice " +
// i);
i++;
}
// Crée une matrice de taille nbContributeurs x nbContributeurs
// initialisés à zéro par défaut
double[][] adj = new double[simpleG.vertexSet().size()][simpleG.vertexSet().size()];
for (DefaultWeightedEdge e : simpleG.edgeSet()) {
Long nodeI = simpleG.getEdgeSource(e);
Long nodeF = simpleG.getEdgeTarget(e);
double w = simpleG.getEdgeWeight(e);
// Remplit la matrice symétrique
int j = contributorIndex.get(nodeI);
int k = contributorIndex.get(nodeF);
adj[j][k] = w;
adj[k][j] = w;
}
return adj;
}
示例4: getCompactness
import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
@Override
public double getCompactness(SimpleWeightedGraph<?, DefaultWeightedEdge> graph) {
double fullWeight = 0;
for (DefaultWeightedEdge edge : graph.edgeSet()) {
fullWeight += graph.getEdgeWeight(edge);
}
return graph.vertexSet().size() > 20 && fullWeight / graph.vertexSet().size() > 0.5 ? 1.0d : 0.0d;
}
示例5: trending
import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
/**
* @param count
* @return the top count list of sets from all hashtable bins
*/
public synchronized List<Set<WriteableImageOutput>> trending(int count) {
final SimpleWeightedGraph<WriteableImageOutput, DefaultWeightedEdge> graph = new SimpleWeightedGraph<WriteableImageOutput, DefaultWeightedEdge>(
DefaultWeightedEdge.class);
for (final TIntObjectHashMap<Set<WriteableImageOutput>> set : this.database) {
set.forEachEntry(new TIntObjectProcedure<Set<WriteableImageOutput>>() {
@Override
public boolean execute(int hashIndex, Set<WriteableImageOutput> itemSet) {
for (final WriteableImageOutput item : itemSet) {
if (!graph.containsVertex(item)) {
graph.addVertex(item);
}
}
final List<WriteableImageOutput> itemList = new ArrayList<WriteableImageOutput>();
itemList.addAll(itemSet);
for (int i = 0; i < itemList.size(); i++) {
final WriteableImageOutput itemA = itemList.get(i);
for (int j = i + 1; j < itemList.size(); j++) {
final WriteableImageOutput itemB = itemList.get(j);
DefaultWeightedEdge edge = graph.getEdge(itemA, itemB);
if (edge == null) {
edge = graph.addEdge(itemA, itemB);
graph.setEdgeWeight(edge, 1);
}
else {
graph.setEdgeWeight(edge, graph.getEdgeWeight(edge) + 1);
}
}
}
return true;
}
});
}
final Set<DefaultWeightedEdge> edges = new HashSet<DefaultWeightedEdge>(graph.edgeSet());
for (final DefaultWeightedEdge e : edges) {
if (graph.getEdgeWeight(e) < 10)
graph.removeEdge(e);
}
final ConnectivityInspector<WriteableImageOutput, DefaultWeightedEdge> conn = new ConnectivityInspector<WriteableImageOutput, DefaultWeightedEdge>(
graph);
final List<Set<WriteableImageOutput>> retList = conn.connectedSets();
Collections.sort(retList, new Comparator<Set<WriteableImageOutput>>() {
@Override
public int compare(Set<WriteableImageOutput> o1, Set<WriteableImageOutput> o2) {
return -1 * ((Integer) o1.size()).compareTo(o2.size());
}
});
return retList.subList(0, count < retList.size() ? count : retList.size());
}