How can I add edges to my graph in a for loop?

dimrizo

I use jgrapht library in Java to create some graphs. I want to iterate through the existing vertices(that I have created in a previous state of the program) and add the corresponding edges depending on some criteria(if statements). As it seems to me the only way to add edges is:

 DefaultWeightedEdge e1 = exampleGraph.addEdge("1", "2");           
 exampleGraph.setEdgeWeight(e1, 20.0);

From my point of view, this won't work in a for loop because it will always refer and change the same object. Any ideas?

DarkJade
for loop
{
    exampleGraph.setEdgeWeight(exampleGraph.addEdge(x, y), w);
}

Did you try something like this?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How come I cannot (for) loop the input for my Graph's nodes and edges?

From Dev

In Matlab, how can I remove nodes with no edges in a directed graph?

From Dev

How to choose edges randomly in my graph?

From Dev

DSE Graph with Java Driver, how to add edges

From Dev

OxyPlot: How can I add text to a graph?

From Dev

JAVA,how can I loop my code

From Dev

How can I add variables into a dictionary with a loop?

From Dev

How can I add the variable every loop?

From Dev

How can I add loop in after function?

From Dev

How to add label to edges in d3 graph

From Dev

how to add random edges to an empty graph untill it becomes connected in python?

From Dev

How to add label to edges in d3 graph

From Dev

How to add nodes and edges to a network analysis graph in Networkx?

From Dev

How can I add a middleware in my route?

From Dev

How can I add exponent in my code

From Dev

How can I add a JScrollPane for my JTextArea?

From Dev

How can I loop traverse a graph through const reference in D?

From Dev

How can I loop traverse a graph through const reference in D?

From Dev

How can I extend the lines of this Highchart series to the edges of my chart area?

From Dev

How can I add shading to edges of the default ASP.NET page?

From Dev

How can I create symmetric edges in Graphviz?

From Dev

How can i pad the edges of a rectangle with points?

From Dev

How can I add an optional input to a graph in TensorFlow?

From Dev

How can I add my custom style for my bootstrap navbar?

From Dev

How can i add my layout to my gallery?

From Dev

How can I add my UserControl to my NugetPackage?

From Dev

Can I register my Java classes as OrientDB Vertices and/or Edges?

From Dev

Can I register my Java classes as OrientDB Vertices and/or Edges?

From Dev

How do I add all results from my loop

Related Related

  1. 1

    How come I cannot (for) loop the input for my Graph's nodes and edges?

  2. 2

    In Matlab, how can I remove nodes with no edges in a directed graph?

  3. 3

    How to choose edges randomly in my graph?

  4. 4

    DSE Graph with Java Driver, how to add edges

  5. 5

    OxyPlot: How can I add text to a graph?

  6. 6

    JAVA,how can I loop my code

  7. 7

    How can I add variables into a dictionary with a loop?

  8. 8

    How can I add the variable every loop?

  9. 9

    How can I add loop in after function?

  10. 10

    How to add label to edges in d3 graph

  11. 11

    how to add random edges to an empty graph untill it becomes connected in python?

  12. 12

    How to add label to edges in d3 graph

  13. 13

    How to add nodes and edges to a network analysis graph in Networkx?

  14. 14

    How can I add a middleware in my route?

  15. 15

    How can I add exponent in my code

  16. 16

    How can I add a JScrollPane for my JTextArea?

  17. 17

    How can I loop traverse a graph through const reference in D?

  18. 18

    How can I loop traverse a graph through const reference in D?

  19. 19

    How can I extend the lines of this Highchart series to the edges of my chart area?

  20. 20

    How can I add shading to edges of the default ASP.NET page?

  21. 21

    How can I create symmetric edges in Graphviz?

  22. 22

    How can i pad the edges of a rectangle with points?

  23. 23

    How can I add an optional input to a graph in TensorFlow?

  24. 24

    How can I add my custom style for my bootstrap navbar?

  25. 25

    How can i add my layout to my gallery?

  26. 26

    How can I add my UserControl to my NugetPackage?

  27. 27

    Can I register my Java classes as OrientDB Vertices and/or Edges?

  28. 28

    Can I register my Java classes as OrientDB Vertices and/or Edges?

  29. 29

    How do I add all results from my loop

HotTag

Archive