ErdosRenyiGenerator de Jung
Bonjour à toutes et à tous,
j'espère que je ne me suis pas trompée de forum. Si c'est le cas, je vous prie de bien vouloir m'indiquer le bon endroit où poster ma question.
Je cherche à dessiner un graphe aléatoire, celui de Erdos. Pour cela, j'ai installé le framework JUNG (Java Universal Network/Graph Framework) qui possède une fonction prédéfinie : ErdosRenyiGenerator.
Mon problème est que dans l'appel de cette fonction, il faut charger les paramètres suivants :
Code:
1 2 3 4 5
| public ErdosRenyiGenerator(org.apache.commons.collections15.Factory<UndirectedGraph<V,E>> graphFactory,
org.apache.commons.collections15.Factory<V> vertexFactory,
org.apache.commons.collections15.Factory<E> edgeFactory,
int numVertices,
double p) |
Pour ce faire, en cherchant sur le net, j'ai écrit ce code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public Erdos() {
// Graph<V, E> where V is the type of the vertices and E is the type of the edges
nodeCount = 0;
edgeCount = 0;
sg = new UndirectedSparseGraph();
vertexFactory = new Factory<Integer>() { // My vertex factory
public Integer create() {
return nodeCount++;
}
};
edgeFactory = new Factory<String>() { // My edge factory
public String create() {
return "E" + edgeCount++;
}
};
} |
pour l'appeler par la suite :
Code:
1 2 3 4 5
| public static void createNetwork() {
Erdos Er = new Erdos();
ErdosRenyiGenerator g = new ErdosRenyiGenerator(SparseGraph.getFactory(), Er.vertexFactory, Er.edgeFactory, 100, .2);
sg = (UndirectedSparseGraph) g.create();
} |
Mais j'ai un bug, au niveau de cette ligne sg = (UndirectedSparseGraph) g.create();
Code:
1 2 3
| Exception in thread "main" java.lang.ClassCastException: edu.uci.ics.jung.graph.SparseGraph cannot be cast to edu.uci.ics.jung.graph.UndirectedGraph
at edu.uci.ics.jung.algorithms.generators.random.ErdosRenyiGenerator.create(ErdosRenyiGenerator.java:64)
at edu.uci.ics.jung.samples.Erdos.createNetwork(Erdos.java:64) |
Quelqu'un pourrait m'aider la dessus, s'il vous plait ? :(