i have problem. have wait method call library finish before can continue code. how can that? code:
random random = new random(); int node1 = random.nextint(graph.getnumberofvertices() + 1); int node2 = random.nextint(graph.getnumberofvertices() + 1); matrixwrappedpath path = graph.getshortestpath(node1, node2); int pathlength = 0; if (path != null) { pathlength = path.getlength(); }
the exception i'm getting library (http://grph.inria.fr/javadoc/index.html) is:
exception in thread "main" java.lang.illegalstateexception: cannot compute distance because 2 vertices not connected
at grph.algo.distance.distancematrix.getdistance(distancematrix.java:56)
at grph.matrixwrappedpath.getlength(matrixwrappedpath.java:47)
the distancematrix class runs bfs (org.dipergrafs.algo.bfs.bfsalgorithm) multithreaded (org.dipergrafs.algo.singlesourcesearchalgorithm, method "compute":
public r[] compute(final grph g, intset sources) { final r[] r = createarray(sources.getgreatest() + 1); new multithreadprocessing(g.getvertices(), grph.getnumberofthreadstocreate()) { @override protected void run(int threadid, int source) { r[source] = compute(g, source); } }; return r; }
) , fills distancematrix. if distancematrix not finished yet, getdistance(node1, node2) method cannot values distancematrix. read countdownlatch
, wait()
, notify()
, can't figure out how this. way solve this?
you're wrong when assuming there multithreading issue there.
the error message clear :
(...)cannot compute distance because 2 vertices not connected
you're taking 2 random nodes in graph, these nodes not connected. that's why library cannot compute distance.
are sure didn't forget add edges in graph ? ;)
Comments
Post a Comment