Re: [jgrapht-users] Edge weights
Brought to you by:
barak_naveh,
perfecthash
From: Joris K. <de...@gm...> - 2015-07-01 23:26:21
|
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...> 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...] > Sent: Wednesday, July 01, 2015 4:05 PM > To: 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/ > _______________________________________________ > jgrapht-users mailing list > jgr...@li... > 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 > jgr...@li... > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > |