Re: [jgrapht-users] Edge weights
Brought to you by:
barak_naveh,
perfecthash
From: <fee...@gm...> - 2015-07-02 14:13:27
|
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 <de...@gm...> 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 <rus...@ho... <mailto:rus...@ho...>> 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: fee...@gm... <mailto:fee...@gm...> [mailto:fee...@gm... <mailto:fee...@gm...>] > Sent: Wednesday, July 01, 2015 4:05 PM > To: jgr...@li... <mailto:jgr...@li...> > 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/ <https://www.gigenetcloud.com/> > _______________________________________________ > jgrapht-users mailing list > jgr...@li... <mailto:jgr...@li...> > https://lists.sourceforge.net/lists/listinfo/jgrapht-users <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/ <https://www.gigenetcloud.com/> > _______________________________________________ > jgrapht-users mailing list > jgr...@li... <mailto:jgr...@li...> > https://lists.sourceforge.net/lists/listinfo/jgrapht-users <https://lists.sourceforge.net/lists/listinfo/jgrapht-users> > |