Weighted graphs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Weighted graphs

Maarten Th. Mulders
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.



Reply | Threaded
Open this post in threaded view
|

Re: Weighted graphs

John Sichi
Administrator
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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jgrapht-users
>



Reply | Threaded
Open this post in threaded view
|

Re: Weighted graphs

Fabian K

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.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: Weighted graphs

Fabian K
In reply to this post by John Sichi
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;
}
Reply | Threaded
Open this post in threaded view
|

Re: Weighted graphs

John Sichi
Administrator
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;
> }


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users