From: SourceForge.net <no...@so...> - 2009-03-28 08:18:35
|
Read and respond to this message at: https://sourceforge.net/forum/message.php?msg_id=6994696 By: bleongki Dear Tom, After further study of the matrixToGraph() method in the GraphMatrixOperations class, I do feel that there is probably a bug with this method that causes the inconsistency between the adjacent matrix and the Jung graph. I have implemented a program SimpleMatrixToGraph10.java to show that. import org.apache.commons.collections15.Factory; import cern.colt.matrix.DoubleMatrix2D; import cern.colt.matrix.impl.SparseDoubleMatrix2D; import edu.uci.ics.jung.graph.Graph; import edu.uci.ics.jung.graph.SparseGraph; import edu.uci.ics.jung.graph.SparseMultigraph; import edu.uci.ics.jung.graph.DirectedGraph; import edu.uci.ics.jung.graph.DirectedSparseGraph; import edu.uci.ics.jung.graph.UndirectedGraph; import edu.uci.ics.jung.graph.UndirectedSparseGraph; import edu.uci.ics.jung.algorithms.matrix.GraphMatrixOperations; import edu.uci.ics.jung.algorithms.layout.Layout; import edu.uci.ics.jung.algorithms.layout.CircleLayout; import edu.uci.ics.jung.visualization.decorators.EdgeShape; import edu.uci.ics.jung.visualization.decorators.ToStringLabeller; import edu.uci.ics.jung.visualization.decorators.NumberEdgeValueStringer; import edu.uci.ics.jung.visualization.BasicVisualizationServer; import java.util.Map; import java.util.HashMap; import java.awt.Dimension; import javax.swing.JFrame; public class SimpleMatrixToGraph10 { public static void main(String[] args) { double[][] edges = { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, {0, 2, 0, 0, 0, 0}, {0, 3, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} }; Map<String,Number> weights = new HashMap<String,Number>(); Factory<Graph<String,String>> graphFactory = new Factory<Graph<String,String>>() { public Graph<String,String> create() { return new SparseGraph<String,String>(); } }; Factory<UndirectedGraph<String, String>> undirectedGraphFactory = new Factory<UndirectedGraph<String,String>>() { public UndirectedGraph<String,String> create() { return new UndirectedSparseGraph<String,String>(); } }; Factory<DirectedGraph<String, String>> directedGraphFactory = new Factory<DirectedGraph<String,String>>() { public DirectedGraph<String,String> create() { return new DirectedSparseGraph<String,String>(); } }; Factory<String> vertexFactory = new Factory<String>() { int n = 0; public String create(){ return "V"+n++; } }; Factory<String> edgeFactory = new Factory<String>() { int i = 0; public String create(){ return "E"+i++; } }; DoubleMatrix2D m = new SparseDoubleMatrix2D(edges); Graph<String,String> g = GraphMatrixOperations.<String,String>matrixToGraph(m, undirectedGraphFactory, directedGraphFactory, vertexFactory, edgeFactory, weights); for(String anEdge : weights.keySet()){ double aWeight = (Double)weights.get(anEdge); System.out.println(anEdge + " " + aWeight); } NumberEdgeValueStringer<String> nEdgeStringer = new NumberEdgeValueStringer<String>(weights); Layout<String, String> layout = new CircleLayout(g); layout.setSize(new Dimension(300,300)); BasicVisualizationServer<String,String> vv = new BasicVisualizationServer<String,String>(layout); vv.setPreferredSize(new Dimension(350,350)); vv.getRenderContext().setEdgeLabelTransformer(nEdgeStringer); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); JFrame frame = new JFrame("SimpleMatrixToGraph10"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); } } The screen capture of the output of this program is available at: http://hk.geocities.com/bleongki/graphics/SimpleMatrixToGraph10.jpg In this program, I have used a double[] [] array to instantiate an object of SparseDoubleMatrix2D as type of DoubleMatrix2D which is in turn passed to the matrixToGraph() method. Intuitively, from the adjacency matrix, there is no edge originating from or terminating at v0 and v5, and all the edges will terminate at v1. However, from the output of the program, it is not the cases. It can be seen from the output that edges do originate from v0 and v5 and all the edges terminate at v3 instead of v1. Can you please help me to clarify my query? Brian ______________________________________________________________________ You are receiving this email because you elected to monitor this forum. To stop monitoring this forum, login to SourceForge.net and visit: https://sourceforge.net/forum/unmonitor.php?forum_id=252062 |