I have instantiated an object like this:
GraphMatrixDirected<String, Integer> g
g is passed to a function like this:
floyd(g);
floyd's signature looks like this:
public void floyd(GraphMatrixDirected<V,E> g)
Eclipse gives me an error saying:
The method floyd(GraphMatrixDirected<V,E>) in the type GraphMatrix<V,E> is not applicable for the arguments (GraphMatrixDirected<String,Integer>)
What do I need to do to fix it?
Edit1:
abstract public class GraphMatrix<V,E> extends AbstractStructure<V> implements Graph<V,E>
Edit2:
public interface Graph<V,E> extends Structure<V>
public abstract class AbstractStructure<E> implements Structure<E>
public interface Structure<E> extends Iterable<E>
/* JDT added extension of Iterable for Java 5 */
Edit 3:
Note: Funtion was changed from floyd
to AllPairsShortestPath
.
public void AllPairsShortestPath(GraphMatrixDirected<V,E> g)
// post: g contains edge (a,b) if there is a path from a to b
{
Iterator<V> witer = g.iterator();
while (witer.hasNext())
{
Iterator<V> uiter = g.iterator();
V w = witer.next();
while (uiter.hasNext())
{
Iterator<V> viter = g.iterator();
V u = uiter.next();
while (viter.hasNext())
{
V v = viter.next();
if (g.containsEdge(u,w) && g.containsEdge(w,v))
{
Edge<V,E> leg1 = g.getEdge(u,w);
Edge<V,E> leg2 = g.getEdge(w,v);
Integer leg1Dist = (Integer)leg1.label();
Integer leg2Dist = (Integer)leg2.label();
Integer newDist = (Integer)leg1Dist+leg2Dist;
E newDistE = (E)newDist;
if (g.containsEdge(u,v))
{
Edge<V,E> across = g.getEdge(u,v);
Integer acrossDist = (Integer)across.label();
if (newDist < acrossDist)
{
across.setLabel(newDistE);
}
}
else
{
g.addEdge(u,v,newDistE);
}
}
}
}
}
}