1
$\begingroup$

I'm assembling graphs programmatically, and looping through EdgeAdd[] a lot.

graph = EdgeAdd[graph, a -> b];

Is there a more efficient way to do the updates "in place" -- as opposed to the normal assignment?

$\endgroup$
  • 3
    $\begingroup$ Graphs are immutable objects ... so the general answer is "no". But perhaps there may be some trick on your particular situation. Tell us more about what you're trying to do $\endgroup$ – Dr. belisarius Dec 18 '15 at 5:43
  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Dec 18 '15 at 7:01
  • 1
    $\begingroup$ You can use sparse arrays to represent graphs. The question is: what else do you want to do with the graphs in the inner loop other than EdgeAdd and whether that thing is easy/fast with a sparse array. $\endgroup$ – Szabolcs Dec 18 '15 at 8:30
  • $\begingroup$ I'm trying to assemble the graph from a list of associations. I was hoping to use something analogous to the AppendTo[] function. I don't have the list of associations when the graph is initially created. Thanks. $\endgroup$ – vonkohorn Dec 18 '15 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.