J'ai un digraphe créé à l'aide:Numéro de retour des bords de chaque sommet dans un graphe orienté (JGraphT)
public static DirectedGraph<Point, DefaultEdge> directedGraph = new DefaultDirectedGraph<Point, DefaultEdge>(DefaultEdge.class);
void setup() {
Point myPoint = new Point(x, y);
Point myNextPoint = new Point(xToFillNext, yToFillNext);
directedGraph.addVertex(myPoint);
directedGraph.addVertex(myNextPoint);
directedGraph.addEdge(myPoint, myNextPoint);
Point mySecondPoint = new Point(x, y);
Point mySecondNextPoint = new Point(xToFillNext, yToFillNext);
directedGraph.addVertex(mySecondPoint);
directedGraph.addVertex(mySecondNextPoint);
directedGraph.addEdge(mySecondPoint, mySecondNextPoint);
System.out.println("#vertices: "+ directedGraph.vertexSet());
}
public static class Point {
public int x;
public int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public String toString() {
return ("[x="+x+" y="+y+"]");
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + this.x;
hash = 71 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object other)
{
if (this == other)
return true;
if (!(other instanceof Point))
return false;
Point otherPoint = (Point) other;
return otherPoint.x == x && otherPoint.y == y;
}
}
Je voudrais obtenir le nombre d'arêtes vers l'extérieur par sommet à l'aide:
directedGraph.outDegreeOf()
mais je ne veux pas le faire par sommet (c'est un code simple pour le rendre plus facile, dans tout mon programme j'ai beaucoup plus de vertices) et je voudrais passer par le vertex set et renvoie le nombre d'arêtes extérieures pour chaque sommet de l'ensemble automatiquement, quel que soit le nombre de sommets.
Comment dois-je procéder pour faire cela?
(j'utiliser le traitement qui est basé sur java)
Que voulez-vous dire exactement quand vous dites « mais je ne veux pas le faire par le sommet sommet"? –