zer0byte
zer0byte

Reputation: 11

JGraphT SimpleGraph and UndirectedGraph

I want make Graph using JGraphT Library. My code is below:

private UndirectedGraph<State, DefaultEdge> graph;
private HashMap<String, State> vertixList;

public  MapGraph(HashMap<String, State> vertixList, List<Transition> transList) {
    graph = new SimpleGraph<State, DefaultEdge>(DefaultEdge.class);
    this.vertixList = vertixList;

    // add all vertices
    for(State s : vertixList.values())
        graph.addVertex(s);

    // add all transitions
    for(Transition t : transList)
        graph.addEdge(t.start, t.end);

}

But it has compile error.

error: incompatible types: SimpleGraph<State,DefaultEdge> cannot be converted 
to UndirectedGraph<State,DefaultEdge>

It occurs line 5. (graph = new SimpleGraph) What can I do? Need help... (I'm using Android Studio!)

Upvotes: 1

Views: 305

Answers (1)

deHaar
deHaar

Reputation: 18588

You have declared your variable graph like

private UndirectedGraph<State, DefaultEdge> graph;

but you try to define it as

graph = new SimpleGraph<State, DefaultEdge>(DefaultEdge.class);

which will not work due to incompatible types.

Your graph is an UndirectedGraph and you assign a SimpleGraph. That is the issue here…

Define it (in line 5) as

graph = new UndirectedGraph<State, DefaultEdge>(DefaultEdge.class);

Upvotes: 1

Related Questions