Edge weights

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

Edge weights

feedlivi@gmail.com
Hi there,  

I’m a newbie using Jgrapht… .My problem  has to do with a large weighted graph (about 2000 edges)   and the assignation of its weights.

All I wanna ask is whether or not weights for a graph can be assigned dynamically  (a loop) rather than static (one by on)...like:

DefaultWeightedEdge e1 = graph.addEdge("vertex1", "vertex2”);
graph.setEdgeWeight(e1, 5);

(I’d have to write this thousand times…. )


Thanks.

Phil


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: Edge weights

Rushang Karia
I am at work right now and do not remember if such a function exists (not worked on weighted graphs a lot). I guess there should be such a function since your problem is quite intuitive.

However,
If no such function exists then you could overload the addEdge() to specify a weight for the WeightedGraph.
The function would be

DefaultWeightedEdge  <V, E> addEdge(V v1, V v2, E weight)
{
        DefaultWeightedEdge e1 = super.addEdge(v1, v2);
        this.setEdgeWeight(e1, weight)
        If(error) return null else return the edge.
}

I am sorry if my reply is brief but I am a bit busy right now. If you need more detailed instructions feel free to reply.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Wednesday, July 01, 2015 4:05 PM
To: [hidden email]
Subject: [jgrapht-users] Edge weights

Hi there,  

I’m a newbie using Jgrapht… .My problem  has to do with a large weighted graph (about 2000 edges)   and the assignation of its weights.

All I wanna ask is whether or not weights for a graph can be assigned dynamically  (a loop) rather than static (one by on)...like:

DefaultWeightedEdge e1 = graph.addEdge("vertex1", "vertex2”); graph.setEdgeWeight(e1, 5);

(I’d have to write this thousand times…. )


Thanks.

Phil


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: Edge weights

Joris Kinable
Three ways to add weighted edges:

1. Use the graph itself:
DefaultWeightedEdge e=graph.addEdge(V vertex1, V vertex2);
graph.setEdgeWeight(e, double weight);

2. Use one of the following methods in the Graphs package:
Graphs.addAllEdges(Graph<? super V,? super E> destination, Graph<V,E> source, Collection<? extends E> edges)
Graphs.addEdge(Graph<V,E> g, V sourceVertex, V targetVertex, double weight)
Graphs.addEdgeWithVertices(Graph<V,E> targetGraph, Graph<V,E> sourceGraph, E edge, double weight)

3. Use the Graph Builder which was added to the latest version of jgrapht:
SimpleWeightedGraph<String, DefaultWeightedEdge> builtWeightedGraph =
        SimpleWeightedGraph.<String, DefaultWeightedEdge>
        builder(DefaultWeightedEdge.class)
        .addEdge(v1, v2, 1.0)
        .addEdge(v1, v2, 2.0)
        .addEdge(v3, v4, 3.0)
        .addEdge(v2, v4, 2.0)
        .build();


br,

Joris Kinable

On Wed, Jul 1, 2015 at 7:13 PM, Rushang Karia <[hidden email]> wrote:
I am at work right now and do not remember if such a function exists (not worked on weighted graphs a lot). I guess there should be such a function since your problem is quite intuitive.

However,
If no such function exists then you could overload the addEdge() to specify a weight for the WeightedGraph.
The function would be

DefaultWeightedEdge  <V, E> addEdge(V v1, V v2, E weight)
{
        DefaultWeightedEdge e1 = super.addEdge(v1, v2);
        this.setEdgeWeight(e1, weight)
        If(error) return null else return the edge.
}

I am sorry if my reply is brief but I am a bit busy right now. If you need more detailed instructions feel free to reply.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Wednesday, July 01, 2015 4:05 PM
To: [hidden email]
Subject: [jgrapht-users] Edge weights

Hi there,

I’m a newbie using Jgrapht… .My problem  has to do with a large weighted graph (about 2000 edges)   and the assignation of its weights.

All I wanna ask is whether or not weights for a graph can be assigned dynamically  (a loop) rather than static (one by on)...like:

DefaultWeightedEdge e1 = graph.addEdge("vertex1", "vertex2”); graph.setEdgeWeight(e1, 5);

(I’d have to write this thousand times…. )


Thanks.

Phil


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: Edge weights

feedlivi@gmail.com
Thank you guys for your replies… I’ve made some changes in my simple code taking into account your advice…..however I’m still getting this error:

Exception in thread "main" java.lang.IllegalArgumentException: loops not allowed
ÏϧϠ       at org.jgrapht.graph.AbstractBaseGraph.addEdge(AbstractBaseGraph.java:243)
ÏϧϠ       at org.jgrapht.Graphs.addEdge(Graphs.java:88)
ÏϧϠ       at JGraphTestDirected.main(JGraphTestDirected.java:77)


My plan is simple…take a matrix with weights…….two for loops to go through it for creating edges and adding weights.


any help will be appreciated.


Phil



On 1/07/2015, at 7:26 pm, Joris Kinable <[hidden email]> wrote:

Three ways to add weighted edges:

1. Use the graph itself:
DefaultWeightedEdge e=graph.addEdge(V vertex1, V vertex2);
graph.setEdgeWeight(e, double weight);

2. Use one of the following methods in the Graphs package:
Graphs.addAllEdges(Graph<? super V,? super E> destination, Graph<V,E> source, Collection<? extends E> edges)
Graphs.addEdge(Graph<V,E> g, V sourceVertex, V targetVertex, double weight)
Graphs.addEdgeWithVertices(Graph<V,E> targetGraph, Graph<V,E> sourceGraph, E edge, double weight)

3. Use the Graph Builder which was added to the latest version of jgrapht:
SimpleWeightedGraph<String, DefaultWeightedEdge> builtWeightedGraph =
        SimpleWeightedGraph.<String, DefaultWeightedEdge>
        builder(DefaultWeightedEdge.class)
        .addEdge(v1, v2, 1.0)
        .addEdge(v1, v2, 2.0)
        .addEdge(v3, v4, 3.0)
        .addEdge(v2, v4, 2.0)
        .build();


br,

Joris Kinable

On Wed, Jul 1, 2015 at 7:13 PM, Rushang Karia <[hidden email]> wrote:
I am at work right now and do not remember if such a function exists (not worked on weighted graphs a lot). I guess there should be such a function since your problem is quite intuitive.

However,
If no such function exists then you could overload the addEdge() to specify a weight for the WeightedGraph.
The function would be

DefaultWeightedEdge  <V, E> addEdge(V v1, V v2, E weight)
{
        DefaultWeightedEdge e1 = super.addEdge(v1, v2);
        this.setEdgeWeight(e1, weight)
        If(error) return null else return the edge.
}

I am sorry if my reply is brief but I am a bit busy right now. If you need more detailed instructions feel free to reply.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Wednesday, July 01, 2015 4:05 PM
To: [hidden email]
Subject: [jgrapht-users] Edge weights

Hi there,

I’m a newbie using Jgrapht… .My problem  has to do with a large weighted graph (about 2000 edges)   and the assignation of its weights.

All I wanna ask is whether or not weights for a graph can be assigned dynamically  (a loop) rather than static (one by on)...like:

DefaultWeightedEdge e1 = graph.addEdge("vertex1", "vertex2”); graph.setEdgeWeight(e1, 5);

(I’d have to write this thousand times…. )


Thanks.

Phil


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users



------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|

Re: Edge weights

Szabolcs Besenyei
As the exception states, you are adding an edge to your graph which results in a loop which is not permitted for the type of graph you are currently working with. Consider using a DirectedPseudograph.

​Regards,​

Besenyei Szabolcs

2015-07-02 17:15 GMT+02:00 [hidden email] <[hidden email]>:
Thank you guys for your replies… I’ve made some changes in my simple code taking into account your advice…..however I’m still getting this error:

Exception in thread "main" java.lang.IllegalArgumentException: loops not allowed
ÏϧϠ       at org.jgrapht.graph.AbstractBaseGraph.addEdge(AbstractBaseGraph.java:243)
ÏϧϠ       at org.jgrapht.Graphs.addEdge(Graphs.java:88)
ÏϧϠ       at JGraphTestDirected.main(JGraphTestDirected.java:77)


My plan is simple…take a matrix with weights…….two for loops to go through it for creating edges and adding weights.


any help will be appreciated.


Phil



On 1/07/2015, at 7:26 pm, Joris Kinable <[hidden email]> wrote:

Three ways to add weighted edges:

1. Use the graph itself:
DefaultWeightedEdge e=graph.addEdge(V vertex1, V vertex2);
graph.setEdgeWeight(e, double weight);

2. Use one of the following methods in the Graphs package:
Graphs.addAllEdges(Graph<? super V,? super E> destination, Graph<V,E> source, Collection<? extends E> edges)
Graphs.addEdge(Graph<V,E> g, V sourceVertex, V targetVertex, double weight)
Graphs.addEdgeWithVertices(Graph<V,E> targetGraph, Graph<V,E> sourceGraph, E edge, double weight)

3. Use the Graph Builder which was added to the latest version of jgrapht:
SimpleWeightedGraph<String, DefaultWeightedEdge> builtWeightedGraph =
        SimpleWeightedGraph.<String, DefaultWeightedEdge>
        builder(DefaultWeightedEdge.class)
        .addEdge(v1, v2, 1.0)
        .addEdge(v1, v2, 2.0)
        .addEdge(v3, v4, 3.0)
        .addEdge(v2, v4, 2.0)
        .build();


br,

Joris Kinable

On Wed, Jul 1, 2015 at 7:13 PM, Rushang Karia <[hidden email]> wrote:
I am at work right now and do not remember if such a function exists (not worked on weighted graphs a lot). I guess there should be such a function since your problem is quite intuitive.

However,
If no such function exists then you could overload the addEdge() to specify a weight for the WeightedGraph.
The function would be

DefaultWeightedEdge  <V, E> addEdge(V v1, V v2, E weight)
{
        DefaultWeightedEdge e1 = super.addEdge(v1, v2);
        this.setEdgeWeight(e1, weight)
        If(error) return null else return the edge.
}

I am sorry if my reply is brief but I am a bit busy right now. If you need more detailed instructions feel free to reply.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Wednesday, July 01, 2015 4:05 PM
To: [hidden email]
Subject: [jgrapht-users] Edge weights

Hi there,

I’m a newbie using Jgrapht… .My problem  has to do with a large weighted graph (about 2000 edges)   and the assignation of its weights.

All I wanna ask is whether or not weights for a graph can be assigned dynamically  (a loop) rather than static (one by on)...like:

DefaultWeightedEdge e1 = graph.addEdge("vertex1", "vertex2”); graph.setEdgeWeight(e1, 5);

(I’d have to write this thousand times…. )


Thanks.

Phil


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users



------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users



------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users