Thread: [jgrapht-users] Weighted graphs
Brought to you by:
barak_naveh,
perfecthash
From: Maarten T. M. <maa...@st...> - 2008-01-21 15:51:17
|
From: Maarten T. M. <maa...@st...> - 2008-01-21 15:58:29
|
Hi all, As I am trying to work with weighted graphs, I've come across a problem I don't understand. My weighted graph contains vertices of type ISynsetID and edges of IPointer. The former gives no problems, but when I try to set the weight of an edge using the graph's setEdgeWeight method, I get an ClassCastException: edu.mit.jwi.item.Pointer (that is the class that implements the IPointer interface). Looking through the source code, I found that it tries to cast my edge to a DefaultWeigtedEdge. I don't see the reason for that. Should my edge class extend DefaultWeightedEdge? I can't find that in the (java)docs, nor on the wiki. Thanks in advance, Maarten Th. Mulders PS. Please excuse my last email, it was send accidentally send without contents. |
From: John V. S. <js...@gm...> - 2008-01-21 18:09:01
|
Yes, either your edge class needs to extend DefaultWeightedEdge, or your graph implementation needs to override setEdgeWeight. JVS Maarten Th. Mulders wrote: > Hi all, > > As I am trying to work with weighted graphs, I've come across a problem I > don't understand. > My weighted graph contains vertices of type ISynsetID and edges of > IPointer. The former gives no problems, but when I try to set the weight > of an edge using the graph's setEdgeWeight method, I get an > ClassCastException: edu.mit.jwi.item.Pointer (that is the class that > implements the IPointer interface). > Looking through the source code, I found that it tries to cast my edge to > a DefaultWeigtedEdge. I don't see the reason for that. Should my edge > class extend DefaultWeightedEdge? I can't find that in the (java)docs, nor > on the wiki. > > Thanks in advance, > > Maarten Th. Mulders > > PS. Please excuse my last email, it was send accidentally send without > contents. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > jgrapht-users mailing list > jgr...@li... > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > |
From: Fabian K <fab...@gm...> - 2010-06-12 14:51:31
|
my graph class: public class GRFGraph extends DefaultDirectedWeightedGraph<GRFNode, GRFEdge> my Edge class: public class GRFEdge extends DefaultWeightedEdge following method doesn't work anymore, it returns null. GRFNode srcNode = graph.getEdgeTarget(new GRFEdge(1)); when my GRFEdge doesnt extend DefaultWeightedEdge it works fine. It will return the node. What is wrong with this call? FYI: in my GRFEdge class I override getWeight method already. @Override public double getWeight() { return weight; } -- View this message in context: http://jgrapht-users.107614.n3.nabble.com/Weighted-graphs-tp107885p890947.html Sent from the jgrapht-users mailing list archive at Nabble.com. |
From: John V. S. <js...@gm...> - 2010-06-12 20:28:07
|
The default edge implementations are optimized to be "intrusive"; that is, they contain direct references to their vertices. When the graph sees an edge class that extends a default edge, it assumes that it can use these references rather than maintaining the edge/vertex association indirectly via a HashMap (which is more expensive). In your case, you are creating a new edge on the fly, so when the graph examines it, the references are null. When you use a non-default implementation everything works because then the new GRFEdge probably Object.equals some existing edge in the graph. JVS Fabian K wrote: > my graph class: > public class GRFGraph extends DefaultDirectedWeightedGraph<GRFNode, GRFEdge> > > my Edge class: > public class GRFEdge extends DefaultWeightedEdge > > following method doesn't work anymore, it returns null. > GRFNode srcNode = graph.getEdgeTarget(new GRFEdge(1)); > > when my GRFEdge doesnt extend DefaultWeightedEdge it works fine. It will > return the node. > > What is wrong with this call? > > FYI: > in my GRFEdge class I override getWeight method already. > > @Override > public double getWeight() { > return weight; > } |
From: Fabian K <fab...@gm...> - 2010-06-12 13:55:33
|
my graph class: public class GRFGraph extends DefaultDirectedWeightedGraph<GRFNode, GRFEdge> my Edge class: public class GRFEdge extends DefaultWeightedEdge following method doesn't work anymore, it returns null. GRFNode srcNode = graph.getEdgeTarget(new GRFEdge(1)); when my GRFEdge doesnt extend DefaultWeightedEdge it works fine. It will return the node. What is wrong with this call? FYI: in my GRFEdge class I override getWeight method already. @Override public double getWeight() { return weight; } -- View this message in context: http://jgrapht-users.107614.n3.nabble.com/Weighted-graphs-tp107885p890828.html Sent from the jgrapht-users mailing list archive at Nabble.com. |