Closed Zincr0 closed 1 year ago
Thanks for your question! You're right: At the moment, edges are immutable. This is mainly because I haven't figured out an appropriate API design yet, but it's definitely a planned feature and it will be a concern in one of the next few releases.
One backward-compatible workaround would be to remove the edge and re-create it with the new weight. In fact, I did this myself and created a small helper function:
func updateEdgeWeight(g graph.Graph[int, int], source, target, value int) {
_ = g.RemoveEdge(source, target)
_ = g.AddEdge(source, target, graph.EdgeWeight(value))
}
Using this function, your example could be solved as follows:
updateEdgeWeight(g, 1, 2, 50)
I hope I'll be able to provide a more convenient solution soon!
Graph.UpdateEdge
will be part of the upcoming release next Monday.
graph v0.20 introduces support for updating edge properties.
Given an already created edge (1 to 2), changing the weight doesn't seems to be currently possible
Tested
none changes the weight.
A function to do this or a workaround in documentation would be great. Very nice library btw.