Frage

I can't find the constructor for a undirected graph, which is an interface... I have been surfing the docs... but don't know how do I initiate an UndirectedGraph Interface.

I have tried with SimpleGraph but it isn't working. Casting a simpleGraph to undirectedGraph isen't working...

Any help is appreciated, thank you.

War es hilfreich?

Lösung

UndirectedGraph is an interface (as you point out). Interfaces don't have constructors, but classes that implement that interface do. If you look at the UndirectedGraph JavaDoc, you'll find all the implementing classes (at least all those in the JGraphT package). There are several.

  • AsUndirectedGraph
  • BlockCutpointGraph
  • ListenableUndirectedGraph
  • ListenableUndirectedWeightedGraph
  • Multigraph
  • Pseudograph
  • SimpleGraph
  • SimpleWeightedGraph
  • UndirectedGraphUnion
  • UndirectedMaskSubgraph
  • UndirectedSubgraph
  • UndirectedWeightedSubgraph
  • UnmodifiableUndirectedGraph
  • WeightedMultigraph
  • WeightedPseudograph

You should find the one that's most appropriate for your situation. Bear in mind that some of these may be abstract classes (I haven't checked them all) and others may not have a public constructor. However, neither of those apply to SimpleGraph which you say you've tried.

Casting a SimpleGraph to an UndirectedGraph certainly ought to work (assuming they have the same generics types). If you're still having problems, I suggest you post (a) the smallest piece of sample code that demonstrates your problem and (b) the particular error message you get / problem you encounter.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top